Minimum requirements to start the Hardware Counter
Posted: Mon Jan 23, 2017 10:00 am
Hello,
will the hardware counter start immediately when it is correct configured? Or is any trigger/start required?
In my tests the count register is always 0x0000, (not counting). I cant get it to count.
Goal of my tests was to count level changes on one gpio-pin (22).
I am not using the IDF driver.
The counter 0 is not paused. And not cleared.
I played with the counter-settings and verified them by a memory dump. My app parses the settings to the hardware.
define myS0 esp32_S0 CNT_UNIT=0&CH0_POS_MODE=inc_counter&CH0_NEG_MODE=inc_counter&CH0_HCTRL_MODE=no_modification&CH0_LCTRL_MODE=no_modification&THR_L_LIM_EN=Disabled&THR_H_LIM_EN=Disabled&THR_ZERO_EN=Disabled&THR_THRES0_EN=Disabled&THR_THRES1_EN=Disabled&FILTER_EN=Disabled
I searched for the problem. What i did before setting up counter 0 itself:
// enable the counter
SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_PCNT_CLK_EN);
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_PCNT_RST);
// config the gpio + gpio_matrix_in
pcnt_unit_t unit = 0;
pcnt_channel_t channel = 0;
int pulse_io = 22;
int ctrl_io = 21;
int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit);
int ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit);
if(pulse_io >= 0) {
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO);
gpio_set_direction(pulse_io, GPIO_MODE_INPUT);
gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
gpio_matrix_in(pulse_io, input_sig_index, 0);
}
if(ctrl_io >= 0) {
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[ctrl_io], PIN_FUNC_GPIO);
gpio_set_direction(ctrl_io, GPIO_MODE_INPUT);
gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY);
gpio_matrix_in(ctrl_io, ctrl_sig_index, 0);
}
Is this the minimum setup to start playing with the Counter?
will the hardware counter start immediately when it is correct configured? Or is any trigger/start required?
In my tests the count register is always 0x0000, (not counting). I cant get it to count.
Goal of my tests was to count level changes on one gpio-pin (22).
I am not using the IDF driver.
The counter 0 is not paused. And not cleared.
I played with the counter-settings and verified them by a memory dump. My app parses the settings to the hardware.
define myS0 esp32_S0 CNT_UNIT=0&CH0_POS_MODE=inc_counter&CH0_NEG_MODE=inc_counter&CH0_HCTRL_MODE=no_modification&CH0_LCTRL_MODE=no_modification&THR_L_LIM_EN=Disabled&THR_H_LIM_EN=Disabled&THR_ZERO_EN=Disabled&THR_THRES0_EN=Disabled&THR_THRES1_EN=Disabled&FILTER_EN=Disabled
I searched for the problem. What i did before setting up counter 0 itself:
// enable the counter
SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_PCNT_CLK_EN);
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_PCNT_RST);
// config the gpio + gpio_matrix_in
pcnt_unit_t unit = 0;
pcnt_channel_t channel = 0;
int pulse_io = 22;
int ctrl_io = 21;
int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit);
int ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit);
if(pulse_io >= 0) {
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO);
gpio_set_direction(pulse_io, GPIO_MODE_INPUT);
gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
gpio_matrix_in(pulse_io, input_sig_index, 0);
}
if(ctrl_io >= 0) {
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[ctrl_io], PIN_FUNC_GPIO);
gpio_set_direction(ctrl_io, GPIO_MODE_INPUT);
gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY);
gpio_matrix_in(ctrl_io, ctrl_sig_index, 0);
}
Is this the minimum setup to start playing with the Counter?