calibadc10

friis

Senior Member
Hi,
I have a problem with ADC reading of humidity:

Supply voltage
ADC reading
calibadc10/Nref
Caocul. supply voltage
------------------------------------------------------------------------------
4.5 877 230 4.56
3.0 822 324 3.23

Supply voltage: As set on the wall ward
ADC reading: readadc10
Nref: as given by calibadc10/debu
Calcul. supply voltage: Vpsu = 1048/Nref

Should'nt I be able to convert 822 to (something close to) 877 from these figures? Or have I misunderstood things?
I have checked internet, but there seems to be so many other problems involved in the questions and answers.
best regards
torben
 

hippy

Technical Support
Staff member
Should'nt I be able to convert 822 to (something close to) 877 from these figures?
I would have expected to be able to do so but it's not clear exactly what hardware you have which may be affecting things.

Your CALIBADC10 readings are what would be expected for 4.5V ( 230 against 232 expected ) but less so at 3V ( 324 against 349 expected ) though it is in the right ballpark.

But I am not sure if knowing the power supply voltage matters. If the humidity sensor is across the same power supply, its voltage would be expected to be proportional to the power supply, a straight READADC10 should deliver roughly the same reading. But it doesn't.

And it doesn't seem to correlate if one assumes the sensor is on a fixed power supply and only the PICAXE supply voltage is changing.

Without knowing what hardware you have, and how it's wired, it is very difficult to assess what the situation is. If the sensor's output isn't proportional to its power supply it is hard to tell what the correlation would be or how one translates between the two readings.
 

hippy

Technical Support
Staff member
readadc10 must have a reference value it sets equal to 1024?
READADC10 will return a value 0-1023; it will be 1023 when the input voltage is about equal to the PICAXE power supply voltage.

What I think you are trying to do is determine the actual voltage (Vadc) on an input -
Code:
 .-------------.------ Vpsu
 |             |
.|.        .---^---.
| |   Vadc |       |
| |<-------| ADC   |
|_|        |       |
 |         `---.---'
 |             |
-^-------------^------ 0V
And that should work. Use CALIBADC10 to determine Nref, and calculate Vpsu, use READADC10 to get an Nadc reading and use Vpsu to determine the Vadc voltage.

And it should be possible to correlate the Nadc reading at one Vpsu to an Nadc at another Vpsu.

But in this case the results you obtain don't allow that to be done. That suggests that whatever is providing the Vadc isn't a potentiometer as assumed above, which isn't having its position unchanged as Vpsu alters, but something more 'active' which does change its characteristics as Vpsu changes.
 

hippy

Technical Support
Staff member
This is the code I would use to calculate what the Vpsu voltage is, and what the Vadc voltage would be both in mV -
Code:
Do
  CalibAdc10 Nref
  ReadAdc10 ADC_PIN, Nadc
  Vpsu = 65472 / Nref * 16
  Vadc = Nadc * 64 / Nref * 16
Loop
Full code showing the maths -
Code:
#Picaxe 08M2

;  .-------------.------ Vpsu
;  |             |
; .|.        .---^---.
; | |   Vadc |       |
; | |<-------| ADC   |
; |_|        |       |
;  |         `---.---'
;  |             |
; -^-------------^------ 0V

Symbol ADC_PIN = C.4

Symbol Nref = w1
Symbol Nadc = w2
Symbol Vpsu = w3
Symbol Vadc = w4

Symbol d5   = b25
Symbol d4   = b24
Symbol d3   = b23
Symbol d2   = b22
Symbol d1   = b21

Do
  CalibAdc10 Nref
  ReadAdc10 ADC_PIN, Nadc
  
  ; Nref = ( Vref*1023 ) / Vpsu
  ; Vpsu = ( Vref*1023 ) / Nref          in V
  ; Vpsu = ( Vref*1023*1000 ) / Nref     in mV
  ; Vpsu = ( 1.024*1023*1000 ) / Nref    in mV
  ; Vpsu = ( 1047552 ) / Nref            in mV
  ; Vpsu = ( (1047552/16) / Nref ) * 16  in mV
  ; Vpsu = ( 65472 / Nref ) * 16         in mV

  Vpsu = 65472 / Nref * 16

  SerTxd("Nref=", #Nref, TAB )
  BinToAScii Vpsu,d5,d4,d3,d2,d1
  SerTxd("Vpsu=", d4,".",d3,d2,d1, "V   " )

  ; Nadc = ( Vadc*1023 ) / Vpsu
  ; Vadc = ( Nadc/1023 ) * Vpsu
  ; Vadc = ( Nadc/1023 ) * ( Vref*1023 ) / Nref
  ; Vadc = ( Nadc*Vref ) / Nref             in V
  ; Vadc = ( Nadc*Vref*1000 ) / Nref        in mV
  ; Vadc = ( Nadc*1.024*1000 ) / Nref       in mV
  ; Vadc = ( Nadc*1024 ) / Nref             in mV
  ; Vadc = ( ( Nadc*1024/16 ) / Nref ) * 16 in mV
  ; Vadc = ( ( Nadc*64 ) / Nref ) * 16      in mV

  Vadc = Nadc * 64 / Nref * 16

  SerTxd("Nadc=", #Nadc, TAB )
  BinToAScii Vadc,d5,d4,d3,d2,d1
  SerTxd("Vadc=", d4,".",d3,d2,d1, "V", CR, LF )

Loop
 

friis

Senior Member
Hi hippy and mikeyBoo,

I am using a Picaxe14M2 and SparkFun two-thronged sensor in a cup of water. I measure the following (waiting 2 sec. after energizing the sensor before measuring):

Code:
 Vpsu                  Vadc              Nadc    calc. Nadc
3.21 V                 2.45                772            781
4.54 V                 3.75                834            845
SparkFun has an example: 1023/3.21 = x/2.45 which gives x = 781 or 1023/4.54 = x/3.75 which gives x = 845. The Nadc calculated values are close to the measured ones.

The measurements depend on the time between energizing the sensor and measuring and the time between measurements.

Is'nt the method then be to get Vpsu and Nadc with fresh batteries and Vpsu and with more or less worn down batteries at every subsequent measurement and ajust the latter Nadc accordingly?
torben
 

hippy

Technical Support
Staff member
A Vadc of 2.45 V at a Vpsu of 3.21 V should give a READADC10 Nadc reading of 780

A Vadc of 3.75 V at a Vpsu of 4.54 V should give a READADC10 Nadc reading of 844

If the sensor were behaving linearly, always outputting a proportional to Vpsu signal, the READADC10 readings should be the same in both cases.

It seems it is not linear so it will be necessary to determine what the non-linearity equation is so one can determine what it is actually measuring at various voltages.

The easiest way to do that would be to hook it up to a bench PSU and vary the voltage and plot on graph paper what READADC10 readings there are for the sensor at those various voltages.

It would be worth providing a link to the sensor product page at Sparkfun as that might help identify what needs to be done.
 

friis

Senior Member
Hi hippy & mikeyBoo,
I assume the the sentence from the manual:

The calibadc/calibadc10 commands can help overcome this issue by providing the ADC reading of a nominal internal reference. Therefore by periodically using the calibadc command you can mathematically calibrate/compensate the readadc command for changes in supply voltage.

means that the manual assumes linearity since it has only one triplet (Vpsu, Nref, Vref) to start with.

But does'nt measurements and calculations show that this is not the case?

The contribution from SparkFun is the formula for the calculation and there is no active component in the moisture sensor..
torben
 

AllyCat

Senior Member
Hi,
... SparkFun two-thronged sensor in a cup of water.
The PICaxe ADC should be quite linear, but it seems that you are trying to measure the "resistance" of water between two conductors and that is probably not at all linear (or constant).

Firstly, pure water has a very high resistance, so you are mainly measuring the effects of impurities in the water. Secondly, you may be electrolysing the water (breaking it into Hydrogen and Oxygen) and that requires a defined voltage (about 1.23 volts), so definitely does not have a fixed resistance (i.e. V / I is not constant).

Cheers, Alan., .
 

hippy

Technical Support
Staff member
The PICaxe ADC should be quite linear, but it seems that you are trying to measure the "resistance" of water between two conductors and that is probably not at all linear (or constant).
^ What he said :)

The PICAXE is pretty linear, and it is possible to use CALIBABC10, Vpsu, Vref and Nref to determine reasonably accurately what Vadc is for a particular Nadc regardless of actual Vpsu.

It is converting the Vadc to what the sensor reading represents at any specific Vpsu which we don't have an equation of calculation for.
 
Top