MCPWM change TIMERn Prescaler
Posted: Wed Mar 01, 2023 9:03 pm
Hi I'm developing a motion controller using ESP32-S3 (follow-up of https://esp32.com/viewtopic.php?f=13&t=30817, that suggestion worked perfectly, thanks)
I want to change at runtime the prescaler of a timer ( while keeping the group scaler the same )
On the struct definition https://github.com/espressif/esp-idf/bl ... L35-L39C36 it is written that the timer should be started and stopped to apply the prescaler change, but even if i do nothing happen
This is an example code of what i'm trying, all other parameter are working except for the prescaler (i'm checking with oscilloscope)
What should i do to update it? Momentarily stopping the single timer is an option (but the other 2 in the group must keep working without interference)
I'm already modulating the Period of the timer, but some time I need a longer Period than the max value so I want to change the Prescaler
How can i achieve this?
Thanks,
Luca
I want to change at runtime the prescaler of a timer ( while keeping the group scaler the same )
On the struct definition https://github.com/espressif/esp-idf/bl ... L35-L39C36 it is written that the timer should be started and stopped to apply the prescaler change, but even if i do nothing happen
This is an example code of what i'm trying, all other parameter are working except for the prescaler (i'm checking with oscilloscope)
- mcpwm_config_t mcpwm_conf {
- .frequency = APB_CLK_FREQ * 2,
- .cmpr_a = 0,
- .cmpr_b = 0,
- .duty_mode = mcpwm_duty_type_t::MCPWM_DUTY_MODE_0,
- .counter_mode = mcpwm_counter_type_t::MCPWM_UP_COUNTER
- };
- ESP_ERROR_CHECK(mcpwm_init(0, 0, &mcpwm_conf));
- MCPWM0.clk_cfg.clk_prescale = ( ( ( APB_CLK_FREQ / 1000000 ) * 2 ) - 1 ); //GROUP CLOCK_IN IS 160MHz, my target is 1us x tick
- ESP_ERROR_CHECK(mcpwm_stop(0, 0));
- MCPWM0.timer[0].timer_cfg0.timer_prescale = 30; //THIS IS NOT WORKING!!!
- MCPWM0.timer[0].timer_cfg1.timer_mod = 0;
- MCPWM0.timer[0].timer_cfg0.timer_period = 5;
- //SETTING OPERATOR ACTIONS HERE
- MCPWM0.update_cfg.global_force_up = 0; //I TRIED THIS TOO
- MCPWM0.update_cfg.global_force_up = 1; //I TRIED THIS TOO
- ESP_ERROR_CHECK(mcpwm_start(0, 0));
- // DO OTHER STUFF
- // UPDATE TIMER PERIOD AGAIN
- // UPDATE TIMER PRESCALER AGAIN, NOT WORKING
- // DO OTHER STUFF AGAIN
- // UPDATE TIMER PERIOD AGAIN
- // UPDATE TIMER PRESCALER AGAIN, NOT WORKING
- // ECC
What should i do to update it? Momentarily stopping the single timer is an option (but the other 2 in the group must keep working without interference)
I'm already modulating the Period of the timer, but some time I need a longer Period than the max value so I want to change the Prescaler
How can i achieve this?
Thanks,
Luca