Home > other >  Accept time appear a large error measurement sensors
Accept time appear a large error measurement sensors

Time:01-16

Want to use through the measured sound time to locate the source of sensor signals, but with the measured values of stm32 timer, always is not accurate, this is why, five sound sensor received five external interruption, and then into whether interrupt judgment for the first time into each time, is will the timer 0, otherwise the timer value, and every time I enter the interrupt I turn off the the interrupt line, prevent into the same interrupt for many times, but the end result is always appear problem, ask bosses, annotations into the code, I would not be changed, then the main function of I again open the interrupt, interrupt code is as follows:
# include "exti. H"
# include "LCD. H"
# include "usart. H"
H # include "is the key."
# include "delay. H"
Extern volatile int flag;
Extern volatile long int time [5];
Extern volatile int sensor [5];
Extern volatile int I;
Void EXTIX_Init (void) {
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
KEY_Init ();
RCC_APB2PeriphClockCmd (RCC_APB2Periph_SYSCFG, ENABLE);

SYSCFG_EXTILineConfig (EXTI_PortSourceGPIOA EXTI_PinSource0);
SYSCFG_EXTILineConfig (EXTI_PortSourceGPIOC EXTI_PinSource1);
SYSCFG_EXTILineConfig (EXTI_PortSourceGPIOD EXTI_PinSource2);
SYSCFG_EXTILineConfig (EXTI_PortSourceGPIOE EXTI_PinSource3);
SYSCFG_EXTILineConfig (EXTI_PortSourceGPIOB EXTI_PinSource4);

EXTI_InitStructure. EXTI_Line=EXTI_Line0 | EXTI_Line1 | EXTI_Line2 | EXTI_Line3 | EXTI_Line4;
EXTI_InitStructure. EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure. EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStructure. EXTI_LineCmd=ENABLE;
EXTI_Init (& amp; EXTI_InitStructure);

NVIC_InitStructure. NVIC_IRQChannel=EXTI0_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x00;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);


NVIC_InitStructure. NVIC_IRQChannel=EXTI1_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x01;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);

NVIC_InitStructure. NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);



NVIC_InitStructure. NVIC_IRQChannel=EXTI3_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x03;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);

NVIC_InitStructure. NVIC_IRQChannel=EXTI4_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0 x04;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=0 x02;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);
}

Void EXTI0_IRQHandler (void) {
EXTI - & gt; IMR&=~ (EXTI_Line0);
If (flag==0) {
TIM_Cmd (TIM3, ENABLE);
TIM_SetCounter (TIM3, 0);
Flag=1;
}
Time [I]=TIM_GetCounter (TIM3);
Sensor [I]=1;
i++;
EXTI_ClearITPendingBit (EXTI_Line0);
}
Void EXTI1_IRQHandler (void) {
EXTI - & gt; IMR&=~ (EXTI_Line1);
If (flag==0) {
TIM_Cmd (TIM3, ENABLE);
TIM_SetCounter (TIM3, 0);
Flag=1;
}
Time [I]=TIM_GetCounter (TIM3);
Sensor [I]=2;
i++;
EXTI_ClearITPendingBit (EXTI_Line1);
}
Void EXTI2_IRQHandler (void) {
EXTI - & gt; IMR&=~ (EXTI_Line2);
If (flag==0) {
TIM_Cmd (TIM3, ENABLE);
TIM_SetCounter (TIM3, 0);
Flag=1;
}
Time [I]=TIM_GetCounter (TIM3);
Sensor [I]=3;
i++;
EXTI_ClearITPendingBit (EXTI_Line2);
}
Void EXTI3_IRQHandler (void) {
EXTI - & gt; IMR&=~ (EXTI_Line3);
If (flag==0) {
TIM_Cmd (TIM3, ENABLE);
TIM_SetCounter (TIM3, 0);
Flag=1;
}
Time [I]=TIM_GetCounter (TIM3);
Sensor [I]=4;
i++;
EXTI_ClearITPendingBit (EXTI_Line3);
}
Void EXTI4_IRQHandler (void) {
EXTI - & gt; IMR&=~ (EXTI_Line4);
If (flag==0) {
TIM_Cmd (TIM3, ENABLE);
TIM_SetCounter (TIM3, 0);
Flag=1;
}
Time [I]=TIM_GetCounter (TIM3);
Sensor [I]=5;
i++;
EXTI_ClearITPendingBit (EXTI_Line4);
}

  • Related