![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I am having problems when trying to get the Timer1 module to interrupt on overflow. I know the timer is actually running as I have tested it by polling TMR1IF and it overflows accordingly. Code: ; Timer1 module setup clrf TMR1L clrf TMR1H BANKSEL PIE1 bsf PIE1,TMR1IE bcf PIR1,TMR1IF BANKSEL T1CON movlw b'00010000' movwf T1CON bsf T1CON,TMR1ON ; Start the timer bsf INTCON,GIE ; Enable interrupts bsf INTCON,PEIE Code: ISR <my rubbish here> BANKSEL PIR1 bcf PIR1,TMR1IF ; Clear the interrupt bit so it can happen again retfie Thought I had something when searching and found the PEIE bit needs to be set, so I did that and still nothing. Any ideas?
__________________ LCDGallery | |
| |
| | #2 | |
| Quote:
If the above is an abbreviated form of your ISR then ignore everything I've said. Mike. | ||
| |
| | #3 |
|
That is precisely what I had done before, which worked as you say, did not know I had to save W and STATUS myself - thought it was done for me. Which datasheet? There is no 12.11 in my copy of the 16F87XA datasheet.
__________________ LCDGallery | |
| |
| | #4 |
|
If you download the data sheet from microchip it's in there. Link to datasheet This is what it recomends you do. Code: interupt movwf int_work
swapf STATUS,W
movwf int_status; status is nibble swaped
; your stuff here
swapf int_status,W
movwf STATUS
swapf int_work,F; swap to file
swapf int_work,W; swap to work
retfie
Mike. | |
| |
| | #5 |
|
Still having problems ![]() Code: movwf int_work
swapf STATUS,W
movwf int_status; status is nibble swaped
BANKSEL PORTB
<my stuff>
BANKSEL PIR1
bcf PIR1,TMR1IF ; Clear the interrupt bit so it can happen again
swapf int_status,W
movwf STATUS
swapf int_work,F; swap to file
swapf int_work,W; swap to work
retfie
__________________ LCDGallery | |
| |
| | #6 |
| Code: ;*********************** ;* Wierd origin stuff * ;*********************** org 0x00 ; Program starts at program memory location 0x00 goto MAIN org 0x04 ; When interrupted, processor looks here - redirect it to my ISR goto ISR GOTO and CALL instruction also take into account of the two higher bits in the PCLATH to form the jump address and PCLATH could have other values when interrupt occurs. You don't have this uncertainty if you put your ISR at 0x04 and do away with the Goto statement.
__________________ L.Chung | |
| |
| | #7 |
|
Found one bug here: Code: BANKSEL PIE1
bsf PIE1,TMR1IE
bcf PIR1,TMR1IF
Fix: Code: BANKSEL PIE1
bsf PIE1,TMR1IE
BANKSEL PIR1
bcf PIR1,TMR1IF
__________________ "Having to do with Motion Control" | |
| |
| | #8 |
|
Motion, well spotted, that should fix it. I was wondering how the rest of his code was working with a ISR that wasn't saving context. Mike. | |
| |
| | #9 |
|
That has fixed it, thanks very much. I can remember myself reading the memory map and seeing (or not!) that PIR was in the same bank as PIE, then when I looked again just now it's moved! :lol: Anyway, thanks again guys.
__________________ LCDGallery | |
| |
|
| Tags |
| interrupting, timer1 |
| Thread Tools | |
| Display Modes | |
| |