-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
timerRead() is returning the last read value, not the actual #3434
Comments
I think i got deeper to the root of the problem.. In the esp32-hal-timer.c the timerRead functions as followed: uint64_t timerRead(hw_timer_t *timer){
timer->dev->update = 1;
uint64_t h = timer->dev->cnt_high;
uint64_t l = timer->dev->cnt_low;
return (h << 32) | l;
} If i put a 1ms delay after the update, it seems to update the register fast enough, so the returned value is right. uint64_t timerRead(hw_timer_t *timer){
timer->dev->update = 1;
delay(1);
uint64_t h = timer->dev->cnt_high;
uint64_t l = timer->dev->cnt_low;
return (h << 32) | l;
} The only practical solutions are to "blind" read once before using the value, or to get a timestamp in the ISR, (pass it in a Task to an usable variable outside the ISR) and compare it against the actual time with esp_timer_get_time(). |
I second this, timerRead() is broken and blind reads help. |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
Is there another option for reporting bugs? It doesn’t seemed to be recognized by espressif. |
[STALE_CLR] This issue has been removed from the stale queue. Please ensure activity to keep it openin the future. |
@EsserPrototyping well, this is a community supported project. Feel free to submit a PR to fix the incorrect behavior. However, using delay() inside the ISR is not likely to be accepted as that can have unintended consequences with the watchdog timer being triggered. |
Ok, thanks. This wasn´t ment to sound like a complaint. I´m not able to fix this and I know that the delay() is no fix too. I just thought there´s maybe a list of known bugs or something like that. |
This may not be a heavily used area of code and that might explain the issue you are seeing. Many people don't understand the proper way to use the hardware timers and end up causing themselves a lot of problems and thus often it is suggested to try the Ticker library for periodic tasks instead. Is there a specific reason you are trying to read the timer value? |
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Hardware:
Board: ESP32 doit
Core Installation version: 1.11.0
IDE name: Platform.io / VSCode
The value of timerRead() is not what it should be. It returns the value from the last read.
If i do three readings in a row, the third gets the first in the row next time i´m reading.
There is a timer runnning in the background (200000 micros) and in the loop im asking three times for the timer value every half second..
without "blind" read:
Debug Messages:
If i read the value four times and only print the the last three readings it is right..
with "blind" read:
Debug Messages:
The text was updated successfully, but these errors were encountered: