Timer #1, Interrupt/128X64 KS0108 conflict
Moderators: David Barker, Jerry Messina
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
Timer #1, Interrupt/128X64 KS0108 conflict
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?
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?
-
- Swordfish Developer
- Posts: 1469
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
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
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
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!!!
ARM CORTEX Rules!!!
-
- Swordfish Developer
- Posts: 1469
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
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.
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.
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 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.
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.
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
-
- Swordfish Developer
- Posts: 1469
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
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.
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.
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
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
#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
-
- Swordfish Developer
- Posts: 1469
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
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.
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
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.
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
Code: Select all
ADCON1 = $0F
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am
Timer versus PLL and Display Static
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.
-
- Registered User
- Posts: 30
- Joined: Mon Nov 22, 2010 3:08 am