Hi
I'm new to forums and pic basic so please forgive if Iv'e missed somthing obvious.
I have built a battery charger, and I am using the 8 bit ADC on the 16f819 to measure the batt voltage and detect when it is fully charged.
The resolution for 8 bits was not quite good enough for my requirements so I want to use it in the 10 bit format.
My circuit and program works when using 8 bit, but when I try to use 10 bit, nothing happens.
I have a simple test circuit with LED's on the output of port b, and I can get the LED's to light, as a bar graph, in approx 10 mV increments.
Using the same test circuit and the code below for 10 bits, the leds are coming on as shown
RB0- on = 0V
RB1- on = 1.26V
RB2- on = 2.52V
RB3- on = 3.78V
RB4- dosn't come on.
Iv'e looked at the data sheet and lots of examples of 10 bit code, but can't see anything wrong with my program. I was hopeing for a resolution of about 5 mV.
I would be very gratefull if sombody could help.
Test program
DEFINE adc_bits 10
DEFINE adc_clock 3
DEFINE adc_sampleus 50
adval VAR WORD
portb=%00000000
trisb=%00000000
trisa=%11111111
adcon1=%100000010
loop:
ADCIN 2, adval
ledtst1:
IF adval > 0 THEN tst2
portb = %00000001
GOTO cont
tst2:
IF adval > 1 THEN tst3
portb = %00000011
GOTO cont
tst3:
IF adval > 2 THEN tst4
portb = %00000111
GOTO cont
tst4:
IF adval > 3 THEN tst5
portb = %00001111
GOTO cont
tst5:
portb = %00011111
cont:
PAUSE 100
GOTO loop
END
Bookmarks