One option I wanted to gauge was using a period timer to launch a callback that polls the GPIO every 5ms. Then using an algorithm to debounce as well as eliminate potential EMI.
I've configured FreeRTOS to use a 1000Hz tick rate, and have wrote the code below to just feasibility test this. At 10ms the watchdog is getting fed, but going down to 5ms has caused problems.
I'm not sure if I'm just doing something wrong here or what. As an aside, and I'm unsure if anyone knows the answer to this, but I'm curious what happens in FreeRTOS if the callback completes before a full tick is up, does that time get lost or does a new tick get started? I highly doubt the callback below takes more than 1 tick (1ms @ 1000Hz) to run, even with all the overhead, so I guess I'm confused why the IDLE task is failing o run in the 4 ticks it has before the next timer?
- #include <string.h>
- #include "esp_timer.h"
- #include "esp_log.h"
- #include "freertos/FreeRTOS.h"
- static const char *TAG = "Timer Test";
- void periodic_timer_callback(void* arg) {
- ESP_LOGI(TAG, "Periodic timer called on core #%d, the time is %llu", xPortGetCoreID(), esp_timer_get_time());
- }
- void app_main(void) {
- esp_timer_handle_t periodic_timer;
- esp_timer_create_args_t periodic_timer_args = {
- .callback = &periodic_timer_callback,
- .name = "test"
- };
- esp_timer_create(&periodic_timer_args, &periodic_timer);
- esp_timer_start_periodic(periodic_timer, 5 * 1000);
- }