2018年11月30日 星期五

DIY - ESP32:ESP32 PCNT API 函數結構件及其它(四十二)

DIY - ESP32:ESP32 PCNT API 函數結構件及其它(四十二):

除了 ESP32 PCNT(Pulse Counter / 脈衝計數器)API 函數模塊外,還提供了結構件(Structures)、巨集(Marco)、 泛型型別定義(Type Definitions)和枚舉(Enumerations)。

1. Structure
1.1. struct pcnt_config_t
Pulse Counter configuration for a single channel.
Public Members
Description
int pulse_gpio_num
Pulse input GPIO number, if you want to use GPIO16, enter pulse_gpio_num = 16, a negative value will be ignored
int ctrl_gpio_num
Control signal input GPIO number, a negative value will be ignored
pcnt_ctrl_mode_t lctrl_mode
PCNT low control mode
pcnt_ctrl_mode_t hctrl_mode
PCNT high control mode
pcnt_count_mode_t pos_mode
PCNT positive edge count mode
pcnt_count_mode_t neg_mode
PCNT negative edge count mode
int16_t counter_h_lim
Maximum counter value
int16_t counter_l_lim
Minimum counter value
pcnt_unit_t unit
PCNT unit number
pcnt_channel_t channel
the PCNT channel

範例:

pcnt_config_t pcnt_config = {

.pulse_gpio_num = 4,              //set gpio4 as pulse input gpio
.ctrl_gpio_num = 5,                 //set gpio5 as control gpio
.channel = PCNT_CHANNEL_0,                    //use unit 0 channel 0
.lctrl_mode = PCNT_MODE_REVERSE,        //when control signal is low, reverse the primary counter mode(inc->dec/dec->inc)
.hctrl_mode = PCNT_MODE_KEEP,   //when control signal is high, keep the primary counter mode
.pos_mode = PCNT_COUNT_INC,     //increment the counter
.neg_mode = PCNT_COUNT_DIS,     //keep the counter value
.counter_h_lim = 10,
.counter_l_lim = -10,
};

2. Macros
Macros
Description
PCNT_PIN_NOT_USED
When selected for a pin, this pin will not be used

3. Type Definitions
Type Definitions
Description
typedef intr_handle_t pcnt_isr_handle_t

4. Enumerations
4.1. enum pcnt_ctrl_mode_t
Selection of available modes that determine the counter’s action depending on the state of the control signal’s input GPIO.
NoteConfiguration covers two actions, one for high, and one for low level on the control input
Enumeration
Description
PCNT_MODE_KEEP = 0
Control mode: won’t change counter mode
PCNT_MODE_DISABLE = 1
Control mode: invert counter mode(increase -> decrease, decrease -> increase)
PCNT_MODE_DISABLE = 2
Control mode: Inhibit counter(counter value will not change in this condition)
PCNT_MODE_MAX

4.2. enum pcnt_count_mode_t
Selection of available modes that determine the counter’s action on the edge of the pulse signal’s input GPIO.
NoteConfiguration covers two actions, one for positive, and one for negative edge on the pulse input
Enumeration
Description
PCNT_COUNT_DIS = 0
Counter mode: Inhibit counter(counter value will not change in this condition)
PCNT_COUNT_INC = 1
Counter mode: Increase counter value
PCNT_COUNT_DEC = 2
Counter mode: Decrease counter value
PCNT_COUNT_MAX

4.3. enum pcnt_unit_t
Selection of all available PCNT units.
Enumeration
Description
PCNT_UNIT_0 = 0
PCNT unit 0
PCNT_UNIT_1 = 1
PCNT unit 1
PCNT_UNIT_2 = 2
PCNT unit 2
PCNT_UNIT_3 = 3
PCNT unit 3
PCNT_UNIT_4 = 4
PCNT unit 4
PCNT_UNIT_5 = 5
PCNT unit 5
PCNT_UNIT_6 = 6
PCNT unit 6
PCNT_UNIT_7 = 7
PCNT unit 7
PCNT_UNIT_MAX

4.4. enum pcnt_channel_t
Selection of channels available for a single PCNT unit.
Enumeration
Description
PCNT_CHANNEL_0 = 0x00
PCNT channel 0
PCNT_CHANNEL_1 = 0x01
PCNT channel 1
PCNT_CHANNEL_MAX

4.5. enum pcnt_evt_type_t
Selection of counter’s events the may trigger an interrupt.
Enumeration
Description
PCNT_EVT_L_LIM = 0
PCNT watch point event: Minimum counter value
PCNT_EVT_H_LIM = 1
PCNT watch point event: Maximum counter value
PCNT_EVT_THRES_0 = 2
PCNT watch point event: threshold0 value event
PCNT_EVT_THRES_1 = 3
PCNT watch point event: threshold1 value event
PCNT_EVT_ZERO = 4
PCNT watch point event: counter value zero event
PCNT_EVT_MAX
PCNT unit 5


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

2018年 11月 30日 天氣報告
氣溫:22.1@ 22:00
相對濕度:百分之 64%
天氣:大致多雲

沒有留言:

張貼留言