PCNT中断注册失败
Posted: Thu Feb 17, 2022 8:43 am
下午好,我现在按照官方的pulse_count_event历程,注册中断失败
\0x1b[0;31mE (15294) pcnt: pcnt isr registration failed, maybe you need `pcnt_isr_unregister` to unregister your isr\0x1b[0m
\0x1b[0;31mE (15294) pcnt: _pcnt_isr_handler_add(252): ISR service is not installed, call pcnt_install_isr_service() first\0x1b[0m
\0x1b[0;31mE (15304) pcnt: pcnt isr registration failed, maybe you need `pcnt_isr_unregister` to unregister your isr\0x1b[0m
\0x1b[0;31mE (15314) pcnt: _pcnt_isr_handler_add(252): ISR service is not installed, call pcnt_install_isr_service() first\0x1b[0m
下面源代码,麻烦给看下,谢谢
static void pcnt_example_init(int unit,int channel, int pin)
{
/* Prepare configuration for the PCNT unit */
pcnt_config_t pcnt_config = {
// Set PCNT input signal and control GPIOs
.pulse_gpio_num = pin,//PCNT_INPUT_SIG_IO0
//.ctrl_gpio_num = PCNT_INPUT_CTRL_IO,
.channel = channel,//PCNT_CHANNEL_0,
.unit = unit,
// What to do on the positive / negative edge of pulse input?
.pos_mode = PCNT_COUNT_INC, // Count up on the positive edge
.neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge
// What to do when control input is low or high?
.lctrl_mode = PCNT_MODE_KEEP, // Reverse counting direction if low
.hctrl_mode = PCNT_MODE_KEEP, // Keep the primary counter mode if high
// Set the maximum and minimum limit values to watch
.counter_h_lim = 5,
.counter_l_lim = 0,
};
/* Initialize PCNT unit */
pcnt_unit_config(&pcnt_config);
/* Configure and enable the input filter */
pcnt_set_filter_value(unit, 100);//100
pcnt_filter_enable(unit);
/* Set threshold 0 and 1 values and enable events to watch */
// pcnt_set_event_value(unit, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
// pcnt_event_enable(unit, PCNT_EVT_THRES_1);
// pcnt_set_event_value(unit, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
// pcnt_event_enable(unit, PCNT_EVT_THRES_0);
/* Enable events on zero, maximum and minimum limit values */
pcnt_event_enable(unit, PCNT_EVT_ZERO);
pcnt_event_enable(unit, PCNT_EVT_H_LIM);
// pcnt_event_enable(unit, PCNT_EVT_L_LIM);
/* Initialize PCNT's counter */
pcnt_counter_pause(unit);
pcnt_counter_clear(unit);
/* Install interrupt service and add isr callback handler */
pcnt_isr_service_install(0);
pcnt_isr_handler_add(unit, pcnt_example_intr_handler, (void *)unit);
// pcnt_isr_register(pcnt_example_intr_handler, NULL, 0, &user_isr_handle);
// pcnt_intr_enable(unit);
/* Everything is set up, now go to counting */
pcnt_counter_resume(unit);
}
\0x1b[0;31mE (15294) pcnt: pcnt isr registration failed, maybe you need `pcnt_isr_unregister` to unregister your isr\0x1b[0m
\0x1b[0;31mE (15294) pcnt: _pcnt_isr_handler_add(252): ISR service is not installed, call pcnt_install_isr_service() first\0x1b[0m
\0x1b[0;31mE (15304) pcnt: pcnt isr registration failed, maybe you need `pcnt_isr_unregister` to unregister your isr\0x1b[0m
\0x1b[0;31mE (15314) pcnt: _pcnt_isr_handler_add(252): ISR service is not installed, call pcnt_install_isr_service() first\0x1b[0m
下面源代码,麻烦给看下,谢谢
static void pcnt_example_init(int unit,int channel, int pin)
{
/* Prepare configuration for the PCNT unit */
pcnt_config_t pcnt_config = {
// Set PCNT input signal and control GPIOs
.pulse_gpio_num = pin,//PCNT_INPUT_SIG_IO0
//.ctrl_gpio_num = PCNT_INPUT_CTRL_IO,
.channel = channel,//PCNT_CHANNEL_0,
.unit = unit,
// What to do on the positive / negative edge of pulse input?
.pos_mode = PCNT_COUNT_INC, // Count up on the positive edge
.neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge
// What to do when control input is low or high?
.lctrl_mode = PCNT_MODE_KEEP, // Reverse counting direction if low
.hctrl_mode = PCNT_MODE_KEEP, // Keep the primary counter mode if high
// Set the maximum and minimum limit values to watch
.counter_h_lim = 5,
.counter_l_lim = 0,
};
/* Initialize PCNT unit */
pcnt_unit_config(&pcnt_config);
/* Configure and enable the input filter */
pcnt_set_filter_value(unit, 100);//100
pcnt_filter_enable(unit);
/* Set threshold 0 and 1 values and enable events to watch */
// pcnt_set_event_value(unit, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
// pcnt_event_enable(unit, PCNT_EVT_THRES_1);
// pcnt_set_event_value(unit, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
// pcnt_event_enable(unit, PCNT_EVT_THRES_0);
/* Enable events on zero, maximum and minimum limit values */
pcnt_event_enable(unit, PCNT_EVT_ZERO);
pcnt_event_enable(unit, PCNT_EVT_H_LIM);
// pcnt_event_enable(unit, PCNT_EVT_L_LIM);
/* Initialize PCNT's counter */
pcnt_counter_pause(unit);
pcnt_counter_clear(unit);
/* Install interrupt service and add isr callback handler */
pcnt_isr_service_install(0);
pcnt_isr_handler_add(unit, pcnt_example_intr_handler, (void *)unit);
// pcnt_isr_register(pcnt_example_intr_handler, NULL, 0, &user_isr_handle);
// pcnt_intr_enable(unit);
/* Everything is set up, now go to counting */
pcnt_counter_resume(unit);
}