2013-08-07 11:14 AM
Can someone please point me in the right direction to use TIM2 or TIM5 as just a free running 32-bit counter, ticking at 1us, that I can read anywhere in my pgm. No I/O or interrupts desired.
None of the examples in the software libs seem to do what I want. Thanks, Bill #simples #that-was-easy2013-08-07 11:19 AM
Just configure the timebase and read TIMx->CNT
2013-08-07 11:24 AM
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = ((SystemCoreClock / 1000000) / 2) - 1; // 1 MHz timebase, assumes APB1 @ SYS/4
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; // Maximal
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
2013-08-07 11:41 AM
Thank you very much, Clive.
I was trying something like that, but the ''doc'' in the stm32f4xx_tim.h file included this: /*!< Specifies the period value to be loaded into the active Auto-Reload Register at the next update event. This parameter must be a number between 0x0000 and 0xFFFF. */ Taken at face value, 0xFFFF wasn't big enough for what I wanted to do.2013-08-07 03:22 PM
I think I ran into that comment the other week, with the F3
STM32F3-Discovery_FW_V1.1.0\Libraries\STM32F30x_StdPeriph_Driver\inc\stm32f30x_tim.huint32_t TIM_Period; /*!< Specifies the period value to be loaded into the active
Auto-Reload Register at the next update event.
This parameter must be a number between 0x0000 and 0xFFFF. */
..
uint32_t TIM_Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
This parameter can be a number between 0x0000 and 0xFFFF */
Pretty much a hold-over from the F1 when all timers were 16-bit, now I have to check the manuals because I can never remember which parts have which timers. The F3 only has one.