Dennis Crawley wrote: > The more I read the manuals and techref, the more I lose my > intuition. I'm trying to make a simple and short routine to deal > with the two *stupid* bits, just in the middle of CCP1CON. The > routine must increment de Duty Cycle of the PWM module, when it's > called. > .... > I've arrived to this workable code: > ;-------------------------------------------- > ;takes 17 cycles and 14 for rollover > PWMDutyIncr > > [snip] > > ;-------------------------------------------- > ;takes 16cyles 20 for rollover > PWMDutyDecr > > [snip] Dennis: The following code has neither been tested nor even assembled, but it should do what you want. Note that it uses the MPASM pseudo-ops defined in the MPASM User's Manual, and that "CCP1X" is defined as "CCP1CON,4". ; 8, 9, OR 11 CYCLES PWMDutyIncr: COMF CCP1CON,W ;CCP1Y:X = 11? ANDLW 00110000B ; BZ INC1L ;If so, we need to inc CCPR1L. Jump. MOVLW 00010000B ;Otherwise, inc CCP1Y:X. We're ADDWF CCP1CON ;guaranteed no overflow into bit 6. GOTO INCDONE ;We're done. Go exit. INC1L: INCF CCPR1L,W ;CCP1Y:X = 11. CCPR1L = 0xFF? BZ INCDONE ;If so, we're done. Go exit. MOVWF CCPR1L ;Otherwise, inc CCPR1L and clear BCF CCP1Y ;CCPR1Y:X to 00. BCF CCP1X ; INCDONE: ;Exit. ;8 9, or 11 CYCLES PWMDutyDecr: MOVLW 00110000B ;CCP1Y:X = 00? ANDWF CCP1CON,W ; BZ DEC1L ;If so, we need to dec CCPR1l. Jump. MOVLW 00010000B ;Otherwise, dec CCP1Y:X. We're SUBWF CCP1CON ;guaranteed no borrow from bit 6. GOTO DECDONE ;We're done. Go exit. DEC1L: TSTF CCPR1L ;CCP1Y:X = 00. CCPR1L = 0x00? BZ DECDONE ;If so, we're done. Go exit. DECF CCPR1L ;Otherwise, dec CCPR1L and set BSF CCP1Y ;CCPR1Y:X to 11. BSF CCP1X ; DECDONE: ;Exit. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu