Hello Eric. Try the following... (MPASM assembler) MOVFW ADRES SUBWF V,W DECF D,W SKPNC INCF D,W MOVWF D MOVWF CCPR1L WBR Dmitry. > I was wondering if some one could help me in figuring out how to compare two > numbers and either add one or subtract one on the pic16c72. > > In the varable V there is a constant 100 > The ADC is read in to W and V needs to be compared with the value > In the varable D is stored the result of the system, initilized to 100, this > is either added to or subtracted to. > > I have tried this but it all it does is give me 50% duty cycle out. > > MOVF ADRES,W ; Get A/D value > SUBWF V,W ; Test it > SKPNC ; Positive? > GOTO POS ; Yes goto add > MOVLW 0x01 ; No setup for subtract > SUBWF D,W ; Subtract one > GOTO CONT ; go to continue > > POS MOVF D,W ;setup for add > ADDLW 0x01 > > CONT MOVWF D ; stores new result back into D for > next loop > MOVWF CCPR1L ; to PWM register channel 1