2013-11-15 08:57 PM
#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
2013-11-15 09:18 PM
No TIM5 on F100 part
2013-11-16 07:57 AM
I was looking at application note:
AN4013
Application note
STM32F1xx, STM32F2xx, STM32F4xx, STM32L1xx,
STM32F30/31/37/38x timer overview
This shows that all F1x devices have the TIM5 peripheral. Is this a typo or am I interpreting this note incorrectly?
2013-11-16 08:12 AM
The
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00251732.pdf
is the controlling document for thehttp://www.st.com/web/catalog/mmc/FM141/SC1169/SS1031/LN775/PF216844
, see pg 29 (and others) You could verify the APB clock enable bits in the two registers, and confirm the TIM5 and TIM8 enable bits are stuck-at-zero. The VL parts should always be viewed as function stripped parts, the reference manuals tend to focus on the highest common denominator. I haven't review the App Note, but it appears to over state the functionality of the chip on the VL Discovery board2013-11-16 08:51 AM
Thank you clive1. I will refer to the data sheet as the definitive source to try confirm things like this in the future. I have run into similar situations in the past and there has been cases where the secondary documentation (application note) is actually right and the primary (data sheet) was wrong. But as you said, the evidence clearly shows the data sheet is correct in this scenario.
I changed my code to use timer 3 and indeed the world is right again after the change.