hello all
who can help me, here after 2 similar codes, I just add or not a Serialprint, and the led blinks, or does not blink. I do not understand, thank you very much
Pat from Toulouse (France)
// arduino code 1
// blinking led OK (with a Serial_print included in the delay loop to read counter value)
unsigned int counter, toggle=0;
void setup()
{ pinMode (13, OUTPUT);
Serial.begin(115200);
// timer 2 configured at 16uS
cli(); // Unactivation of the globale interruption
bitClear (TCCR2A, WGM20); // WGM20 = 0
bitClear (TCCR2A, WGM21); // WGM21 = 0
TCCR2B = 0b00000110; // Clock / 256 soit 16 uS et WGM22 = 0
TIMSK2 = 0b00000001; // Locale interruption autorised by TOIE0
sei(); // Activation of the globale interruption
}
void loop()
{ start:
if (toggle==0){digitalWrite(LED_BUILTIN,0);
toggle=1-toggle;}
else {digitalWrite(LED_BUILTIN,1);
toggle=1-toggle;}
counter=0;
delay_1s:
if (counter < 1000){
// Serial.print(counter);
goto delay_1s;}
goto start;}
ISR(TIMER2_OVF_vect)
{ TCNT2 = 256 - 62; // 62 x 16 µS ~ 1ms
counter++;}
// arduino code 2
// blinking led KO (without Serial_print included in the delay loop !!!)
unsigned int counter, toggle=0;
void setup()
{ pinMode (13, OUTPUT);
Serial.begin(115200);
// timer 2 configured at 16uS
cli(); // Unactivation of the globale interruption
bitClear (TCCR2A, WGM20); // WGM20 = 0
bitClear (TCCR2A, WGM21); // WGM21 = 0
TCCR2B = 0b00000110; // Clock / 256 soit 16 uS et WGM22 = 0
TIMSK2 = 0b00000001; // Locale interruption autorised by TOIE0
sei(); // Activation of the globale interruption
}
void loop()
{ start:
if (toggle==0){digitalWrite(LED_BUILTIN,0);
toggle=1-toggle;}
else {digitalWrite(LED_BUILTIN,1);
toggle=1-toggle;}
counter=0;
delay_1s:
if (counter < 1000){
// Serial.print(counter);
goto delay_1s;}
goto start;}
ISR(TIMER2_OVF_vect)
{ TCNT2 = 256 - 62; // 62 x 16 µS ~ 1ms
counter++;}