IntervalTimer library

@peekay123 I created a gist with all the required files. I do have some code in there that I commented out while testing but it does not seem to affect it very much.

The code currently uses TIMER4 which works OK for the most part, but I’d really like to use the regular TIMER1.

@davethebrave, I will look at the code later. As for the timers, the ones available to the user are TIMER2, 3 and 4 as TIMER1 is used for systick and the foundation firmware.

@davethebrave, I can’t see anything obvious. Do you have an oscilloscope or logic analyzer to test with?

Hey @peekay123 are you tried to use IntervalTimer and DS1820 temperature sensor together?
I use such setup:

INTERVAL.begin(FUNCTION, 500, uSec);

And if you add dallas temperature reading into loop then allways it returns 1200 C or -0.06250 C. When I remove IntervalTimer then all works and I’ll get correct value?

Do you have an idea why it so?

The OneWire library modifies the GPIO registers and may affect the operation of the timers. I have to do some heavy duty reading of the STM32F10x reference manual to figure it out.

1 Like

Any updates regarding this? :blush:

@markopraakli Not yet. I am sick AND away from home till next week. Do you have an oscilloscope?

Hi,

Just out of curiosity, have you tried to change timer interrupt priority?

@DBear, some Serial data dropouts were reported and it turns out the priority was too high. I am revising the library now to lower the priority to a “sweet” level (10) and will re-publish the library once it’s tested. Thanks for the suggestion! :smile:

@peekay123, I think I have faced with that problem, eventually using RX DMA of USART1 solved my problem :-). Thanks for the Library!

1 Like

@peekay123 First, thanks for putting this together. I’m working on a little test program using your library and it seems that the call back function is getting called as soon as I enable the interrupt then continuing to get called every expected interval. Does that make sense to you? I would have expected it to get called only after the first interval elapsed. Do you have any thoughts about this?

Thanks in advance.

@matt_ri, when you allocate a timer, the interrupt is enabled as well. However, the interrupt should not fire until the first timer period has elapse. Can you share your code? I am not sure what you mean by:

@peekay123 Sure. Below is my test code. It’s purpose is to check if the core is connected. If not, it tries to connect. The use of the interrupt is to stop the blocking Spark.connect() function.
Note that I added a flag to “ignore” the first call to the interrupt:

// This #include statement was automatically added by the Spark IDE.
#include "SparkIntervalTimer/SparkIntervalTimer.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

IntervalTimer startup_timer;

bool connecting = false;
bool first_call = true;

void kill_connecting(void);

void setup() {
  Serial.begin(9600);
  delay(5000);
  Serial.println("");
  Serial.print(millis());
  Serial.println(": Setup Complete");
//  Spark.connect();
}

void kill_connecting(void)
{
    if (first_call) {
        first_call = false;
        Serial.print(millis());
        Serial.println(": First Call");
    }
    else if (!Spark.connected()) {
        Serial.print(millis());
        Serial.println(": Disconnecting");
        Spark.disconnect();
        Serial.print(millis());
        Serial.println(": ending timer");
        startup_timer.end();
        connecting = false;
    }
}

void loop() {
    if (Spark.connected()) {
        Serial.print(millis());
        Serial.println(": Connected!");
    }
    else if (!connecting) {
        Serial.print(millis());
        Serial.println(": Not-Connected");
        Serial.print(millis());
        Serial.println(": Starting interrupt");
        first_call = true;
        startup_timer.begin(kill_connecting, 12000, hmSec);
        connecting = true;
        Spark.connect();
    }
    delay(300);
}

Thanks for your help. I appreciate it.

Hi,
I just tried to compile your library on the firmware-feature-hal-no-cloud branch, because the cloud code eats too much FLASH.
After correcting some issues with “varible defined but not used” errors (why are these errors and no warnings, seems the compiler options are a bit paranoid) I at last have an error which I cannot solve.

The library uses the ISR vectors
extern void (*Wiring_TIM2_Interrupt_Handler)(void);
extern void (*Wiring_TIM3_Interrupt_Handler)(void);
extern void (*Wiring_TIM4_Interrupt_Handler)(void);

But these are not existent in that “hal” branch. Does anyone know where to find them or how are they named now?

Thanks
Thorsten

1 Like

I am also in need of assistance to be able to use the TimerLibrary with HAL branch… Anyone got it to work yet?

@Bluescreen and @geert, I’ve been chasing my tail on projects for the Maker Faire. I have not had a chance to compile the SparkIntervalTimer with the HAL. I’ll be taking a look at it in the coming days. :smile:

@peekay123, I just got it to work... You want me to do a pull request on separated branch?

@geert, that sounds great! I’ll validate the fix and hold off until the HAL is officially released before merging. Thanks! :smiley:

I have the commit here. Maybe you can create a feature/hal branch on your github and merge it in there for now? :slight_smile: Thanks for the good work on the library btw, works perfect! :wink:

1 Like

@geert, thanks for your kind words. I will be working with Spark to (hopefully) bring the Timer management to a whole new level for the Photon/Electron. It won’t be in the initial release but some fantastic new stuff on the Photon will blow you away! :smiley:

2 Likes