2009-07-09 08:30 PM
Trouble with using TIM8 for PWM
2011-05-17 04:16 AM
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.2011-05-17 04:16 AM
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?2011-05-17 04:16 AM
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 ]2011-05-17 04:16 AM
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...
2011-05-17 04:16 AM
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, Florian2011-05-17 04:16 AM
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 advance2011-05-17 04:16 AM
hey guys;
all the problem was about TIM_OCInitStructure.TIM_OCPolarity... it works fine with = TIM_OCPolarity_Low; thanks all:)