Hi,
I'm programming an ATMEGA3208 (megaAVR) for the first time. I'm trying to port a PWM/Timer code from an ATTINY84, it's outputting a 1khz PWM with modulation (LFO) on PINA6:
volatile uint16_t msturns = 0;
volatile uint16_t ledturns = 0;
volatile uint8_t inc = 0;
volatile uint16_t pwm;
volatile uint16_t speed;
void Timerinit(void)
{
DDRA |= (1<<PINA6); //PWM pin as output
TCNT0 = 0; //timer0, fast PWM, OCRA as TOP, enable compare A interrupt, 1024 prescaler
OCR0A = 100;
TCCR0A |= (1<<WGM00) | (1<<WGM01);
TIMSK0 |= (1<<OCIE0A);
TCCR0B |= (1<<WGM02) | (1<<CS02) | (1<<CS00);
ICR1 = 999; //timer1, fast PWM, ICR1 as TOP, enable overflow interrupt and compare A interrupt, no prescaler
TCNT1 = 0;
OCR1A = 300;
TCCR1A |= (1<<COM1A1);
TIMSK1 |= (1<<OCIE1A);
TCCR1A |= (1<<WGM11);
TIMSK1 |= (1<<TOIE1);
TCCR1B |= (1<<WGM12) | (1<<WGM13) | (1<<CS11);
}
ISR(TIM1_OVF_vect)
{
msturns++; //ms increment if timer1 overflow
ledturns++;
}
ISR(TIM1_COMPA_vect)
{
cli(); //updates mod pwm duty cycle
OCR1A = pwm;
sei();
}
ISR(TIM0_COMPA_vect)
{
inc++; //increment position in wavetable
cli();
OCR0A = speed; //update mod speed
sei();
}
The timer configuration on the ATMEGA3208 is quite different, any tips on which direction I should go to implement it would be awesome!
Thank you!



