I have a 'for' loop in which I wish to do something (for test, make a time reading) each predefined time interval of several tens micros.
I initialize a hardware compare timer, define interrupt handler, sets the period and starts the timer in the setup.
I expect the loop to halt in each cycle until the timer reaches a certain value (0 or any) and then make the next loop.
At the end of the loop number, the program is expected to exit the loop and proceed in the main loop, until the function will be called again.
Here is a basic example of what I need:
void program()
{
for (int i = 0; i<100;i++)
{
while (timer !=0) //Wait until timer fires (resets to 0 or other).
timearray[i]=micros();
}
}
I assume I need to use an interrupt(?), but I can not use an external function, as I want the interrupt inside my function.
Does anyone know how I can make this work?
Thanks
samtal