Analogue input basic test is failing???

OLDmarty

Senior Member
Hi All,
I recently wired together 8x 10K pots to test some of my coding with Analogue inputs etc.

I'm using a 40X2 (pic 18F45k22), and i've chosen Port D as my analogue input port for all 8 pots under test.

Using the simplest code (below), i can clearly see the following occur in the Terminal window:
Pot on D.0 (ADC20) - works full range 0 to 255.
Pot on D.1 (ADC21) - works full range 0 to 255.
Pot on D.2 (ADC22) - works full range 0 to 255.
Pot on D.3 (ADC23) - works approx 1/2 way (or thereabouts) up to to 255, but will never go down to 0 when the pot is completely set to 0 position.
Pot on D.4 (ADC24) - works full range 0 to 255.
Pot on D.5 (ADC25) - works full range 0 to 255.
Pot on D.6 (ADC26) - seems to always be stuck on '0' no matter where the pot is turned.
Pot on D.7 (ADC27) - works approx 1/2 way (or thereabouts) up to to 255, but will never go down to 0 when the pot is completely set to 0 position.

ALL the pots have their ends bussed to each other, so there's a row of "+5v" pot-ends, and a row of "0v" pot-ends, then the 8 wipers wire into Port-D.0 to D.7.
I have measured the pot-ends to confirm there's definitely 0v-to-5v across each pot, with varying voltage on each wiper as expected.

Have i missed something with the ADC configuration that could be causing me this problem?
As the code shows, i haven't used any ADC config info because a lot of what i read about 40X2 and ADC config didn't seem applicable to my use.
(not needing different reference voltages and not needing CALIB to turn analogue pins back into digital pins etc).

The pots are all the same brand/type from good ol' ebay, so maybe i just have a mix of good/badly made pots giving me grief?
I'm yet to re-check each pot on my test panel when i get back to the workbench next week.


Code:
#PICAXE 40X2            ; Define PICAXE 40X2 type
#NO_DATA                 ; Ignore EEPROM data - loads program faster
#NO_TABLE                ; Ignore TABLE data - loads program faster

#Terminal 9600

Initialize:                ' Initialise pins and set up variables

; Setup all the port bits to a clean state...
dirsA=%11111111     ; set ALL Port-A bits to OUTPUTS.
dirsB=%11111111     ; set ALL Port-B bits to OUTPUTS.
dirsC=%11111111     ; set ALL Port-C bits to OUTPUTS.
dirsD=%00000000     ; set ALL Port-D bits to INPUTS.
   
; Reference of which bits are assigned to which Analogue input names...    
; ADC20 Analog input = port D.0
; ADC21 Analog input = port D.1
; ADC22 Analog input = port D.2
; ADC23 Analog input = port D.3
; ADC24 Analog input = port D.4
; ADC25 Analog input = port D.5
; ADC26 Analog input = port D.6
; ADC27 Analog input = port D.7

Do

     readadc 20, b0        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.
     readadc 21, b1        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.         
     readadc 22, b2        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.
     readadc 23, b3        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.    
     readadc 24, b4        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.
     readadc 25, b5        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.    
     readadc 26, b6        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.
     readadc 27, b7        ;read pot value on pin C.5 (ADC17) to set the "pattern" value for the loader.    
     
     SerTxd( "  Pot1:", #b0, "  Pot2:", #b1,"  Pot3:", #b2,"  Pot4:", #b3,"  Pot5:", #b4,"  Pot6:", #b5,"  Pot7:", #b6,"  Pot8:", #b7, CR )
 
     Pause 1000    ;Display POT values in terminal window each second (or adjust for quicker updates).

Loop
 

premelec

Senior Member
"I have measured the pot-ends to confirm there's definitely 0v-to-5v across each pot, with varying voltage on each wiper as expected. " If you did this why do you doubt the pot integrity? Presume you measured at actual PICAXE pin rather than at pot.... ;-0
 

OLDmarty

Senior Member
"I have measured the pot-ends to confirm there's definitely 0v-to-5v across each pot, with varying voltage on each wiper as expected. " If you did this why do you doubt the pot integrity? Presume you measured at actual PICAXE pin rather than at pot.... ;-0
I believe the pot(s) in question might not have the full range of resistance across them.
While i did quickly measure some 'varying' voltage on the 8 wipers, i didn't stay at work long enough to do a complete sweep of each wiper as we were closing shop.
I'll look deeper into this on Monday, but just thought i'd see if i wasn't setting up or clearing something in the picaxe that could be giving me odd readings too.
 

Flenser

Senior Member
OLDmarty,

Some background info for you.

The pic 18F45k22 chip only has one ADC module and when you read an ADC value on one of the pins there is an internal switch that connects the ADC module input to the pin you have specified. i.e. you can only read the ADC value on one pin at a time.

This figure showing the internal ADC circuitry from the 18F45k22 manual:
23180

If the ADC readings are working on most of your pins it indicates that the ADC module is probably working OK and your problems getting the reading you expect on one or two pins is most likely due to an issue with the external wiring and/or components.

I guess it is possible that the internal switch has been damaged for the pins that you have problems with the readings. I'm not sure how you would go about confirming that.

Flenser
 

OLDmarty

Senior Member
I guess it is possible that the internal switch has been damaged for the pins that you have problems with the readings. I'm not sure how you would go about confirming that.

Flenser
Hi Flenser,
I have more 40X2's that i can try, this will at least confirm any 'differences' if the same 'faulty' pots operate the same way or if it disappears altogether.
Something else to eliminate anyway ;-)

cheers.
 

techElder

Well-known member
OLDmarty, the first thing that I would test is to add a delay after each of those readadc statements. Give the ADC some more time to complete the conversion.
 

OLDmarty

Senior Member
OLDmarty, the first thing that I would test is to add a delay after each of those readadc statements. Give the ADC some more time to complete the conversion.
Thanks TE,
I imagine something around 1-10 milliseconds (or upto 100mS at very worst case?) would be enough recovery time in between reads?
I guess i need to play with the numbers to confirm if/when all 8 Analogue inputs reading correctly (or not) and go from there.
 

hippy

Senior Member
The first thing I would try is to take a known working pot, say the one connected to D.0 and see what happens when that pot is connected to D.6 and D.7.

If D.6 and D.7 read 0-255 then it would seem to be pots for D.6 and D.7 which are the issue, otherwise some issue with D.6 and D.7 pins which would need investigating.

Adding a PAUSE either before or after a READADC should have no effect on its operation or results. The READADC will only close its sampling gate when it begins executing and will have completed its sampling and conversion before it ends.

In some cases, where there is excessive source impedance, the sampling capacitor may not have fully matched the source level before the sampling gate is opened, the reading held and the result is sampled. The reading may therefore be higher or lower than it should be.

The solution there is to do multiple READADC readings of the ADC channel.

For example going from reading a full V+ (255) to 0V (0) pot may during the first sampling discharge the cap down to say only 50 which is an erroneous result. A second sampling will continue the discharge with its result ideally being the correct 0.
 

OLDmarty

Senior Member
The first thing I would try is to take a known working pot, say the one connected to D.0 and see what happens when that pot is connected to D.6 and D.7.

If D.6 and D.7 read 0-255 then it would seem to be pots for D.6 and D.7 which are the issue, otherwise some issue with D.6 and D.7 pins which would need investigating.

Adding a PAUSE either before or after a READADC should have no effect on its operation or results. The READADC will only close its sampling gate when it begins executing and will have completed its sampling and conversion before it ends.

In some cases, where there is excessive source impedance, the sampling capacitor may not have fully matched the source level before the sampling gate is opened, the reading held and the result is sampled. The reading may therefore be higher or lower than it should be.

The solution there is to do multiple READADC readings of the ADC channel.

For example going from reading a full V+ (255) to 0V (0) pot may during the first sampling discharge the cap down to say only 50 which is an erroneous result. A second sampling will continue the discharge with its result ideally being the correct 0.
Thanks Hippy,
I'm definitely looking to put the working pot/wire D.0 onto other pots to eliminate where the 'fault' lies.

This is simply a plastic enclosure with 8 pots mounted on the lid, that i plan to use as a pot-jig for any future projects needing pots etc.
The 8 pot wipers, +5v and 0v all run into a 16-way ribbon cable that is 100cm's long before it terminates into my picaxe developer board via an IDC16pin connector.
I was thinking the 100cm's of ribbon may have introduced some weird capacitance that interferes with the ADC inputs, but then i have 5 pots basically working correctly.

(i'm yet to measure the ribbon wires and make sure i didn't IDC crimp any of the adjacent wires to eachother).

cheers.
 

hippy

Senior Member
100cm should be okay considering they are 10K pots and driven by V+ and 0V. There may be a bit of noise but a 100nF capacitor on the PICAXE input pins would probably sort that out. A ~100uF, and maybe 100nF, might be an idea at the pot-box end to keep what's across the pots nice. But I wouldn't have predicted any serious issues.

A quick way to check wiring is to connect up V+ and 0V set all the pots mid-way, then measure the voltage as you move mid-top-bottom-mid on each. If they don't all cover the whole range there's probably a mis-wiring.
 

OLDmarty

Senior Member
Well, as i expected, 3x dodgy "new" pots not even manufactured correctly, glad i only bought 10 and not 500 lol.
These are just standard metal-can 16mm case size linear pots.

In future i'll stick to the green alps/alpha 9mm pots instead ;-)

Sheesh!

Thanks to all for your input.
 
Top