ADC3 on M20?

Hansb56

New Member
Hallo,

I 'm making a simple indication of the level of water in my watertank in the caravan.
I'ts a can with ca 40 liters of water.
With a simple system of sensors and a probe I put every x minuts a pulse on the probe.
During the pulse I can read out the inputs If they are under water I read about 200 - 220 of the 255, if the are above the waterlevel I read 0. I pull the inputs down with a 470k resistor.
So far so good.
But one of the inputs (input ADC-3,C3, pin nr7) of my M20 has a curious behaviour. I'ts completely foating. With a 470k resistor it's about zero, but it stays zero when I pulse. With a 5,7M resistor I can see differense between pulse and no pulse, but not very relaeble.
I've tried another M20 and a 20M2, but i'ts with the same result.
Is this a hardware isue??
Sorry, the description is in dutch. As you can see in the code I've experimentend with some pause ect. There is no difference.

Hans



Code:
[color=Green]'water niveaumeter caravan.
'20m, 4 voelers, 5 niveauleds
'1 led algemeen
'1 x drukknop inschakelen niveau
#Rem korte beschrijving:
door puls op de probe te zetten en vervolgens gedurende de puls op 4 meetpennen te meten of ze in het water staan of niet is het mogelijk met 5 leds het waterniveau aan te geven.

probe:onder in de tank
Geen pen in water:   rood
pen1: op 20% hoogte  rood+oranje
pen2: op 40% hoogte  rd+or+grn
pen3: op 60% hoogte  rd+or+grn+grn
pen4: op 80% hoogte  rd+or+grn+grn+grn

De drukknop meet de hoogte van het water in de tank. (geen continue meting ivm electrolyse)
of eens per x tijd meten en de laatste waarneming laten staan.

pin bezetting
1  = V+        20 = V-
2  = RXD       19 = TXD
3  = InH4      18 = led1      
4  = toets     17 = led2   
5  =           16 = led3   
6  =           15 = led4      
7  = inH3      14 = led5      
8  = inH2      13 = probe
9  = inH1      12 = 
10 =           11 = led 

evt 11 en 3 wisselen, 11 is dan probe en 3 is dan disp uit, pwm aansturing van 3 segment display
#Endrem

'toetsroutie nog toevoegen
'gevoeligheid pinc.3 is anders dan de andere drie. Hardware probleem?[/color]

[color=Black]init:[/color]
[color=Navy]#picaxe [/color][color=Black]20M[/color]
[color=Navy]#No_data[/color]
[color=Blue]Setfreq  M8[/color]

[color=Green]'toewijzen alias:[/color]
[color=Blue]Symbol [/color][color=Black]inh1 [/color][color=DarkCyan]= [/color][color=Blue]C.1
Symbol [/color][color=Black]inh2 [/color][color=DarkCyan]= [/color][color=Blue]C.2
Symbol [/color][color=Black]inh3 [/color][color=DarkCyan]= [/color][color=Blue]C.3
Symbol [/color][color=Black]inh4 [/color][color=DarkCyan]= [/color][color=Blue]C.7
Symbol [/color][color=Black]dtoets[/color][color=DarkCyan]=[/color][color=Purple]pinC.6[/color]
[color=Blue]Symbol [/color][color=Black]led1 [/color][color=DarkCyan]= [/color][color=Blue]B.0
Symbol [/color][color=Black]led2 [/color][color=DarkCyan]= [/color][color=Blue]B.1
Symbol [/color][color=Black]led3 [/color][color=DarkCyan]= [/color][color=Blue]B.2
Symbol [/color][color=Black]led4 [/color][color=DarkCyan]= [/color][color=Blue]B.3
Symbol [/color][color=Black]led5 [/color][color=DarkCyan]= [/color][color=Blue]B.4
Symbol [/color][color=Black]probe [/color][color=DarkCyan]= [/color][color=Blue]B.5
Symbol [/color][color=Black]led [/color][color=DarkCyan]= [/color][color=Blue]B.7[/color]


[color=Green]'toewijzing variabelen
'symbol b0= W0 vrijhouden
'symbol b1=[/color]

[color=Blue]Symbol [/color][color=Black]inho1 [/color][color=DarkCyan]= [/color][color=Purple]b2[/color]
[color=Blue]Symbol [/color][color=Black]inho2 [/color][color=DarkCyan]= [/color][color=Purple]b3[/color]
[color=Blue]Symbol [/color][color=Black]inho3 [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]
[color=Blue]Symbol [/color][color=Black]inho4 [/color][color=DarkCyan]= [/color][color=Purple]b5[/color]
[color=Blue]Symbol [/color][color=Black]toets [/color][color=DarkCyan]= [/color][color=Purple]b6[/color]
[color=Blue]Symbol [/color][color=Black]tel [/color][color=DarkCyan]= [/color][color=Purple]b7[/color]
[color=Blue]High [/color][color=Black]led1,led2,led3,led4[/color]
[color=Blue]Pause [/color][color=Navy]1000[/color]
[color=Blue]Low [/color][color=Black]led1,led2,led3,led4



Main:[/color]
[color=Blue]Gosub [/color][color=Black]lees[/color]
[color=Blue]Gosub [/color][color=Black]display1[/color]
[color=Green]'Gosub toetsin[/color]

[color=Blue]Goto [/color][color=Black]main

Lees:[/color]
[color=Green]'ongeveer 1 x per 60 seconden het niveau meten
'of slechts meten als er op de knop gedrukt wordt.
'of led's continue aan, verversen 1  per uur of zo of bij wijziging van de meetwaarden Kan dat???
' bijv door te meten na begruik van de pomp?  

'LEES probe
'If tel = 60 Then       '1 meting per minuut 
   [/color][color=Blue]High [/color][color=Black]probe
   [/color][color=Green]'Pause 50
   [/color][color=Blue]Readadc [/color][color=Black]inh1, inho1
   [/color][color=Green]'Pause 50
   [/color][color=Blue]Readadc [/color][color=Black]inh2, inho2
   [/color][color=Green]'Pause 500
   [/color][color=Blue]Readadc [/color][color=Black]inh3, inho3
   [/color][color=Green]'Pause 500
   [/color][color=Blue]Readadc [/color][color=Black]inh4, inho4
   [/color][color=Green]'Pause 50

   [/color][color=Blue]Low [/color][color=Black]probe
   [/color][color=Blue]Let [/color][color=Black]tel[/color][color=DarkCyan]=[/color][color=Navy]0[/color]
[color=Green]'endif[/color]
[color=Blue]Pause [/color][color=Navy]1000[/color]
[color=Black]tel[/color][color=DarkCyan]=[/color][color=Black]tel[/color][color=DarkCyan]+[/color][color=Navy]1[/color]
[color=Blue]Sertxd([/color][color=Black]#[/color][color=Purple]b2[/color][color=Black],[/color][color=Red]" .B2."[/color][color=Black],#[/color][color=Purple]b3[/color][color=Black], [/color][color=Red]" .B3."[/color][color=Black], #[/color][color=Purple]b4[/color][color=Black], [/color][color=Red]" .B4."[/color][color=Black],#[/color][color=Purple]b5[/color][color=Black], [/color][color=Red]" .B5."[/color][color=Black],[/color][color=Purple]b6[/color][color=Black], [/color][color=Red]" .toets."[/color][color=Black],[/color][color=Blue]Cr[/color][color=Black],[/color][color=Blue]Lf)
Return[/color]

[color=Black]Display1:[/color]
[color=Green]'stuurt de leds van de niveaumeter.
'If toets=1 Then[/color]
[color=Blue]High [/color][color=Black]led1                           [/color][color=Green]'brand altijd; minder dan 20%[/color]
[color=Blue]If [/color][color=Black]inho1 [/color][color=DarkCyan]>[/color][color=Navy]150 [/color][color=Blue]Then High [/color][color=Black]led2 [/color][color=Blue]endif  [/color][color=Green]'20-40%[/color]
[color=Blue]If [/color][color=Black]inho1 [/color][color=DarkCyan]<=[/color][color=Navy]50 [/color][color=Blue]Then Low [/color][color=Black]led2 [/color][color=Blue]endif   
If [/color][color=Black]inho2 [/color][color=DarkCyan]>[/color][color=Navy]150 [/color][color=Blue]Then High [/color][color=Black]led3 [/color][color=Blue]endif  [/color][color=Green]'40-60%[/color]
[color=Blue]If [/color][color=Black]inho2 [/color][color=DarkCyan]<=[/color][color=Navy]50 [/color][color=Blue]Then Low [/color][color=Black]led3 [/color][color=Blue]endif
If [/color][color=Black]inho3 [/color][color=DarkCyan]>[/color][color=Navy]150 [/color][color=Blue]Then High [/color][color=Black]led4 [/color][color=Blue]endif  [/color][color=Green]'60-80%[/color]
[color=Blue]If [/color][color=Black]inho3 [/color][color=DarkCyan]<=[/color][color=Navy]100 [/color][color=Blue]Then Low [/color][color=Black]led4 [/color][color=Blue]endif
If [/color][color=Black]inho4 [/color][color=DarkCyan]>[/color][color=Navy]150 [/color][color=Blue]Then High [/color][color=Black]led5 [/color][color=Blue]endif  [/color][color=Green]'80-100%[/color]
[color=Blue]If [/color][color=Black]inho4 [/color][color=DarkCyan]<=[/color][color=Navy]50 [/color][color=Blue]Then Low [/color][color=Black]led5 [/color][color=Blue]endif[/color]
[color=Green]'endif[/color]
[color=Blue]If [/color][color=Black]toets[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]Then
Pause [/color][color=Navy]5000[/color]
[color=Green]'Low led1,led2,led3,led4,led5       'afhankelijk of drukknop of continue gemeten wordt[/color]

[color=Blue]endif
Return[/color]

[color=Black]toetsin:[/color]
[color=Blue]If [/color][color=Black]dtoets[/color][color=DarkCyan]=[/color][color=Navy]1 [/color][color=Blue]Then
   If [/color][color=Black]toets[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]Then 
      [/color][color=Black]toets[/color][color=DarkCyan]=[/color][color=Navy]1
   [/color][color=Blue]Else
      [/color][color=Black]toets[/color][color=DarkCyan]=[/color][color=Navy]0
   [/color][color=Blue]endif
endif
Do Until [/color][color=Black]dtoets[/color][color=DarkCyan]=[/color][color=Navy]0 [/color][color=Blue]High b.0 Loop   [/color][color=Green]'wacht tot toets is losgelaten[/color]
[color=Blue]Low [/color][color=Black]led[/color]
[color=Blue]Return[/color]
 

hippy

Technical Support
Staff member
Has it never worked or was it working but has stopped working ?

It could be that water resistance is just too high from the pulse emitter to the input, or perhaps there is some other issue.

What happens if you connect the input pin for a sensor which does work to the pin of the one which does not; does the one which did not work then reflect the one which does ?

Are you using an AXE027 download cable to observe the SERTXD output or something else ?
 

Hansb56

New Member
No, that input never works, the other three are working fine. The distance between the pulse emmiter and the inputs are only cm. It's not critical, when I make it a 10 or more cm there is no different reading.
The sentorpins are for testing peaces of UTP-cable. That peace of cable is ok.
I use the Original AXE027 cable and use leds for the level-reading. For testing I just do SERTXD and read the valables on screen.
Four inputs, al the same wired, and just one with a different behaviour.
Strange!

Hans
 

BESQUEUT

Senior Member
But I'm still curious why this happens.
Touch is a capacitive sensor.
The insulated wire act as a condensor to ground, variable with water level...
To be sure with the ground I have an inox wire in the water, connected to Picaxe ground.

My insulated wire have an horizontal path at top, and another one at low level. So I can detect theses two points.

With resistive sensor, rain water resistance vary depending with ph...
 
Last edited:

Hansb56

New Member
Hi Besqueut

Thanks for your reply

I think I can follow what you mean, exept the two horizontal path at the top and bottom.
I understnd that ther is a capacity between the groud-wire and the isolated wire, and that the capacity varies with the waterlevel.
So the readout is a function of the level.
Why the two path?

Hans
 

BESQUEUT

Senior Member
Why the two path? s
This circuit is used for a sump tank. The pump fill up main rain water tank.
I want to detect low level to stop pump.
And if rain is not too heavy, I want to wait for high level before restarting pump.
A little horizontal path at theses points is usefull to calibrate sensor and after that make obvious low and high level even if there is a little drift.
This is absolutely not necessary.
IHMO, capacitive sensing if more reliable than resistive sensing.
Your wires (insulated and ground if used) have to be fasten because capacity depend from distance from insulated wire to ground...
My sump tank is PVC. That is why I need a ground pôle (inox sheet at the very botom)
If your tank is concrete, ground is generally enought.
If metal connect ground to tank.

I use standard 1,5mm 220V copper wire.
If condenser is not enought, you can try a 2,5mm wire, and even a loop (so you don't have to insulate end...)
For end insulation, I use epoxy glue and an heat shrinkable tube.
 
Last edited:

Hansb56

New Member
Thanks,

I understand the principle and it sounds logic to me
I give it a try. When it works it's fine for me.
I use a plastic tank in my caravan. It's a smal caravan for our holiday's but I'm to lazy to check the waterlevel so.........

But I'm still wondering why one input has a different behaviour than the three others. :mad:

Hans
 

AllyCat

Senior Member
Hi Hans,

But one of the inputs (input ADC-3,C3, pin nr7) of my M20 has a curious behaviour. I'ts completely foating. With a 470k resistor it's about zero, but it stays zero when I pulse. With a 5,7M resistor I can see differense between pulse and no pulse, but not very relaeble.
I've tried another M20 and a 20M2, but i'ts with the same result.
Microchip "recommend" that the source resistance for ADC inputs should be less than 10 kohms and you are using a value almost 50 times larger than that! Many users have claimed that a larger resistance "can" be used for ADC measurements, but all PIC{axe} pins have multiple (different) functions, so maybe Leg 7 has different internal hardware connections which mandate the "global" figure ( <10k for all ADC pins) that Microchip has specified.

Also, some PICs (and PICaxes) do have an occasional "bug" (or "unexpected behaviour"), I found (a PWM) one on Leg 8 of the 20M2, so maybe you have found another on Leg 7. The PICaxe 20M2 "remaps" the Port.Pin connections relative to the base PIC chip (where Leg 7 is actually ADC input 7) so there is some scope for an occasional bug to creep in.

However,as already discussed above, using the "Touch" mode is lkely to be much more satisfactory for your application. But note that each input must be calibrated separately, an admission that "not all pins are created equal".

Cheers, Alan.
 

Goeytex

Senior Member
There is no hardware issue with the Picaxe/PIC microcontroller. I have a 20M2 on the bench now with a 10K pot connected to C.3/Pin 7. The output is rock solid and ranges perfectly from 0 to 1023 using Readadc10.


As Alan previously noted, the specified minimum ADC input impedance is 10k ohms. You can easily test the functionality of the ADC Pin by connecting a 10K potentiomenter to the ADC input. With ReadADC the value should swing from 0 to 255. ReadADC10 should swing from 0 to 1023.

If the values are not correct then the most likely culprit is poor grounding. The ADC input ground must be tied to Picaxe Ground, preferably as close to the Picaxe 0V pin as possible. Another sign of poor grounding is when the ADC value will not go all the way down to "0".

If you must connect a high impedance signal to an ADC input, it can be buffered with an OPAMP.
 

hippy

Technical Support
Staff member
But I'm still wondering why one input has a different behaviour than the three others. :mad:
Did you try any of the previous tests suggested or undertake any diagnostics to check that the pin is working or attempt to determine where the fault may be ?
 

Hansb56

New Member
Yes,

I know that the impedance is 10k.
So I new that I tried something out of the specs of the PIC.
But still..... I put 4 resistors of 100K to ground to "pull" the 4 adc-inputs to ground.
And when I put te inputs into water and give a pulse (+5v) into the water 3 of the 4 inputs are going high. The 4th input reacts different.

When I use a potmeter like you suggest it works as aspected. So the pic is ok.

I just wundered why 3 of the 4 do what I want and the 4th doesn't.

Chanche your 10k pot for 4 times a 100k and see what happens.

Still confused,

Hans
 

hippy

Technical Support
Staff member
And when I put te inputs into water and give a pulse (+5v) into the water 3 of the 4 inputs are going high. The 4th input reacts different.

I just wundered why 3 of the 4 do what I want and the 4th doesn't.
Swap the 3rd input with the 4th. Does the 4th now work, the 3rd now not work ?
 

Hansb56

New Member
no,

No difference.

I had some problems with uploading the schematic but here it is.
I use to try no specific sensors, but just a peace of UTP-cable and a glass of water.
Swapping has no effects.

I'll try the touch version for my watercan, so that problem is solved.

But I keep wondering.......................

greatings Hans

watermeting.jpg
 
Top