It looks like you are corrupting the data in ADRESH with the subwf ADRESH,1 instruction which, for clarity, should be written as subwf ADRESH,F because you are storing the result of the subtraction in ADRESH. But you really should do this instead: subwf ADRESH,W because you want to preserve the data in ADRESH. This is also bad; movf Peak. I'm sure you intended this; movf Peak, W
Code:
Wait btfsc ADCON0,GO ;Wait for conversion to complete
goto Wait
movfw Peak ;get Peak value '0' to w
[COLOR="Red"]subwf ADRESH,1[/COLOR] ;do ADC-Peak
btfss STATUS,C ;C set if ADC>Peak
goto DoneMax ;not higher
movfw ADRESH ;is higher
movwf Peak ;so copy to peak
goto Main ;do it again!
DoneMax
[COLOR="RoyalBlue"]movf Peak[/COLOR] ;Write **AMPLITUDE** result to PORTC
movwf PORTC ;LEDs
goto loop_abc
loop_abc
clrwdt
goto loop_abc
Last edited: