Not sure what the ADC reading should be. It depends on the ADC reference voltage as well as the input voltage. If you have a 12 bit adc with a 2.56V reference a one volt input would give a reading of 1600. Basically it would be ( Vin / Vref * ADCmax ).
In the case of a PH meter since water is neutral PH it would be in the middle of the range so I would expect the reading should be approximately half of the full scale of the ADC. What ADC are you using?
the adc is a TLV2543 spec sheet posted earlier in the thread. its a 12bit 11 channel ADC with a 3.3v refrence
Using the formula you posted previously, it should be reading 1240. I can live with a 10 millivolt mismatch on my meter.
Here is a snippet of code, when the input is shorted, the ph reading is 5.1. It should be 7.
I converted this code from Tracy's Allens PBASIC code.
mv := fm.FFloat(adc.GetData(0)) ' Get millivolt reading from ADC
frac := fm.FDiv(700.0,828.0) ' Fraction of 7.00 pH units per 0.828 volt change 700/828
offset := fm.FMul(mv,frac) ' convert from millivolts to pH
adjust := fm.FSub(offset,845.0) ' 845 is the 1 volt offset, times 700/828
pha := fm.FSub(700.0,adjust) ' adjusts to pH 7.00 at 1 volt input, decreasing in acid
ph := fm.FDiv(pha,100.0) ' round it off
I think you need to do the calibration at this point. For best accuracy you really need calibration solution for both ends of the scale and mid point (PH = 7) if it is a linear curve. A 5 point calibration would be even better, particularly if it is not linear. The general formula is a + bx for a linear curve, where x is the ADC reading, a is the offset (the 10mV) and b would be the slope of the calibration curve.
pHloop:
gosub ADread ' return millivolts, mV, not shown
pH = mV ** 55405 ' stamp's way to multiply times 700/828 (see below)
pH = pH - 845 ' 845 is the 1 volt offset, times 700/828
pH = 700 - pH ' adjusts to pH 7.00 at 1 volt input, decreasing in acid
debug rep "-"\pH.bit14,dec abs (pH/100),".".dec2 abs pH ' display with decimal point xx.xx
goto pHloop
I think you are formally close on the PBASIC to Spin translation. As Kwinn has pointed out, for best results it will need calibration for the range of interest.
The numbers in the math assume that the electrode sensitivity is 59.16 mV per pH unit, times a gain of x2 in the amplifier, and that comes out to 118.32 mV/pH unit at the ADC. The math then converts a change of 118 mV at the ADC to a digital display change of 100, or 1.00 pH unit. The ** multiplier in either PBASIC or SPIN does that scaling, multiply times 100/118. The amplifier offset is 1000 mV, and subtracting 845 removes that offset. Then the final step (which could be combined with the previous one), puts in the offset 700 for pH 7. That happens when the input voltage is zero (neutral pH).
In practice, the electrode sensitivity will not be exactly 59.16 mV per pH unit, and there will likely be a small voltage offset in neutral pH (not pH7 => 0 volts exactly). The sensitivity is predictably dependent on temperature, too (higher mV/pH at higher temperatures). The math you have will be a good first approximation.
In Spin, the code for display will depend on what kind of display you have, terminal screen, TV, LCD? SimpleSerial would be a good start for a terminal screen, or the DEBUG equivalents from the BS2 functions library.
the problem I am having is converting this pH.bit14,dec abs (pH/100),".".dec2 abs pH
I cant seem to find anything equivalent to the .bitx
my first atttempt was:
frac := fm.FDiv(7.0,0.828) ' Fraction of 7.00 pH units per 0.828 volt change 700/828
offset := fm.FMul(frac,1000.0)
resolution := fm.FDiv(3.3,4096.0) ' adc resolution per step
mv := fm.FFloat(adc.GetData(1)) ' Get reading from ADC
mv := fm.FMul(mv,resolution) ' Convert to actual voltage
mv := fm.FMul(mv,1000.0) ' Convert to millivolts
ph := fm.FMul(mv,frac) ' convert from millivolts to pH
ph := fm.FSub(ph,offset) ' 1 volt offset compensation
ph := fm.FSub(7.0,ph) ' adjusts to pH 7.00 at 1 volt input
ph := fm.FDiv(ph,10.0)
This works buts is very erratic the reading will jump from 7 to 8 and back to six. the adc output changing from 1231 to 1232 or 1230 will cause this. So I wanted to try and duplicate your code as closely as possible to try to smooth it out.
frac := fm.FDiv(700.0,828.0) ' Fraction of 7.00 pH units per 0.828 volt change 700/828
offset := fm.FMul(frac,1000.0)
resolution := fm.FDiv(3.3,4096.0) ' adc resolution per step
mv := fm.FFloat(adc.GetData(1)) ' Get reading from ADC
mv := fm.FMul(mv,resolution) ' Convert to actual voltage
mv := fm.FMul(mv,1000.0) ' Convert to millivolts
ph := fm.FMul(mv,frac) ' convert from millivolts to pH
ph := fm.FSub(ph,offset) ' 1 volt offset compensation
ph := fm.FSub(700.0,ph) ' adjusts to pH 7.00 at 1 volt input
ph := fm.FDiv(ph,100.0) ' move decimal place by 2
perhaps I read over it, But at what point are You using a standard buffer solution of lets say 7ph to calibrate this Ph meter?
I haven't seen any standards as far as PH goes? Or any sample test data?
Back about 15 or 20 years ago I had to use a resistive device to simulate the reading from the PH prob. It was the most inaccurate
way of calibrating a meter that their was. No one could get the PH and temp rite By using this method.
You need some 7PH buffer for a STD and some 10PH buffer for a SPAN.
I use buffer solutions from HACH. Their certified and very accurate. I would get 7PH and 10PH Buffer solution and measure PH and
Temp. all at the same time.
_____________$WMc%___________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
Greg, initially I thought you were going to have a calibration routine in the software and use standard buffer solution. If you took that approach you would not need to convert the adc reading to millivolts and then to PH. The simplest (and most accurate) way to calibrate would be to have buffer solution for each end of the scale and DI water for neutral. With the adc readings at those known PH values you can convert directly from adc reading to PH.
There will be software calibration eventually, right now I am just trying to get the circuit to work. After getting the code the work reliably, I removed the ground clip and attached the PH Probe and got nothing. I think the new op amp is the problem. The new op amp (tle2141IP) has an nc on pin 8 yet the cas3140 calls it strobe and there is a cap across pins 5 and 8. I will work on it some more
tomorrow, but it looks like its back to the drawing board.
Looking at the spec sheet for the 2141 vs CA3140, it looks like the only thing you should need to do is remove the 100pF cap between pins 5 and 8.
Pin 8 is not connected to anything.
Pin 1 and 5 are offset N1 and N2 respectively. ** These would normally be left unconnected but could have a 5K pot with wiper to VCC- if offset null is reqd.
Pin 2 and 3 are - and + inputs respectively. ** Same as 3140 so no change required.
Pin 6 is the output. ** Same as 3140 so no change required.
Pin 4 and 7 are VCC- and VCC+ respectively. ** Same as 3140 so no change required.
It appears that the new op amp is not sensitive enough to pick up the ph probe output. I went back over the circuit and retested everything again. When I hook up the ph probe,
nothing happens. So I took a 3 volt source and connected it to the 10K resistor and the output started changing. I have an lf356 I am going to check the pin out on and see if I can drop it
into the ic socket.
the LF356 did the trick. I put the probe in ph 4 calibration it reported 4.4. So the math is pretty close. I need to do the calibration and temperature compensation now
Congratulations. Good luck with the rest of the project.
PS - I took a close look at the data sheet for the TLE2141 and noticed that it is not a FET input op amp, so the input impedance would be too low for the PH probe signal.
Comments
In the case of a PH meter since water is neutral PH it would be in the middle of the range so I would expect the reading should be approximately half of the full scale of the ADC. What ADC are you using?
the adc is a TLV2543 spec sheet posted earlier in the thread. its a 12bit 11 channel ADC with a 3.3v refrence
Using the formula you posted previously, it should be reading 1240. I can live with a 10 millivolt mismatch on my meter.
Here is a snippet of code, when the input is shorted, the ph reading is 5.1. It should be 7.
I converted this code from Tracy's Allens PBASIC code.
perhaps you can help me out here:
here is the stamp code:
Here is what I have derived:
The last line
debug rep "-"\pH.bit14,dec abs (pH/100),".".dec2 abs pH
I cannot figure out a spin translation
Greg
The numbers in the math assume that the electrode sensitivity is 59.16 mV per pH unit, times a gain of x2 in the amplifier, and that comes out to 118.32 mV/pH unit at the ADC. The math then converts a change of 118 mV at the ADC to a digital display change of 100, or 1.00 pH unit. The ** multiplier in either PBASIC or SPIN does that scaling, multiply times 100/118. The amplifier offset is 1000 mV, and subtracting 845 removes that offset. Then the final step (which could be combined with the previous one), puts in the offset 700 for pH 7. That happens when the input voltage is zero (neutral pH).
In practice, the electrode sensitivity will not be exactly 59.16 mV per pH unit, and there will likely be a small voltage offset in neutral pH (not pH7 => 0 volts exactly). The sensitivity is predictably dependent on temperature, too (higher mV/pH at higher temperatures). The math you have will be a good first approximation.
In Spin, the code for display will depend on what kind of display you have, terminal screen, TV, LCD? SimpleSerial would be a good start for a terminal screen, or the DEBUG equivalents from the BS2 functions library.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
the problem I am having is converting this pH.bit14,dec abs (pH/100),".".dec2 abs pH
I cant seem to find anything equivalent to the .bitx
my first atttempt was:
This works buts is very erratic the reading will jump from 7 to 8 and back to six. the adc output changing from 1231 to 1232 or 1230 will cause this. So I wanted to try and duplicate your code as closely as possible to try to smooth it out.
Greg
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
That was it. This works perfectly now.
I haven't seen any standards as far as PH goes? Or any sample test data?
Back about 15 or 20 years ago I had to use a resistive device to simulate the reading from the PH prob. It was the most inaccurate
way of calibrating a meter that their was. No one could get the PH and temp rite By using this method.
You need some 7PH buffer for a STD and some 10PH buffer for a SPAN.
I use buffer solutions from HACH. Their certified and very accurate. I would get 7PH and 10PH Buffer solution and measure PH and
Temp. all at the same time.
_____________$WMc%___________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
tomorrow, but it looks like its back to the drawing board.
Greg
Pin 8 is not connected to anything.
Pin 1 and 5 are offset N1 and N2 respectively. ** These would normally be left unconnected but could have a 5K pot with wiper to VCC- if offset null is reqd.
Pin 2 and 3 are - and + inputs respectively. ** Same as 3140 so no change required.
Pin 6 is the output. ** Same as 3140 so no change required.
Pin 4 and 7 are VCC- and VCC+ respectively. ** Same as 3140 so no change required.
It appears that the new op amp is not sensitive enough to pick up the ph probe output. I went back over the circuit and retested everything again. When I hook up the ph probe,
nothing happens. So I took a 3 volt source and connected it to the 10K resistor and the output started changing. I have an lf356 I am going to check the pin out on and see if I can drop it
into the ic socket.
Greg
the LF356 did the trick. I put the probe in ph 4 calibration it reported 4.4. So the math is pretty close. I need to do the calibration and temperature compensation now
PS - I took a close look at the data sheet for the TLE2141 and noticed that it is not a FET input op amp, so the input impedance would be too low for the PH probe signal.