cancel
Showing results for 
Search instead for 
Did you mean: 

how to generate phase shifted PWM using STM32F334?

Posted on March 01, 2017 at 05:51

we are trying to implement full bridge phase shifted DC DC converter using STM32F334. All examples show control of duty cycle. Can someone provide examples of phase shift variation?

Thanks 

Regards

Anusha

3 REPLIES 3
Posted on March 01, 2017 at 23:17

You mean two waveforms of the same period and duty cycle, but mutually phase shifted?

  1. Chose two timers, let's denote them A and B, so that they can be linked, timer A be master of timer B (see the table at TIMx_SMCR for timers linking)
  2. Enable output pins for say CH1 on both timers
  3. Set up required period in timer A. Set timer B to maximum period
  4. Set both timers to output compare, PWM mode, and set the TIMx_CCR1 register to the same value (say, 1/3 of ARR for a starting value) and enable output compare output in both.
  5. In timer A, set say CH2 to the desired phase difference (say 2/3 of ARR). Set CH2 to output compare. Select CH2 compare as TRGO.
  6. In timer B, set slave mode to reset, and select timer A as TRGI source.
  7. Enable both timers.
  8. Observe and enjoy 😉

JW

Posted on March 02, 2017 at 05:52

Thanks JW.

I will check and get back  

Regards

Anusha

Posted on May 31, 2017 at 19:15

Ramachandran.Anusha

you can generate phase-shifted PWM signals with 2 different ways :

1) You can use the feature : Output toggle which can generate up to 4 phase-shifted PWM signals with controlled shift but all signals have the same duty-cycle which is 50%.

2) You can as a second alternative generate 2 phase-shifted PWM signals with controlled shift and duty-cycle : of course, signals have the same frequency which is the mainTimer frequency.

Here you can find a configuration of the asymmetric PWM mode in the STM32F7 microcontroller :

For further information you can look at the reference manual the application note and the datasheet. You can make the same configuration in your STM32F334 but you should look before at the datasheet to configure pins correctly.

/*************************** Author : Omar Bouzourraa ********************/

/*!< At this stage I am going to configure TIM4 in PWM output Asymmetric mode

using registers' direct access.

In the datasheet of the stm32f7xx microcontroller, user can find that

the TIM4 channels are connected to PB6,PB7,PB8,PB9 and can be remapped

to PD12,PD13,PD14,PD In this program, TIM4 channels will be connected

to their default pins.

!!!! Source clock for the counter is the internal main clock coming from RCC

*/

/* Enabling GPIOB by configuring RCC_AHB1ENR which enables the GPIOB clock*/

RCC->AHB1ENR |= 1<<1;

/* Enabling TIM4 clock by configuring ther RCC-APB1ENR */

RCC->APB1ENR |= 1<<2;

/*************************************************************************/

/* selecting AF mode*/

GPIOB->MODER |= (2<<(2*6)) + (2<<(2*7)) + (2<<(2*8)) + (2<<(2*9));

/* Selecting output type : push-pull is selected in order to have more current in output*/

GPIOB->OTYPER = 0;

/* Selecting Output Speed : very high speed */

GPIOB->OSPEEDR = (3<<(2*6)) + (3<<(2*7)) + (3<<(2*8)) + (3<<(2*9));

/* TIM4 is connected to Alternate function 2*/

/* Connectinng GPIOB : PB6,PB7,PB8,PB9 to alternate function 2*/

GPIOB->AFR[0] = (2<<(4*6)) + (2<<(4*7));

GPIOB->AFR[1] = (2<<(4*0)) + (2<<(4*1));

/**************************************************************************/

/* Configuration of TIM4 Time-base*/

/*Timer_frequency = APB1_frequency/((1 + prescaler value)(1 + Timer period)*2

!!! When Asymmetric mode is configured,

*/

/* period configuration*/

TIM4->ARR = 0xFFFF;

/* Prescaler configuration*/

TIM4->PSC = 0;

/* configuration of CC1 in channel 1 : PB6*/

TIM4->CCR1 = (int)(0.4*TIM4->ARR);

/* configuration of CC2 in channel 2 : PB7*/

TIM4->CCR2 = (int)(0.6*TIM4->ARR);

/* configuration of CC3 in channel 3 : PB8*/

TIM4->CCR3 = (int)(0.8*TIM4->ARR);

/* configuration of CC4 in channel 4 : PB9*/

TIM4->CCR4 = (int)(0.8*TIM4->ARR);

/*

PWM in channel1 : PB6 will have a duty-cycle (0.4 + 0.6)/2 = 0.5 = 50%

PWM in channel3 : PB8 will have a duty-cycle (0.8 + 0.8)/2 = 0.6 = 60%

Signal in channel3 is shifted with an angle theta = (0.8 - 0.4)*360 = 144°

*/

/*************************************************************************/

/* Timer mode and counter configuration */

/* Enable TIM4 counter and configure counting mode as center-aligned mode1 : mode1,mode2,or mode3 will give the same wave form */

TIM4->CR1 |= 1 + (1<<5);

/* Configure TIM4_CH1,CH2,CH3 and CH4 as output and configure the asymmetric mode1 : Actually there is also mode2 */

TIM4->CCMR1 |= (0xE<<12) + (0xE<<4); //TIM_CH1 and CH2 config

TIM4->CCMR2 |= (0xE<<12) + (0xE<<4); //TIM_CH3 and CH4 config

/* Enable output on CH1,CH2,CH3 and CH4 and configure polarity as high in all channels*/

TIM4->CCER |= (1<<0) + (1<<4) +(1<<8) +(1<<12);