Pulse Width Modulation with 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.

Comments

  1. Gravis says:

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

  2. 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?

  3. 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

  4. pff says:

    Don’t forget normal motors!

    Use PWM to reduce the speed without loosing torque.

  5. 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?

  6. 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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s