Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Level shifting

  1. #1
    Senior Member
    Join Date
    Sep 2019
    Posts
    233

    Level shifting

    Hello all

    I want to jump over to Teensy 4.1's, as 3.2's appear to be impossible to find at the moment.

    So, I want to incorporate level shifting in my board design and I see that Sparkfun and other people use a small 3 pin device. Any idea what that part is? BS170?

    I understand that I can use something like a 74HCTxx. I basically want to make all the pins 5v tolerant.

    But, I assume the analogue pins still have to stay 3.3v input? Would level shifting these analogue pins make them read 0-5v?

    Also, if I make the 3.3v pins 5v tolerant with a level shifter, will it still operate correctly at 3.3v high?

    I could voltage divide, but I would like to do the job properly

    Thanks

  2. #2
    Junior Member
    Join Date
    May 2021
    Location
    Canada
    Posts
    16
    Well, the answers to your questions are pretty much the standard Engineering response to any question: "It depends".

    Quote Originally Posted by SteveSFX View Post

    So, I want to incorporate level shifting in my board design and I see that Sparkfun and other people use a small 3 pin device. Any idea what that part is? BS170?

    I understand that I can use something like a 74HCTxx. I basically want to make all the pins 5v tolerant.
    The Sparkfun level shifters use BSS138 mosfets, the schematics are readily available: http://cdn.sparkfun.com/datasheets/B...irectional.pdf
    Resistive and mosfet shifters are slower than a 74HCT125, but cheaper. Do you intend to read high frequency signals?
    There are several threads on level shifting all over the forum, e.g. https://forum.pjrc.com/threads/55427...light=74HCT125

    Quote Originally Posted by SteveSFX View Post

    But, I assume the analogue pins still have to stay 3.3v input? Would level shifting these analogue pins make them read 0-5v?
    You can't use digital level shifting on an analog input as it'll saturate the signal to the HIGH logic voltage level. Again, the solution depends on your needs: Depending on what type of signal you intend to sample, a simple resistive voltage divider might suffice. A more robust solution would involve opamps, which have great input impedance and also serve as a voltage buffer.

    Quote Originally Posted by SteveSFX View Post

    Also, if I make the 3.3v pins 5v tolerant with a level shifter, will it still operate correctly at 3.3v high?
    A logic HIGH at 3.3V logic is usually around 2.4V, which should be plenty to drive any 5V input pin HIGH with no problems. See here too: https://learn.sparkfun.com/tutorials...s-logic-levels

  3. #3
    Senior Member
    Join Date
    Sep 2019
    Posts
    233
    Thank you for the valuable advice

  4. #4
    Senior Member
    Join Date
    Sep 2019
    Posts
    233
    Am I correct in thinking that if I use a 74HCT125 to level shift, it is only one direction? (3.3v>5v) ?

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,787
    Yes, confirmed, using 74HCT125 powered with 5V, the level shifting is unidirectional from 3.3V to 5V.

    And as a general rule, for unidirectional signals, using a unidirectional buffer is almost always better that using a bidirectional level shifter. Also know that the BSS138-based (or similar mosfet & two resistor) level shifters, like the Sparkfun product mentioned in msg #2, are far too slow for TriantaduoWS2811.

    Another general rule is each of these 74HC chips should have a 0.1uF ceramic capacitor connected its power and GND pins, located as close as reasonably possible with minimized wire length. X5R or X7R type ceramic is best. If you build that TriantaduoWS2811 shifter circuit using 1 74HCT125 to level shift and 4 74HC595, plan on using 5 capacitors, one for each chip. The 74HC chips need power in short but large pulses. Ceramic capacitors located close by provide those pulses of current from the energy stored nearby. Without the capacitors, those brief but large pulses of current have to flow through lengthy wires, which can cause all sorts of noise and interference problems. Using the capacitors prevents those issues.

  6. #6
    Senior Member
    Join Date
    Sep 2019
    Posts
    233
    Thank you Paul
    Still in my learning years with all this (not that I have many years left lol). As a rule, I always put a 100nf directly across the supply of my IC pins in any design as close as possible.

  7. #7
    Senior Member
    Join Date
    Sep 2019
    Posts
    233
    OK. Now apologies for the awful MS Paint diagram... all I had to hand

    I was trying to design some kind of multiple option for inputs and/or outputs on a Teensy 4.1 pin. I have some nice small 3 position rotary pcb switches that I could use up.

    Does this circuit even seem logical? I know the Mocd208 opto-isolator part works, as I have used this before.

    Position 1: Shifted 3.3v to 5v output
    Position 2: Analogue in via a voltage divider
    Position 3: Optically isolated digital input

    If this was practical, would there be any side effect of combining those 3 input/output terminals (into one pin)? Would the 12k/22k voltage divider upset the level shifter? (probably)

    Click image for larger version. 

Name:	Input selector.png 
Views:	19 
Size:	26.2 KB 
ID:	28077

  8. #8
    Senior Member
    Join Date
    May 2017
    Posts
    320
    The 74HCT125 enables are active low, you would tie that to ground instead of +5 volts.

    Side effects of connecting switch 1,2,3 together puts the 10K and 22k resistors in parallel. You could just not use the 10K resistor and the 22k would provide the pulldown. If you were receiving an analog signal, the input to the 74HCT125 would not be just high or low. When the input is in the range of 0.8 to 2 volts, the 74hct125 could oscillate and draw extra current.

    Personally I would ask why you want to complicate things. Why not just decide before hand what the job of each Teensy pin will be and provide the correct circuit.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •