Below is the entirety of my prototype code, the cycling of pin 13 is what I use to confirm the board is restarting. The board resets continually on this implementation of initialising the interrupt. There is no code implemented for the interrupt, simply initialising the interrupt and specifically enabling the Output Compare Interrupt by setting its bit high is enough to cause the crash. The evidence of the crash is the onboard LED cycling as instructed in the setup()
routine.
I have tried setting OCR3A
in one and two operations, I have tried initialising TIMSK3
and not, I have tried intialising TCNT3
to zero and non-zero values, and setting the prescaler with the bit shift and the discrete value, nothing seems to work..
What is going on?
void FlashLED() {
digitalWrite(13, !digitalRead(13));
delay(100);
digitalWrite(13, !digitalRead(13));
delay(100);
digitalWrite(13, !digitalRead(13));
delay(100);
digitalWrite(13, !digitalRead(13));
delay(100);
}
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
FlashLED();
// Initialise timer 3 and interrupt
noInterrupts();
TCCR3A = 0;
TCCR3B = 0;
TIMSK3 = 0;
TCNT3 = 0;
// Initialise OCR3A in two operations, as OCR3A = 62500; Serial.print(OCR3A); yields 36 (low byte only)
unsigned int count = 62500;
OCR3AH = count >> 8;
OCR3AL = count;
TCCR3B |= 1 << WGM32; // CTC Mode
//TCCR3B |= 4; // Prescaler 256
TCCR3B |= 1 << CS32; // Prescaler 256
TIMSK3 |= 1 << OCIE3A; // Output Compare Interrupt Enable
interrupts();
}
void loop() {
// put your main code here, to run repeatedly:
}
Update:
I had also been trying with an empty ISR handler and discounted its effect:
ISR(Timer3_COMPA_vect) {
}
However, as the astute viewer would notice, the signature is incorrect in its capitalisation. The correct handler is
ISR(TIMER3_COMPA_vect) {
}
This has resolved the issue.
OCR3A = count
to set both the H and L register with only one line of code. – Gerben Jan 13 at 19:19