Fix: add glitch filter to pcnt
parent
58702666f2
commit
8f1add76b8
|
|
@ -15,8 +15,8 @@
|
||||||
#define PCNT_B_PIN 2 /* Rotary Encoder B Pin */
|
#define PCNT_B_PIN 2 /* Rotary Encoder B Pin */
|
||||||
|
|
||||||
/* Pulse Count Settings */
|
/* Pulse Count Settings */
|
||||||
#define PCNT_HIGH_LIMIT 100
|
#define PCNT_HIGH_LIMIT 100 /* 100 total steps */
|
||||||
#define PCNT_LOW_LIMIT -100
|
#define PCNT_LOW_LIMIT -1
|
||||||
|
|
||||||
static QueueHandle_t pcnt_queue = NULL;
|
static QueueHandle_t pcnt_queue = NULL;
|
||||||
|
|
||||||
|
|
@ -42,6 +42,12 @@ void app_main(void){
|
||||||
pcnt_unit_handle_t pcnt_unit = NULL;
|
pcnt_unit_handle_t pcnt_unit = NULL;
|
||||||
ESP_ERROR_CHECK(pcnt_new_unit(&pcnt_unit_config, &pcnt_unit));
|
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 */
|
/* Configure PCNT A & B channels and get handles */
|
||||||
ESP_LOGI(TAG, "Setting up Pulse Counter Channels");
|
ESP_LOGI(TAG, "Setting up Pulse Counter Channels");
|
||||||
pcnt_chan_config_t pcnt_chan_a_config = {
|
pcnt_chan_config_t pcnt_chan_a_config = {
|
||||||
|
|
@ -66,7 +72,7 @@ void app_main(void){
|
||||||
|
|
||||||
/* Install watch points */
|
/* Install watch points */
|
||||||
ESP_LOGI(TAG, "Installing watch points and callback handler");
|
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++) {
|
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]));
|
ESP_ERROR_CHECK(pcnt_unit_add_watch_point(pcnt_unit, watch_points[i]));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue