Hello.
I've built a simple circuit, with 16F870 and MAX6126 as reference voltage supply.
The problem is that I can't write a code that will properly convert read data into voltage.
By using external multimeter, I've determined that with 678 read by ADC, voltage is 3 volts. Based on this, I've created a conversion formula, but it does not appears to work correctly, for example, when input is 4.1v, it reads as 4.35 volts. And when input is 1.4V, it reads as 1V. The code is as follows (based on :
Code:
Include "modedefs.bas" ' Include serial modes
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %10000001 ' Set PORTA analog and right justify result
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44
DEFINE OSC 4
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval Var word ' Create adval to store result
droebiti var word 'temporal value
mainloox:
ADCIN 0, adval ' Read channel 0 to adval
droebiti=adval*44 'convert to volts
Lcdout $fe,$c0, "Value: ", DEC adval, " " ' Display the decimal value
Lcdout $fe,$80, "Voltage: ", DEC (droebiti / 10000), ".", DEC4 droebiti, " V "
Pause 100 ' Wait .1 second
Goto mainloox ' Do it forever
What I'm doing wrong?
I'm using 10k pot with middle pin tied to RA0, one pin tied to Vss and another to voltage reference output. This might be the issue?
Bookmarks