Page 1 of 1
Working with interrupts.
Posted: Mon Feb 11, 2013 6:16 pm
by billduck
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
Re: Working with interrupts.
Posted: Mon Feb 11, 2013 6:53 pm
by kersing
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?
Re: Working with interrupts.
Posted: Mon Feb 11, 2013 7:48 pm
by billduck
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.
Re: Working with interrupts.
Posted: Tue Feb 12, 2013 12:14 am
by kersing
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?
Re: Working with interrupts.
Posted: Tue Feb 12, 2013 3:12 am
by billduck
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
Re: Working with interrupts.
Posted: Tue Feb 12, 2013 11:41 pm
by kersing
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.
Re: Working with interrupts.
Posted: Fri Feb 15, 2013 9:43 pm
by billduck
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.