How would i set about reading PWM signals with the Arduino
and converting them into a more easily used format (like a number from 0 to 180).
Thanks
Tim
How would i set about reading PWM signals with the Arduino
and converting them into a more easily used format (like a number from 0 to 180).
Thanks
Tim
https://www.arduino.cc/en/Tutorial/PWM is how and quite easy to create a PWM. But you asked how to read. This is much harder since we have to talk about rising and falling edges. A good look is http://www.benripley.com/diy/arduino/three-ways-to-read-a-pwm-signal-with-arduino/ Once you say use method one, you need to convert that into a 0-180 scale by saying 100% equal 180 and 0% equal 0 over a fixed time domain. Another more interesting way using an Arduino is Arduino - SecretsOfArduinoPWM . But this is hardware specific.
Clem
From pages 118-119 of ATmega328 datasheet:
"16.6 Input Capture Unit
The Timer/Counter incorporates an Input Capture unit that can capture external events and give them a time-stamp indicating time of occurence. The external signal indicating an event, or multiple events, can be applied via the ICP1 pin or alternatively, via the analog-comparator unit. The time-stamps can then be used to calculate frequency, duty-cycle, and other features of the signal applied."
That's where I would start. Since the hardware side is sitting there for free (as part of the same module that does the PWM, if I'm understanding the datasheet correctly), why not use it? How easy it would be to use from the Arduino coding system I've got no idea - I've never used a Arduino, so someone else will have to comment about the practicality of setting it up and reading it.
It works!
I used method one and it is a vary small amount of code.
Tim