PHXSYS wrote: > The program displays the results, but the overflow does not work. > The LED display 255, then appear to roll over. It should read a max > of 250. .... > > CLRF PULSE1S ;Clear previous value > > CAP_C > > BSF PORTA,0 ;START CAPACITOR CHARGE > NOP ;Time to charge > MOVLW b'11111111' ;Set PortA,0 to input > TRIS PORTA ;Teach portA > > MEAS1 > > CLRWDT > BTFSS PORTA,0 ;Test A0 skip if 1 > RETURN ; > > INCFSZ PULSE1S,F ;Inc pulse1s skip if 0 > GOTO MEAS1 ; > > MOVLW 0FAH ;LOAD MAX PULSE; 250 > SUBWF PULSE1S, w ;Subtract current value from it > BTFSS STATUS, C ;If carry = 1, result is positive > GOTO BEGIN ;No it is not -> goto down > MOVLW 0FAH ;Load Maximum Pulse Width > MOVWF PULSE1S ;Store it in the position Value location Nichole: The PIC will only reach the first "MOVLW 0FAH" when PULSE1S is incremented fropm 255 to 0... If PULSE1S is less than or equal to 255 when PORTA:0 goes low, the RETURN will be taken and your "limit to 250" code won't even be executed. Now... When the "limit" code IS executed, PULSE1S will always be equal to 0, so the SUBWF (which subtracts 250 from PULSE1S) will always be negative, and the GOTO BEGIN will always be taken. Basically, your code is badly broken. If I were writing it, I'd do something like this: MOVLW 250 ;Start at 250 (we'll be counting down). MOVWF PULSE1S ; CAP_C: BSF PORTA,0 ;Charge the cap. NOP ; MOVLW 11111111B ;Stop charging and prepare to time the TRIS PORTA ;discharge. MEAS1: CLRWDT ;Reset the watchdog timer. BTFSS PORTA,0 ;If the cap has discharged, jump to GOTO CLEANUP ;CLEANUP. DECFSZ PULSE1S ;Otherwise, decrement PULSE1S. GOTO MEAS1 ;If PULSE1S has not yet reached 0, ;loop back. ; At this point, we've either looped 250 times, or the cap ; has discharged. Either way, PULSE1S = 250 - [number of loops]. MOVF PULSE1S,W ;PULSE1S = 250 - PULSE1S. SUBLW 250 ; MOVWF PULSE1S ; RETURN ;Return with PULSE1S = number of loops, ;limited to a maximum of 250. -Andy P.S. Note that the last four lines of my suggested code are different from what I sent you in private e-mail... Please disregard that earlier response. === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499