Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F677 detect incoming voltage using ADC

Status
Not open for further replies.

ben8118

New Member
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.
 
I believe that you are using the Vdd as an external voltage reference. This voltage drops when the battery voltage drops.. so the ADC reading is always the same if you try to read the battery voltage.

What you need to do is to use the Vdd as a voltage reference and read the 0.6V internal reference with the ADC. The ADC values will increase when the battery voltage drops.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top