Button press interrupt

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Button press interrupt

Post by billduck »

The attached image shows a 5 button shield plugged into an UNO. When I press a button, the software shows the millivolt range that is tested for, and the actual millivolts read. The 5 buttons on the LCD form a voltage divider with an input to AN0.
In one version of the program, I enable the interrupt and disable the sub call. Compile and run. It only works on 3 right buttons. But if I disable the interrupt and do a sub call in main, compile and run, It works for all 5 buttons. I note that the 2 buttons
Attachments
WhichButton_With Interrupt.fcfx
(21.64 KiB) Downloaded 153 times
PuttonPress.jpg
PuttonPress.jpg (106.67 KiB) Viewed 2764 times

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Button press interrupt

Post by mnf »

You shouldn't do the display and delays in the interrupt handler....

Interrupt handler needs to check which button is pressed - set a global with this value and then return.

Calling it as a macro - timing is much less critical.

Martin

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: Button press interrupt

Post by billduck »

I implemented the code to where the interrupt handler sets a global value. I have the same problem, in that 2 of the buttons do not set the MenuPosition (global value) and display text indicating so.
I note that the 2 buttons that do not respond have the highest analog voltage - 2.2 to 3.2 and 3.2 to 4.2.
I do not fully understand the properties / settings for the pushbutton. Conversion speed and aquisition cycles.
Attachments
WhichButton_With Interrupt_MenuPosition.fcfx
(27.35 KiB) Downloaded 150 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Button press interrupt

Post by medelec35 »

You need to change your flowchart to the way martin has stated.
You have still got LCD components within the interrupt handler.
You must never add components that contain delays like LCD or delays themselves to interrupts.
Only use interrupts for inputs/outputs and setting flags (bool variable set to 1 then the variable is read outside the interrupt.
Interrupts should be kept as small as possible, and allowed to exit normally i,e no call macros.
Martin

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Button press interrupt

Post by LeighM »

Also, the interrupt responds to a digital level change, so some of the voltage transitions might not trigger an interrupt

billduck
Posts: 159
Joined: Thu Jul 01, 2010 1:57 am
Has thanked: 23 times
Been thanked: 16 times
Contact:

Re: Button press interrupt

Post by billduck »

The solution that I chose was to just check if a button press is sensed in Main. Since it detects any 1 of 5 buttons. Forget the interrupt.
I also found out that on the MEGA, that Analog Input 0 is on Port F and IOC PortF (interrupt on change - Port F) is not available.
Thanks for the suggestions.

Post Reply