My MCU is ATmega1608. I am trying to calculate the time spent in a while loop. The only reason to calculate time spent in the loop is to find out if my peripheral is stopped or not by polling the status bit of timer. If it is stopped than I have to set a flag. This peripheral is TCB in singleshot mode.
// ***** If counter is not running , wait for atleast one pulse to start ***** //
while(!(TCB1.STATUS & TCB_RUN_bm))
I want to know how much time is spend in this loop. If my program does not come out of this while loop in 17us, then I have to set a flag. How to find how much time does this execution takes?
That is not a complete while() loop since you do not show the body
unsigned long startTime = millis();
// reset your flag
while(!(TCB1.STATUS & TCB_RUN_bm)) {
if ( millis() - startTime > 17 ) {
// set your flag
break;
}
...