Pulse Width Modulation with microcontrollers

posted Jun 26th 2011 1:09pm by
filed under: Microcontrollers

Those following the ProtoStack tutorials will be happy to hear that there is a new installment which explains Pulse Width Modulation. If you’ve never heard of PWM before, it’s a method of generating a signal that is logic 1 for a portion of the time and logic 0 for the remainder of the time. It is the most commonly used method for dimming an LED, and that’s [Daniel's] example in this tutorial. But you’ll also find it used in many other applications such as servo motor control and piezo speaker control.

[Daniel] starts off with a brief explanation of duty cycle, then moves on to some examples of hardware and software PWM. Many of the AVR microcontrollers have a hardware PWM feature that allows you to configure a pin that toggles based on a target timer value. This is demonstrated using an ATmega168, but a method of using interrupts and your own code is also covered in case you don’t have a hardware PWM pin available.



6 Responses to Pulse Width Modulation with microcontrollers

  • Gravis says:

    PWM is good if you are robotics fiend because servos are controlled with pulses. http://www.rcheliwiki.com/Servo_protocol

  • Gagan says:

    Hi
    Nice tutorial. Nowdays I am also working on PWM. I i I am able to generate PWM from lookup table. Would like to understand the flow diagram for multiple pwm control. i am doing coding in assembly. also using interrupts. On for duty cycle and other for freq. and there is also typical prob for 100 percent and 0 percent . how you are handeling it?

  • Tweeks says:

    Perfect timing.. Was just going to start gathering some material to do my own Hackerspace class on servos and steppers. This will help. Is it GPL/copyleft?

    Tweeks

  • pff says:

    Don’t forget normal motors!

    Use PWM to reduce the speed without loosing torque.

  • Brian Neeley says:

    Since PWM is often used to drive sets of three LEDs (red-green-blue), I’ve wondered if there is much difference (power wise) in trying to balance the on-off time (ie: all three on and off at the same time; or only one (or two) on at a time) among the three LEDs. Has anyone seen any research on this?

  • Tyson says:

    Great tutorial! Glad to see someone is working on teaching the kiddies the real C code, instead of that Arduino nonsense.
    Keep up the great work!

  • Leave a Reply

    XHTML: You can use these tags: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Hack a Day serves up fresh hacks each day, every day from around the web as well as hacking related news.

    Send us your hacks






         




    Hacks

    Resources