Howto properly configure MCPWM

arnoldg
Posts: 3
Joined: Sun Sep 01, 2019 6:07 am

Howto properly configure MCPWM

Postby arnoldg » Sun Oct 13, 2019 6:50 pm

Hello,

I'm working on a leading edge dimmer, there for i would like to use the MCPWM functionality of the ESP32.
But i'm a bit stuck.

This is what i have so far:

Code: Select all

  #define GPIO_PWM0A_OUT    0
  #define GPIO_PWM0B_OUT    0
  #define GPIO_PWM1A_OUT    0
  #define GPIO_PWM1B_OUT    0
  #define GPIO_PWM2A_OUT    0
  #define GPIO_PWM2B_OUT    0
  #define GPIO_CAP0_IN      0
  #define GPIO_CAP1_IN      0
  #define GPIO_CAP2_IN      0
  #define GPIO_SYNC1_IN     0
  #define GPIO_SYNC2_IN     0
  #define GPIO_FAULT0_IN    0
  #define GPIO_FAULT1_IN    0
  #define GPIO_FAULT2_IN    0
#define GPIO_SYNC0_IN     ZCD_Pin
  //Setup MCPWM for Dimming
  mcpwm_pin_config_t pin_config = {
      .mcpwm0a_out_num = GPIO_PWM0A_OUT,
      .mcpwm0b_out_num = GPIO_PWM0B_OUT,
      .mcpwm1a_out_num = GPIO_PWM1A_OUT,
      .mcpwm1b_out_num = GPIO_PWM1B_OUT,
      .mcpwm2a_out_num = GPIO_PWM2A_OUT,
      .mcpwm2b_out_num = GPIO_PWM2B_OUT,
      .mcpwm_sync0_in_num = GPIO_SYNC0_IN,
      .mcpwm_sync1_in_num = GPIO_SYNC1_IN,
      .mcpwm_sync2_in_num = GPIO_SYNC2_IN,
      .mcpwm_fault0_in_num = GPIO_FAULT0_IN,
      .mcpwm_fault1_in_num = GPIO_FAULT1_IN,
      .mcpwm_fault2_in_num = GPIO_FAULT2_IN,
      .mcpwm_cap0_in_num = GPIO_CAP0_IN,
      .mcpwm_cap1_in_num = GPIO_CAP1_IN,
      .mcpwm_cap2_in_num = GPIO_CAP2_IN};
  mcpwm_set_pin(MCPWM_UNIT_0, &pin_config);

  // Define PWM_Out in the header file, this is the output pin to the mosfets
  mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM0A, PWM_Out);

  mcpwm_config_t pwm_config;
  pwm_config.frequency = 100; //frequency = 100Hz
  pwm_config.cmpr_a = 100;    //duty cycle of PWMxA = 60.0%
  pwm_config.counter_mode = MCPWM_UP_COUNTER;
  pwm_config.duty_mode = MCPWM_DUTY_MODE_0;
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_0, &pwm_config); //Configure PWM0A & PWM0B with above settings

  mcpwm_set_duty_type(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_OPR_A, MCPWM_DUTY_MODE_0);
  mcpwm_start(MCPWM_UNIT_0, MCPWM_TIMER_0);
  mcpwm_sync_enable(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SELECT_SYNC0, 990);
i don't what to define the unused pins, now to get the sketch compiled i set all the inputs to 0, i think that is not the right way.
I only need to set the mcpwm_sync0_in_num pin.
How can i do that ?

Who is online

Users browsing this forum: No registered users and 70 guests