Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! 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

Junior Member level 1
Joined
Feb 12, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Kuala Lumpur
Activity points
1,419
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.



Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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.
 
Last edited by a moderator:

1024 is for 5v, resolution will be 0.0048828125v/step. I am not so familiar with asm hence cannot say on asm. if you want help i can tell you in JAL. the open sorce software.
regards ani

- - - Updated - - -

you can try this hex adc is in low res code is for 16f877 it will turn off led when voltage drops below 2.5v


regards ani
 

Attachments

  • 0503.rar
    601 bytes · Views: 83
Last edited:

The voltage only detect 5v or any voltage?

My power source is battery which is 3.3V
 

as you said with the hex file i submitted the led will be on for voltages above 2.5v and off below 2.5v.
regards ani
 

Would you mind please give the assembly code. This is because I don't know which LED and ADC port that it is using.
 

I am using JAL v2 for programming while compiling an asm code is automaticaly generated that is kept for your reference along with HEX in the new attachment along with this replay. This code is specifically made for you with 16f677 lib. my earlier code was for 16f877 as i have already told.Hope this will help.
regards ani
 

Attachments

  • 16f677.rar
    5.8 KB · Views: 79

if you found the code usefull click the button(helped me) corresponding to that post.
regards ani
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top