diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 6afea108f17..460684b0a1a 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -14,15 +14,30 @@ void loopTask(void *pvParameters) { setup(); for(;;) { - micros(); //update overflow loop(); } } +void vMicrosOverflowTask(void *pvParameters) +{ + // In order no to miss overflow it will be enought to check micros() each half of full overflow + static const uint32_t taskDelayMs = UINT32_MAX + / CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ // one full overflow occurs in uS + / 1000 // in millisec + / 2 // half of full overflow cycle + / portTICK_PERIOD_MS; // RTOS const to convert in ms + + for (;;){ + micros(); //update overflow + vTaskDelay(taskDelayMs); // ~ each 9 sec at 240Mhz + } +} + extern "C" void app_main() { initArduino(); - xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, ARDUINO_RUNNING_CORE); + xTaskCreatePinnedToCore(vMicrosOverflowTask, "microsTask", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL, ARDUINO_RUNNING_CORE); + xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, ARDUINO_RUNNING_CORE); } #endif