cancel
Showing results for 
Search instead for 
Did you mean: 

Timer change output compare mode to PWM

sebastianr
Associate II
Posted on February 15, 2012 at 16:19

Hello,

I want to use a a advanced control timer (TIM8) of my STM32F103ZG (on STM3210E-EVAL) for motor control. I have problems generating the PWM signal at the right time. I initialize the timer the same way as in the 6-step example out of the std. peripherals lib examples, i.e.:

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;

Later I try to start the PWM output mode with:

TIM_SelectOCxM(TIM8, TIM_Channel_1, TIM_OCMode_PWM1);

TIM_CCxCmd(TIM8, TIM_Channel_1, TIM_CCx_Enable);

This has no effect. When I use

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

instead in the init phase, then PWM output works. I use an oscilloscope for verification.

Thanks.

best regards,

sebastian
3 REPLIES 3
pentti
Associate II
Posted on February 16, 2012 at 11:24

Hi Sebastian, I had the same problem.  Solution is that you should be also change to PORT and PIN.

You can find right port and pins the next Document ID 15818 Rev 8 table 7.

If you want to use timer 8, using port C and pin numbers 6(channel 1),7(channel 2),8(channnel 3) and 9(channel 4). 

And remember that those pins are also connected to timer 3. 

BR:

   Pentti

sebastianr
Associate II
Posted on February 16, 2012 at 13:02

Hi,

I don't understand exactly what you mean. The appropriate GPIOs are already configured correctly for alternate function, e.g.

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

What else do  have to do with them? In the 6-step commutation example delivered with the std peripheral lib, I cant find more information, too.

regards,

sebastian

pentti
Associate II
Posted on February 17, 2012 at 07:00

Hi Sebastian, if you want to use timer 8 the you have to use Port C.  Channel 1 is connected to port C pin 6, channel 2-> PC7, channel 3-> PC8 and channel 4-> PC9.