Fix: pulse count now correctly interrupts on one turn
parent
531cb9b0a9
commit
3d9281a537
|
|
@ -11,12 +11,13 @@
|
||||||
#include "hal/pcnt_types.h"
|
#include "hal/pcnt_types.h"
|
||||||
|
|
||||||
/* Pinouts */
|
/* Pinouts */
|
||||||
#define PCNT_A_PIN 5 /* Rotary Encoder A Pin */
|
#define PCNT_A_PIN 4 /* Rotary Encoder A Pin */
|
||||||
#define PCNT_B_PIN 4 /* Rotary Encoder B Pin */
|
#define PCNT_B_PIN 5 /* Rotary Encoder B Pin */
|
||||||
|
#define GPIO_BTN_PIN 6 /* Rotary Encoder switch */
|
||||||
|
|
||||||
/* Pulse Count Settings */
|
/* Pulse Count Settings */
|
||||||
#define PCNT_HIGH_LIMIT 100 /* 100 total steps */
|
#define PCNT_HIGH_LIMIT 2 /* 100 total steps */
|
||||||
#define PCNT_LOW_LIMIT -100
|
#define PCNT_LOW_LIMIT -2
|
||||||
|
|
||||||
static QueueHandle_t pcnt_queue = NULL;
|
static QueueHandle_t pcnt_queue = NULL;
|
||||||
|
|
||||||
|
|
@ -24,6 +25,7 @@ static const char *TAG = "RE Demo"; /* logging tag */
|
||||||
|
|
||||||
pcnt_unit_handle_t pcnt_unit;
|
pcnt_unit_handle_t pcnt_unit;
|
||||||
|
|
||||||
|
|
||||||
/* Pulse Counter Callback */
|
/* Pulse Counter Callback */
|
||||||
static bool pcnt_cb(pcnt_unit_handle_t unit, const pcnt_watch_event_data_t *edata, void *user_ctx) {
|
static bool pcnt_cb(pcnt_unit_handle_t unit, const pcnt_watch_event_data_t *edata, void *user_ctx) {
|
||||||
BaseType_t high_task_wakeup;
|
BaseType_t high_task_wakeup;
|
||||||
|
|
@ -72,7 +74,7 @@ static void pcnt_init() {
|
||||||
|
|
||||||
/* 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[] = {-10, 10};
|
int watch_points[] = {-2, 2}; /* This encoder has detents which change in steps of 2 */
|
||||||
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]));
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +95,6 @@ static void pcnt_init() {
|
||||||
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));
|
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Main Loop */
|
/* Main Loop */
|
||||||
void app_main(void){
|
void app_main(void){
|
||||||
|
|
||||||
|
|
@ -101,15 +102,11 @@ void app_main(void){
|
||||||
pcnt_init();
|
pcnt_init();
|
||||||
|
|
||||||
/* Log counter value */
|
/* Log counter value */
|
||||||
int pulse_count = 0;
|
|
||||||
int event_count = 0;
|
int event_count = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (xQueueReceive(pcnt_queue, &event_count, pdMS_TO_TICKS(1000))) {
|
if (xQueueReceive(pcnt_queue, &event_count, portMAX_DELAY)) {
|
||||||
ESP_LOGI(TAG, "Watch point event, count: %d", event_count);
|
ESP_LOGI(TAG, "Watch point event, count: %d", event_count);
|
||||||
} else {
|
|
||||||
ESP_ERROR_CHECK(pcnt_unit_get_count(pcnt_unit, &pulse_count));
|
|
||||||
ESP_LOGI(TAG, "Pulse count: %d", pulse_count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue