Question
Timer 5 never counts from zero
Posted on November 16, 2013 at 05:57
#define SYS_CLK 24000000 /* in this example we use SPEED_HIGH = 24 MHz */
#define DELAY_TIM_FREQUENCY 1000000 /* = 1MHZ -> timer runs in microseconds */
/* Enable timer clock - use TIMER5 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
/* Time base configuration */
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = (SYS_CLK / DELAY_TIM_FREQUENCY) - 1;
TIM_TimeBaseStructure.TIM_Period = UINT16_MAX;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
/* Enable counter */
TIM_Cmd(TIM5, ENABLE);
I used the above code and the timer never counts above zero. I dug around some posts and saw some others had trouble because they didn't enable the clock, but I did include that line.
I thought that with the pre-scaler set that it will be counting up in microseconds so the period should be 1 and tried 1 instead of UINT16_MAX but that had no effect, count is always 0.
So after reading other posts, the documentation and trying to modify some of the setup values I still can't get this timer to count.
Does the use of systick or USART somehow disable the use of TIM5? I could not find anything that says this is true but unless there is something I missed in the code above I don't know what else to try.
The board is a STM32VL Discovery, in case that matters