It's been a while since I posted anything here because since the last post I rode my motorcycle from Austin, TX to Burlington, ME and back and had a 2 week vacation in Finland, Norway, and Sweden. After a 3-week recovery, I am back to PIC programming.

I'm having trouble with the 16-bit mode of timer0 in a PIC18f2620. I don't seem to be able to get TMR0H to change. Basically I'm trying to get it to count from 0 to 65535 in about 26.2 MS, but TMR0H never seems to change. Here's the code

Code:
 
;**********************************************************************
 
;    Files Required:     P18F2620.INC                                  *
;**********************************************************************
;    Notes: Future version will incorporate                           *
;    1) Low battery detector to start a flashing warning when the       *
;       voltage drops below 3v/cell for LIPO's                          *
;     2) A digital compass so the quadracopter has a sense of           *
;        direction.                                                      *
;     3) A GPS so the quadracopter is capable of moving to specific      *
;        coordinates.                                                  *
;**********************************************************************
    errorlevel         -302                     ; wrong bank warning
    LIST             P=18F2620                ;directive to define processor
    #include         
            ;processor specific variable definitions
 
    CONFIG WDT=OFF                            ; disable watchdog timer
    CONFIG MCLRE = ON                        ; MCLEAR Pin on
    CONFIG DEBUG = OFF                        ; Disable Debug Mode / RB6-7 are I/O pins
    CONFIG LVP = OFF                        ; Low-Voltage programming disabled (necessary for debugging)
    CONFIG OSC = HSPLL
 
    CBLOCK    0x080
WREG_TEMP                                    ;variable used for context saving 
STATUS_TEMP                                    ;variable used for context saving
BSR_TEMP                                    ;variable used for context saving
    ENDC
 
;*****************************************************************************************
;    DEFINES VARIABLES                                                                      *
;*****************************************************************************************
; PORTA definitions
#define FRONT         PORTA,0                    ; Front servo output
#define BACK         PORTA,1
#define LEFT         PORTA,2
#define RIGHT         PORTA,3
 
; define input pulses
#define AILERON        rb_read,4                ; Aileron input
#define ELEVATOR    rb_read,5
#define THROTTLE    rb_read,6
#define RUDDER        rb_read,7
 
#define             RUDDER_PULSE    FLAGS,0
#define             IN_OUTPUT        FLAGS,1
 
    udata
w_temp                res    1                    ; variable used for context saving
status_temp            res 1                    ; variable used for context saving
pclath_temp            res    1                    ; variable used for context saving
 
FLAGS                res    1                    ; just a byte for various flags
rb_read                res 1                    ; storage loc for the inputs
 
aileron_high_l        res 1                    ; timer0 low byte
aileron_high_h        res 1                    ; timer0 high byte
aileron_low_l         res 1                    
aileron_low_h         res 1                    
 
throttle_high_l        res 1                    ; timer0 low byte
throttle_high_h        res 1                    ; timer0 high byte
throttle_low_l         res 1                    
throttle_low_h         res 1                    
 
elevator_high_l        res 1                    ; timer0 low byte
elevator_high_h        res 1                    ; timer0 high byte
elevator_low_l         res 1                    
elevator_low_h         res 1                    
 
rudder_high_l        res 1                    ; timer0 low byte
rudder_high_h        res 1                    ; timer0 high byte
rudder_low_l         res 1                    
rudder_low_h         res 1                    
 
 
        code        0x0000
          goto           main                    ; Reset Vector, go to beginning of program
 
        ORG         0x0008                     ; high priority interrupt vector location
        bra         high_int                ; high priority interrupt, goto high_int
 
        ORG            0x0018                    ; low priority interrupt vector
        movff        STATUS,STATUS_TEMP        ; save STATUS register
        movff        WREG,WREG_TEMP            ; save working register
        movff        BSR,BSR_TEMP            ; save BSR register
 
        call        low_int
 
        movff        BSR_TEMP,BSR            ;restore BSR register
        movff        WREG_TEMP,WREG            ;restore working register
        movff        STATUS_TEMP,STATUS        ;restore STATUS register
 
        retfie
 
main:
        clrf        ADCON0                    ; Turn off A/D converters
        movlw        0x0F                
        movwf        ADCON1                    ; All pins are Digital I/O                         
        movlw        0x07                    
        movwf        CMCON                    ; turn off the comparators
        clrf        TRISA                    ; all pins are outputs                            
        movlw        0xF0    
        movwf        TRISB                    ; 7:4 input, 3:0 outputs 
        clrf        TRISC                    ; all outputs
        clrf        PORTA                    ; all zeros
        clrf        PORTB                    ; all zeros
        clrf        PORTC                    ; all zeros
 
; Set TMR0 to 16-bit mode, interrupt every 26.2ms & enable RB change
        movlw        B'10000001'             
        movwf        T0CON                    ; timer0 enable, 16-bit, 1:4
        movlw        B'11101000'
        movwf        INTCON                     ; Global IE, Peripheral IE, TMR0 Overflow Int Enable, RB change
        clrf        INTCON2 
        movlw        0
        movwf        TMR0H
        movwf        TMR0L                     ; set the timer0 offset for 26.2ms
        clrf        CVRCON                    ; comparators off
 
        clrf        rb_read
        clrf        FLAGS
 
loop:
        goto        loop
 
high_int
        btfsc        INTCON, TMR0IF            ; if TMR0IF is set, it's a clock interrupt
        call        clock_isr
        btfsc        INTCON, RBIF            ; if RBIF is set, it's a data change interrupt
        call        data_isr
        retfie        FAST
 
low_int                                      ; comes here on low priority interrupt
 
        return
 
;********************************************************************************************************
clock_isr:
;********************************************************************************************************
; reset the timer0 to interrupt after 26.2ms
        movlw        0                        ; set timer for 26.2ms
;        movwf        TMR0H
        movwf        TMR0L
        bcf            INTCON, TMR0IF            ; reset the timer0 interrupt flag
clock_exit
        return                               ; return from interrupt
 
;********************************************************************************************************
data_isr:
;********************************************************************************************************
        movf        PORTB, w                ; get 4 inputs (clear the mismatch)    
        bcf            INTCON, RBIF            ; clear the interrupt flag
        movwf        rb_read                    ; move w register to rb_read
 
        return                              ; return from interrupt
 
        END
I'm using MPLAB 8.46 and only the TMR0L is incrementing. ???

Posted by PickyBiker

===================

Posted by Bruce:

Place TMR0_Internal in the watch window VS TMR0H & TMROL. With MPSIM you sometimes need to place TMRx_Internal in the watch windows VS TMRxH since this is a shadow register on some, and doesn't update like normal.

Edit: Attempted to move this thread from the PBP section, and deleted by mistake, so re-posted relevant portions here. Sorry..