Having problems getting the LTC1298 to read more accurately.
pimp200277
Posts: 22
Hi,
My problems is I can't seem to get my ADC - LTC1298 (12-bit analog to digital converter) to read my pH sensor accurately enough.
My pH sensor output for what I am measuring·is suppose to be ·about 2.25volts.
so after converting the analog reading to voltage·using this formula··Vref *·analog reading / 4096
I am only getting for an output the number·" 2 ".
CODE:
' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS····· CON·· 9······· ' Chip Select
DIO_10· CON·· 10······ ' Data I/O pin 10
CLK···· CON·· 11······ ' Clock
' LTC1298 configuration
AD····· VAR·· Word···· ' Variable to hold 12-bit AD result.
config· VAR·· Nib
v······ VAR·· Byte
HIGH CS··············· ' Deactivate ADC to begin.
HIGH DIO_10··········· ' Set data pin for first start bit.
again:
· GOSUB convert···················· ' Get data from ADC.
· GOSUB calc_volt
· DEBUG· "A/D Reading: ",DEC AD,CR
· DEBUG· "volt Reading: ",DEC v, CR
· PAUSE 500······························· ' Wait a half second.
GOTO again································ ' Endless loop.
Calc_Volt:
v = 5 * AD / 4096
convert:
config = config | %1011
· LOW CS·································· ' Activate the ADC.
· SHIFTOUT DIO_10,CLK,LSBFIRST,[noparse][[/noparse]config\4]· ' Send config bits.
· SHIFTIN DIO_10,CLK,MSBPOST,[noparse][[/noparse]AD\12]······ ' Get data bits.
· HIGH CS································· ' Deactivate the ADC.
RETURN···································· ' Return to program.
Results:
A/D Reading: 2129
volt Reading: 2
A/D Reading: 2128
volt Reading: 2
A/D Reading: 2126
volt Reading: 2
A/D Reading: 2130
volt Reading: 2
A/D Reading: 2126
volt Reading: 2
I tired putting "DEC3" instead of "DEC" on the Debug volt reading line and I got this:
A/D Reading: 2127
volt Reading: 002
A/D Reading: 2129
volt Reading: 002
A/D Reading: 2127
volt Reading: 002
A/D Reading: 2128
volt Reading: 002
A/D Reading: 2129
volt Reading: 002
Any Suggestions on what I should try?
My problems is I can't seem to get my ADC - LTC1298 (12-bit analog to digital converter) to read my pH sensor accurately enough.
My pH sensor output for what I am measuring·is suppose to be ·about 2.25volts.
so after converting the analog reading to voltage·using this formula··Vref *·analog reading / 4096
I am only getting for an output the number·" 2 ".
CODE:
' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS····· CON·· 9······· ' Chip Select
DIO_10· CON·· 10······ ' Data I/O pin 10
CLK···· CON·· 11······ ' Clock
' LTC1298 configuration
AD····· VAR·· Word···· ' Variable to hold 12-bit AD result.
config· VAR·· Nib
v······ VAR·· Byte
HIGH CS··············· ' Deactivate ADC to begin.
HIGH DIO_10··········· ' Set data pin for first start bit.
again:
· GOSUB convert···················· ' Get data from ADC.
· GOSUB calc_volt
· DEBUG· "A/D Reading: ",DEC AD,CR
· DEBUG· "volt Reading: ",DEC v, CR
· PAUSE 500······························· ' Wait a half second.
GOTO again································ ' Endless loop.
Calc_Volt:
v = 5 * AD / 4096
convert:
config = config | %1011
· LOW CS·································· ' Activate the ADC.
· SHIFTOUT DIO_10,CLK,LSBFIRST,[noparse][[/noparse]config\4]· ' Send config bits.
· SHIFTIN DIO_10,CLK,MSBPOST,[noparse][[/noparse]AD\12]······ ' Get data bits.
· HIGH CS································· ' Deactivate the ADC.
RETURN···································· ' Return to program.
Results:
A/D Reading: 2129
volt Reading: 2
A/D Reading: 2128
volt Reading: 2
A/D Reading: 2126
volt Reading: 2
A/D Reading: 2130
volt Reading: 2
A/D Reading: 2126
volt Reading: 2
I tired putting "DEC3" instead of "DEC" on the Debug volt reading line and I got this:
A/D Reading: 2127
volt Reading: 002
A/D Reading: 2129
volt Reading: 002
A/D Reading: 2127
volt Reading: 002
A/D Reading: 2128
volt Reading: 002
A/D Reading: 2129
volt Reading: 002
Any Suggestions on what I should try?
Comments
Try multiplying your equation by 100, and then the output should be 225.
Then, you could print that, or if you really wanted to, parse it and add a "."
That is not the problem though. In convert use this equation instead of 5*AD/4000:
v = 8000 ** AD
Then the answer when AD=2129 will be 259, which you can display with a decimal point...
DEBUG "volt Reading: ",DEC v/100,".",DEC2 v, CR
Why 8000 ** AD? That is the same as 8000/65536, where the division by 65536 is implied in the ** operator. And the fraction you want is 500/4096 = 8000/65536.
Need more accuracy for roundoff? Use
v = 40000 ** AD * 2
DEBUG "volt Reading: ",DEC v/1000,".",DEC3 v, CR
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I will give your suggestion a try.
The results were:
A/D Reading: 2128
volt Reading: 0.03
A/D Reading: 2129
volt Reading: 0.03
A/D Reading: 2129
volt Reading: 0.03
A/D Reading: 2126
volt Reading: 0.03
A/D Reading: 2127
volt Reading: 0.03
A/D Reading: 2125
volt Reading: 0.03
A/D Reading: 2126
volt Reading: 0.03
A/D Reading: 2126
volt Reading: 0.03
A/D Reading: 2127
volt Reading: 0.03
A/D Reading: 2127
volt Reading: 0.03
A/D Reading: 2129
volt Reading: 0.03
A/D Reading: 2124
volt Reading: 0.03
A/D Reading: 2129
volt Reading: 0.04
A/D Reading: 1882
volt Reading: 2.02
A/D Reading: 1874
volt Reading: 2.02
A/D Reading: 1869
volt Reading: 2.02
A/D Reading: 1852
volt Reading: 2.02
A/D Reading: 1835
volt Reading: 2.02
A/D Reading: 1826
volt Reading: 2.02
A/D Reading: 1806
volt Reading: 2.02
A/D Reading: 1789
volt Reading: 2.02
A/D Reading: 1781
volt Reading: 2.02
A/D Reading: 1773
volt Reading: 2.02
A/D Reading: 1764
volt Reading: 2.02
A/D Reading: 1759
volt Reading: 2.02
A/D Reading: 1754
volt Reading: 2.02
A/D Reading: 1742
volt Reading: 2.02
A/D Reading: 1721
volt Reading: 2.02
A/D Reading: 1703
volt Reading: 2.02
A/D Reading: 1698
volt Reading: 2.02
A/D Reading: 1687
volt Reading: 2.02
A/D Reading: 1677
volt Reading: 2.02
A/D Reading: 1673
volt Reading: 2.02
A/D Reading: 1672
volt Reading: 2.02
A/D Reading: 1672
volt Reading: 2.02
A/D Reading: 1666
volt Reading: 2.02
A/D Reading: 1664
volt Reading: 2.02
A/D Reading: 1657
volt Reading: 2.02
A/D Reading: 1660
volt Reading: 2.02
A/D Reading: 1655
volt Reading: 2.02
A/D Reading: 1648
volt Reading: 2.02
So now I only have 1 problem how do I get the Volt Reading to Change along with the A/D Reading at the same time it Changes?
As you can see from the results above the A/D readings are changing but the volt Reading remains the same.
CODE:
' {$STAMP BS2}
' {$PBASIC 2.5}
' Pin Assignments
CS CON 9 ' Chip Select
DIO_10 CON 10 ' Data I/O pin 10
CLK CON 11 ' Clock
' LTC1298 configuration
AD VAR Word ' Variable to hold 12-bit AD result.
pH VAR Word ' pH value of the water
config VAR Nib
v VAR Byte
v2 VAR Byte
HIGH CS ' Deactivate ADC to begin.
HIGH DIO_10 ' Set data pin for first start bit.
again:
GOSUB convert ' Get data from ADC.
GOSUB calc_volt
DEBUG "A/D Reading: ",DEC AD,CR
DEBUG "volt Reading: ",DEC v/100,".",DEC2 v, CR
PAUSE 500 ' Wait a half second.
GOTO again ' Endless loop.
Calc_Volt:
v = 8000 ** AD
v2 = v * 100
RETURN
convert:
config = config | %1011
LOW CS ' Activate the ADC.
SHIFTOUT DIO_10,CLK,LSBFIRST,[noparse][[/noparse]config\4] ' Send config bits.
SHIFTIN DIO_10,CLK,MSBPOST,[noparse][[/noparse]AD\12] ' Get data bits.
HIGH CS ' Deactivate the ADC.
RETURN ' Return to program.
And these Results:
A/D Reading: 1547
volt Reading: 1.88
A/D Reading: 1544
volt Reading: 1.88
A/D Reading: 1545
volt Reading: 1.88
A/D Reading: 1548
volt Reading: 1.88
A/D Reading: 1549
volt Reading: 1.89
A/D Reading: 1550
volt Reading: 1.89
A/D Reading: 1551
volt Reading: 1.89
A/D Reading: 1546
volt Reading: 1.88
A/D Reading: 1552
volt Reading: 1.89
A/D Reading: 1556
volt Reading: 1.89
A/D Reading: 1555
volt Reading: 1.89
A/D Reading: 1556
volt Reading: 1.89
A/D Reading: 1556
volt Reading: 1.89
A/D Reading: 1561
volt Reading: 1.90
A/D Reading: 1558
volt Reading: 1.90
A/D Reading: 1561
volt Reading: 1.90
A/D Reading: 1778
volt Reading: 2.17
A/D Reading: 1781
volt Reading: 2.17
A/D Reading: 1778
volt Reading: 2.17
A/D Reading: 1763
volt Reading: 2.15
A/D Reading: 1766
volt Reading: 2.15
A/D Reading: 1761
volt Reading: 2.14
A/D Reading: 1761
volt Reading: 2.14
A/D Reading: 1775
volt Reading: 2.16
A/D Reading: 1761
volt Reading: 2.14
A/D Reading: 1757
volt Reading: 2.14
A/D Reading: 1754
volt Reading: 2.14
A/D Reading: 1757
volt Reading: 2.14
without having to make a new line everytime there's a new value. I just want 2 lines of results:
1 - A/D reading
1 - volt reading
That keep changing values without having the results keep listing like in my post above
DEBUG CRSRXY, #, #
Where #,# is the x, y location (column, row I think - and they start at 0) You don't have to reprint the whole line either, just the part that changes.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Rick
DEBUG HOME, "A/D Reading: ",DEC AD,CLREOL,CR
DEBUG "volt Reading: ",DEC v/100,".",DEC2 v,CLREOL,CR
You can read about the control characters in the manual along with the DEBUG command.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com