Hi All,
I'm trying to get a 16-bit timer counter running, with interrupts on a Mega 2560 without destroying millis().
I've tried all 16-bit timer counters (1,3,4,5) with the following code, and all destroy millis() and make it run slow.
Any suggestions?
void timers_and_pwm_setup(){
noInterrupts();
//SETUP INTERRUPT FOR INPUT AVERAGING ///////////////////
//set timer2 interrupt at 16mS (62.5Hz)
TCCR4A = B00000000;// set entire TCCR4A register to 0
TCCR4B = B00000000;// set entire TCCR4B register to 0
TCNT4 = 33535;
TCCR4B = B00000010;// Set CLK prescaler of div8. 16MHz / 8 = 2MHz
// enable overflow interrupt
TIMSK4 = B00000001;
interrupts();
}
and the ISR...
ISR(TIMER4_OVF_vect)
{
TCNT4 = 33535;
//MORE CODE HERE...
}
Both my 8-bit timer counters are already in use, and I need another with an interrupt enabled.
I should also mention I've got a WDT enabled, and quite a bit of code in my setup script. It's definitely not rebooting.
Bevan