2014-01-29 10:43 PM
Hi, I need to implement acculate delay_us. Try to use timer like this.
void
delay_us ( uint32_t usec )
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd ( RCC_APB1Periph_TIM2, ENABLE );
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock / 1000000) - 1;
TIM_TimeBaseStructure.TIM_Prescaler = usec - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
while
(TIM_GetFlagStatus(TIM2, TIM_FLAG_Update) == RESET );
TIM_ClearFlag (TIM2, TIM_FLAG_Update);
/* TIM2 disable counter */
TIM_Cmd(TIM2, DISABLE);
TIM_DeInit(TIM2);
}
But it doesn't work. it struct on while loop.
I have to run this delay on the FreeRTOS. What is the best way to do?
I used XTAL for CPU 25 MHz and set SystemCoreClock with 150000000.
#timer-delay
2014-01-29 11:33 PM
Check the TIM_Period and TIM_Prescaler assignement in your code
2014-01-29 11:51 PM
You mean the value of
TIM_Period and TIM_Prescaler, right?
Or check the value is already kept on the register. If this, how we check it?2014-01-30 01:05 AM
Sorry for unclear answer
T
he
prescaler
must containthe
frequency divider
for
the timer
tick
you want (
The calculation
depends on
how are configured
the
AHBx
APBx
clocks) ThePeriod
field must contain thetimer
delay
in multiples of the
timer
tics