possible Timer update bug?

Thorvard
Posts: 2
Joined: Mon Feb 13, 2017 5:12 pm

possible Timer update bug?

Postby Thorvard » Mon Jun 05, 2017 3:29 pm

I noticed a possible bug with the update of timers. When doing a write access to TIMG_T1UPDATE_REG(n) the counter value of the timer should be copied to the TIMG_T1LO_REG(n) register, but that seems to lag behind sometimes and an old value is read.

The following arduino code reproduces the issue:

Code: Select all

#include "Esp.h"
#include "driver/timer.h"

uint64_t chipid;
hw_timer_t *myTimer = NULL;
#define TIM_CNT (*(volatile uint32_t *)TIMG_T1LO_REG(1))
#define TIM_UPDATE (*(volatile uint32_t *)TIMG_T1UPDATE_REG(1))
void setup() {
  Serial.begin(115200);
  Serial.print("SDK Version: ");
  Serial.println(ESP.getSdkVersion());
  myTimer = timerBegin(3, 1, true);
  timerStart(myTimer);
  for (int i = 0; i < 20; i++) {
    vTaskSuspendAll();
    taskDISABLE_INTERRUPTS();
    TIM_UPDATE = 1;
    volatile uint32_t t1 = TIM_CNT;
    volatile uint32_t t2 = TIM_CNT;
    taskENABLE_INTERRUPTS();
    xTaskResumeAll();
    Serial.printf("Loop %d - T1: %d T2: %d\n", i, t1, t2);
  }
  timerStop(myTimer);
}

void loop() {
  // put your main code here, to run repeatedly:

}
T1 and T2 should be identical, but see for yourself:
SDK Version: v2.0-rc1-761-g65acd99c
Loop 0 - T1: 0 T2: 58
Loop 1 - T1: 6142 T2: 6142
Loop 2 - T1: 7934 T2: 7934
Loop 3 - T1: 7934 T2: 9732
Loop 4 - T1: 37777 T2: 37777
Loop 5 - T1: 138470 T2: 138470
Loop 6 - T1: 138470 T2: 246109
Loop 7 - T1: 246109 T2: 353745
Loop 8 - T1: 461384 T2: 461384
Loop 9 - T1: 461384 T2: 569019
Loop 10 - T1: 676670 T2: 676670
Loop 11 - T1: 787769 T2: 787769
Loop 12 - T1: 898878 T2: 898878
Loop 13 - T1: 898878 T2: 1009987
Loop 14 - T1: 1124570 T2: 1124570
Loop 15 - T1: 1124570 T2: 1242623
Loop 16 - T1: 1242623 T2: 1360680
Loop 17 - T1: 1478733 T2: 1478733
Loop 18 - T1: 1478733 T2: 1596790
Loop 19 - T1: 1714841 T2: 1714841

Is there a problem in my code or is this some bug in the silicon?
As a workaround reading the value twice works.

best regards, Thorvard

Who is online

Users browsing this forum: No registered users and 49 guests