I'm fairly new to avr programming and I'm trying to simply fade 3 leds independently connected to ATtiny84 pwm pins. Right now I have code that should chnage brightness of two different leds. Here is my code:
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB |= (1 << PB2); // PWM output on PB2
TCCR0A = (1 << COM0A1) | (1 << WGM00); // phase correct PWM mode
OCR0A = 0x10; // initial PWM pulse width
TCCR0B = (1 << CS01); // clock source = CLK/8, start PWM
DDRA |= (1<<PA6); // make OC1A (DDA6) PWM output pin
TCCR1A = (1<<COM1A1) | (1<<COM1B0) | (1<<WGM00); // Clear OC1A/OC1B on Compare Match (bit 7 + 6)
// PWM, Phase Correct
TCCR1B = (1<<CS02); // 256 prescaler
while(1)
{
// change PWM pulse width every 2 seconds
_delay_ms(2000);
OCR0A = 0x10;
OCR1A = 0x10;
_delay_ms(2000);
OCR0A = 0x30;
OCR1A = 0x30;
_delay_ms(2000);
OCR0A = 0x50;
OCR1A = 0x50;
_delay_ms(2000);
OCR0A = 0xA0;
OCR1A = 0xA0;
}
}
The code is mostly copied from internet and I don't really understand the initializations, but now the led connected to PB2 works fine but the one connected to PA6 is not working right. PA6 led does change its brightness accordingly but it also flickers on and off rapidly (about 10 times a second).
First I thought it had something to do with PA6 being also MOSI pin for programming but disconnecting programmer didn't help.
Any help is appreciated! Also any tips for avr programming in general are more than welcome!