Timer #1, Interrupt/128X64 KS0108 conflict

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Timer #1, Interrupt/128X64 KS0108 conflict

Post by Intellisenc » Thu Oct 27, 2011 4:15 pm

I recently added timer #1 with interrupt to my code and all works well except that I get random pixels turned on with my 128X64 display.

I can read the display well. It just compromises the quality to have the small amount of static in the display. Any suggestions on where to look for the conflict?

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Thu Oct 27, 2011 5:58 pm

Probably stating the obvious, but it sounds like something you're doing in the timer ISR is either corrupting some shared ram or messing with the LCD hardware pins.

What's the timer ISR look like?

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Sat Oct 29, 2011 9:03 pm

What does ISR stand for? I see now that it is not as prominent as it was. I have to work to get it to show up, but eventually it does.

Const T1Period As Word = 65536-50000+6
Const Int_Total As Byte = 40
Dim int_counter,days,secs,mins,hrs As Byte

Interrupt RTC()
T1ON = 0
T1 = T1 + T1Period
T1ON = 1
Dec(int_counter)
If int_counter = 0 Then
int_counter = Int_Total
Inc(secs)
If secs = 60 Then
secs = 0
Inc(mins)
If mins = 60 Then
mins = 0
Inc(hrs)
If hrs = 24 Then
hrs = 0
Inc(days)
If days = 7 Then
days = 0
End If
End If
End If
End If
End If
T1IF = 0
End Interrupt
Sub Initializetimer()
int_counter = Int_Total
update = false
INTCON = 192
T1CON = 0
T1 = 65536-50000
T1IE = 1
T1IF = 0
T1ON = 1
Enable(RTC)
End Sub

rmteo
Posts: 237
Joined: Fri Feb 29, 2008 7:02 pm
Location: Colorado, USA

Post by rmteo » Sat Oct 29, 2011 10:32 pm

Use code tags, makes it easier to read.

Code: Select all

Const T1Period As Word = 65536-50000+6
Const Int_Total As Byte = 40
Dim int_counter,days,secs,mins,hrs As Byte

Interrupt RTC()
T1ON = 0
T1 = T1 + T1Period
T1ON = 1
Dec(int_counter)
If int_counter = 0 Then
int_counter = Int_Total
Inc(secs)
If secs = 60 Then
secs = 0
Inc(mins)
If mins = 60 Then
mins = 0
Inc(hrs)
If hrs = 24 Then
hrs = 0
Inc(days)
If days = 7 Then
days = 0
End If
End If
End If
End If
End If
T1IF = 0
End Interrupt
Sub Initializetimer()
int_counter = Int_Total
update = false
INTCON = 192
T1CON = 0
T1 = 65536-50000
T1IE = 1
T1IF = 0
T1ON = 1
Enable(RTC)
End Sub
Why use 8 bits when you can have 32?
ARM CORTEX Rules!!! :D :D :D

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sun Oct 30, 2011 2:15 pm

ISR = Interrupt Service Routine, or just the "interrupt" routine in SF terms.

I don't see anything in that code that jumps out at me. Normally, what I'd be looking for inside the interrupt() routine are things like:
- calling a subroutine/function
- accessing local/compiler generated stack-frame variables
- accessing arrays or strings

Sometimes very simple statements can get you into trouble when used inside an interrupt routine, and there are extra steps you need to take to protect things.

That routine does none of the above, and looking at the asm listing it looks pretty "safe". Hard to see how it would have an effect on another module.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Sun Oct 30, 2011 2:19 pm

Thanks for looking at it. I will experiment and see if I can drill down to the root cause.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Mon Oct 31, 2011 1:18 am

I confirmed that the random short vertical lines go away with interrupt disabled and also found that these lines appear after a glcd.cls when I go from one screen to another.

I am able to make them go away by adding a delayms(60) after each glcd.cls. Possibly the interrupt slows something down and the glcd.cls does not complete.

Obviously a greenhorn perspective, but the solution works for now.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Tue Nov 01, 2011 1:10 pm

I still get a very few random vertical lines.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Tue Nov 01, 2011 2:14 pm

If adding delays helps, then it sounds more like you might have an issue with writing to the lcd too fast/while it's busy.

The KS0108 driver seems to be set up to use the lcd BUSY status flag, so if everything is working properly that shouldn't be a problem.

What device are you compiling for, and how are the GLCD #options defined, especially #option GLCD_DATA? Could you also show how you're setting up the pic IO ports?

I can't explain why the timer interrupt routine would show problems. If anything I would think it would help a little since it would slow down writes a touch, but timing-related issues can be funny things.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Tue Nov 01, 2011 5:36 pm

I am using the 18F 4620 and 18F4685. I have to double check the 4685, but I think it does the same thing.

#OPTION GLCD_DATA = PORTD
#OPTION GLCD_RS = PORTB.2
#OPTION GLCD_EN = PORTB.4
#OPTION GLCD_RST = PORTB.5
#OPTION GLCD_RW = PORTB.3
#OPTION GLCD_CS1 = PORTB.1
#OPTION GLCD_CS2 = PORTB.0
#OPTION GLCD_ASPECT_RATIO = 50
#OPTION GLCD_INIT_DELAY = 100
#OPTION GLCD_INVERT_CS = TRUE
#OPTION OW_PIN = PORTC.0
#OPTION GLCD_SCREEN_WIDTH = 128
#OPTION GLCD_SCREEN_HEIGHT = 64
#OPTION GLCD_MODEL = KS0108

TRISA = (TRISA And 240) Or 4
TRISA.2 = 0
TRISA.0 = 1
TRISA = (TRISA And 240) Or 2
TRISA.1 = 0
TRISA.3 = 1
ADCON1 = 2
TRISA = 0

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Tue Nov 01, 2011 8:46 pm

This is probably chasing a wild goose, but you're leaving the ADC pins all set for analog mode.
The LCD control pins are on some of those pins, and I wonder if you're seeing a RMW effect when the control lines are changed.

Code: Select all

TRISA = (TRISA And 240) Or 4
TRISA.2 = 0
TRISA.0 = 1
TRISA = (TRISA And 240) Or 2
TRISA.1 = 0
TRISA.3 = 1
ADCON1 = 2
TRISA = 0
I'm not sure what all the TRISA manipulations are for unless you're using some open-drain connections on those pins, but try adding

Code: Select all

ADCON1 = $0F
at the end of that sequence. For the 4620, that will set all of the pins to digital mode. Test that and see if it makes a difference.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Timer versus PLL and Display Static

Post by Intellisenc » Tue Feb 28, 2012 2:29 am

It looks to be is a combination of the timer, 4 X PLL and the KS0108. When I either disable timer #1 or switch the internal oscillator to 4Mhz instead of 8Mhz the display static goes away. I would like to use 8Mhz, but will stay with 4Mhz for now.

Intellisenc
Registered User
Registered User
Posts: 30
Joined: Mon Nov 22, 2010 3:08 am

Post by Intellisenc » Mon Jun 11, 2012 3:25 pm

I added "Low (PORTC.0)" before code including GLCD.WriteAt and the display is now clean. Port C.0 has multiple 1-Wire devices.

Post Reply