Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HardwareTimer repeating when it shouldn't on Esp8266 #2710

Closed
mikee47 opened this issue Jan 13, 2024 · 3 comments
Closed

HardwareTimer repeating when it shouldn't on Esp8266 #2710

mikee47 opened this issue Jan 13, 2024 · 3 comments
Labels

Comments

@mikee47
Copy link
Contributor

mikee47 commented Jan 13, 2024

This code (modified Basic_Blink sample) doesn't work as expected:

#include <SmingCore.h>
#include <HardwareTimer.h>

#define LED_PIN 2

HardwareTimer procTimer;

bool state = true;

void IRAM_ATTR blink()
{
	digitalWrite(LED_PIN, state);
	state = !state;
}

void init()
{
	Serial.begin(COM_SPEED_SERIAL);
	Serial.systemDebugOutput(true);

	debug_i("Welcome");

	pinMode(LED_PIN, OUTPUT);
	procTimer.initializeMs<250>(blink).startOnce();

	auto timer = new SimpleTimer;
	timer->initializeMs<1000>([]() { debug_i("Hello"); });
	timer->start();
}

We expect the LED to toggle once then stop, but instead it keeps flashing at ~1.7s intervals. This is because the timer is still enabled and just keeps wrapping. Confirmed using HardwareTimer1<TIMER_CLKDIV_256> and we get ~27s intervals.

So timer needs to be explicitly disabled in the callback.

Adding this to the driver code is going to add latency, so will need to take a closer look at this. Suggestions welcome!

Discovered after dealing with another issue, see #2709

@mikee47
Copy link
Contributor Author

mikee47 commented Jan 13, 2024

As far as I can tell the hardware timer has always behaved like this. Probably safest to keep as-is.

@mikee47
Copy link
Contributor Author

mikee47 commented Jan 15, 2024

@slaff Any thoughts on this issue?

@slaff
Copy link
Contributor

slaff commented Jan 16, 2024

Probably safest to keep as-is.

Exactly, keep it as it is.

@mikee47 mikee47 closed this as completed Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants