Forum Rule: Always post complete source code & details to reproduce any issue!
-
IntervalTimer question
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. 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() {
}
-
Senior Member+
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.
-
Actually I'm running RC servos, so the pulse is around 1,500 microseconds every 20 milliseconds.
-
Senior Member+
... 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);...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules