2014-09-10 07:33 AM
Hello,
For a datalogging appIication (STM32F401 Discovery), TIM2 is used as an interrupt for ADC sampling rate .
/*----------------------------------------------------------------------------
Configuring TIM2 to trigger the ADC sampling rate
*----------------------------------------------------------------------------*/
void TIM2_Config(void)
{
TIM_TimeBaseInitTypeDef TIM2_TimeBase;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseStructInit(&TIM2_TimeBase);
TIM2_TimeBase.TIM_Period = ((80000000 / 100000) - 1);
TIM2_TimeBase.TIM_Prescaler = 0:
TIM2_TimeBase.TIM_ClockDivision = 0;
TIM2_TimeBase.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM2_TimeBase);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
/*----------------------------------------------------------------------------
Configuring Global interupt based on TIM2
*----------------------------------------------------------------------------*/
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
Next step is to enable TIM2 based on a external interrupt generated by the rising edge of GPIO PE What's the best way to create such an interrupt configuration? Any examples?
#interrupt #timer2014-09-10 08:58 AM
STM32F401-Discovery_FW_V1.0.0\Projects\Peripheral_Examples\EXTI_Example\main.c
EXTI_Line15 EXTI15_10_IRQHandler EXTI15_10_IRQn2014-09-11 04:29 AM
Hi,
thanks for the tip! Most important part is that TIM2 will be set to 0 on a rising edge of PE15, so the logging interval timer TIM2 start counting from zero when a rising edge from PE15 comes in. I'm thinking of the interrupt handling below:void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line15) != RESET)
{
TIM_SetCounter(TIM2, 0);
EXTI_ClearITPendingBit(EXTI_Line15);
}
}
Note: EXTI interrupt will get a higher priority than TIM2
Is this implementation correct?