I am having some problems with PWM and I am hoping someone can help me out...
I am using the STK500 board with a mega8515 running at ~1 Mhz. I just want to use all three of the mega8515's PWM channels for fading the LEDs on the STK500 board.
I can get Timer0 to work just fine. This code works perfectly (Phase correct 8 bit PWM):
#include#include #include #include #include int main(void) { PORTB=0x00; DDRB |= 1<<0; TCCR0 = 1<<WGM00 | 1<<COM01 | 1<<COM00 | 1 << CS00; OCR0=0x10; while (1) { // just looking at the leds }; }
I can modify OCR0 from 1 to 255 and it works great.
Unfortunately using Timer1 is where the problem comes in.
Modified: DDRB |= 1<<0 | 1<<1 | 1<<1; // Three LEDs should be controlled by PWM TCCR1A= 1<< COM1A1 | 1<<COM1B1 | 1<<WGM10; // Phase correct PWM mode (mode 1 - 8 bit) TCCR1B= 1<< CS10; // No prescaling OCR1A = 0x01; OCR1B = 0xF0;
Unfortunately, the PORTB LEDs 1 and 2 never change their intensity. I also calculated the frequency from the given equation in the datasheet it seems that the maximum freq is ~200 Hz so if I set OCR1A it should be 1 Hz, which I think should result in a visibly less intense LED emission.
Does anyone know what I am doing incorrectly? It seems like it should be straightforward but I have been unable to get Timer1 PWM channels to work.