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.

Need help with Volt reading.

Status
Not open for further replies.

mastero

Member
Hello Friends

PIC16f690 @ 4mhz internal clock

Reading voltage at AN9 0vdc ~ vdc 4.46
Vdd as ref @ 4.46vdc
AN9 input via 5k pot with vdd as 4.46 and Vss as 0.00

Code:
'PIC16F690

Define CONFIG = 0x30f4
Define CLOCK_FREQUENCY = 4
AllDigital

Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
Dim digi3 As Byte
Dim digi2 As Byte
Dim digi1 As Byte
Dim digi0 As Byte
Dim temp As Word
Dim binval As Word
Dim volt As Word
'------------------------------------
ADCON0.ADON = 1
ADCON0.VCFG = 0
ADCON0.ADFM = 0
ADCON1 = 0x00

ADCON1 = %01010000
ANSELH.ANS9 = 1

TRISA = %00000000
TRISB = %00000000
TRISC = %10000000
'------------------------------------
Define LCD_BITS = 4
Define LCD_DREG = PORTC
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 0
Define LCD_RWREG = 0
Define LCD_RWBIT = 0
Define LCD_EREG = PORTA
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Lcdinit
Lcdcmdout LcdClear


main:  'main loop
    
    Gosub readadc
    Gosub bin2asc
    Lcdcmdout LcdClear
    Lcdout "Volt: ", digi3, digi2, ".", digi1, digi0

    Goto main

    End

readadc:

    Adcin 9, volt
    
        If volt > 0 Then
        
            volt = volt / 2
            
            binval = volt
        Endif
    Return

bin2asc:

digi3 = binval / 1000
temp = binval Mod 1000

digi2 = temp / 100
temp = temp Mod 100

digi1 = temp / 10
digi0 = temp Mod 10

digi3 = digi3 Or 0x30
digi2 = digi2 Or 0x30
digi1 = digi1 Or 0x30
digi0 = digi0 Or 0x30
    Return

The voltage on the DMM at pin AN9 and the result is off a few milli volts
any ideas ?

Thanx
Mastero
 
I believe he's using Vdd as the reference, which happens to be 4.46V.

The resolution of a 10-bit ADC is Vref/1024, in this case:

4.46/1024 = 0.00436V × 1000mV/V = 4.36mV.

So your measurements can't be better than a few mV off. If you need better results, you need an ADC with more bits.
 
Hi friends ......

Reached a bump need a push help please !!!!

CODE SNIP:~

bin2asc:
digi3 = binval / 1000
temp = binval Mod 1000
digi2 = temp / 100
temp = temp Mod 100
digi1 = temp / 10
digi0 = temp Mod 10

digi3 = digi3 Or 0x30
digi2 = digi2 Or 0x30
digi1 = digi1 Or 0x30
digi0 = digi0 Or 0x30

The above code works fine 00.00 reading
my bump is i need to read 00.000
any direction will be good ! code is same as in first post.

Thanx
Cheers
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top