Shop OBEX P1 Docs P2 Docs Learn Events
Four input 5 volt to 3.3 volt level shifter — Parallax Forums

Four input 5 volt to 3.3 volt level shifter

Martin_HMartin_H Posts: 4,051
edited 2012-11-14 14:30 in General Discussion
I want to multiplex the input pin on a Propeller chip with four 5 volt sensors (e.g. four two pin ultrasonic sensors). My thinking is that I need four diodes coupled with a voltage divider. The diodes only allow the sensors to pull the line high, since they are wire OR-ed together any sensor can pull the line high, but the line is normally pulled low by a pull down resistor. The schematic looks like this:

multiPlexedLevelShifter.jpg


In use I pulse out the sensor's enable line and then read the multiplexed input line. That way I can use five pins instead of eight.
1024 x 627 - 32K

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-17 10:39
    I see you are using 1N1001 diodes. These have a voltage drop of about 1.1volts, other have a drop of .6-.7V and Schottky diodes are even lower at about 0.3V or so.

    You could use two 1n914 diodes in series to get get as much as 1.4 volts of drop. They are also smaller and maybe even faster to respond.

    At that point, you would not need any voltage divider. Just construct pairs in series and test for the actual voltage drop as there is some variation. The only other issue is whether you end up having two or more signals received at the same time, this is not really ORed as one input won't exclude another. You are really providing a mixed analog input.

    You might just consider a logic chip to avoid mixed inputs. It may be possible to have a 5 volt logic chip powered with open collector output that is pulled up to merely 3.3v

    http://www.electronicspoint.com/level-shifter-t137105.html

    You may have to use a quad 2 input NOR chip to get four inputs and an uninverted output. But be careful to make sure your output is not inverted from what you want.

    This is the chip I am think of, but I guess the intermediate outputs would require a +5 pullup; only the final output would be a 3.3V pullup.

    http://www.cs.smith.edu/~thiebaut/270/datasheets/sn74ls33rev5.pdf
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-17 11:03
    Forget the diodes and divider gingerbread; do it the modern way. Use three sections of a 74LVC32 quad 2-input OR gate, powered from 3.3V. The inputs are 5V-tolerant.

    -Phil
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-17 11:48
    Thanks Loopy and Phil. It sounds like the basic concept I was trying to build will work, but a real OR gate would probably be less trouble. Something to add to my next Digi-Key order.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-17 12:02
    http://www.ni.com/white-paper/3544/en

    This may help some. I was a bit uncertain about '5 volt tolerant inputs', but it eliminates the need for open-collectors as the chip can be powered by 3.3v and without the pullups. I guess you would not need NOR, just plain OR would work. But since you are building 4 inputs from pairs, either one does the same final result.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-17 12:10
    It's much easier to simply use 4 10K resisters for inputs.
    This is wrong!!
    See post below.
    Sorry.

    Duane J
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-17 12:17
    It's much easier to simply use 4 10K resisters for inputs.

    Duane J

    Agreed.

    Martin, are these SR04 ultrasounds?

    My thought was to use a separate Prop pin (output mode) for each trigger and then just tie all the echo pins together an watch it with a single Prop pin (input mode). It would probably be better to have a 10K resitor on each echo pin, but I think even if all the echo pins came through the same resistor things would work. (Assuming you'll trigger them one at a time.) This way it would take five Prop pins to use four ultrasound sensors. (I haven't tried this yet.)

    Edit: The above is a very bad idea. Using only resistors may damage the ultrasound modules. See post #12 for a better alternative.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-17 12:19
    It's much easier to simply use 4 10K resisters for inputs.

    Duane, is the idea that the sensors that are low are no different from pull down resistors? While the one that is high pulls up the output? In effect you put the prop input in the middle of a voltage divider?
    Duane Degn wrote: »
    Agreed.

    Martin, are these SR04 ultrasounds?

    My thought was to use a separate Prop pin (output mode) for each trigger and then just tie all the echo pins together an watch it with a single Prop pin (input mode). It would probably be better to have a 10K resitor on each echo pin, but I think even if all the echo pins came through the same resistor things would work. (Assuming you'll trigger them one at a time.)

    Yes. I guess what I'm worried about is a low output on one messing up the high output of another. So I was trying to find a way to isolate them from each other. But let the prop see all of them.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-17 12:20
    @Duane C. Johnson and the other Duane...
    Sure, but you are mixing signals, not having one exclude others. I'm sure we can get into a passionate debate about using resistors versus diodes to create voltage drops, but neither is really the right solution for 4 alternating inputs going to one pin unless you are absolutely sure that any two or more signals won't overlap.

    Isn't the objective to measure how long the signal goes high?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-17 12:28
    It's much easier to simply use 4 10K resisters for inputs.
    Without the diodes? That won't work if the sensor outputs are push-pull or have built-in pull-down resistors. I would also argue that passive components are not inherently "easier" than active components. This is a bias, I believe, among older designers who remember a time when active components were much more expensive. Nowadays, overall component count becomes an overriding factor, especially when assembly costs come into play.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-17 12:36
    @a passionate debate about using resistors versus diodes to create voltage drops, but neither is really the right solution for 4 alternating inputs going to one pin unless you are absolutely sure that any two or more signals won't overlap.

    I save my passionate debates for pseudoscience. :smile:
    Without the diodes? That won't work if the sensor outputs are push-pull or have built-in pull-down resistors.

    Loopy and Phil, I don't know if the resistor only method would work. I've been planning on trying this for a while. I have four ultrasounds in front of me so I'll give it a try. I'm glad Martin asked about this.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-17 14:08
    Sorry guys;

    I misunderstood what Martin was looking for.
    I was going off the message title.
    Forget what I said in my message above.

    Since Martin is combining 4 5V inputs to one pin his circuit would work just fine.
    R1 should be about 10K. (Must be greater than about 3.3K.)
    R2 should be about 100K. (Should be about 10 times larger than R1.)
    There is nothing critical about the values
    Almost any regular diode would work. I suggest the generic 1N4148.
    Martin had 1N4001 diodes in the schematic.
    While these 1 Amp diodes will work, it's usually preferred to use small signal diodes for this.

    Duane J
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-17 15:27
    Sorry guys;

    I misunderstood what Martin was looking for.
    I was going off the message title.
    Forget what I said in my message above.

    Since Martin is combining 4 5V inputs to one pin his circuit would work just fine.
    R1 should be about 10K. (Must be greater than about 3.3K.)
    R2 should be about 100K. (Should be about 10 times larger than R1.)
    There is nothing critical about the values
    Almost any regular diode would work. I suggest the generic 1N4148.
    Martin had 1N4001 diodes in the schematic.
    While these 1 Amp diodes will work, it's usually preferred to use small signal diodes for this.

    Duane J

    Is there really a need for the voltage divider? Wouldn't a single 10K series resistor be enough (after the diodes)?

    I don't mean to come across agumentative. Sometimes I think I know something (about an aspect of electronics) when I don't and I appreciate being corrected.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-17 15:57
    Duane Degn wrote: »
    Is there really a need for the voltage divider? Wouldn't a single 10K series resistor be enough (after the diodes)?

    I don't mean to come across agumentative. Sometimes I think I know something (about an aspect of electronics) when I don't and I appreciate being corrected.

    The diodes prevent zero volts from being seen by the Propeller pin. So you need r2 to pull down to zero volts when no output is active. You also need r1 to keep 5 volts away from the Propeller pin.

    Duane J, thanks for the values for r1 and r2.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-17 17:01
    Hi Duane; (Nice name!)
    Duane Degn wrote: »
    Is there really a need for the voltage divider? Wouldn't a single 10K series resistor be enough (after the diodes)?
    Its not really a voltage divider, well OK just a bit.

    R2 is what is called a "Pull Down" resistor.
    Any of the diodes can pull up the voltage to the pin through the 10K resistor.
    However, if all diodes are low there is no current path to bring the pin low without R2.
    R2, guarantees there will be a low on the pin when all diodes are low.
    R2, can be almost any value from 39K to 1M or so assuming R1 is 10K.
    R2 can't be to small or it would be a voltage divider and then the voltage
    can't get high enough to be a high on the pin.

    Hope that explains it.

    Duane J
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-17 20:27
    Hope that explains it.

    Very well.

    Thank you.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-18 06:20
    Went to bed last night pondering what happens when two or more signals overlap. It now seems to me that the logic chip and the diodes would provide just about the same results. After all, when the first signal shuts down, the second one would take over.

    If that is the case, you could still use the 4 sharing one pin -- but timing of ultrasonic pings in software are an equally important issue as there has to be some sort of rest period between each one to allow the microcontroller to get a good reading.

    The issue of needing a pull down is a bit of surprise, but makes sense. So I guess diodes alone might be a bad idea.


    The problem with using a logic chip solution is that each stage will introduce a time delay. If the OR gates hae a 25 nano second delay and you wire this up with 3 of them, you get a 50 nano second delay. With diodes, there may be nearly no delay.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-18 09:30
    The gate delay for each stage of a 74LVC32A OR gate is 3.8 ns. max. over the commercial temperature range and can be as low as 1 ns.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-18 19:29
    I haven't tried using multiple SR04 sensors with diodes yet, but I've tried them out with resistors.

    A Prop can monitor three echo lines with a single I/O pin using a 4.7K resistor on each of the three echo lines. The Prop can't seem to read any of the echo lines if a fourth sensor is added.

    By changing the constant "ULTRASOUND_DEVICES_USED" the attached program can monitor up to three sensors.

    Here's the output with three SR-04 sensors attached to the Propeller.
       Ultrasound Demo
       Range[0] = 1305 mm
       Range[1] = 1311 mm
       Range[2] = 387 mm
    
    

    Hopefully diodes will allow more than three echo lines to be monitored with a single I/O pin.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-18 19:52
    I'm not surprised that enough sensors eventually overwhelmed a single high signal. My guess is that the exact number of sensors you can connect without the diodes will vary depending upon the sensors too. The diodes coupled with the pull down should allow four.

    Keep us posted, I will likely be trying this shortly.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-10-18 20:14
    With just resistors, you will have the pull-down currents of the inactive sensors in parallel with the single pull-up current of the active one. Eventually, as more sensors are added, the former will overwhelm the latter. Moreover, without diodes, you run the risk of overcurrents in the paralleled circuit.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-18 20:45
    Martin_H wrote: »
    Keep us posted, I will likely be trying this shortly.

    I just found my signal diodes. I'll probably continue with this tomorrow.
    Moreover, without diodes, you run the risk of overcurrents in the paralleled circuit.

    Thanks Phil. I should have thought of this. I'll make sure and use diodes from here on out.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-19 01:26
    Okay, I did a bit of research again and Phil's solution of a 74LV32 powered at 3.3V with a 5V input is NOT supported in the PDF documentation as they assert that logic Vin should be a maximum of Vcc.

    While I suspect this to be merely a technicality, it does seem to argue that an Open-collector solution is best for a jump from +5 to +3.3V

    But because the LV version of logic will operate fine with +5 Vcc, it does make sense that the inputs are +5 tolerant, even when +3.3V is the Vcc.

    Of course, this may all be a tempest in a teapot as I cannot find any LVC pdfs, so presume LV is the same.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-19 01:54
    My mistake. 74LVxxx and 74LVCxxx are NOT the same. The LVC is specifically designed to operate as a level shifter and has 5 volt tolerant inputs. Simply put, this is new technology and very handy with voltages dropping to 3.3v and 1.8v
  • tonyp12tonyp12 Posts: 1,950
    edited 2012-10-19 07:33
    4-to-1 AND gates would also work, if sensor uses pull-up and one one go low when out-gate responds as it needs 4 out 4 to be true.
    These are dual so you get two sets of 4-to-1
    http://www.mouser.com/Semiconductors/Logic-ICs/Gates-AND-NAND-OR-NOR/_/N-581znZscv7?P=1yzxcukZ1yzxcumZ1z0w8z3Z1z0sqnhZ1z0spnpZ1z0sqo2Z1z0sqruZ1yzmm10Z1yzmm18Z1yzmm1bZ1yzmm1cZ1z0y22eZ1z0jmci&Ns=Pricing%7c0
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-19 08:23
    I just tried Martin's original schematic with four ultrasound sensors. It worked great.

    As Duane J. suggested, I used 1N4148 diodes. I used 4.7K for R1 and 47K for R2.

    Thanks for asking about this Martin. I learn a lot around here.

    I used the program I posted earlier but changed one of the constants:
    ULTRASOUND_DEVICES_USED = 4
    

    Here's the output.
    Ultrasound Demo
       Range[0] = 1428 mm
       Range[1] = 1420 mm
       Range[2] = 375 mm
       Range[3] = 403 mm
    

    As you may guess, two sensors were pointing one direction with the other two pointing the opposite direction.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-19 10:15
    Duane Degn wrote: »
    I just tried Martin's original schematic with four ultrasound sensors. It worked great.

    Hurray, I only minored in EE, so I'm happy when I'm alert to a potential issue and design a schematic that solves the problem. Even when it is something small like this.
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2012-10-20 11:32
    Another DIY alternative would be good ol' RTL (Resistor-Transistor Logic)

    RTL_IOR.png


    This inverts. When all of the inputs are low, the output is pulled high by R6. When one or more input goes high, the input voltage divider brings the transistor above it's 0.6V threshold and the output goes low. There is a limit to the number of inputs, before you have to start adding diodes at the input (DTL). The RTL circuit as shown can be speeded up by adding small capacitors in parallel with the input resistors and by adding a Schottky diode between the base-collector to prevent the transistor from going deep into saturation.
    154 x 113 - 3K
  • Martin_HMartin_H Posts: 4,051
    edited 2012-10-20 17:13
    That's interesting too. All we need now is Erco to produce a relay solution.
  • ercoerco Posts: 20,254
    edited 2012-11-14 14:30
    Martin_H wrote: »
    All we need now is Erco to produce a relay solution.

    Dang it, I missed this whole party while I was gone for a week driving cross-country...
Sign In or Register to comment.