Hello All. First post - great community.
I started playing with the PWM function yesterday and quickly realised that the posts I read never really came up with a definitive answer to how to use the period and duration parameters (and the limits on their values).
I played with the LED dimmer contributed by 'dab' on 16th August, and it worked fine and all made sense. This uses the SetDutyCycle(duty) method, where the clock free-runs at 10kHz, and the duty cycle is expressed as a percentage [duty takes integer values 0-100]. duty = 100 has it on all the time, duty = 0 has it off all the time.
So far so good.
Then I started using the SetPulse(period, duration) method. I'd seen other posts which indicated that the values of period and duration changed the characteristics of the pulse, but they all used huge numbers (allegedly in nanoseconds). These didn't always work, and gave incorrect periods and durations. I spent an afternoon with an oscilloscope trying different values and came to the following conclusions:
period and duration can only take values in the range 0 - 65535 (they are 16 bit unsigned integers).
These period and duration values represent microseconds
duration must be smaller than period, or ouput appears to be always ON
If you use values > 65535, it MAY work (the upper bits in the uint may be ignored), but the values will not be what you expect.
Thus, SetPulse(10000, 1000) produces a pulse every 10 ms (100 Hz) of duration 1 ms (a duty cycle of 10%)
The lowest frequency you can get is when period = 65535, giving period of 65.5 ms (=15.2 Hz)
The highest frequency you can get is SetPulse(2,1): period = 2 us (500 kHz) duty cycle 50%.
I hope this helps.
I keep reading promises of documentation . . . . c'mon chaps
PWM demystified
Started by Philip, Oct 28 2010 03:52 PM
5 replies to this topic
#2
Posted 04 November 2010 - 07:44 AM
Thank you for this clarification.
Now excuse my noob question, what is the best approach to generate a PPM frame?
I mean a group of 8 pulses, each of them in the 1-2msec range, and the frame delimiter of 4msec.
I assume I already have the 8 channels values stored somewhere in an array.
Now excuse my noob question, what is the best approach to generate a PPM frame?
I mean a group of 8 pulses, each of them in the 1-2msec range, and the frame delimiter of 4msec.
I assume I already have the 8 channels values stored somewhere in an array.
#4
Posted 23 January 2011 - 03:45 AM
Hi Renatoa
I've never tried this. Do you really need to change it that quickly (once every pulse could be once every 100us)? [I suppose you must or you wouldn't be asking]. You may well be on the limits of what .NET can do - I've not tried timings for sub millisecond stuff, and I wonder how periodic garbage collection might influence it even if you could.
I would be interested if anyone has tried this type of timing; e.g. would a ThreadSleep of 1ms used to switch something ON-OFF-ON- etc. really work properly - anyone?
Phil
I've never tried this. Do you really need to change it that quickly (once every pulse could be once every 100us)? [I suppose you must or you wouldn't be asking]. You may well be on the limits of what .NET can do - I've not tried timings for sub millisecond stuff, and I wonder how periodic garbage collection might influence it even if you could.
I would be interested if anyone has tried this type of timing; e.g. would a ThreadSleep of 1ms used to switch something ON-OFF-ON- etc. really work properly - anyone?
Phil
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











