diff --git a/main/esp32_rgb_rotary_encoder.c b/main/esp32_rgb_rotary_encoder.c index 50fc7c4..c80c3c2 100644 --- a/main/esp32_rgb_rotary_encoder.c +++ b/main/esp32_rgb_rotary_encoder.c @@ -15,8 +15,8 @@ #define PCNT_B_PIN 2 /* Rotary Encoder B Pin */ /* Pulse Count Settings */ -#define PCNT_HIGH_LIMIT 100 -#define PCNT_LOW_LIMIT -100 +#define PCNT_HIGH_LIMIT 100 /* 100 total steps */ +#define PCNT_LOW_LIMIT -1 static QueueHandle_t pcnt_queue = NULL; @@ -42,6 +42,12 @@ void app_main(void){ pcnt_unit_handle_t pcnt_unit = NULL; ESP_ERROR_CHECK(pcnt_new_unit(&pcnt_unit_config, &pcnt_unit)); + /* Setup glitch filter */ + pcnt_glitch_filter_config_t filter_config = { + .max_glitch_ns = 1000 + }; + ESP_ERROR_CHECK(pcnt_unit_set_glitch_filter(pcnt_unit, &filter_config)); + /* Configure PCNT A & B channels and get handles */ ESP_LOGI(TAG, "Setting up Pulse Counter Channels"); pcnt_chan_config_t pcnt_chan_a_config = { @@ -66,7 +72,7 @@ void app_main(void){ /* Install watch points */ ESP_LOGI(TAG, "Installing watch points and callback handler"); - int watch_points[] = {PCNT_LOW_LIMIT, -50, 0, 50, PCNT_HIGH_LIMIT}; + int watch_points[] = {PCNT_LOW_LIMIT, 1, PCNT_HIGH_LIMIT}; for (size_t i = 0; i < sizeof(watch_points) / sizeof(watch_points[0]); i++) { ESP_ERROR_CHECK(pcnt_unit_add_watch_point(pcnt_unit, watch_points[i])); }