Lowering PWM Frequency
Started by Joshk, Jul 12 2012 03:21 AM
8 replies to this topic
#1
Posted 12 July 2012 - 03:21 AM
I am running version 4.2 and vb code on a Netduino and NetduinoPlus. I am very much needing to slow down the frequency of the PWMs to 200hz. Sometimes 50hz. I understand changes are planned, will this become possible? Thanks for any info.
#2
Posted 12 July 2012 - 04:44 AM
Hi Joshk,
Custom frequency will become possible with the upcoming 4.2 RTM firmware for Netduino. We expect the .NET MF 4.2 firmware to hit the release milestone within the next month or two.
Chris
- Arron Chapman and Joshk like this
#3
Posted 12 July 2012 - 01:31 PM
Hi there!
I was under the impression that variable frequency can be accompished by setting the ON- and OFF-durations respectively but I guess I'm wrong then?
200 Hz could then be achieved by setting both ON- and OFF-duation to250us 2 500us each (for a 50% duty cycle).
I haven't tried this though so maybe ability to set duration is exactly what is missing in the current implementation?
EDIT: I made an error above, the duration should be 2.5ms or 2 500us. Sorry.
I was under the impression that variable frequency can be accompished by setting the ON- and OFF-durations respectively but I guess I'm wrong then?
200 Hz could then be achieved by setting both ON- and OFF-duation to
I haven't tried this though so maybe ability to set duration is exactly what is missing in the current implementation?
EDIT: I made an error above, the duration should be 2.5ms or 2 500us. Sorry.
- Joshk likes this
#4
Posted 12 July 2012 - 01:54 PM
With some creative math, it can be lowered indeed. How do you want to change the pulse? by dutycycle?
- Joshk likes this
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#5
Posted 12 July 2012 - 07:12 PM
Hi hanzibal,
In the traditional SecretLabs PWM classes, the PWM clock is set to 10,000 cycles/second. You can change the frequency using SetPulse -- but it has to be a multiple of 10k/sec.
With the new classes, you'll be able to set a faster frequency (based on a higher clock speed).
Chris
- Joshk likes this
#6
Posted 12 July 2012 - 09:21 PM
Thanks, I wrote the above from the top of my head and since the parameters for SetPule(period, duration) are microseconds I thought any period and duration was valid as long as 0 <= duration <= period.In the traditional SecretLabs PWM classes, the PWM clock is set to 10,000 cycles/second. You can change the frequency using SetPulse -- but it has to be a multiple of 10k/sec.
I find this a bit strange though since forum member Philip did some tests on PWM using his oscilloscope and seems to have found that you can set pretty much any frequency between 16.5Hz and 500kHz. Maybe he never did measure the really low frequencies but simply calculated them:
http://forums.netdui...wm-demystified/
or am I missing something here?
I should probably get my scope out and measure for myself when I find the time.
- Joshk likes this
#7
Posted 13 July 2012 - 01:46 AM
Thanks for all the replies and definitely the approximate timeline. I considered the period/duration but it's not worth the hassle if setFrequency is in the near future. I was unsure if that was a one-off thing command either, requiring a loop. So 50hz is expected to be in the operating range, cool.
#8
Posted 13 July 2012 - 01:48 AM
Stefan, yes - I want to set the frequency and control the duty cycle during run time.
#9
Posted 13 July 2012 - 07:58 AM
I myself made a wrapper that gives some more PWM options. For more details see http://netmftoolbox....re.Netduino.PWM
It contains this method:
Keep in mind! My classes work in nanoseconds. The default netduino PWM works with microseconds. So you need to multiply by 1000000 instead of 1000000000 if you want to do the math directly on your Netduino.
It contains this method:
/// <summary>Sets the signal as dutycycle</summary> /// <param name="dutyCycle">The amount of changes per second</param> /// <param name="frequency">The PWM frequency</param> public void SetDutyCycle(uint dutyCycle, uint frequency = 1000) { float period_ns = (1 / (float)frequency) * 1000000000; // multiply with 1000000000 to get nano seconds float duration_ns = (float)dutyCycle / 100 * period_ns; this.SetPulse((uint)period_ns, (uint)duration_ns); }This shows the math that you need.
Keep in mind! My classes work in nanoseconds. The default netduino PWM works with microseconds. So you need to multiply by 1000000 instead of 1000000000 if you want to do the math directly on your Netduino.
- Joshk likes this
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users