Dear all,
The project I handle need to detect the incoming voltage. I'm detecting 2 x AAA battery (3.3v), when voltage drop below than 2.5V will turn off LED.
The problem I facing is I cannot get the reading correctly. I using assembly to write. I even copy and paste the code example from the datasheet, I still unable to get correct data. Below is the coding I take from the datasheet and modify. I using internal oscillator/clock.
BANKSEL ADCON1 ;
MOVLW B'01110000' ;ADC Frc clock
MOVWF ADCON1 ;
BANKSEL TRISA ;
BSF TRISA,0 ;Set RA0 to input
BCF TRISC,4 ;turn on LED2
BANKSEL ANSEL ;
BSF ANSEL,0 ;Set RA0 to analog
BANKSEL ADCON0 ;
MOVLW B'10000001' ;Right justify,
MOVWF ADCON0 ; Vdd Vref, AN0, On
MOVLW 0X64 ;1MS
MOVWF ONEMSCOUT
CALL DELAYONEMS ;Acquisiton delay
BSF ADCON0,GO ;Start conversion
BTFSC ADCON0,GO ;Is conversion done?
GOTO $-1 ;No, test again
BANKSEL ADRESH ;
MOVF ADRESH,W ;Read upper 2 bits
MOVWF RESULTHI ;store in GPR space
BANKSEL ADRESL ;
MOVF ADRESL,W ;Read lower 8 bits
MOVWF RESULTLO
BTFSC RESULTLO,7
BSF LED2
GOTO $+1
GOTO $-1
I calculate 1 step is 0.003v (1024/3.3v).
When incoming voltage is 3.3, the LED is turn on.
When voltage is 2.5, the LED should turn off, but the LED is turn on.
I have troubleshoot by change to other port such as port c. The problem still unsolved.
Thanks.
The project I handle need to detect the incoming voltage. I'm detecting 2 x AAA battery (3.3v), when voltage drop below than 2.5V will turn off LED.
The problem I facing is I cannot get the reading correctly. I using assembly to write. I even copy and paste the code example from the datasheet, I still unable to get correct data. Below is the coding I take from the datasheet and modify. I using internal oscillator/clock.
BANKSEL ADCON1 ;
MOVLW B'01110000' ;ADC Frc clock
MOVWF ADCON1 ;
BANKSEL TRISA ;
BSF TRISA,0 ;Set RA0 to input
BCF TRISC,4 ;turn on LED2
BANKSEL ANSEL ;
BSF ANSEL,0 ;Set RA0 to analog
BANKSEL ADCON0 ;
MOVLW B'10000001' ;Right justify,
MOVWF ADCON0 ; Vdd Vref, AN0, On
MOVLW 0X64 ;1MS
MOVWF ONEMSCOUT
CALL DELAYONEMS ;Acquisiton delay
BSF ADCON0,GO ;Start conversion
BTFSC ADCON0,GO ;Is conversion done?
GOTO $-1 ;No, test again
BANKSEL ADRESH ;
MOVF ADRESH,W ;Read upper 2 bits
MOVWF RESULTHI ;store in GPR space
BANKSEL ADRESL ;
MOVF ADRESL,W ;Read lower 8 bits
MOVWF RESULTLO
BTFSC RESULTLO,7
BSF LED2
GOTO $+1
GOTO $-1
I calculate 1 step is 0.003v (1024/3.3v).
When incoming voltage is 3.3, the LED is turn on.
When voltage is 2.5, the LED should turn off, but the LED is turn on.
I have troubleshoot by change to other port such as port c. The problem still unsolved.
Thanks.