Analog Multiplexers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey how's it going so today I thought we would talk about analog multiplexers in a previous video the one that I did about the HC 165 shift register someone in the comments asked whether we could talk about analog multiplexer so that that's what I thought we would do today so just like the HC 165 is a really great way to read a lot of digital inputs with only a few number of pins required on your microcontroller analog and multiplexers let you do the same thing by multiplexing the analog input so let's say you've got some potentiometers or some sensors or something like that that makes analog voltages and you want to read them you can use analog multiplexer x' to hook up a whole bunch of them to your microcontroller now in fact most microcontrollers actually already have an analog multiplexer inside because when you see the micro and it says it has let's say 16 analog inputs they don't mean that there's 16 analog to digital converters they usually actually mean there's only one analog to digital converter and 16 inputs that are internally multiplexed so why would you not want to just use those that built-in multiplexer well it's definitely easier to use because it's its built-in you send a message right to a specific register and you can switch which input is being read and so on but the disadvantage is that in most cases multiplexers like that can't be reassigned to other pins and many microcontrollers also have other functions on those same pins so let's say you needed some I squared C an SPI and a UART and so on and you also wanted analog chances are that those those pins are going to be needed for one or function or the other so you're going to have a limited choice as to which pins you can use for analog and how many of them are available so and the other reason is let's say you just want to have a whole bunch of inputs like let's say you've got a big mixing board or something with like 32 or 48 faders on it you're gonna be hard pressed to find a microcontroller with that many inputs so being able to do it externally lets you expand the number of inputs and it also allows you to decide to put those multiplexers near where the actual signals are being generated let's say on like a control panel board or something like that and that simplifies the wiring in the application so let's take a look at some classic chips that have been used for decades and there's variants of them still available and they're used all the time for doing exactly what we're talking about so let's let's take a look at the datasheet for that right now so this is the CD 40 51 52 and 53 series there's three different chips they have different configurations but basically work the same way internally and there's newer versions of them as well that aren't in the sort of classic CMOS style so if you have lower voltage requirements there's some 7400 series versions of them and basically what they do is they allow you to multiplex pretty much any kind of signal it doesn't have to be digital it's like a an analogue switch that's electronically controlled so let's take a look at some of the versions here there's three different chips with different pin notes the first one here the 4051 this one has basically eight inputs or outputs and one common now see how it says e'en out this is really interesting because B since it's analog obviously you can put in voltages any voltage you want within or within the necessary or the the allowed range of voltages the voltages can actually go in or out of either side so what it means is that in our case when we're talking about multiplexing analog inputs you could have eight voltages here and then one output that goes to your microcontroller but there's other applications and I'm sure you can think of some where let's say you were to have one input you would want it to feed to multiple outputs now you can only do one at a time in this case because it just selects one of eight that's what this little section here does is that decodes the binary signals and chooses one of the eight switches but there's some applications that that would be kind of neat to do and then there's a couple other versions this version here the 4052 this actually has two four channels which is they're controlled from the same input so whatever channel is selected on x over here is the same one that's selected on Y and then this one the 4053 this is actually I think the most useful one this is the one that I use most often this is actually two ins and one out but you get three of those and the best part about it is that they're all independently controllable there's just a bit for each one that selects whether it's the C Y or C X and I've used these lots of times in both directions from going 2 to 1 and 1 to 2 and so on with in mostly analog synthesizer circuits where I want to do crazy things like flipping the signal over you can run these really fast like at audio rates even and have them do all kinds of interesting things so let's go over to the workbench and we're going to look at basically some of the aspects of how you would use these and some of the limitations to keep in mind when you're using them so I'm just going to do some little jot notes here and we can talk about some of the ideas so let's say let's just talk about a four channel one here's here's my four channel MUX there's four inputs right here we've got our two inputs let's call them a and B and these ones are going to be the ones that we control with a binary code so there's four combinations you can put on there and let's call this a B C and D these inputs not to be confused with these ones over here anyway here's your microcontroller MCU and here's your analog input and so let's say over here just let's use our typical example of reading in some potentiometers so we've got let's say four potentiometers here and these are connected to the power supply and ground so when you turn these pots up and down let's say these are on your control panel the voltage here will go from zero or ground all the way up to the power supply voltage and that would normally be the same power supply voltage that's feeding your micro over here so let's say these are wired through to your micro and your micro is going to use two output pins out one and out two let's call it and in software you're going to select one of these or one of these channels by setting the combination whether it's so here's this would be a B C and D and so we would have the value of this actually let's call this out out one and out two this would be like zero zero one one or zero one zero one something like that and so these would come in it doesn't matter which way these are that's basically there's four combinations and that's that's it so a few things to think about here when you're using these is first of all the voltage range both of your micro and of the multiplexer chip itself so often these chips have some logic level conversion and actually we could see that in the datasheet when we when we were looking at that first block on the left and I'll actually just switch back to it really quick so you can have a look at it see that first block on the left right over here this basically takes your control signals and changes the voltage range to match what this what this stuff actually requires to control the actual switch this little TG here is the actual switch so one thing to think about though is that make sure you read the datasheet because and I've actually been burned by this before the range of voltages that you can use here to control it let's say your microcontroller is running on 3.3 volts or something the range of voltages here has to be correct - based on the the analog signals that you've got coming in here now one good thing is some of these chips are actually allow you to to use power supply voltages for the actual chip that go above and below ground so you could actually switch like analog audio signals and things like that with a chip like this but only within a specific range so you have to be really careful to read the the datasheet specs correctly in this case we would just be feeding this from the same voltage probably that we're using this would be grounded like that that we're using over here so the whole system is running on the same range of voltages so there's no problem but yeah keep that in mind if you're thinking of doing it with analog signals like like audio and control voltage signals for synthesizers and things like that double check that your control voltages will actually turn them on and off properly another thing to think about here is that these are not a relay just because just like we have to worry about our power supply voltages it's sort of the same thing when you turn this on let's say this path is connected to a to the output here this is not like a piece of wire inside this isn't like turning on a relay we already know that these voltages have to be within the range of the power supply here and these control voltages have to be compatible to some extent not the same voltages necessarily but definitely within a specific range also this isn't like a relay in that this has a resistance this has a limit to the amount of current that can go through here and and it has a bandwidth usually the bandwidth is pretty high like you could easily put you know video signals and things like that but this isn't going to be zero ohms so if we think about it like as if we're just hooking a wire up here that's not really the effect that we're going to get and it does have an implication in some circumstances so for instance these older chips have internal resistances when they're on of something like hundreds of ohms maybe two or three hundred ohms now depending on what source you have over here and how fast you want to sample resistance like this might change the performance of your system enough to create a problem so that's something you have to think about will this internal resistance you know affect the the reading of your signal will it cause a voltage error let's say you're trying to measure voltages really accurately definitely if you have a few hundred ohms here and the source impedance is you know maybe a few thousand ohms only definitely that's going to be a problem there's going to be a voltage drop there and that could affect your reading so keep that in mind also that number is not really guaranteed it's quite a large range if you look in the datasheet so that's something to keep in mind certainly you don't want to put a lot of current through here now in the case of what we're doing with this circuit that would actually work fine there wouldn't be very much current running through here as long as this is set as an input on the micro then that's probably fine and then the other thing to think about with respect to this resistance has to do with what actually goes on inside the microcontroller when it's trying to measure the signal so a typical microcontroller will talk about this in another video typical microcontroller essentially we're going to ignore the multiplexer that may or may not be in there has a small capacitor it's really quite small but it's not zero capacity it does have a size in Pico farad's or something like that so when you when you want to measure an input you have to charge or discharge if there's already voltage in there you have to charge or discharge this capacitor and put your voltage on there so by selecting this input this pot is sitting here at some value you're going to have to wait long enough for this capacitor to reach the voltage that's on here if you want to get an accurate reading and what will happen when you actually start the conversion process is there will actually be a switch here so let's just rub that out there's a switch here that will open to disconnect the input from that capacitor so that while this is making a conversion this goes into your convey to D converter o ADC sorry about my bad writing and the converter takes a number of cycles to actually take the reading and that's something to keep in mind is that that process is kind of an iterative process in the case of most analog to digital converters and what that means is that any variation on here will cause errors in here and that's why the input gets disconnected but the problem is that this has to have enough capacity to hold the charge for as long as it takes for the a-to-d converter to do the conversion and so let's say you've got your potentiometer here that's got resistance there's resistance in here let's suppose that this micro also has a multiplexer which is commonly the case there's more resistance in there and what that means is that you have to hold this input on for long enough to to fully charge up that capacitor enough that the voltage will be the one that you want to actually measure so that limits the speed at which you can do this process if you want to read one channel after or another you can't just start going it like tens of kilohertz or hundreds of kilohertz it probably will start to give you errors in the readings now it's not going to explode or do anything bad but what you'll start to see is one of two things either the readings won't be really correct they'll usually be high or low or something and the other thing that you'll have is you'll start to notice that adjacent channels will interact with one another because let's say you've charged this one up let's say this is set to full and this one set to OFF this will charge up and then this one we'll have to discharge that capacitor all the way down to zero and if it can't do that then some of the voltage that was put on by this guy will be left on there when the conversion is done and so if you start to turn a pot and you see your adjacent values kind of adjusting a little bit then that's probably what's happening so a lot of things to think about but super useful technique and something that I should I would definitely recommend experimenting with a good way to start working on stuff like this is to basically have sort of bread boarding approach to it before you go and make an expensive board try to try to get something working on on on your bench first so anyway that's it for this video and I hope that I've inspired you to go and read a bit more about this stuff these are really really you know jelly bean components that are easy to get easy to use you just have to be aware of some of the limitations read the data sheets do some experimentation on your own and hope that this helps you in your next project take it easy
Info
Channel: Shiftedphase
Views: 8,509
Rating: undefined out of 5
Keywords: analog, electronics, microcontrollers, arduino
Id: cMMjLCKDXH0
Channel Id: undefined
Length: 16min 47sec (1007 seconds)
Published: Sun Mar 19 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.