2013-04-03 07:55 AM
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
2013-04-03 08:17 AM
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
2013-04-03 08:43 AM
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...)2013-04-03 09:14 AM
A good quality reed switch may eliminate such ''bounce.''
eliminate? probably not completely/always. I would not design anything that could not handle bonceNote 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
2013-04-03 11:12 PM
Thanks to every one
2013-04-05 12:46 AM
2013-04-05 12:54 AM
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.2013-04-05 07:38 AM
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