As mentioned above, I've added every single register entry that I could find that was related to timer1.
The interrupt now executes, but I'm getting weird results.
Firstly here's the code for the registry entrys I've added:
I'm thinking I've added too many, but I don't really know how they work - even after reading the datasheet several times. If anyone has any comments to make about these I'd be most grateful, I really am trying to learn.Code:T1CON = %00110001 'ENABLE X,X,PRESCALER = 8,X,X,X,TMR1ON INTCON = %11001000 'ENABLE GIE,PEIE,x,x,GPIE,x,x,x GIE var INTCON.7 PEIE var INTCON.6 TMR1IE var PIE1.0 TMR1ON var T1CON.0 TMR1IE = 1 ' PEIE = 1 'WHO KNOWS GIE = 1 'WHAT ALL OF PIR1.0 = 0 'THESE DO, BUT IT TMR1H = 0 'DIDN'T START TMR1L = 0 'WITHOUT THEM.
Here's the interrupt routine again:
and here's the results on the serial port:Code:DISABLE' INTERRUPT INTCODE: IF SERVO1 = 0 THEN HSEROUT ["FIRST IF - POSITION: ",DEC POSITION,10] TMR1H = ((65535 - POSITION)/256) 'EXTRACT HIGH BYTE INTO TIMER1 TMR1L = ((65535 - POSITION)-(TMR1H*256)) 'EXTRACT LOW BYTE HSEROUT ["HIGH: ", DEC TMR1H," LOW: ", DEC TMR1L,10] SERVO1 = 1 HSEROUT ["SERVO1: ",DEC SERVO1,10,10] ENDIF IF SERVO1 = 1 THEN HSEROUT ["SECOND IF - TMROFF: ",DEC TMROFF,10] TMR1H = ((65535 - TMROFF)/256) 'EXTRACT HIGH BYTE INTO TIMER1 TMR1L = ((65535 - TMROFF)-(TMR1H*256)) 'EXTRACT LOW BYTE HSEROUT ["HIGH: ", DEC TMR1H," LOW: ", DEC TMR1L,10,10,13] SERVO1 = 0 HSEROUT ["SERVO1: ",DEC SERVO1,10,10] ENDIF INTCON.0 = 0 PIR1.0 = 0 RESUME ENABLE' INTERRUPT
FIRST IF - POSITION: 225
HIGH: 12 LOW: 64
SERVO1: 0
This is where it gets weird. I'm trying to extract the high and low bits for timer1, ie. I want the timer to countdown for the amount of time stored in 'position'. So the timer has to equal 65535 - Position. I need to break this down into the high and low bits for tmr1H and tmr1L. So tmr1H = 65535 - position / 256 etc. (much thanks to Aratti for helping me with that).
The strange thing is the value that the PIC has calculated for high and low.
high should equal (65535 - 225(value for position is shown in serout))/256 = 255.11 (I know we'll lose the .11)
Low should equal ((65535 - 225)-(255*256) = 30
of course this last value won't be correct until the first one comes out right, but even with the first incorrect value from formula one in place it's still all wrong.
I can't figure it out. Why so far out?
It looks too simple to go wrong. I'm missing something.
Can hair be glued back in?
I can't find a smilie for crying desperately...




Bookmarks