mcpwm: fix the fault handling and capture issues
1. The fault signal 3 for unit 2 is corrected to the right value 2. Now `mcpwm_fault_set_oneshot_mode` will clear the status before, no need to reset the peripheral. 3. The capture feature relies on the prescaler, but it's only initialized in the mcpwm_init funciton, which is used to initialize a PWM channel. This means, the capture may not work correctly if no PWM channel is enabled. Now the prescaler is also updated when `mcpwm_capture_enable` is called.
This commit is contained in:
parent
3c6f992cf0
commit
919dbdd170
1 changed files with 7 additions and 1 deletions
|
@ -79,7 +79,7 @@ esp_err_t mcpwm_gpio_init(mcpwm_unit_t mcpwm_num, mcpwm_io_signals_t io_signal,
|
|||
MCPWM_CHECK((GPIO_IS_VALID_OUTPUT_GPIO(gpio_num)), MCPWM_GPIO_ERROR, ESP_ERR_INVALID_ARG);
|
||||
gpio_set_direction(gpio_num, GPIO_MODE_OUTPUT);
|
||||
gpio_matrix_out(gpio_num, PWM1_OUT0A_IDX + io_signal, 0, 0);
|
||||
} else if (io_signal >= MCPWM_SYNC_0 && io_signal < MCPWM_FAULT_2) {
|
||||
} else if (io_signal >= MCPWM_SYNC_0 && io_signal <= MCPWM_FAULT_2) {
|
||||
gpio_set_direction(gpio_num, GPIO_MODE_INPUT);
|
||||
gpio_matrix_in(gpio_num, PWM1_SYNC0_IN_IDX + io_signal - OFFSET_FOR_GPIO_IDX_1, 0);
|
||||
} else {
|
||||
|
@ -625,6 +625,9 @@ esp_err_t mcpwm_fault_set_oneshot_mode(mcpwm_unit_t mcpwm_num, mcpwm_timer_t tim
|
|||
MCPWM_CHECK(mcpwm_num < MCPWM_UNIT_MAX, MCPWM_UNIT_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
MCPWM_CHECK(timer_num < MCPWM_TIMER_MAX, MCPWM_TIMER_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&mcpwm_spinlock);
|
||||
//clear the ost triggered status
|
||||
MCPWM[mcpwm_num]->channel[timer_num].tz_cfg1.clr_ost = 1;
|
||||
MCPWM[mcpwm_num]->channel[timer_num].tz_cfg1.clr_ost = 0;
|
||||
if (fault_sig == MCPWM_SELECT_F0) {
|
||||
MCPWM[mcpwm_num]->channel[timer_num].tz_cfg0.f0_ost = 1;
|
||||
MCPWM[mcpwm_num]->channel[timer_num].tz_cfg0.f0_cbc = 0;
|
||||
|
@ -656,6 +659,9 @@ esp_err_t mcpwm_capture_enable(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t ca
|
|||
{
|
||||
MCPWM_CHECK(mcpwm_num < MCPWM_UNIT_MAX, MCPWM_UNIT_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&mcpwm_spinlock);
|
||||
//We have to do this here, since there is no standalone init function
|
||||
//without enabling any PWM channels.
|
||||
MCPWM[mcpwm_num]->clk_cfg.prescale = MCPWM_CLK_PRESCL;
|
||||
MCPWM[mcpwm_num]->cap_timer_cfg.timer_en = 1;
|
||||
MCPWM[mcpwm_num]->cap_cfg_ch[cap_sig].en = 1;
|
||||
MCPWM[mcpwm_num]->cap_cfg_ch[cap_sig].mode = (1 << cap_edge);
|
||||
|
|
Loading…
Reference in a new issue