Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Lowering PWM Frequency


  • Please log in to reply
8 replies to this topic

#1 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

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 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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

#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

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 to 250us 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.

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

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?
"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

#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

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

#6 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 12 July 2012 - 09:21 PM

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.

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.

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.

#7 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

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 Joshk

Joshk

    Advanced Member

  • Members
  • PipPipPip
  • 72 posts

Posted 13 July 2012 - 01:48 AM

Stefan, yes - I want to set the frequency and control the duty cycle during run time.

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

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:
        /// <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.
"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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.