IntervalTimer question

twiereng

Member
In the simple example here I start an IntervalTimer with 20 msec. callback. In the function called I have a 10 msec. delay. My question is does this delay eat up half of my computational time, or is the delay handled in the background. View attachment Timer_example.ino

volatile int usec_F = 10000;

IntervalTimer timerFront;
timerFront.begin(front_Servos, 20000);

void front_Servos()
{
digitalWrite(2, HIGH);
delayMicroseconds(usec_F);
digitalWrite(2, LOW);
}

void setup() {
timerFront.begin(front_Servos, 20000);
}

void loop() {


}
 
Use of any delay will block and not return to loop() or other code - except higher priority interrupts

Code shown has 20 msec delay - then sits 10 msec. If this is the desired behavior the timer could be set to 10 msec and just toggle the pin #2 HIGH then LOW on alternate calls.
 
... after reading "20 msec. callback. In the function called I have a 10 msec. delay" delay of 1.5 ms wasn't known

@luni has timers that can do a one shot - assume it could be triggered for interrupt in the needed 1,500 us.

Or a second intervalTimer could be started when desired with digitalWrite(2, HIGH); and stopped perhaps with the digitalWrite(2, LOW);

So the delayMicroseconds(usec_F); would block execution - but only for the noted time usec_F in delayMicroseconds(usec_F);...
 
Back
Top