Hello, I'm using ESP32 WROOM32 DevKit V1 with ESP-IDF v5.5.1 and I'm having trouble getting the MCPWM to generate a pulse series. I currently create pulses on a GPIO pin with `gpio_set_level` commands, using a high time and low time I read from memory. These parameters rarely change (especially the high time). So, I want to start using the PWM module for this task, in order to free up the CPU.
In the new setup, I can compile and download the program, I get no runtime errors, and it seems to execute all the necessary commands, but the oscilloscope shows no output (whereas in the previous setup I could measure the pulses).
Here is more or less what I do.
To initialise the timer:
```
mcpwm_timer_config_t timer_config = {
.group_id = TIMER_GROUP_OUT,
.clk_src = MCPWM_TIMER_CLK_SRC_DEFAULT,
.resolution_hz = OUT_CHANNEL_CLOCK_FREQ,
.count_mode = MCPWM_TIMER_COUNT_MODE_UP,
.period_ticks = initial_period,
};
mcpwm_new_timer(&timer_config, timer);
```
To initialise the channel:
```
mcpwm_oper_handle_t oper;
mcpwm_gen_handle_t generator;
gpio_config_t io_conf = {
.pin_bit_mask = 1ULL << PULSE_OUTPUT_PIN,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = (gpio_pullup_t)1,
.pull_down_en = (gpio_pulldown_t)0,
.intr_type = GPIO_INTR_DISABLE,
};
gpio_config(&io_conf);
gpio_set_level(PULSE_OUTPUT_PIN, 0);
mcpwm_operator_config_t op_config={
.group_id=TIMER_GROUP_OUT,
.flags={
.update_gen_action_on_tez = 1,
},
};
mcpwm_new_operator(&op_config, &oper);
mcpwm_operator_connect_timer(oper, timer_handle);
mcpwm_comparator_config_t cmp_config = {
.flags = {
.update_cmp_on_tez=1,
},
};
mcpwm_new_comparator(oper, &cmp_config, comparator);
mcpwm_comparator_set_compare_value(*comparator, initial_high_time);
mcpwm_generator_config_t gen_config = {
.gen_gpio_num = PULSE_OUTPUT_PIN,
};
mcpwm_new_generator(oper, &gen_config, &generator);
mcpwm_gen_timer_event_action_t tim_action={
.direction=MCPWM_TIMER_DIRECTION_UP,
.event=MCPWM_TIMER_EVENT_EMPTY,
.action=MCPWM_GEN_ACTION_HIGH,
};
mcpwm_generator_set_action_on_timer_event(generator, tim_action);
mcpwm_gen_compare_event_action_t com_action={
.direction=MCPWM_TIMER_DIRECTION_UP,
.comparator=*comparator,
.action=MCPWM_GEN_ACTION_LOW,
};
mcpwm_generator_set_action_on_compare_event(generator, com_action);
```
To start the timer:
```
mcpwm_timer_enable(timer_handle);
mcpwm_timer_start_stop(timer_handle, MCPWM_TIMER_START_NO_STOP);
```
The plan is to then use an interrupt when I need to change the period or the high time. But I can't even get it to start producing pulses with the initial period and high time. I may be missing something obvious, but consulting the provided MCPWM example projects didn't turn up anything.
Can you help me? Thanks in advance.
No output from MCPWM
-
Vaia_Patta
- Posts: 2
- Joined: Thu Oct 02, 2025 4:21 am
Re: No output from MCPWM
Update: The problem was somehow resolved; I'm not sure how or when, because I could swear I was only changing unrelated code. I'm sorry I can't be more helpful for future users that might run into the same problem.
Who is online
Users browsing this forum: Qwantbot and 5 guests