Dynamic light sleep strange behaviour
Posted: Fri Dec 23, 2022 9:29 am
Hi,
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:
Here are the results measured with a logic analyser. First is the start sequence with 5s, later the sleep time (pin state low) should start with 5s and increase every iteration for 5s.
Is it not possible to change the timer wake up dynamical or do I have some bug in the code?
Thank you
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