2014-11-24 08:27 AM
Hi,
I have this timervoid InitializeTimer(void)
{
TIM_TimeBaseInitTypeDef timerInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
timerInitStructure.TIM_Prescaler = 0;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = (84000000 / 2000) - 1; //2000Hz
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
/* Activación de la interrupción */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //Activa todos los canales
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
TIM_TimeBaseInit(TIM2, &timerInitStructure); // guarda cambios en init timer
NVIC_Init(&NVIC_InitStructure); // guarda cambios en el registro nvic
//Activa el Timer
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
how to read the value from the main fuction?
thanks
2014-11-24 10:17 AM
current = TIM2->CNT;
2014-11-25 02:44 AM
ok thank.
I have a new simple timervoid INTTIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 100000 - 1; // 1 MHz down to 10 Hz
TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1; // 84Mhz Down to 1 MHz
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* TIM2 enable counter */
TIM_Cmd(TIM3, ENABLE);
}
10 Hz.
in the main function:
while(1) {
current=TIM3->CNT;
printf(''%i
'', current); }
but it's too fast respect the timer; how to
synchronize
the main fuction with the timer? I would like to read 10 printf per second, notthousand
s thanks2014-11-25 05:00 AM
Consider using SysTick to mark time, or evaluate how far the counter has advanced before printing it.