Syncing Timers with MCPWM (v.4.3)

moveoverwrover
Posts: 1
Joined: Thu Jan 11, 2024 7:43 pm

Syncing Timers with MCPWM (v.4.3)

Postby moveoverwrover » Thu Jan 11, 2024 8:02 pm

I'm trying to generate 6 synchronized PWM signals. The code below generates the 6 signals at the correct frequency and duty cycle (which I can verify on a scope) but each signal is only synchronized with its pair within the same timer. For instance, MCPWM0A and MCPWM0B on MCPWM_TIMER_0 are synced, but they are not synced to the two signals on timer 1 or timer 2. I'm using the legacy MCPWM library with v4.3, but I'm willing to switch to any version that works. I'm attempting to use sync_enable on lines 38 and 39, but I know that the third parameter (sync_sig) is not set up. I would like to use an internal sync to sync all 3 timers (such as syncing Timer 1 and Timer 2 to Timer 0). I've attached images from a scope comparing MCPWM0A and MCPWM2B.
https://docs.espressif.com/projects/esp ... tml#adjust

Code: Select all

[env:esp32dev]
platform = espressif32@4.3
board = esp32dev
framework = espidf
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/mcpwm.h"
  5. #include "soc/mcpwm_periph.h"
  6.  
  7. void mcpwm_example_gpio_initialize(void)
  8. {
  9.     printf("initializing mcpwm gpio...\n");
  10.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, 18); // Channel 0: GPIO 18
  11.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0B, 15); // Channel 1: GPIO 15
  12.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1A, 21); // Channel 2: GPIO 21
  13.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM1B, 5);  // Channel 3: GPIO 5
  14.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM2A, 4); // Channel 4: GPIO 4
  15.     mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM2B, 19); // Channel 5: GPIO 19
  16. }
  17.  
  18. void app_main()
  19. {
  20.     // Initialize MCPWM GPIO
  21.     mcpwm_example_gpio_initialize();
  22.  
  23.     // Configuration for MCPWM
  24.     mcpwm_config_t pwm_config = {
  25.         .frequency = 800,    // Frequency (Hz) for channels
  26.         .cmpr_a = 50.0,      // Duty cycle for channels 0
  27.         .cmpr_b = 50.0,      // Duty cycle for channels 1
  28.         .counter_mode = MCPWM_UP_COUNTER,
  29.         .duty_mode = MCPWM_DUTY_MODE_0
  30.     };
  31.  
  32.     // Initialize MCPWM units and timers
  33.     mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config); // Timer 0 for channels 0, 1,
  34.     mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config); // Timer 1 for channels 2, 3
  35.     mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config); // Timer 2 for channels 3, 4
  36.  
  37.     //I need to synchronize all 3 of Unit 0's timers (i.e. sync timer1 and timer2 to timer0)
  38.     mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_1, 1, 0);
  39.     mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_2, 1, 0);
  40. }
  41.  
Attachments
MCPWM0A and MCPWM2B.jpg
MCPWM0A and MCPWM2B.jpg (2.51 MiB) Viewed 56847 times
MCPWM0A and MCPWM2B difference.jpg
MCPWM0A and MCPWM2B difference.jpg (2.07 MiB) Viewed 56847 times

Who is online

Users browsing this forum: No registered users and 117 guests