I have a code which takes always different time to execute. After this execution the MCU has to go to light sleep, but always wake up at same time (with accuracy of few 100ms). I calculate the code execution time correctly but when setting the sleep wake up value its only the first time correct, and later wrong. I have setup a small test program where the strange behaviour can be simulated:
- gpio_set_level(DEVICE_DEBUG_PIN, 1);
- vTaskDelay(pdMS_TO_TICKS(5000));
- uint64_t testTim = 5 * 1000000;
- printf("START SLEEP TIME: %lld\n", testTim);
- gpio_set_level(DEVICE_DEBUG_PIN, 0);
- vTaskDelay(pdMS_TO_TICKS(5)); /* Small delay just to make shure pin goes low before sleep */
- esp_timer_start_periodic
- while(1){
- esp_sleep_enable_timer_wakeup(testTim);
- esp_light_sleep_start();
- gpio_set_direction(DEVICE_DEBUG_PIN, GPIO_MODE_OUTPUT);
- gpio_set_level(DEVICE_DEBUG_PIN, 1);
- vTaskDelay(pdMS_TO_TICKS(2000));
- testTim += 5000000;
- gpio_set_level(DEVICE_DEBUG_PIN, 0);
- vTaskDelay(pdMS_TO_TICKS(5)); /* Small delay just to make shure pin goes low before sleep */
- }
Is it not possible to change the timer wake up dynamical or do I have some bug in the code?
Thank you