2014-05-15 08:06 AM
Hi, I am using uvision4 with stm32f1xx to meansure frequency counting the time of the falling edge pulse. I need a high precision to meansure frequency from 0Hz to 240Hz. The first thing that I do was to set the prescaler to mensure 240Hz. That is ok, the problem is that I cant get when the timer count overflow to mensure frequency from 61 to 0. The program enter in theTIM_IT_Update all the time, what am I doing wrong? void RCC_Configuration(void){
/* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseStructure.TIM_Period = 65535; //20 mS TIM_TimeBaseStructure.TIM_Prescaler = Prescaler_Pickup - 1; //1 uS 1 MHz TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); } void TIM2_IRQHandler (void) { if(TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET){ /* Clear TIM3 Capture compare interrupt pending bit */ TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); if(CaptureNumber == 0){ /* Get the Input Capture value */ IC3ReadValue1 = TIM_GetCapture1(TIM2); CaptureNumber = 1; estourou_timer = 0; } else if(CaptureNumber == 1){ /* Get the Input Capture value */ IC3ReadValue2 = TIM_GetCapture1(TIM2); /* Capture computation */ if (IC3ReadValue2 > IC3ReadValue1){ Capture = (estourou_timer * 65535) + (IC3ReadValue2 - IC3ReadValue1); } else{ Capture = (estourou_timer * 65535) + ((0xFFFF - IC3ReadValue1) + IC3ReadValue2); } /* Frequency computation */ Pickup_1_FLOAT = (float) (72000000/Prescaler_Pickup) / Capture; if(Pickup_1_FLOAT < Menor_Med) Menor_Med = Pickup_1_FLOAT; CaptureNumber = 0; } }
if((TIM_GetITStatus(TIM2, TIM_IT_Update) == SET )){ //overflow
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
estourou_timer++;
}
} void TIM2_Configuration(){
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM2, &TIM_ICInitStructure); /* TIM enable counter */ TIM_Cmd(TIM2, ENABLE); /* Enable the CC1 Interrupt Request */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE); TIM_ICInit(TIM2, &TIM_ICInitStructure); /* TIM enable counter */ TIM_Cmd(TIM2, ENABLE); /* Enable the TIM3 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); }2014-05-23 11:44 PM
The timer synchronization is described on
http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf
, not AN2592. AN4013 Application Note: STM32F0, STM32F1, STM32F2, STM32F4, STM32L1 series,STM32F30xC/Bx, STM32F358xC, STM32F37x, timer overview ''3.1 Timer system link STM32 timers are linked together internally for timer synchronization or chaining. Each timer has several internal trigger inputs and outputs. These signals allow the timer to be connected with other timers.''