Page 1 of 1

MCPWM Sync issue

Posted: Wed Feb 02, 2022 7:00 am
by Alphabetix
Hey folks, I'm having two issues after upgrading via board manager to v2.0.2

I've fiddled for a few hours but I am stuck. The documentation is a bit "light" on syncing and I'm unable to find any v2 examples. I don't believe the code below is doing anything :D

Three outputs on

Code: Select all

  
  mcpwm_config_t pwm_config;
  
  pwm_config.frequency = PULSE_FREQUENCY;
  pwm_config.cmpr_a = 50.0;
  pwm_config.cmpr_b = 50.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);
  pwm_config.cmpr_a = 5.0;
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config);
  
  mcpwm_sync_config_t sync_config;

  sync_config.sync_sig = MCPWM_SELECT_TIMER0_SYNC;
  sync_config.timer_val = 0;
  sync_config.count_direction = MCPWM_TIMER_DIRECTION_UP;

  mcpwm_sync_configure(MCPWM_UNIT_0,MCPWM_TIMER_1, &sync_config);
  mcpwm_sync_configure(MCPWM_UNIT_0,MCPWM_TIMER_2, &sync_config);

  MCPWM0.timer[1].timer_sync.timer_synci_en = 1;
  delayMicroseconds(1000);
  MCPWM0.timer[1].timer_sync.timer_synci_en = 0;

  MCPWM0.timer[2].timer_sync.timer_synci_en = 1;
  delayMicroseconds(1000);
  MCPWM0.timer[2].timer_sync.timer_synci_en = 0;
Neither MCPWM_TIMER_1 nor MCPWM_TIMER_2 is syncing with MCPWM_TIMER_0.

Also, changing the value of

Code: Select all

sync_config.timer_val = 0;
does not affect the phase for either timer.

So, has anyone any ideas on why nothing is syncing?

Thanks :)

Re: MCPWM Sync issue

Posted: Fri Feb 04, 2022 1:43 am
by Alphabetix
For anyone interested, after pulling the mcpwm library apart, I found out what was wrong. Added the following line

mcpwm_set_timer_sync_output(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SWSYNC_SOURCE_TEZ);

Code: Select all

mcpwm_config_t pwm_config;
  
  pwm_config.frequency = PULSE_FREQUENCY;
  pwm_config.cmpr_a = 50.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);
  pwm_config.cmpr_a = 5.0;
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_1, &pwm_config);
  mcpwm_init(MCPWM_UNIT_0, MCPWM_TIMER_2, &pwm_config);

  mcpwm_set_timer_sync_output(MCPWM_UNIT_0, MCPWM_TIMER_0, MCPWM_SWSYNC_SOURCE_TEZ);   

  mcpwm_sync_config_t sync_config;

  sync_config.sync_sig = MCPWM_SELECT_TIMER0_SYNC;
  sync_config.timer_val = 0;
  sync_config.count_direction = MCPWM_TIMER_DIRECTION_UP;

  mcpwm_sync_configure(MCPWM_UNIT_0,MCPWM_TIMER_1, &sync_config);
  mcpwm_sync_configure(MCPWM_UNIT_0,MCPWM_TIMER_2, &sync_config);