hello again,
my problem is still present. Here after 2 identical codes excepted a Serial.print() present in the delay loop of the 1st one. This 1st on is ok (blinking at 0.5Hz). Without this Serial.print() in the 2nd code, apparently the loop never stops so the led do not blink.
I tried also with "while" instruction instead "if", but the problem is always present !! could you hive me a solution to supress the serial.print. in the loop.Thank you a lot (in fact I need this kind of loop for the code I am developping for my dynamic simulator using simtools).
// 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()
{
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;}
}
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()
{
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){
goto delay_1s;}
}
ISR(TIMER2_OVF_vect)
{ TCNT2 = 256 - 62; // 62 x 16 µS ~ 1ms
counter++;}