cancel
Showing results for 
Search instead for 
Did you mean: 

External interrupt and input capture

sak hos
Associate III
Posted on September 06, 2017 at 13:47

Hello,

I'm using STM32F103c8t6 with CubeMX and in my application i'm using many Pins as External interrupt source and i have two questions:

1-An action must be done after pressing then releasing the button (rising edge then falling edgre) so for the first callback i should ckeck if there is a rising edge and for the second callback ihave to check if it's a falling egde, an action shoul be done. is that possible ?

2-In order to protect my application from parasites can i use input capture with all the pins in order to detect if the duration between the rising and the falling edge is to small, no action to be should happen, is that possible ?

Thank youn

2 REPLIES 2
Posted on September 06, 2017 at 14:44

Hello!

For the first question, of course is possible but only if you have a debouncing 'mechanism' not to detect the bounces of button.

For the second question , in case you mean 'parasites' the bouncing of buttons,  yes  also!.

To debounce buttons you can use (by hardware means)  in series resistors and parallel capacitors. (take a look at various schematics at ST boards)

For the second question , a solution may includes some delay (preferable non blocking delay)  on detection of first edge  after push the button,  and after this delay (30 ms e.g.)  to check for state of pin.  If state is 'button pressed' then you can suppose a positive pressed button and  not a 'parasite'.  

Regards

vf

Alan Chambers
Associate II
Posted on September 06, 2017 at 18:01

You are describing debouncing - a short delay to eliminate noisy transients. I usually do this as follows:

1. The edge is detected in an EXTI interrupt. I think you are doing this.

2. The interrupt handler starts (or restarts) a timer on every call. I always use software timers based around SysTick, so I have an independent timer for every pin. 10ms is enough to do the trick in most cases.

3. When the timer expires, I know there have been no interrupts for 10ms, and compare the current state of the pin to the previous debounced state. If it differs, I have a button press or release.

Another solution is to frequently poll the pins (e.g. every 1ms) and keep track of how many ticks have passed since the pin state changed. I find this method less satisfactory, but I can't always use interrupts for all inputs.