Question
STM32F100 Timer-Clock
Posted on November 12, 2011 at 15:41
Hello forum!
I'm trying to get familiar with the timers in the STM32 but now I got stuck at a problem I can't solve, first here's the concerned function: void TIM4_Configuration(void) { /* Compute the prescaler value -> @24MHz Prescaler = 0 */ int PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); /* TIM4 PWM2 Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 15535; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM4, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable); /* OPM Bit -> Only one pulse */ TIM4->CR1 |= (1 << 3); /* TIM3 enable counter */ TIM_Cmd(TIM4, ENABLE); } The purpose of this code is generating a pulse with a certain width ( TIMx_ARR - TIMx_CCR1 says the reference-manual, that means TIM_Period - TIM_Pulse using the library-structures , at least I think so :) ). My problem now is that the pulse width is exact three times longer than the calculation says. A example how I calculated the pulse-width, so you can check if it's right : SystemCoreClock = 24Mhz TIM_Period = 65535 TIM_Pulse = 15535 (1 / SystemCoreClock) * (TIM_Period - TIM_Pulse) equals 2ms. What am I missing? Thank you in advance! Chris #timer-one-pulse