23 Analog inputs?

Denzel

Senior Member
I need to measure the analogue input from 21 potentiometers (10k) and Im after any suggestions as to how this is possible.

Ive considered using 7 picaxe 08ms (each with 3 adc pins) and a 28X that links them all up, and I can do this, I have done it before with 5 08ms and an 18X but its messy and confusing. I was thinking about something along the lines of a matrix, kind of like a telephone keypad where you have 6 outputs to turn 9 pots on/off and they all link to one adc input?

im just tossing ideas around but if each output had a transistor(s) you could essentially make a tree diagram and with only 5 outputs you could have 32 output combinations?

you can see im in a puddle :p any help would be appreciated
 

MFB

Senior Member
Two analog multiplexers

This is a pretty common instrumentation requirement and the normal way to measure lots of analog inputs is to use multiplexer chips. You will need to use two 16-channel analog multiplexers to feed a single ADC input. Their address lines will have to be connected in parallel to the same four PICAXE digital outputs. This would of course result in the same channel on each multiplexer being selected at the same time. To over come this problem each multiplexer chip also has an enable input, which must be selected alternately by two more PICAXE outputs (or one output plus an inverter).

Just search the Maxim site for 'single rail analog multiplexers' and you will find lots of applications information that explains the above techniques in more detail.
 

BeanieBots

Moderator
What you are looking for is a called an "analogue multiplexer" look it up on Google. There quite a few different types.
They take a digital address which then selects which input is directed to its output and then fed to your PICAXE ADC input.
Most have either 8 or 16 input lines so will need several to do 21 inputs but it would still be much easier than lots of 08Ms.

Alternatively, consider a few 40X1s or wait a bit and get a few 28X2s.
 

hippy

Technical Support
Staff member
I believe it is possible to use the 14M and have 8 ADC channels, leaving SERTXD as an output, and pin 3 as an input. Three 14M's would give 24 ADC channels.

I considered a keypad matrix arrangement ( the posts are somewhere on the forum ) but it isn't really practical.
 

Denzel

Senior Member
...

regarding my submarine...
I have been away for the past few weeks hence the lack of replies. you will notice I have done so now.

This is a seperate project i have been comissioned for. its for analysis of a structure that can twist and bend, I am to test the maximum (in degrees) the structure can twist and bend, I have had a lot of difficulty sourcing rotation sensors.


I was aware of these multiplexers but unsure as to their compatibility with the picaxe chips. These will be excellent im sure,
Thanks again

Denz
 

MFB

Senior Member
Make sure you use a multiplexer that works over the who ADC range. Many are non-linear near ground, unless they have a negative supply. Only a 'single-rail' type should be used with the PICAXE.
 

hippy

Technical Support
Staff member
More info from here, but datasheet seems to have got mangled with some other ...

http://www.byvac.co.uk/bv/bv4205.htm

Given the spec and its capabilities I doubt it would be too wide from the mark to guess it's a PICmciro or something similar. Seems a similar pin-out to other products sold and that makes sense.
 

jglenn

Senior Member
That would be surprising if a pic chip, as none I have seen run on 2V, or
have pins 1 and 20 for the power supply. What the heck cpu's run on 2V???

I must have been sleeping under a tree..:eek:
 

hippy

Technical Support
Staff member
That would be surprising if a pic chip, as none I have seen run on 2V, or
have pins 1 and 20 for the power supply. What the heck cpu's run on 2V???

I must have been sleeping under a tree..:eek:
Perhaps :)

The 08M, 14M, 20M, 28X1 and 40X1 can all run down to 2V, and the 20M's have +V on pin 1, 0V on pin 20. From that starting point, there's a remarkable correlation of pin allocation with the 16F690, albeit with ADC channels numbered differently.
 

premelec

Senior Member
128 channels A/D!

at analog.com look at preliminary specs for ADAS1128 - an example of what's coming to use with your X3 parts....
 

jglenn

Senior Member
Thanks Hippy, I did not know that, even after reading the manual. :D
Everything I am doing is based on 5V, because I must interface to RC systems.

Once in awhile someone needs a battery powered app, 2V is new territory for me. I like the thing to work to half the batt voltage, as it depletes, so would probably shoot for 3 or 4V. A single cell lithium is 4V, conveniently. Of course, 2 AAA in series is nice too.
 

hippy

Technical Support
Staff member
That ADAS1128, 128 channels of 24-bit looks interesting, but mini-BGA package, 10mm by 10mm, means it's going to have to come ready-built on a breakout board for most people here to use.
 

Mycroft2152

Senior Member
Have you calculated the scan time for reading all 21 pots?

If you are looking to determine the maximum flex of 21 sensors, you may not be able to keep up using a PICAXE.
 

MPep

Senior Member
Follow that link, at bottom of page under "Weblinks" there is mention of Peratech. Suggest you contact them.
 

Denzel

Senior Member
...

Ok, ive setup a small scale test of my apparatus.
I have 4 10k linear pots attached in a chain like structure that fits to the contours of a 20 cm object.
I am tryin to read their values one at a time through a 4051BE multiplexer (analog 8input). I have the pots in parallel, set up as the manual states when reading adc. (pots: far left pin and far right pin to +4.5v and 0v respectively and center pin to adc input) where I replace the adc input with a multiplexer input. then I run the output of the multiplexer to adc 0 on my picaxe 28x. I have two seperate power supplies both 4.5v one for logic, one for the pots.
I select which pot I want by making outputs 0,1,2 high or low.

The trouble I am having is this...

I take a reading of each pot into a variable then after all four readings I have a debug. The first dubug always displays the correct reading, i.e all adc values are correct. However the next debug goes out of whack every value is wrong and they dont seem to be responding to pot movement at all, and if they do, the values seem to all change when one pot is moved. at about the third or fourth debug the values go back to normal and then the cycle repeats again???

im rather lost,
is their something im missing?
do you never put pots in parallel?

Thanks in advance
Denz
 

inglewoodpete

Senior Member
You've probably heard it before but can you post your (whole) test code? The test routine should only do the switching of the 4051 and reading the ADC. The snip you gave above is a bit brief.

Perhaps, for the test you could use a PB switch to step through the various inputs, sending a debug or SerTxd before moving to the next one.

The 4051 is quick to switch (check the data sheet). The ADC connection to a particular channel may be 'floating', though (not connected properly).
 

hippy

Technical Support
Staff member
It shouldn't be necessary to add any delays after switching before reading unless there's something in the circuit causing some problem. The failure shown by debug after the first set of readings suggests that you aren't setting the multiplex address correctly after the first set of sequencing is done or there's some error in the code. As suggested, it is perhaps best to post your full code.
 

boriz

Senior Member
How many degrees do these pots rotate? How bendy is your rig?

Seems to me that you would need major bending just to register the smallest possible change in the ADC readings.
 

Denzel

Senior Member
Here is my code:

Main:
pause 1000
low 0 'address 0
low 1
low 2
pause 100
readadc 0,b1

high 0 'address 1
low 1
low 2
pause 100
readadc 0,b2

low 0 'address 2
high 1
low 2
pause 100
readadc 0,b3

high 0 'address 3
high 1
low 2
pause 100
readadc 0,b4

debug
goto main

The pots rotate around 100 degrees (+/- 50 deg from center point). Im aiming to measure changes of about 4 degrees or higher
 

inglewoodpete

Senior Member
The code looks OK, so I suspect there could be something lurking in the wiring.

I re-read your description of your circuit. The only thing you haven't said is that the two 0v rails from the supplies are commoned together. They are, aren't they?

If they are, does the debug show a consistant pattern each time it is powered up. (like you say: 1st pass is OK then it fouls up for (x) loops then goes good then returns to bad??)

Yes, its fine to connect many 10k pots in parallel.
 

Denzel

Senior Member
...

Yes the two 0v are connected.
I have tried with one supply and two supplies with the same problem.

my readings are basically as follows... (with chain in a straight line i.e. all angles are the same.)

debug 1:

b1 = 93 'correct
b2 = 93
b3 = 93
b4 = 93

debug 2:

b1 = 107 'erratic results with no chain movement
b2 = 53
b3 = 255
b4 = 48

debug 3:

b1 = 62 'still erratic results with no apparent sequence or relation
b2 = 62
b3 = 56
b4 = 172

debug 4:

b1 = 93 'back to normal again
b2 = 93
b3 = 93
b4 = 94

this cycle repeats forever, (note the values in debug 2 and 3 never repeat they are always random)
 

Denzel

Senior Member
...

Could it be something to do with the adc input floating?
I have tried putting a resistor (27k) from the input to ground with no effect.

Denz
 

hippy

Technical Support
Staff member
It looks like you are reading a floating input, the 4051 is an 8-to-1 selector so it could be an addressing problem. There are three things you can try -

1) Put a scope on the lines to see what the chip is actually being instructed to do and is doing.

2) Connect the unused inputs to 0V/5V/other pot one at a time and determine which are being routed through.

3) Disconnect the ABC select lines from the PICAXE, connect to 0V/5V and check each reads the selected pot.

As the code looks okay I would suspect a wiring error in the circuit.
 

Denzel

Senior Member
...

thanks hippy,
i'll play around and measure the three things you have suggested. Having never worked with multiplexers I don't fully understand how they work and therefore troubleshooting is a little less straight forward.

I'll get back with my results.

Cheers
Denz
 

BeanieBots

Moderator
The basic idea is very simple. You can think of them as little more than a set of relays connected to one input. By applying the appropriate logic, the relays are enegised such that alternative sources are connected to your single 'input'. Thus, if the selected source is not connected to anything, then it will appear as if your input is not connected to anything.
 

Denzel

Senior Member
...

Ok Heres an update...

I have realised that my addressing was slightly out, that is, I thought my picaxe outputs 0,1,2 went to the corresponding input 0,1,2 on the multiplexer, I was wrong, 2 and 0 were switched. I was a wally for checking all the wiring except which wires went to which pins.

So having adjusted my program to suit here are my results:
I have grounded all the remaining multiplexer inputs one at a time and come to the conclusion that I am measuring all the correct inputs/pots. Having left the pins grounded (apart from the four pots) I am getting better results, but not good results.

My analog readings of the mechanism in a straight line are 135 for all pots,
and every reading as long as i dont move it is 135, for all pots always. This is a good start. However as soon as I move one or more pots, all the analog readings change, the reading of the pot I moved is not relative to how/which direction I moved it and after 2 debugs of all (even pots I havent moved) readings coming as some erratic number, all readings goto '0' until I staighten the mechanism out again.

Although this is an improvement its still far from what it should be.

Any further help would be much appreciated, I am extremely grateful for the help I have received in this thread already.

Denz
 

Denzel

Senior Member
...

Solved it...

I got a hold of another multiplexer (the same type 4051) did a straight swap and its working perfectly,

Frustrating, but the problems solved :)

Thanks guys. This thread will be very useful to others when troubleshooting multiplexer problems, one would imagine.

Cheers
 

inglewoodpete

Senior Member
Hmm. I posted but it disappeared.

CMOS chips are very sensitive to electrostatic discharge: that's why they are supplied in conductive foam or packaging. You have just learnt a valuable lesson.
 
Top