CN-0398 error in calibrated pH calculation equation library?


I'm working in the development of a pH meter, and I have a doubt regarding offset_voltage correction in the pH calculation, because there is a sign in an equation which is different in the circuit note and the code from github corresponding to it .

In the library CN0398.cpp from EVAL-ADICUP360 ADuCM360_demo_cn0398 , in line 216, CN0398::read_ph(float temperature) function, the equation to calculate pH is:

float m =  (calibration_ph[1][0] - calibration_ph[0][0]) / (calibration_ph[1][1] - calibration_ph[0][1]);
ph = m * (volt - calibration_ph[1][1] + offset_voltage) + calibration_ph[1][0];

where the variables are:

calibration_ph[1][0] : pH value of second calibration point

calibration_ph[0][0] : pH value of first calibration point

calibration_ph[1][1] : voltage value of second calibration point

calibration_ph[0][1] : voltage value of first calibration point

volt : measured voltage

Why is the offset being added and not subtracted?

CN-0398 Circuit note in page three shows the equations used to get this. First, it calculates the slope m diving voltages by pH values, which is just the opposite as it's done in the code above, where pH values are divided by voltages. (equation 2)

Then, equation (3) is supposed to be the way of getting the unkown pH: 

x = ((y - y1) + m * x1 - b) / m

where b is the offset_voltage, x the unknown pH, y is the measured voltage, x1 the pH at calibration point 1, y1 is pH value at calibration point 1, and m the slope.

If I substitute x by ph, y by volt,  and m by 1/m into equation (3), to compare the equation in the code with the one in the circuit note, I get:

ph = ((volt - y1) + (1 / m) * x1 - b)) / (1 / m)

If I multiply by m, I get:

ph = m * (volt - y1 - b) + x1,

which is:  ph =  m * (volt - calibration_ph[1][1] - offset_voltage) + calibration_ph[1][0];

I'm not sure how equation 3 is calculated, and I would appreciate if steps from equation (2) to equation (3) could be explained in more detail, but it makes sense to subtract the offset instead of adding it.

Thus, is the sign of the offset_voltage in the code wrong? I have checked also in ADuCM360_demo_Smart_Greenhouse CN0398.c library, and the offset is also added and not subtracted.

I would very much appreciate if anyone could clarify this issue.

Many thanks and best regards, 


Clarified the question in the first sentence
[edited by: AlvaroMuro at 1:39 PM (GMT 0) on 21 Feb 2019]
Parents Reply Children
No Data