AnsweredAssumed Answered

Need help with PWM toggle mode phase shift

Question asked by brand.christiaan on Jul 21, 2015
Hi

I have read through a couple of posts that clive1 has made regarding phase shifts in toggle mode. I need 120º shifts between each of the 3 PWM channels. I get 120º shift between channel 1 and 2, but anything more than 30º shift between channel 2 and 3 the PWM flatlines.

The code I use:

  TimerPeriod = (SystemCoreClock / 22500);
 
  Channel1Pulse = (TimerPeriod / 6);
 
  Channel2Pulse = (TimerPeriod / 6) + ((TimerPeriod * 2) / 3);
 
  Channel3Pulse = (TimerPeriod / 6) + ((TimerPeriod * 3) / 3);

  /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = TimerPeriod - 1;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  /* Channel 1, 2,3 and 4 Configuration in Toggle mode */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;

  TIM_OCInitStructure.TIM_Pulse = Channel1Pulse;
   TIM_OC1Init(TIM1, &TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
  TIM_OC2Init(TIM1, &TIM_OCInitStructure);

  TIM_OCInitStructure.TIM_Pulse = Channel3Pulse;
  TIM_OC3Init(TIM1, &TIM_OCInitStructure);

Images to illustrate what happens:
Shift of 30º - https://drive.google.com/open?id=0B9k0m1UMqSODdEdLYnpERWpLeEk
Shift of anything more - https://drive.google.com/open?id=0B9k0m1UMqSODc0NvZUxuVDV3b0U

Outcomes