Hello: Using latest studio 6 & GCC install, for XMEGA 16D4 and compiler optimization setting -O3. Set up a timer0 compare interrupt @ 2 KHz from a 20 MHz clock...all works fine, no problem at all.
To check on a scope, I put in a small dumb delay to give some pulse width, works fine.
When I remove the single line semicolon after the "for" the for loop quits working (compiles into dust ) & I get very narrow 2KHz pulses (due to 2KHz irq being extremely quick in & out)...OK
With the semicolon removed the second led I/O becomes part of the "for"...WHY does the "for" get optimized away??--just wondering. I'd think it would stay functional.
Maybe the compiler is smart enough to see the volatile abc will just reach 50 & the port will be cleared 50 times, so it just sets it and be done with it (no loop).
If that is the case, why does it keep the for loop when the semicolon is present?
volatile int abc=0; volatile int slow_tick=0; ISR(TCC0_CCA_vect,ISR_BLOCK) //TIMER tick interrupt { slow_tick++; PORTE.OUTSET=TESTPIN_PE; for(abc=0;abc<50;abc++) ; //note this semicolon..... PORTE.OUTCLR=TESTPIN_PE; }
Edit: typo in title