Skip to main content
Associate II
June 9, 2025
Question

How to Synchronize PWM Channels from Different eMIOS in SPC58?

  • June 9, 2025
  • 0 replies
  • 350 views

Hello everyone,

I'm working with SPC58 microcontrollers and configuring 6 PWM channels using different eMIOS. The PWM channels within the same eMIOS are properly synchronized, but the channels from a different eMIOS are not synchronized as expected.

I have attached a figure illustrating the issue. How can I configure the PWM channels from different eMIOS to ensure proper synchronization? Are there specific settings or registers I should adjust?

Any insights or recommendations would be greatly appreciated.

Thank you in advance!

#define kPWM_PWMPERIOD (5000U) /* 50% */
#define DEADTIME_BASE (10U)
#define DELAY_BASE DEADTIME_BASE / 2


void PWM_start(PWMDriver *pwmp, PWMConfig *config)
{
 pwm_lld_start(pwmp, config);
}

void PWM_setDutyCycle(PWMDriver *pwmp, pwmchannel_t channel, pwmcnt_t width, pwmcnt_t deadTime, pwmcnt_t delay)
{
 pwm_lld_enable_channel(pwmp, channel, PWM_PERCENTAGE_TO_WIDTH(pwmp, width), deadTime, delay, 0);
}

void PWMConfig(void)
{
 PWMconfig[kWH1_ID] = (PWM_Config_t){&PWMD12, CH_WH1}; /* eMIOS 1 Channel 3 */
 PWMconfig[kWL1_ID] = (PWM_Config_t){&PWMD12, CH_WL1}; /* eMIOS 1 Channel 5 */
 PWMconfig[kWH2_ID] = (PWM_Config_t){&PWMD19, CH_WH2}; /* eMIOS 2 Channel 29 */
 PWMconfig[kWL2_ID] = (PWM_Config_t){&PWMD12, CH_WL2}; /* eMIOS 1 Channel 1 */
 PWMconfig[kWH3_ID] = (PWM_Config_t){&PWMD17, CH_WH3}; /* eMIOS 2 Channel 11 */
 PWMconfig[kWL3_ID] = (PWM_Config_t){&PWMD12, CH_WL3}; /* eMIOS 1 Channel 2 */

 /* Initialize and enable the PWM driver.*/
 PWM_start(&PWMD12, &pwm_config_PWM_MOTOR_CONFIG_emios1);
 PWM_start(&PWMD17, &pwm_config_PWM_MOTOR_CONFIG_emios2);
 PWM_start(&PWMD19, &pwm_config_PWM_MOTOR_CONFIG_emios2);

 PWM_setDutyCycle(PWMconfig[kWH1_ID].pPWMd, PWMconfig[kWH1_ID].PWMchannel, kPWM_PWMPERIOD, DEADTIME_BASE, 0); /* eMIOS 1 Channel 3 */
 PWM_setDutyCycle(PWMconfig[kWL1_ID].pPWMd, PWMconfig[kWL1_ID].PWMchannel, kPWM_PWMPERIOD, 0, DELAY_BASE); /* eMIOS 1 Channel 5 */
 PWM_setDutyCycle(PWMconfig[kWH2_ID].pPWMd, PWMconfig[kWH2_ID].PWMchannel, kPWM_PWMPERIOD, DEADTIME_BASE, 0); /* eMIOS 2 Channel 29 */
 PWM_setDutyCycle(PWMconfig[kWL2_ID].pPWMd, PWMconfig[kWL2_ID].PWMchannel, kPWM_PWMPERIOD, 0, DELAY_BASE); /* eMIOS 1 Channel 1 */
 PWM_setDutyCycle(PWMconfig[kWH3_ID].pPWMd, PWMconfig[kWH3_ID].PWMchannel, kPWM_PWMPERIOD, DEADTIME_BASE, 0); /* eMIOS 2 Channel 11 */
 PWM_setDutyCycle(PWMconfig[kWL3_ID].pPWMd, PWMconfig[kWL3_ID].PWMchannel, kPWM_PWMPERIOD, 0, DELAY_BASE); /* eMIOS 1 Channel 2 */
}

Image20250609131049.jpg