feat!: main structure of handle changed to double pointer
This commit is contained in:
1 parent
935d3b4b97
commit
75134fbb2e
5 files changed
+264
-134
No files matched your search
@@ -1,20 +1,22 @@
|
||||
# ESP32 ESP-IDF component for tachometer (via rotary optical encoder)
|
||||
|
||||
## Tested on
|
||||
|
||||
1. [ESP32 ESP-IDF v6.0.0](https://docs.espressif.com/projects/esp-idf/en/v6.0/esp32/index.html)
|
||||
|
||||
## SAST Tools
|
||||
|
||||
[PVS-Studio](https://pvs-studio.com/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code.
|
||||
|
||||
## Features
|
||||
|
||||
1. Support up to 8 tachometers on one device.
|
||||
1. Quadrature encoder support via ESP-IDF PCNT peripheral in quadrature decoder mode.
|
||||
2. Automatic RPM calculation based on configurable pulses-per-revolution.
|
||||
3. Periodic RPM sampling via ESP-Timer at 100 Hz (10 ms interval).
|
||||
4. Configurable GPIO pull-up resistors for encoder A/B phases.
|
||||
5. PCNT glitch filter (1000 ns) to reject spurious transitions.
|
||||
6. Watch points at ±32767 for overflow detection.
|
||||
7. Multiple tachometers supported — each requires its own PCNT unit and timer.
|
||||
|
||||
## Attention
|
||||
## Note
|
||||
|
||||
1. For correct operation, please enable the following settings in the menuconfig:
|
||||
Enable the following settings in menuconfig:
|
||||
|
||||
```text
|
||||
PCNT_CTRL_FUNC_IN_IRAM
|
||||
@@ -25,7 +27,7 @@ PCNT_ISR_IRAM_SAF
|
||||
|
||||
In an existing project, run the following command to install the components:
|
||||
|
||||
```text
|
||||
```bash
|
||||
cd ../your_project/components
|
||||
git clone https://github.com/aZholtikov/zh_tachometer
|
||||
```
|
||||
@@ -36,27 +38,37 @@ In the application, add the component:
|
||||
#include "zh_tachometer.h"
|
||||
```
|
||||
|
||||
## Examples
|
||||
## Example
|
||||
|
||||
```c
|
||||
#include "zh_tachometer.h"
|
||||
|
||||
zh_tachometer_handle_t tachometer_handle = {0};
|
||||
static 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);
|
||||
|
||||
esp_err_t ret = zh_tachometer_init(&config, &tachometer_handle);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOG_ERROR("zh_tachometer", "Initialization failed: %s", esp_err_to_name(ret));
|
||||
return;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
uint16_t rpm = 0;
|
||||
ret = zh_tachometer_get(&tachometer_handle, &rpm);
|
||||
if (ret == ESP_OK) {
|
||||
printf("Tachometer value is %d rpm.\n", rpm);
|
||||
}
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
zh_tachometer_deinit(&tachometer_handle);
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user