50f3af41e7fd7c3eef84a6f45a55be9cbc3a8be2
ESP32 ESP-IDF component for tachometer (via rotary optical encoder)
Features
- Quadrature encoder support via ESP-IDF PCNT peripheral in quadrature decoder mode.
- Automatic RPM calculation based on configurable pulses-per-revolution.
- Periodic RPM sampling via ESP-Timer at 100 Hz (10 ms interval).
- Configurable GPIO pull-up resistors for encoder A/B phases.
- PCNT glitch filter (1000 ns) to reject spurious transitions.
- Watch points at ±32767 for overflow detection.
- Multiple tachometers supported — each requires its own PCNT unit and timer.
Using
In an existing project, run the following command to install the components:
cd ../your_project/components
git clone https://github.com/aZholtikov/zh_tachometer
In the application, add the component:
#include "zh_tachometer.h"
Example
#include "zh_tachometer.h"
zh_tachometer_handle_t *tachometer_handle = NULL;
void app_main(void)
{
esp_log_level_set("zh_tachometer", ESP_LOG_ERROR);
zh_tachometer_init_config_t config = ZH_TACHOMETER_INIT_CONFIG_DEFAULT();
config.a_gpio_number = GPIO_NUM_26;
config.b_gpio_number = GPIO_NUM_27;
config.encoder_pulses = 3600;
zh_tachometer_init(&config, &tachometer_handle);
for (;;)
{
uint16_t value = 0;
zh_tachometer_get(&tachometer_handle, &value);
printf("Tachometer value is %d rpm.\n", value);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
Description
ESP32 ESP-IDF component for tachometer (via rotary optical encoder).
85 KiB
0 Stars
1 Watchers
0 Forks
Languages
C
99%
CMake
1%