2018年11月29日 星期四

DIY - ESP32:ESP32 PCNT API 函數(四十一)

DIY - ESP32:ESP32 PCNT API 函數(四十一):

ESP32 的 IDF 內 PCNT (Pulse Counter / 脈衝計數器)API 函數模塊用於計算輸入信號的上升沿(Rising Edges)和下降沿(Falling Edges)的數量。函數模塊還可以設定輸入訊號的要求和中斷等等。
ESP32 PULSE_CNT 遞增 / 遞減計數圖
功能 - pcnt_unit_config
原型:esp_err_t pcnt_unit_config(const pcnt_config_t *pcnt_config)
參數:pcnt_config: Pointer of Pulse Counter unit configure parameter
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Configure Pulse Counter unit. This function will disable three events: PCNT_EVT_L_LIM, PCNT_EVT_H_LIM, PCNT_EVT_ZERO.
範例:

功能 - pcnt_get_counter_value
原型:esp_err_t pcnt_get_counter_value(pcnt_unit_t pcnt_unit, int16_t *count)
參數:pcnt_unit: Pulse Counter unit number
            count: Pointer to accept counter value
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Get pulse counter value.
範例:

功能 - pcnt_counter_pause
原型:esp_err_t pcnt_counter_pause(pcnt_unit_t pcnt_unit)
參數:pcnt_unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Pause PCNT counter of PCNT unit.
範例:

功能 - pcnt_counter_resume
原型:esp_err_t pcnt_counter_resume(pcnt_unit_t pcnt_unit)
參數:pcnt_unit: PCNT unit number, select from pcnt_unit_t
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Resume counting for PCNT counter.
範例:

功能 - pcnt_counter_clear
原型:esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit)
參數:pcnt_unit: PCNT unit number, select from pcnt_unit_t
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Clear and reset PCNT counter value to zero.
範例:

功能 - pcnt_intr_enable
原型:esp_err_t pcnt_intr_enable(pcnt_unit_t pcnt_unit)
參數:pcnt_unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Enable PCNT interrupt for PCNT unit.
NoteEach Pulse counter unit has five watch point events that share the same interrupt. Configure events with pcnt_event_enable() and pcnt_event_disable()
範例:

功能 - pcnt_intr_disable
原型:esp_err_t pcnt_intr_disable(pcnt_unit_t pcnt_unit)
參數:pcnt_unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Disable PCNT interrupt for PCNT unit.
範例:

功能 - pcnt_event_enable
原型:esp_err_t pcnt_event_enable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
參數:unit: PCNT unit number
            evt_type: Watch point event type. All enabled events share the same interrupt (one interrupt per pulse counter unit).
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Enable PCNT event of PCNT unit.
範例:

功能 - pcnt_event_disable _div
原型:esp_err_t pcnt_event_disable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
參數:unit: PCNT unit number
             evt_type: Watch point event type. All enabled events share the same interrupt (one interrupt per pulse counter unit).
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Disable PCNT event of PCNT unit.
範例:

功能 - pcnt_set_event_value
原型:esp_err_t pcnt_set_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t value)
參數:unit: PCNT unit number
            evt_type: Watch point event type. All enabled events share the same interrupt (one interrupt per pulse counter unit).
            value: Counter value for PCNT event
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Set PCNT event value of PCNT unit.
範例:

功能 - pcnt_get_event_value
原型:esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t *value)
參數:unit: PCNT unit number
            evt_type: Watch point event type. All enabled events share the same interrupt (one interrupt per pulse counter unit).
            value: Pointer to accept counter value for PCNT event
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Get PCNT event value of PCNT unit.
範例:

功能 - pcnt_isr_register
原型:esp_err_t pcnt_isr_register(void (*fn)(void *), void *arg, int intr_alloc_flags, pcnt_isr_handle_t *handle, )
參數:fn: Interrupt handler function.
            arg: Parameter for handler function
            intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
            handle: Pointer to return handle. If non-NULL, a handle for the interrupt will be returned here. Calling esp_intr_free to unregister this ISR service if needed, but only if the handle is not NULL.
返回:ESP_OK Success
            ESP_ERR_NOT_FOUND Can not find the interrupt that matches the flags.
            ESP_ERR_INVALID_ARG Function pointer error.
說明:Register PCNT interrupt handler, the handler is an ISR. The handler will be attached to the same CPU core that this function is running on. Please do not use pcnt_isr_service_install if this function was called.
範例:

功能 - pcnt_set_pin
原型:esp_err_t pcnt_set_pin(pcnt_unit_t unit, pcnt_channel_t channel, int pulse_io, int ctrl_io)
參數:unit: PCNT unit number
            channel: PCNT channel number
            pulse_io: Pulse signal input GPIO
            ctrl_io: Control signal input GPIO
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Configure PCNT pulse signal input pin and control input pin.
NoteSet the signal input to PCNT_PIN_NOT_USED if unused.
範例:

功能 - pcnt_filter_enable
原型:esp_err_t pcnt_filter_enable(pcnt_unit_t unit)
參數:unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Enable PCNT input filter.
範例:

功能 - pcnt_filter_disable
原型:esp_err_t pcnt_filter_disable(pcnt_unit_t unit)
參數:unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Disable PCNT input filter.
範例:

功能 - pcnt_set_filter_value
原型:esp_err_t pcnt_set_filter_value(pcnt_unit_t unit, uint16_t filter_val)
參數:unit: PCNT unit number
            filter_val: PCNT signal filter value, counter in APB_CLK cycles. Any pulses lasting shorter than this will be ignored when the filter is enabled.
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Set PCNT filter value.
Notefilter_val is a 10-bit value, so the maximum filter_val should be limited to 1023.
範例:

功能 - pcnt_get_filter_value
原型:esp_err_t pcnt_get_filter_value(pcnt_unit_t unit, uint16_t *filter_val)
參數:unit: PCNT unit number
            filter_val: Pointer to accept PCNT filter value.
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Get PCNT filter value.
範例:

功能 - pcnt_set_mode
原型:esp_err_t pcnt_set_mode(pcnt_unit_t unit, pcnt_channel_t channel, pcnt_count_mode_t pos_mode, pcnt_count_mode_t neg_mode, pcnt_ctrl_mode_t hctrl_mode, pcnt_ctrl_mode_t lctrl_mode)
參數:unit: PCNT unit number
            channel: PCNT channel number
            pos_mode: Counter mode when detecting positive edge
            neg_mode: Counter mode when detecting negative edge
            hctrl_mode: Counter mode when control signal is high level
            lctrl_mode: Counter mode when control signal is low level
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Set PCNT counter mode.
範例:

功能 - pcnt_isr_handler_add
原型:esp_err_t pcnt_isr_handler_add(pcnt_unit_t unit, void (*isr_handler)(void *), void *args, )
參數:unit: PCNT unit number
            isr_handler: Interrupt handler function.
            args: Parameter for handler function
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Add ISR handler for specified unit.
Call this function after using pcnt_isr_service_install() to install the PCNT driver’s ISR handler service.
The ISR handlers do not need to be declared with IRAM_ATTR, unless you pass the ESP_INTR_FLAG_IRAM flag when allocating the ISR in pcnt_isr_service_install().
This ISR handler will be called from an ISR. So there is a stack size limit (configurable as “ISR stack size” in menuconfig). This limit is smaller compared to a global PCNT interrupt handler due to the additional level of indirection.
範例:

功能 - pcnt_isr_service_install
原型:esp_err_t pcnt_isr_service_install(int intr_alloc_flags)
參數:intr_alloc_flags: Flags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
返回:ESP_OK Success
            ESP_ERR_NO_MEM No memory to install this service
            ESP_ERR_INVALID_STATE ISR service already installed
說明:Install PCNT ISR service.
NoteWe can manage different interrupt service for each unit. This function will use the default ISR handle service, Calling pcnt_isr_service_uninstall to uninstall the default service if needed. Please do not use pcnt_isr_register if this function was called.
範例:

功能 - pcnt_isr_service_uninstall
原型:void pcnt_isr_service_uninstall(void)
參數:
返回:
說明:Uninstall PCNT ISR service, freeing related resources.
範例:

功能 - pcnt_isr_handler_remove
原型:esp_err_t pcnt_isr_handler_remove(pcnt_unit_t unit)
參數:unit: PCNT unit number
返回:ESP_OK Success
            ESP_ERR_INVALID_ARG Parameter error
說明:Delete ISR handler for specified unit.
範例:


相關網址:
※ DIY - ESP32:ESP32 PCNT 脈衝計數器電路(三十八)
※ DIY - ESP32:ESP32 PCNT 脈衝計數器程式(三十九)
※ DIY - ESP32:ESP32 PCNT API 函數模塊介紹(四十)
※ DIY - ESP32:ESP32 PCNT API 函數結構件及其它(四十二)

2018年 11月 29日 天氣報告
氣溫:21.5@ 19:40
相對濕度:百分之 68%
天氣:天色大致良好

沒有留言:

張貼留言