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
6 replies to this topic
#1
Posted 28 October 2010 - 03:52 PM
#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.
#3
Posted 06 January 2011 - 07:31 PM
Nobody generated PPM with Netduino to share some code ?
I can use SetPulse only to generate a single channel, how to change pulse duration from pulse to pulse?
Any event at end of pulse, to load the value for the next ?
#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
#5
Posted 23 January 2011 - 06:22 AM
Sure I need it, was the purpose I bought this card...
I wonder if someone could implement in as a new class in Netduino, if I have all the required code in C ?
#6
Posted 28 July 2011 - 12:50 PM
Since noone has offered ant solution to this, what about using I2C or SPI bus to do it?
You could buffer up a command to send 1024 bits and change the number of 1s to adjust the pulse width.
I don't know what control you have over the bus speed though.
#7
Posted 18 August 2014 - 02:23 AM
So you are saying I can not get 1Hz frequency with netduino ? I hope it get fixed in netduino 2.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users