analogWrite() microseconds

bloodline

Well-known member
It would be useful for precise timing situations, to be able to set the duty cycle of the PWM pins in microseconds. I hope such a feature could be added to the Teensdyduino API :)
 
That should be very easy to derive from what analogWriteResolution() you use, what and what analogWriteFrequency(pin, frequency) you've set and finally what analogWrite() value you have programmed ?
 
That should be very easy to derive from what analogWriteResolution() you use, what and what analogWriteFrequency(pin, frequency) you've set and finally what analogWrite() value you have programmed ?

Easy to derive indeed, but what overhead does the analogWrite() have? Setting the duty cycle in time would be a much simpler function.

-Edit-
For anyone who may benefit from this: To work out the analogWrite value required to achieve a specific pulse width (in microseconds); where resolution is the resolution of the analogWrite function in bits, pulseWidth is the required pulse width in microseconds and frequency is the frequency of the analogWrite function in hz...

value = pow(2, resolution) * (pulseWidth / ( (1/frequency) * 1000000) );

A bit compute heavy IMHO :-(
 
Last edited:
Back
Top