/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / PWM Time shifting signal

Username:     
Password:     
             

Forum

# 1   2013-01-10 10:24:30 PWM Time shifting signal

waytae
New member
Registered: 2013-01-10
Posts: 1

PWM Time shifting signal

Hi,

I program a PWM signal in PB4 port using TIM3 using this program

int main (void)
{
while(1)
{
TIM3->CCR1 = 1000 ;       
}
}

/*____________________________TIM3______________________________*/
  /* TIM3 clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  /* GPIOB Clock  */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_0 | GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_TIM3);
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_TIM3);
//________________________________________________________________
/*__________________________TIM3____________________________________*/

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 1999;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: Channel1 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC1Init(TIM3, &TIM_OCInitStructure);
  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC2Init(TIM3, &TIM_OCInitStructure);
  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel3 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC3Init(TIM3, &TIM_OCInitStructure);
  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);

  /* PWM1 Mode configuration: Channel4 */
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 0;
  TIM_OC4Init(TIM3, &TIM_OCInitStructure);
  TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
  TIM_ARRPreloadConfig(TIM3, ENABLE);


  /* TIM3 enable counter */
  TIM_Cmd(TIM3, ENABLE);
//________________________________________________________________


It gives a PWM with 50% Duty Cycle

I want to shift time of this signal like this

https://my.st.com/public/STe2ecommunities/ImageLibrary/images.jpeg

I have already Signal 1 i want to create Signal 2 shifted by period T

https://my.st.com/public/STe2ecommunities/ImageLibrary/sigops1.png

What parameter have i to change ?

i try to change

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

from 0 to 1 the signal change but i don't understand the ClockDivision   effect

What is the ClockDivision  interval variation to shift signal ?

Thanks smile

Offline

 

# 2   2013-01-14 15:11:15 PWM Time shifting signal

Etienne.C
Administrator
Registered: 2012-12-04
Posts: 71

Re: PWM Time shifting signal

Hello,

If you change TIM_TimeBaseStructure.TIM_ClockDivision  to 1 you will just change the frequency.
To change the phase it's more complex, I suggest you to read the ST documentation that you can find in our Ride documentation: STM32F10xxx_reference_manual.pdf (p282).
Also you can have a look of the ST forum.

Regards,

Etienne

Offline

 

Board footer