Rgb Led Driver

Discussion in 'General Electronics Chat' started by emporiumx, Jun 21, 2008.

  1. emporiumx

    Thread Starter Member

    Feb 16, 2007
    Hi All

    I am looking at designing a RGB Led controller based on a pic microcontroller (most probably a 16f877A)

    I have had very little experience with 'proper' pwm.

    I was wondering if I could have the three channels for the colors run on timed delay loops to achieve color control.

    Ie Could you in theory feed in RGB color values and have the colors come on one at a time with delay loops rather than simultaneousley.

    Would this work effectively?


  2. roddefig

    Active Member

    Apr 29, 2008
    I'm not familiar with the "standard" way of doing PWM, but I think the most straight-forward thing to do would be to setup a timer that would count for the total period of your PWM.

    1. At the beginning of the cycle determine the length of time that you want your R, G, and B outputs on.
    2. When the timer starts or restarts at zero then set your R, G, and B outputs high.
    3. As the timer counts compare the value in the count register with the values that you determined for your R, G, and B outputs. When it hits one of those values then flip the respective output off.
    4. Rinse, repeat.

    This might not be the best way to do this in a microcontroller, because if you can't have three different compare values to trigger interrupts then you'll have to have the microcontroller busy loop and watch the timer value, which is wasteful.

    One possible way to get around that problem would be to set the lowest value in the compare register to trigger the interrupt, then when that interrupt is triggered toggle the respective output and reload the next lowest value, and the same for the third output. The only problem would be if the microcontroller can't reload the compare register fast enough and you "miss" your value.