I have attempted to code a program that recognizes a push-button push and displays some text as a result. It is attached. I am using PortB Change.
The program 1.)Calls Init (Sets LCD Contrast and Outputs 1 to switches).
2.)Then a macro, that senses the switch positions and assigns their input state to a bool variable.
3.)Then an ISR to print "Got It", if a PB is pushed.
The while(1) loop prints "waiting", and cycles forever, waiting for the ISR, in which "Got It" would be displayed in the LCD.
Thanks
Working with interrupts.
Moderator: Benj
-
billduck
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Working with interrupts.
- Attachments
-
- Picture if the setup.
- BreadBoard Setup (2).JPG (108.14 KiB) Viewed 4491 times
-
- Interrupt for1 second when a PB is Pushed.fcf_avr
- I can not get it to simulate or work on an Arduino MEGA, with Pushbuttons and an LCD. The LCD display's "waiting", and would display "Got it" if it worked.
- (19.23 KiB) Downloaded 260 times
-
kersing
- Valued Contributor

- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Working with interrupts.
I do not have the AVR version of Flowcode so I haven't opened your program, but do you print "Waiting" continuously in the loop? If so, would it not overwrite the "Got it" message the ISR displays before you get a chance to read that message?
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
billduck
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Working with interrupts.
Thanks.
In the attached, in Main, I clear the screen, wait 1 sec, print "Waiting", then clear the screen, wait 1 sec.
In the ISR Routine, I do the same thing. I added a print statement, indication that I am in the ISR routine, but looped in the No decision path.
The program never gets to the ISR.
I added a screen shot of what the Init macro does.
In the attached, in Main, I clear the screen, wait 1 sec, print "Waiting", then clear the screen, wait 1 sec.
In the ISR Routine, I do the same thing. I added a print statement, indication that I am in the ISR routine, but looped in the No decision path.
The program never gets to the ISR.
I added a screen shot of what the Init macro does.
- Attachments
-
- Init.png
- This is the init macro, run before the main loop.
- (93.43 KiB) Downloaded 288 times
-
- ISR_Routine.png
- (112.7 KiB) Downloaded 288 times
-
- Main Routine.png
- (81.45 KiB) Downloaded 288 times
-
kersing
- Valued Contributor

- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Working with interrupts.
Generally it is not a good idea to delay for significant amounts of time in interrupt routines. You want them to be handled as soon as possible to avoid missing the next interrupt.
For testing purposes I would remove the clear/print waiting sequence from the main loop. Also in the interrupt, clear screen first and print message next. That way you can be sure you will never miss the message if the code is called.
I am not seeing obvious issues in the flow, could you attach the generated C code?
For testing purposes I would remove the clear/print waiting sequence from the main loop. Also in the interrupt, clear screen first and print message next. That way you can be sure you will never miss the message if the code is called.
I am not seeing obvious issues in the flow, could you attach the generated C code?
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
billduck
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Working with interrupts.
Attached id the C file. Also the FC File.
I wrote a short one, where there is no ISR, but just looking at the switches, and the program sees Ports B4 to B7 when a button pushed.
Thanks
I wrote a short one, where there is no ISR, but just looking at the switches, and the program sees Ports B4 to B7 when a button pushed.
Thanks
- Attachments
-
- Interrupt for1 second when a PB is Pushed.fcf_avr
- Slightly modified FC file, with your suggestions.
- (20.59 KiB) Downloaded 285 times
-
- Interrupt for1 second when a PB is Pushed.c
- This is the C file
- (12.94 KiB) Downloaded 284 times
-
kersing
- Valued Contributor

- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: Working with interrupts.
Looking at the generated C code I see you have a macro Sense_PortB which switches the Port B pins to input just after you have switched them to output and made them high for the pin change function. Also you test the pin status in that macro, but it is only called at the start of the program, not in the interrupt code and not in the loop. This way the value of UP_RUNPB will be set once (when Sense_PortB is called) and stay the same.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
billduck
- Posts: 162
- Joined: Thu Jul 01, 2010 1:57 am
- Has thanked: 23 times
- Been thanked: 16 times
- Contact:
Re: Working with interrupts.
There must be a mapping problem. Of the 2 FC programs attached, the only difference is that the interrupt is either a PortB change (No work) or a PortE/J change (Works).
In both cases, I look at pin B5 to invoke the interrupt. I might add that the interrupt works if the input is on B0 to B6.
In both cases, I look at pin B5 to invoke the interrupt. I might add that the interrupt works if the input is on B0 to B6.
- Attachments
-
- Photo showing triggering the interrupt and LED.
- Resistor_ Gnd to B5.JPG (138.18 KiB) Viewed 4437 times
-
- Button_LED_Works.fcf_avr
- Interrupt is PortE/J, Change is on B5
- (13.5 KiB) Downloaded 259 times
-
- Button_LED_Does Not Work.fcf_avr
- Interrupt is PortB, Change is on B5
- (8 KiB) Downloaded 270 times