cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupts are not occurring in order

Manjunatha S
Associate II
Posted on April 03, 2013 at 16:55

Hi! All,

I have a reed switch based Wind Speed and wind direction sensor(anemometer), these two reed switches(one for wind speed and another for direction) are connected to pull ups so that it generates the digital pulse as the switches closes and opens. i configured two interrupts for each reed switches but i should get one interrupt at a time that is one contact closure at a time and i am getting these in ossciloscope but i am not getting the one interrupt at a time rather i am getting same interrupt at two times. can any one tell me the what is the reason ? and to overcome this.

gpio initialization
void WS_Init_Wind_Sensors_Input()
{
GPIO_InitTypeDef gpio_init_structure;
EXTI_InitTypeDef exti_init ;
/* Enable GPIO clocks */
RCC_AHBPeriphClockCmd(WIND_SPEED_SENSOR_RCC_AHBPeriph | WIND_DIRECTION_SENSOR_RCC_AHBPeriph, ENABLE);
gpio_init_structure.GPIO_Pin = WIND_SPEED_SENSOR_GPIO_PIN;
gpio_init_structure.GPIO_Mode = GPIO_Mode_IN;
gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio_init_structure.GPIO_Speed = GPIO_Speed_40MHz;
gpio_init_structure.GPIO_OType = GPIO_OType_PP;
/* Initialise the GPIO accordingly */
GPIO_Init(WIND_SPEED_SENSOR_GPIO_PORT, &gpio_init_structure);
gpio_init_structure.GPIO_Pin = WIND_DIRECTION_SENSOR_GPIO_PIN;
/* Initialise the GPIO accordingly */
GPIO_Init(WIND_DIRECTION_SENSOR_GPIO_PORT, &gpio_init_structure);
/* The syscfg module is clocked */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* The EXTI mux is on exti line RG_EXTI_PINSOURCE for this GPIO pin */
SYSCFG_EXTILineConfig(WIND_SPEED_SENSOR_EXTI_PortSource,WIND_SPEED_SENSOR_EXTI_PinSource);
/* The EXTI mux is on exti line RG_EXTI_PINSOURCE for this GPIO pin */
SYSCFG_EXTILineConfig(WIND_DIRECTION_SENSOR_EXTI_PortSource,WIND_DIRECTION_SENSOR_EXTI_PinSource);
EXTI_StructInit(&exti_init);
exti_init.EXTI_Line = WIND_SPEED_SENSOR_EXTI_LINEx;
exti_init.EXTI_LineCmd = ENABLE;
exti_init.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&exti_init);
/*Enable the interrupt in the NVIC */
INIT_NVIC_Enable_Peripheral_Interrupt(WIND_SPEED_SENSOR_EXTIx_IRQn,0,0);
exti_init.EXTI_Line = WIND_DIRECTION_SENSOR_EXTI_LINEx;
exti_init.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&exti_init);
/*Enable the interrupt in the NVIC */
INIT_NVIC_Enable_Peripheral_Interrupt(WIND_DIRECTION_SENSOR_EXTIx_IRQn,0,0);
}
//interrupt handler
void EXTI9_5_IRQHandler(void)
{
if( (EXTI_GetITStatus(EXTI_Line9) == SET ))
{
EXTI_ClearITPendingBit(EXTI_Line9);
USART_Send_String(''TD>>>>>>>>>\r\n '');
}
if((EXTI_GetITStatus(EXTI_Line6) == SET ))
{
USART_Send_String(''TS!!!!!!!!!!!!!!!!!\r\n '');
}
}

Tanking you. #interrupts
7 REPLIES 7
emalund
Associate III
Posted on April 03, 2013 at 17:17

 i should get one interrupt at a time that is one contact closure  at a time and i am getting these in ossciloscope but i am not getting the one interrupt at a time rather i am getting same interrupt at two times.

 

how fast is your scope?

I smell switch bounce

Erik
jj2
Associate II
Posted on April 03, 2013 at 17:43

A good quality reed switch may eliminate such ''bounce.''

Note your use of a Uart transmission - w/in your interrupt handler.  Due to the slow speed of the Uart - might this ''prolong'' the time spent in this interrupt - unnecessarily.

Always suggest that each interrupt be first tested/verified by itself (i.e. enable only 1 interrupt source connection at a time).  Only move on to your 2nd (or beyond) once the first has checked out.  Following this method you can confirm that both sources indeed trigger your interrupt - and you may then ''hone in'' on the difficulty your report.

(I'd replace the Uart transmission w/simple bit set (different for each interrupt source) which could be monitored via an led - and causes no such ''prolong'' of your interrupt service...)

emalund
Associate III
Posted on April 03, 2013 at 18:14

A good quality reed switch may eliminate such ''bounce.''

 

eliminate? probably not completely/always. I would not design anything that could not handle bonce

Note your use of a Uart transmission - w/in your interrupt handler. 

whether related or not GET RID OF IT!

not adhering to KISS (Keep ISRs Short and Simple) has caused loads of trouble for lots of people

Erik
Manjunatha S
Associate II
Posted on April 04, 2013 at 08:12

Thanks to every one

Manjunatha S
Associate II
Posted on April 05, 2013 at 09:46

200MHz 1G samples/sec

Manjunatha S
Associate II
Posted on April 05, 2013 at 09:54

Hi! malund. erik,

Thanks for your replay, also i need to find the time between TS_1 and TS_2, TS_1 and TD_1 for this i am using timer. in ISR i read the timer count is it safe? if not  can you suggest me some other method to do so? You can find the attachment for more information.

thank you.

emalund
Associate III
Posted on April 05, 2013 at 16:38

reading and saving a timer count in an ISR should be perfectly safe; however process it outside the ISR.  Remember variables shared between an ISR and the main code have to be declared volatile