Pulse-width Modulation on the PIC 16F877A
Posted on : 11-04-2006 | By : Geoff | In : Programming, Technology
1
Ok, so if you made it past the title, you’re doin’ good. The 16F877A is a microcontroller made by microchip, and I just happen to be using it at work.
Pulse-width modulation is a way of controlling the brightness of an LED, not through resistance, but rather through its duration of being lit. For instance, an LED at half brightness would be on for exactly 1/2 of the time. Basically, it would switch back and forth between on and off at an even pace.
Last night, I had to find a way to control the brightness of a strand of LEDs based only on a 0-7 value off of an analog potentiometer. By design, the maximum brightness for the LEDs will be 1/8 of their maximum ability. This was to reduce heat and fire hazard.
With PWM, since the LED’s on-time is inversely preportional to its off-time, the calculation was rather simple. At the maximum setting (7), the LEDs are on 1/8th of the time. So I made the total duty cycle 56 clock cycles. I then assigned ON_TIME = Knob_Setting and OFF_TIME = 56 – Knob_Setting. This created a whole duty cycle where the LED was on and off evenly with the knob setting.



i want a firestarter made from LEDs!!