Mike - K8LH
Well-Known Member
That example was for an 8 bit timer. I understand updating 16 bit timers may involve updating each half of the register in a certain order.
Last edited:
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
if(PIR1.CCP1IF) // CCP1 REGISTER COMPARE TMR3 Interrupt?
{
sCCPR1=BamH;
sCCPR1<<=4; // (changing this to 7 and then it works????)
CCPR1=sCCPR1;
itmp=0x01;
itmp<<=Bambit;
if(gamma[level] & itmp) LEDRED=1; else LEDRED=0;
asm INCF _BAMbit+0, 1 //
asm MOVLW 7 //
asm ANDWF _BAMbit+0, 1 // BAMbit = ( BAMbit+1 ) & 7
asm BZ LBL00 // if(Bambit==0) BamH= 0b11111110;
asm RLCF _BamH // BamH<<=1;
asm GOTO LBL01 // Were done for now
asm LBL00:
asm MOVLW 0b00000001 //
asm MOVWF _BamH // BamH= 0b11111110;
asm LBL01:
PIR1.CCP1IF = 0; // clear T0 Int flag
}
if(PIR1.CCP1IF) // CCP1 COMPARE TMR3 16mhz (1T=128 cycles) refrsh = 488 hz
{ // Total now is 60 cycles
asm MOVWF _BamL // Save W
asm MOVFF STATUS,_sSTATUS // Save STatus
asm MOVFF FSR0L,_sFSR0L // Save STatus
asm MOVFF FSR0H,_sFSR0H // Save STatus
// Load next BamTiming
asm MOVFF _sCCPR1H,CCPR1H
asm MOVFF _sCCPR1L,CCPR1L
// Start Precalc
// itmp<<=Bambit (51 cycles optimized to 7 cycles)
asm MOVLW 0x90 // masks[] at 0x90
asm MOVWF FSR0L // Point to masks[]
asm CLRF FSR0H
asm MOVF _Bambit,0 // Store in W
asm ADDWF FSR0L,1 // Store in F
asm MOVFF INDF0,_itmp
if(gamma[level] & itmp) LEDRED=1; else LEDRED=0; // 20 cycles
// LEDRED^=1; // Invert Bit at LATA,2
// BAMbit = ( BAMbit+1 ) & 7 and calculate next CCP COMPARE value
asm INCF _BAMbit+0, 1 //
asm MOVLW 7 //
asm ANDWF _BAMbit+0, 1 // BAMbit = ( BAMbit+1 ) & 7
asm BZ LBL00 // if(Bambit==0) BamH= 0b11111110;
asm RLCF _BamH // BamH<<=1;
asm GOTO LBL01 // Were done for now
asm LBL00:
asm MOVLW 0b00000001 //
asm MOVWF _BamH // BamH= 0b11111110;
asm LBL01:
// sCCPR1<<=7; // Takes > 40 cycles optimized to 6 cycles
asm CLRF _sCCPR1L
asm MOVFF _BamH,_sCCPR1H
asm RRCF _sCCPR1H,1 // Rotate Right store in F
asm BNC LBL02
asm BSF _sCCPR1L,7 // Set bit 7
asm LBL02: // Result 0BBBBBBB:B0000000 / 1T=128 cycles
PIR1.CCP1IF = 0; // clear T0 Int flag
asm MOVFF _sFSR0H, FSR0H // Restore FSR0H
asm MOVFF _sFSR0L, FSR0L // Restore FSR0L
asm MOVFF _sSTATUS, STATUS // Restore STATUS
asm MOVF _BamL,0 // Restore W
}