cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with using TIM8 for PWM

jbsnyder
Associate II
Posted on July 10, 2009 at 05:30

Trouble with using TIM8 for PWM

16 REPLIES 16
jbsnyder
Associate II
Posted on May 17, 2011 at 13:16

Hmm.. otherwise I'm not sure.

You probably shouldn't need the TIM_SetCompare1 since that should already be set with the TIM_Pulse.

Have you checked that the timer is actually running? I.e.: maybe run in a loop and get the counter value and set a pin based on that that you can check with a scope.

You could also use things like: TIM_ForcedOC1Config to see if forcing the OC state causes your PWM pin to change.

You could also try initiating an immediate update of some of the registers using: TIM_PrescalerConfig

Not sure if all of those are present in your version of the drivers.

ozenozkaya
Associate II
Posted on May 17, 2011 at 13:16

you are right! tim3 is not running;

when i watch a=TIM_GetCounter(TIM3); a is always 0. what can be the reason for TIM3 problem?

swhite
Associate III
Posted on May 17, 2011 at 13:16

Quote:

you are right! tim3 is not running;

Are the system clocks running?

Code:

<BR> // Set the AHB clock (HCLK) equal to the system clock (SYSCLK). <BR> <BR> RCC_HCLKConfig(RCC_SYSCLK_Div1); <BR> <BR> // Set the (high speed) APB2 clock (PCLK2) to the system clock. <BR> // APB2 can run up to 72MHz. <BR> <BR> RCC_PCLK2Config(RCC_HCLK_Div1); <BR> <BR> // Set the (low speed) APB1 clock (PCLK1) to the system clock/2. <BR> // APB1 can only run up to 36MHz. <BR> <BR> RCC_PCLK1Config(RCC_HCLK_Div2); <BR>

[ This message was edited by: swhite on 09-07-2009 16:58 ]

ozenozkaya
Associate II
Posted on May 17, 2011 at 13:16

yep, they all work since i can get counter values from both TIM1 and TIM2 but not TIM3.... TIM2 and TIM3 are actually very similar what is the problem with TIM3; couldnt understand...

e-design
Associate II
Posted on May 17, 2011 at 13:16

Hi ozenozkaya,

in your previous post you wrote:

''RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM3 , ENABLE);''

But TIM3 is attached to APB1 and not to APB2.

To enable the clock for TIM3 you must write:

''RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);''

Hope that helps.

Regards, Florian

ozenozkaya
Associate II
Posted on May 17, 2011 at 13:16

this works! in the configuration like: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);

gets the TIM3 value.

but; still pwm doesnt work with:

GPIO_InitTypeDef GPIO_InitStructure;

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_OCInitTypeDef TIM_OCInitStructure;

//this pin functions as AF; when remapping

GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);

//GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3, ENABLE);

/*GPIOC Configuration: TIM3 channel 1 */

/* make sure that C port is opened in RCC*/

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = 999;

TIM_TimeBaseStructure.TIM_Prescaler = 0;

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_Channel = TIM_Channel_1;

TIM_OCInitStructure.TIM_Pulse = 500;

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OCInit(TIM3, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

TIM_ARRPreloadConfig(TIM3, ENABLE);

/* TIM3 enable counter */

TIM_Cmd(TIM3, ENABLE);

thanks in advance

ozenozkaya
Associate II
Posted on May 17, 2011 at 13:16

hey guys;

all the problem was about TIM_OCInitStructure.TIM_OCPolarity...

it works fine with = TIM_OCPolarity_Low;

thanks all:)