Using Timer Interrupt and Reload Timer

kian79
Posts: 28
Joined: Thu Jun 13, 2019 3:27 am

Using Timer Interrupt and Reload Timer

Postby kian79 » Thu Jul 18, 2019 3:05 am

Hi all,

I have setup a timer interrupt to trigger every 5 seconds. However if a button is pressed before 5 seconds is up, the timer should restart again.

Is there a way to reload the timer without having to reinitalise the timer all over again? Currently only this works:

Code: Select all

        Serial.println("Reload Timer");
        timerAlarmDisable(timer);		// stop alarm
        timerDetachInterrupt(timer);	// detach interrupt
        timerEnd(timer);			// end timer

        timer = timerBegin(0, 80, true);	// start time again
        timerAttachInterrupt(timer, &onTimer, true);	// attach interrupt again
        timerAlarmWrite(timer, 5000000, true);	// start alarm again
        timerAlarmEnable(timer);  	// enable alarm again

User avatar
HermannSW
Posts: 97
Joined: Fri Oct 27, 2017 6:58 am
Location: Eberbach, Germany
Contact:

Re: Using Timer Interrupt and Reload Timer

Postby HermannSW » Thu Jul 18, 2019 5:47 am

I think "timerRestart()" is what you want.
But you need this fix to get it working correctly:
https://github.com/espressif/arduino-es ... -507039927

Who is online

Users browsing this forum: No registered users and 66 guests