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

More PWM questions!

pwm dutycycle() frequency()

  • Please log in to reply
2 replies to this topic

#1 Verdris

Verdris

    Advanced Member

  • Members
  • PipPipPip
  • 128 posts
  • LocationReno, NV

Posted 24 January 2013 - 11:30 PM

I've gotten a rudimentary version of my frequency sweep program working, I just have a question about the language. Specifically, why do I need to specify a duty cycle each time I change the frequency? Here's the code that works:

        public static void Main()        {            PWM FreqOut = new PWM(PWMChannels.PWM_PIN_D10, 1000, .5, false);            int[] Frequencies = new int[10] { 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };            while (true)            {                for (int i = 0; i < 10; i++)                {                    FreqOut.Stop();                    FreqOut.Frequency = Frequencies[i];                    FreqOut.DutyCycle = 0.5;                    FreqOut.Start();                    Debug.Print(Frequencies[i].ToString());                    Thread.Sleep(4000);                }            }        }

 

But if I comment out line 25, then it gives me a flat signal until the frequency switches to 1000Hz, then pumps out the square wave as expected.



#2 Strut

Strut

    Member

  • Members
  • PipPip
  • 18 posts

Posted 25 January 2013 - 12:56 AM

I've been  studying PWM in the new 4.2.2  firmware and this peaked my curiosity. Sorry in advance for asking questions instead of answering them ;)

 

 

I see your using the Microsoft.Hardware.PWM namespace. Its interesting that the Secretlabs wrapper only exposed dutycycle. 1MHz is the current default PWM clock, I wonder if fractions are software enabled?

 

Will a start/stop work as expected if you don't change the freq?



#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 January 2013 - 12:57 AM

Hi Verdris, Internally, the NETMF PWM class stores dutycycle as duration and frequency as period. The duration is a subset of the period. So when you change the period (or frequency), you'll probably need to also update the duration (or duty cycle). Chris





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.