cancel
Showing results for 
Search instead for 
Did you mean: 

How to recognize which edge lead to EXTI

matic
Associate III
Posted on January 12, 2016 at 22:06

How do you recognize, which edge lead to EXTI, if it is configured for rising and falling edges?

Now, I look a state of that pin in IDR register, immediately when EXTI occurs. But in that time, between cause of interrupt and my reading, pin could already be toggled. Is there any other, more secure way?

Thanks
10 REPLIES 10
Posted on January 12, 2016 at 22:40

Use a TIM?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Radosław
Senior
Posted on January 12, 2016 at 22:55

Set active only one edge, in interrupt change the edge, after that you can check if state is changed to eliminate VERY short pulses.

matic
Associate III
Posted on January 13, 2016 at 06:39

@clive: How do you think that I should use TIM? Don't understand?

@dembek.radoslaw: You thought that I make interrupt with let say rising edge, then stop program inside of interrupt routine, force pin back to 0 (to GND) and see if value in IDR register has changed to 0, too?

re.wolff9
Senior
Posted on January 13, 2016 at 08:37

What dembek is trying to say is: set exti to trigger on rising edge. 

In the interrupt, check the signal. If it is high, you just got a simple rising edge, change exti to do falling edge next. 

If the signal is low, you just got a short pulse, leave exti at rising edge triggering. 

Do the same for the falling edge. 

Posted on January 13, 2016 at 13:11

@clive: How do you think that I should use TIM? Don't understand?

Review the manual?

ONE pin, for either CH1/CH2 or CH3/4 pairing, configure the time base in a maximal mode, and then the paired channels (Direct + Indirect) to input capture the time stamp of opposite edges of the same input, and interrupt.

For high rates use DMA to capture the edge time stamps.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
matic
Associate III
Posted on January 13, 2016 at 21:42

But what would I know then, if I capture time stamps of two consecutive opposite edges?

What I want to know is, which edge triggered an EXTI, if EXTI is configured on rising and falling edge.

Radosław
Senior
Posted on January 13, 2016 at 21:48

I tell you how to do it, with ensurence to detect corect edge.

Posted on January 13, 2016 at 22:19

FFS

You'd use a TIM in place of an EXTI, you'd get both edges, they would flag different interrupts, and the time of arrival would be time stamped.

Pretty much any case where you look at the EXTI source via the state of the GPIO pin, or toggle the edge causing the interrupt, you have the potential for a race condition if the frequency is high, the pulse is glitchy in nature, or you've got an IRQ with some long latency.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on January 13, 2016 at 22:20

YOU: Is there any other, more secure way?

ME: Use a TIM
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..