cancel
Showing results for 
Search instead for 
Did you mean: 

PWM same Dutycycle, different starttime (Phaseshift)

markus23
Associate
Posted on August 26, 2013 at 14:21

0690X000006050PQAQ.png

Hello,

is it possible to configure the PWM Outputs to drive all three Channels with the same Dutycycle, but starting delayed (Phaseshifted)?

I configured the PWMs with a common Timebase TIM1.

Is there a chance to use a second timer to generate the delay, maybe by manipulating the countingregisters?

#pwm-phaseshift
9 REPLIES 9
florentino
Associate
Posted on September 17, 2013 at 05:03

I am also trying to accomplish what you were trying and I am wondering if you were able to do it. If you did, could you please explain how you did it?

Thanks

Posted on September 17, 2013 at 14:48

Well, your alternatives would seem to be using the toggle mode with CCRx placed at 120 degree shifts, or updating CCRx values actively during each CCx interrupt.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
florentino
Associate
Posted on September 17, 2013 at 17:23

Thanks for the reply Clive.

Creating the phase shift is what I am having trouble understanding, by any chance you have some sample code to create a phase shift? By the way, could this be accomplished using one timer only or I need a timer for each PWM?

Thanks

Posted on September 17, 2013 at 18:28

The thing to remember is each timer has a SINGLE counting element. If your speed requirements are sufficiently slow you can advance CCRx compare points in an interrupt, and control phase, duty and frequency. Toggle mode is particularly helpful here as it allows hard edge placement, and some latency in the interrupt processing.

I posted a toggle mode quadrature example recently, but that's two channels from a single timer with a 90 degree phase shift.

In terms of understanding the timers there is the documentation, and example code in the library. The timers are complex, I don't pretend to know all the features/limitations.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 17, 2013 at 18:38

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/quadrature%20output%20-%20STM32F407&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=71]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fquadrature%20output%20-%20STM32F407&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FAllItems.aspx¤tviews=71

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 18, 2013 at 02:26

// STM32F4-Discovery TIM4 Triphase Output PD.12, PD.13 and PD.14 - sourcer32@gmail.com
#include ''stm32f4xx.h''
//******************************************************************************
void RCC_Configuration(void)
{
/* enable peripheral clock for TIM4 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* GPIOD clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
}
//******************************************************************************
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIOD Configuration: TIM4 on PD12/PD13/PD14 LED */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect TIM4 pin */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4); // PD12 TIM4_CH1 GREEN
GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4); // PD13 TIM4_CH2 ORANGE
GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_TIM4); // PD13 TIM4_CH3 RED
}
//******************************************************************************
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
int Prescaler, Period;
Prescaler = ((SystemCoreClock / 2) / 360000); // ~360 KHz timebase, assumes APB1 H/4 TIMCLK4 H/2
Period = 36000; // ~10 Hz -> ~ 5 Hz
// The toggle halves the frequency
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = Period - 1;
TIM_TimeBaseStructure.TIM_Prescaler = Prescaler - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* Output Compare Toggle Mode configuration: Channel 1, 2 and 3 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
/* Don't want to set 0 or Period, but have 3 points at 120 degrees from each other */
TIM_OCInitStructure.TIM_Pulse = ((Period * 1) / 3) - 1;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = ((Period * 2) / 3) - 1;
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = ((Period * 3) / 3) - 1;
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
}
//******************************************************************************
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
TIM4_Configuration();
while(1); /* Infinite loop */
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
feliphe
Associate
Posted on March 08, 2016 at 13:33

Hi guys,

I am developing one of my first projects using an STM32 microcontroller. It is a sensorless brushless gimbal, where I am going to use a IMU sensor as feedback to control the rotor position.

For now I am trying to at least power on the motor and make it rotate for a little bit. I am using the STM32F100RB board and the L6234 (3 phase half bridge driver). 

What libraries should I download from ST or how can I change the code you posted in order to make ir work in the STM32F100RB.

Thank you,

Feliphe

Posted on March 08, 2016 at 15:12

This code uses the Standard Peripheral Library (SPL) relatively portable across families, perhaps you can start with that?

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257890

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on March 08, 2016 at 17:05

Hi goncalves_galiza.fel, 

For the STM32 libraries, there is :

- The old standard peripheral library that you can download it here 

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257890

- The new Hal library that you can download it from here 

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897/PF260820

The STdPeriph contains more Timer examples that can help you and get inspiration to achieve you goal. from this path: STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\TIM

The 

http://www.st.com/web/en/resource/technical/document/reference_manual/CD00246267.pdf

 and 

http://www.st.com/web/en/resource/technical/document/datasheet/CD00251732.pdf

will be your support for details/clarification.

Also, you can get further information from the Timer overview Application note 

http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf

-Hannibal-