Page 1 of 1

LCD write corrupted by interrupts?

Posted: Thu Jan 28, 2010 11:50 am
by jadiflow
This is a funny one.
I'm seeing erratic lcd behaviour (jumping cursor, non-alphabetic characters) after a few minutes of running my program. I'm tracking an encoder with ioc and then start a clock for debouncing. Any of those interrups may occur while writing to the lcd, and I have a hunch that upsets it, but so far no hard evidence as to the cause. It works correctly while simulating. I've cut the program down to just the encoder stuff and the lcd writing.
Interestingly, sometimes it displays random-looking characters or strings, sometimes again displays the log-on message that I display at start-up. It looks as if there is a mix up in a jump or return stack within the lcd routines when interrupted.
Is that a valid possibility? Any tips how I can test that?

thanks,

jan didden

Re: LCD write corrupted by interrupts?

Posted: Thu Jan 28, 2010 12:11 pm
by Benj
Hello Jan

If you have a LCD clear somewhere in your main loop then changing this to a start may help you to eliminate any corruption as it starts to happen.

Are you calling any of the LCD routines from your interrupts? This could be what is causing the adverse effects. Instead you could set a flag variable in the interrupt and then service the flag in your main routine.

Re: LCD write corrupted by interrupts?

Posted: Thu Jan 28, 2010 2:09 pm
by jadiflow
Yes, if I do a start/clear just prior to a write, it clears the junk and gets back to normal. But that's no real solution of course.
I do set a couple of flags at interrupt and process them later, trying to keep interrupt processing to a minimum.

There is something to these interrupts. I tried, in the same program, to use TMR1 as a low speed interrupt for some led indicating functions. Program starts up and hangs immediately without any user action, even with the interrupt service routine doing nothing, just entering and leaving again. Then I changed the timer to TMR2, and it works. Weird.

jan didden

Re: LCD write corrupted by interrupts?

Posted: Fri Jan 29, 2010 5:02 pm
by jadiflow
Hello Ben, just thought about something.

If an interrupt occurs, there's a central dispatcher determining which type of int it was and transferring execution accordingly.
What would happen if an interrupt occured while the dispatcher (or the int specific code) was being executed? Is that stuff reentrant?

thanks,

jan didden