Help with PWM - Netduino Plus 2 (and Netduino Plus 1) - Netduino Forums
   
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

Help with PWM


  • Please log in to reply
1 reply to this topic

#1 Stormstar

Stormstar

    New Member

  • Members
  • Pip
  • 6 posts

Posted 08 September 2013 - 03:09 PM

Hey,

 

I'm trying to color an RGB led with 3 PWM channels. I can color the led a few colors but i'm not sure this is exactly what i want.

 

In my code i need to set a frequency and cycle duration. But what do they do? I set them 10000 and 0, and figured out that by changing the duty cycle i can color my leds a bit. Is it possible to make more colors by changing the frequency? Or how are these values working together?

 

static PWM ledR = new PWM(PWMChannels.PWM_PIN_D11, 10000, 0, false);

 

 



#2 Arbiter

Arbiter

    Advanced Member

  • Members
  • PipPipPip
  • 132 posts
  • LocationBrisbane, Australia

Posted 09 September 2013 - 04:21 AM

Frequency is Hz. Your value of 10000 means that a pulse will be generated every tenth of a millisecond. Duration is in microseconds. Your duration of zero will produce either nothing at all or a brief twitch because the rising and falling edges aren't truly vertical.

 

To produce a 50% duty cycle you need the duration to be half the interval. Specifying a frequency of 100Hz ie an interval of 10ms, you will need a period of 5000µs (5ms) to get 50%, so values of 1000, 2000, 3000, 4000, 5000 will produce duty cycles of 10%, 20%, 30%, 40% and 50%.

static PWM ledR = new PWM(PWMChannels.PWM_PIN_D11, 100, 4000, false); //40%

You could also run a short interval (higher frequency) with narrower pulses.

static PWM ledR = new PWM(PWMChannels.PWM_PIN_D11, 10000, 30, false); //30%

This will produce a smoother steadier glow.

 

I haven't played with an RGB LED but I imagine that it's essentially three LEDs in one package, probably with three signal leads one for each of R, G and B, and a shared earth lead. Presumably you will use three separate PWMs to control the intensities of R G B to mix your own colour; if you skip the PWMs and pull all three control leads high I imagine you would get bright white.

 

There is another constructor that allows duration to be specified in nanoseconds. Be aware that the inductance of thick conductors may become significant at higher frequencies. You won't notice in the kilohertz range that you seem to want to use.

 

Servomotors expect a frequency of 50Hz (an interval of 20ms) and the pulse width is what controls the servomotor. A pulse width of 1000µs turns the servo as far counter-clockwise as it will turn, and a pulse width of 2000µs turns it as far clockwise as it will go. A pulse width of 1500µs turns the servo to the centre of its range which is generally regarded as the zero position.

static PWM servo = new PWM(PWMChannels.PWM_PIN_D11, 50, 1500, false); //centre position

Other frequencies and durations may work because the servo is actually controlled by the voltage produced in an RLC circuit inside it which is a function of the duty cycle. But the specification calls for the interval and range of duration I have specified above, and there are quite enough surprises in the world without going looking for them. On the other hand if you don't mind damaging a few servos, out of range values can produce some quite fascinating behaviour.


One day, all this too shall parse.




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.