NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » RGB PWM. Cannot get led to completely turn off.
July 02, 2011 by uml_12 |
Hey, I am experimenting with timer 0 and timer 2. I am using OCR0A/B and OCR2B set for 8bit fast PWM: COM1A1/A0 = 11 = clear OC1A/B on compare match. output low. COM1B1/B0 = 10 = set OC1A/B at bot (non inverting) WGM13/12/11/10 = 0101 = fast PWM 8-bit CS12/11/10 = fclk/ 256 FOC1A/B = 00 = no force output (non PWM mode) COM2A1/A0 = 10 = Clear OC2A on compare match, set OC2A at bottom COM2B1/B0 = 10 = clear OC2B on compare match, set OC2B at bottom WGM2/1/0 = 011 = fast PWM CS22/21/20 = 110 = fclk / 256 prescaler My goal is to basically set up all the registers and what not for PWM and use a for loop to fade the led in white, back out, wait and repeat. Theoretically, in my mind at least, the led (common cathode. each anode connected to a 470ohm resistor and then to the respective pin) should start totally void of color. Gradually it will fade in white and fade back out. But what is actually happening is that when I connect power to my 168 instantly it illuminates blue. And the blue never really goes away. I have similar code in another file im trying to run that cycles through many other colors besides white. And while I get most of those other colors, blue always dominates the output. Any clues ? The code: / PD3 = Green (OC2B) PD6 = Red (OC0A) PD5 = Blue (OC0B) / define F_CPU 14745600include <stdio.h>include <avr/io.h>include "../libnerdkits/delay.h"int main(){
|
---|---|
July 02, 2011 by uml_12 |
*correction .. change this: COM1B1/B0 = 10 = set OC1A/B at bot (non inverting) to this: COM1B1/B0 = 10 = set OC1A/B at BOTTOM (non inverting) |
July 04, 2011 by uml_12 |
apparently the easiest thing to do is turn off the problematic pin when the corresponding compare register reaches zero and then turn it back on when the register increases again. I can't figure out why this is an issue .. owell. |
Please log in to post a reply.
Did you know that you can build a giant scrolling LED array with our microcontroller kit? Learn more...
|