Switching between analogue inputs

oracacle

Senior Member
Is there a simple and cheap way to get a picaxe controlled setup for switching between analogue input.
There are 2 possible sources for 2 analogue inputs. I thought about using a DPDT read relay, or maybe 2 DPST reed relays. I have only been able to find DPDT ones that cost around £18. Having dual DPST sees kind of bulky, The only other option wold be opto-isolator. I have some 4N25 (I have tested these with analogue through puton the switched side and they seem fine), but 4 would be needed along with some logic to inverted one per channel making it as bulky, if not more, as dual reed relays. Its looking like I will only have one spare pin to operate the switch mechanism as well, maybe 2.
This is going to be a mobile device that may get dropped, so solid state is preferred but not critical.

Not sure if something like this has been done before. Most thing have been I would think.
 

oracacle

Senior Member
That's not quite there
heres a little asci art that may explain better

Code:
         [color=Black]_______[/color]
[color=Navy]1 [/color][color=Black]In[/color][color=DarkCyan]----[/color][color=Black]|       |
        |[/color][color=Blue]Switch [/color][color=Black]|[/color][color=DarkCyan]-----> [/color][color=Black]Picaxe[/color]
[color=Navy]2 [/color][color=Black]In[/color][color=DarkCyan]----[/color][color=Black]|___[/color][color=DarkCyan]^[/color][color=Black]___|
            |
Control[/color][color=DarkCyan]-----[/color]
each input 1 or 2 will must not interfere with analogue signal, control comes from a picaxe, after the switch section the signal is then fed back to the ADC on the same picaxe. both input should not be active at the same time.

A quick little experiment on the bread board shows the it can be made with 2 4N25 and a 458B transistor.
 

techElder

Well-known member
Uh, 4016s have been used for that since their inception.

It also depends on the input impedance and whether you have plus/minus supply available. They are somewhat more linear that way.

Also, understand that you can parallel any of the four switches in the package.
 
Last edited:

oracacle

Senior Member
I presume I am looking at the right data sheet
http://www.ti.com/lit/ds/symlink/cd4016b.pdf
It would still need extra logic to do what was need as far as I can see. There is no negative supply, the analogue signal will not go negative either.
Input will either be from a op-amp or another picaxe.

Using the CD4016B will still need the Transistor inverter to switch each of the switches inversely in pairs.
The attached shows the setup that, although bulky does work for switching between 2 input to one ADC and controlled by the picaxe that needs the signal.
 

Attachments

oracacle

Senior Member
Uh, 4016s have been used for that since their inception.

It also depends on the input impedance and whether you have plus/minus supply available. They are somewhat more linear that way.

Also, understand that you can parallel any of the four switches in the package.
So essentially I end up with the same as the op-couple circuit, but in single package and 2 transistors, instead of 4 and 2 transistors.
I will order a couple and see how I get on.
 

AllyCat

Senior Member
Hi,

(HC)4053 is the triple "changeover" version of the quad 4016 / 4066 bilateral switches. Generic CMOS "4000" series for up to 12v rating or HC/HCT for (faster) 5 volt operation. Series resistance can be up to 100 ohms or so, but that's not normally an issue with an ADC input.

Or for low series resistance and isolation, etc., quite small encapsulated changeover relays (not reed) are available for a Pound or two.

Cheers, Alan.

PS: Or you can use one of the switches inside the 4016/4066 package as an "inverter" for the control input of the second channel. ;)
 
Last edited:

Pongo

Senior Member
I must be missing something here. If the need is to switch two analog signals to the A/D input of a picaxe, instead of using a spare picaxe pin to do the switching, why not just use that pin as a second A/D input and do the switching in the code?
 

oracacle

Senior Member
I assume that is a cryptic clue to how the signals are connected
Working on what little I currently know, connect analogue signal 1 to signal A in/out and signal b out/in. Then connect there respective counterparts to the ADC. Each of the control pins goes to the same Picaxe pin, when that goes high/low it will switch each of the switches direction inversely to one another.

The CD4066 should be a better choice, some of those should here in the next couple of days
 

Buzby

Senior Member
Which Picaxe chip are you using ?. Are you sure you can't arrange the pin usage so as to give you two analogue input pins ?.

All 'switching' is then just software, no need for an output control pin, and no need for another chip.

Cheers,

Buzby
 

Buzby

Senior Member
Here is how to wire a 4066 or 4016 to make a SPDT switch. Just needs one resistor.

Code:
    +5v ---------------------------------
           |
           |                 in 1
           |                  |
          4K7                 |
           |                  o
           +--------------+>|    Gate 2
           |                  o
           o                  |
       +>|    Gate 1          |
       |   o                  |
       |   |                  +----- Out
       |   +-- 0v             |
       |                      |
Ctrl --+                      |
       |                      o
       +------------------+>|    Gate 3
                              o
                              |
                              |
                             in 2
 

oracacle

Senior Member
I ma using a 20X2. The reason for this is actually because I use the analogue interrupt triggered by the comparator.
Weirdly there will actually be digital signals passed through as well.
There 2 analogue sensors in the system. then a digital sensors can be plugged in, the ADC pins set to digital for run of serial communications and one things are set running they then switched back to analogue to re-enable to interrupt conditions.
This is being investigated along side if there will be enough space to be able to use a digital hardware interrupt and either is selected. The code isn't finished and stand at 3916 bytes with other feature to add.

Thing like PWM selectable between one, the other or both on C5 and C4. I may have to make some concessions somewhere but I will see how it goes.
I often think that investigating more than one option is worth while. You may come up with a better idea, some one else may have a better idea, or something all together different comes along. This is why I always try and bread board before I actually start assembling a project, it highlights problems and errors in ones thinking.
 

hippy

Technical Support
Staff member
Here's one simple solution for switching two analogue signals to one ADC which may work -


Code:
                ___             ___
Analogue 1 >---|___|-------.---|___|---.---> ADC
                ___        |    ___    |
Analogue 2 >---|___|---.---|---|___|---'
                       |   |
                       |   `---------------< S1
                       |
                       `-------------------< S2
Set S1 to input and S2 low to read Analogue 1, S2 to input and S1 low to read Analogue 2.

For the first, reading Analogue 1, S2 low, that's the equivalent of -

Code:
                ___             ___
Analogue 1 >---|___|-----------|___|---.---> ADC
                                       |
Analogue 2 >-----.                     |
                .|.                   .|.
                |_|                   |_|
                 |                     |
                 `---------------------^---< 0V
It's not quite 0V, but may be good enough. It actually might be better with diodes -

Code:
                ___ 
Analogue 1 >---|___|-------.---|>|---.---> ADC
                ___        |         |
Analogue 2 >---|___|---.---|---|>|---'
                       |   |
                       |   `-------------< S1
                       |
                       `-----------------< S2
 

oracacle

Senior Member
There are two analogue sensors that are connected, one to ADC5 (B.3) and one to ADC6 (B.4) this is why I need to switch 2 pair of analogue signals. From page 50 of the basic commands manual comparator 1 can only have its reference voltage from the IVR or internal 1.024v, but comparator 2 can have both of these or from ADC4 (B.2). although the list shows ADC2(B.1) with the diagram showing ADC4. I suspect it got missed a copy and paste (reference on the 28x2 is shown as ADC2). The diagram in the X2 summery shows ADC4 and the online command list shows ADC2. There is a bit of conflict here, I haven't had issue as I am using the IVR for both comparators.

I did not see any reference to C.3/ADC7. I haven't read the PIC data sheet any detail either so it maybe I am overlooking something.
 

hippy

Technical Support
Staff member
You are correct; the IVR/ADC2 reference for the C2 comparator in the PICAXE Basic command Manual and online does appear to be incorrect; should be ADC4 as shown in the PDF diagram, not ADC2. We have updated the online command documentation.

From looking at the Microchip data sheet both C1 and C2 comparators can select their '-' input from ...

Code:
C12IN0-  RA1  AN1  ->  ADC1  B.0
C12IN1-  RC1  AN5  ->  ADC5  B.3  Comp2-
C12IN2-  RC2  AN6  ->  ADC6  B.4  Comp1-
C12IN3-  RC3  AN7  ->  ADC7  C.3
Their '+' inputs come from IVR or ...

Code:
C1IN+    RA0  AN0  ->  ADC0  A.0  Serial Out
C2IN+    RC0  AN4  ->  ADC4  B.2  Comp2+
That C1IN+ is used for Serial Out so means it cannot be selected for input so only IVR is available for C1.

The C12Nx- selections are defaulted to predefined pins by the COMPSETUP command, to make B.2 (C2+), B.3 (C2-), B.4 (C1-) adjacent and logical, but can be adjusted by using PEEKSFR/POKESFR after a COMPSETUP, untested -

Code:
Symbol CM1CON0 = $6D
Symbol CM2CON0 = $6B

PeekSfr CMxCON0, b0
b0 = b0 & %11111100 | n  ; 0=B.0, 1=B.3, 2=B.4, 3=C.3
PokeSfr CMxCON0, b0
I had previously miscounted pins so had lost ADC1 B.0 from the list of earlier inputs. I have added that in to the earlier post.

I think you should be able to switch from interrupting on ADC5 (B.3) to ADC6 (B.4) just by adjusting the COMPSETUP command, again untested ...

Code:
;          9876543210    76543210
CompSetup %xx11[b]01[/b]xx11 , %xxxxxxxx ; Interrupt on C1, ADC5 (B.4)
CompSetup %xx11[b]10[/b]xx11 , %xxxxxxxx ; Interrupt on C2, ADC6 (B.3)
 

oracacle

Senior Member
I have spent a few hours before work fiddling with a CD4066. Buzbys' wiring works fine, but would require 2 CD4066

So I had a fiddle around with some transistors and came up with the below. I suspect from the component count it will not be any smaller but does work as I need it to.
 

Attachments

steliosm

Senior Member
How about this one: CD74HC4067
It's actually able to multiplex 16 analog signals, so you have plenty of space to expand :)
You can find it on ebay as well for about 1 euro.
 

AllyCat

Senior Member
Hi,

I suspect from the component count it will not be any smaller but does work as I need it to.
As mentioned in #7, an HC4053 will give 3 changeover analogue switches (or an HC4052 will give dual 4-input switches) in a single 16-pin package, with no additional components.

Or if you can use SMD, there are various 5-pin (SP - ST) or 8-pin (DP - ST) "Bilaterral switches" (Analogue) for example this , but I didn't see any DT.

Cheers, Alan.
 
Last edited:
Top