Lower Limit to SparkIntervalTimer of 5ms?

@peekay123, I haven’t found this mentioned anywhere but when I use the SparkIntervalTimer, it seems that I run into a lower limit on ISR execution every 5ms. Is that correct? Is there anyway to get around this? I was hoping to execute it every 500us.

In this stripped code, a value of 9 (4.5ms) in this command doesn’t seem to execute the ISR:
myTimer.begin(Sample, 9, hmSec);

But a value of 10 does work. My goal was a value of 1…

#include "SparkIntervalTimer.h"
#define PUBLISH_TIME 3000      // 1000ms = every second

IntervalTimer myTimer;

// for now...all these are global
unsigned long currentMillis, prior_publish_time;
bool timer_started = false;
volatile unsigned long currentMillisx[8]; 

void Sample(void);

void setup() {
}

void loop() {
  currentMillis = millis();

  if (!timer_started) {
    myTimer.begin(Sample, 9, hmSec);
    timer_started = true;
  }

// Print the most recent buffer
  if ((currentMillis - prior_publish_time) >= PUBLISH_TIME) {
    for(int i = 0; i < 8; i++){
      Serial.printlnf("%lu",currentMillisx[i]);
    }
    Serial.printlnf("");
    prior_publish_time = currentMillis;
  }
}

void Sample(void) {
static int counter = 0;
  currentMillisx[counter] = millis(); 

  if (counter < 7) counter++;
  else counter = 0;
}

SAMPLE OUTPUT with value of 10 which corresponds to ISR execution every 5ms ( (with 9 or less, all show up as 0)

9050
9055
9017
9022
9028
9033
9039
9044

12042
12047
12053
12014
12020
12025
12031
12036

@Jonpcar you can go down to 20 or so microseconds with SparkIntervalTimer. In your code you read millis() which does not work as expected in an ISR. Use micros() instead to do your testing.

1 Like

Thanks @peekay123, I do remember reading that somewhere, but it didn’t register.

@peekay123, so I tried it with micros() command in the ISR and once again it works for a value of 10 in that instruction (5ms), but if I put 9 it still fails. EDIT: using the uSec designation DOES work.

myTimer.begin(Sample, 9, hmSec); doesn’t work
myTimer.begin(Sample, 4500, uSec); DOES WORK

Also, I am not very good at this library “stuff”, is there a SparkIntervalTimer command that supports something below resolution of 500us, I was only familiar with the hmSec and mSec designations for the frequency.` EDIT found this one uSec…and it DOES work if I specify 500us.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.