Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: IntervalTimer question

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    5

    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() {


    }

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,136
    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.

  3. #3
    Junior Member
    Join Date
    Jun 2017
    Posts
    5
    Actually I'm running RC servos, so the pulse is around 1,500 microseconds every 20 milliseconds.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    17,136
    ... 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
  •