Level converting problem - Page 1
Forum section: electronics / beginners

author: FrankT
author_rank: Regular Contributor
timestamp: December 13, 2014, 10:08:39 pm
content: I'm driving a WS2801 string of LEDs using the XMEGA-C3 Xplained demo board (with an Atmega384C3 microcontroller).The LED strip is running at 5v (wall wart), and the uC at 3.3v, onboard regulation, powered by the wall wart.The datasheet says logic high, VIH is 0.8*Vdd, or 4v, which is too high for the uC 3.3v to turn on.I though this should be a simple case of using either a transistor, fet, or driver IC to convert the 3.3v signals (SPI) to 5v, but it's been a nightmare getting this to work.The data signal from the uC is SPI - I want to run at about 1MHz.The current iteration of my circuit is just using a 7407 (OC driver) wired to Vcc=5, with 2k7 resistor to Vcc on the open collector outputs. The uC outputs are going directly to the 7407 inputs. I've put this together on a solderless breadboard.Attached is a screen shot of the scope showing capture.Channels 3/4 (Pink/Dark blue) are the SPI clk/MOSI lines from uC.Channels 1/2 (Yellow/cyan) are the outputs of the 7407.Firstly, I don't understand why the level converted clock signal is taking so long to ramp up. I've had to reduce the clock speed from 1MHz to 250kHz to get an output single.Secondly, the MOSI line exhibits the same ramp up behaviour, except it also gets these glitches on the clock rising edge - increasing the output voltage over 5v.Any ideas where I should start looking?

author: dannyf
author_rank: Super Contributor
timestamp: December 13, 2014, 11:52:33 pm
content: Quotethat's your problem: the bus is being pulled up by that 2.7k resistor. So any capacitance on the bus will slow it down.Solution obviously is to lower the pull-up resistor or to use a totem output stage.BTW, if your mcu can handle 5v (even if it runs on 3.3v), its output stage is infinitely better than 7407.

author: FrankT
author_rank: Regular Contributor
timestamp: December 14, 2014, 12:12:14 am
content: Thanks for the reply. I have a bad habit of, when a circuit doesn't work, either scrap it and find another that does the same thing, or just randomly adjust components (like caps and resistors) until it works.I'd seen the term "totem output" before, but your reply got me googling it. I need a quick and dirty fix, so just switching to a 7404 with totem output fixed it.Thanks

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 12:17:02 am
content: If you need only unidirectional comunicationg line, level translation from 3.3V to 5V is easy as fuck, by using any TTL compatible logic gate, like 74HCT series. Vih is 2.4V nominally. And the back translation from 5V to 3.3V.. thats a bit problematic.First, I don't know XMEGA series much, but do they have 5V tolerant IO pins? (personally, I don't think so)... the second solution... use a level translation logic gate, some types are intended for this purpose, so they work from 3V supply and have inputs 5V tolerant. But I don't remember any type, maybe something from 4500 logic series, there were some level translators if I remember it right.Better solution would be actually to use a proper level translator device, which would do the whole job just in one package. Use the farnell's or mouser's catalogue search tool, to find some chips capable of level translation.Avoid using any open colector (+ pullup) solutions for level translation. This is only applicable for very low capacitance bus with low to medium speed. The LED string is a loooooong bus cable/wiring with awful capacitance - the pullup is just to big (too high resistance) to charge the capacity of the wires/bus fast enough, to enable 1mps communication. Proper bus/line driver has an output impedance as small as 30 ohms. (which ou will never get with a simple device like open collector driver with pullup)If you want to use 7404 as a convertor from 3 to 5 volt logic, you MUST use a type with TTL compatible input, such as 74HCT (the letter T at the end is important). Without the TTL compatibility inputs, this would not work, becaus standard CMOS levels are defined as logic zero below 0.3Vcc and logic high over 0,7Vcc, which equals over 3,5 volts at 5 volt supply to the gate, to flip the input to logic one.//Oh yes, and I think that LVC logic series are capable of downconverting logic leves, so they can operate from 3V and have 5V inputs - but rather check that in a datasheet.

author: dannyf
author_rank: Super Contributor
timestamp: December 14, 2014, 12:27:08 am
content: QuoteThe quick and dirty fix is a no-fix: run the leds at 3.3v - I can confirm for you that it absolutely works fine under 3.3v, as I am staring at one right this moment,.If you have to to level shift, google a Philips application note for i2c left shifters - it uses mosfets but can be done with bjts as well for uni-lateral transmission.If you need, I can post you a schematic to get you going.

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 12:30:06 am
content: no, jus f..g no. That single-mosfet level shifters are absolutely useless for fast SPI datarates with a looong high capacitance wiring. That is applicable only for the snail slow I2C on a board, when the capacitance is low so s the trace length.FrankT: This yould also help!http://www.ti.com/lit/sg/scyb018f/scyb018f.pdf

author: miguelvp
author_rank: Super Contributor
timestamp: December 14, 2014, 03:42:48 am
content: For high speeds this will helphttp://www.wvshare.com/product/74LVC8T245-Board.htmI believe they have an ebay store:http://www.ebay.com/itm/74LVC8T245-Bus-Transceiver-Module-Development-Board-with-TTL-Voltage-Translation-/261245515841If you order from their direct site it's strange and it involves e-mails but you can pay with paypal if you want. Ebay products offerings are more pricey but easier to order that way.I did purchase one but it's in my bin of things to try.

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 12:23:40 pm
content: Lets ask:The LED strip thingy is powered from 5V. What digital signals do that need? Does it have (respectively does it need) fullduplex SPI with all lines neccessary? (MISO, MOSI, SCK, NSS)? I think, that the LED strip can by actually driven by transmitt-only SPI, which only needs three lines. (MOSI, SCK, NSS). Therefore you need to only convert three outputs from the MCU from 3V logic to 5V logic. For that purpose, it is enough to use any TTL compatible gate powered from 5V, like 74HCT245. (why HCT, explanation above). And the simple signel 74HCT245, which is also available in DIP package will doo exactly what you need. (Or you can use any HCT series gates, not only 245, it will work fine with HCT04 or anything like that).So is the SPI you need only simplex? (transmitt only) -> then use only HCT logic gate to convert 3V logic to 5V.Is the SPI needed full duplex (transmit and receive concurrently)? Then you need another solution. But the previous might be exactly what you need to use.Have a nice day :-)

author: FrankT
author_rank: Regular Contributor
timestamp: December 14, 2014, 07:21:22 pm
content: Thanks for all the tips.The led string is a chain - logic signal only needs to power the first LED, then it forwards on the signal to the next, etc.It has a CLK and DATA signal, so it was easy to use the SPI peripheral to drive it.I used a SN7404 - just what I had lying around. The datasheets says it has a Vlo 0.8v and Vhi 2v.I've used other driving methods, including the dedicated level translating chips, but I needed a solution for this weekend - through hole and in my parts draw was a requirement.On the topic of level shifting, my first attempt was a simple fet circuit like that attached.Would this suffer from the issues as the OC logic? I didn't have a logic level through hole fet, so I tried to solder a SOT23 to a perf-board, but I couldn't get it to work - similar slow rise time, and a strange delay before any movement.Thanks,Frank

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 07:26:56 pm
content: The fet in that connection actually makes OC logic inverting gate. With all the problems associated with it. As it was explained somewhere at the top, the OC logic drives logic LOW by switching on the tansistor, but the logic HIGH is driven by the resistor - which gives you fairly large output impedance, so the rising edge of the generated signal is too slow. Proper logic gate ("push-pull", "totempole" or how you like to name that) has two driving transistors, usualy* one for driving low, one for high.*TTL logic mostly gives weaker 1 than 0. But todays CMOS based logic has both transistors of almost equal strength (the higside Pchannel a little weaker). Standard MOS gate output has an output impedance of about 50 to 100 ohms, bus driver logic has around 30 ohm. Special digital logic chips are surprisingly special and have special properties, such as AVR microcontrollers, which especially have wery strong drivers capable of sourcing or sinking higher than average currents. Today, we have sooo many chips around, things cannot be that simply categorized and the datasheet always makes the rules.SN7404 is an old TTL bitch, thats why it works pretty in this sitaution. So you did that right :-)It has a CLK and DATA signal, so it was easy to use the SPI peripheral to drive it.- Sure, that is simplex (transmitt only) SPI.

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 08:29:05 pm
content: One last thing to this topic: If you need a level convertor fast and now, like you did, you can also use interesting two-transistor levelshifter circuit, instead of that problematic "OC gate" circuit.Look at the schematic: There are two transistors. The lower one also needs a base resistor, when drivin from CMOS logic (like a microcontroller).You can use also smallsignal MOS transistor, like 2N7000 or BS170, then you will not need any resistor. Only the upper pullup, which might by a few kiloohms.The diode might be a 1n4148 or so, better a smallsignal schottky (bat42 etc), to get lower saturation voltage, VOL(max).And how does that work? Simple. The lower transistor (NPN or N-MOS) work just as the inverting OC logic gate we've seen before. But the output voltage is then fed to an emitter folower (yes, there MUST be an bipolar junction transistor, NPN). The Em. follower will give you very low impedance high voltage.The only issue is that it gives you output voltage of Vsupply minus BE junction drop (0.6V) minus base current times the resistor voltage drop (which is mostly negligible).When you switch on the lower transistor, the load capacitance (connected to the output) is then discharged rapidly through the lower transistor and the diode. (the upper T. Em. follower is therefore disabled, he has almost zero volt on his base).So this circuit is inverting (easily overcome be simple software mod in the microcontroller) and has a powerfull low impedance output capable of FAST driving high capacitive load, such as power mosfets! Yes, this can be used as simple gatedriver for a power mosfet like IRF3205, or so. Just put appropriate supply voltage, for power mosfets use 12 to 15 volts. Don't forget to add appropriate gate series resistance. This driver is simple, but can drive power mosfets at tens of kilohertz, unlike all the simple "OC like" circuits, which people usually use without knowing any of the issues with that.I hope, this circuit might help someone, not many people have this circuit ready for use in their mind, when designing projects.Note: I wouldn't bother to use this circuit for level converting for logic circuits. Just too many components involved for one signal line. But very handy for mosfet driving or other similar stuff. The output is very powerfull, can deliver a hundreds of miliamps in a pulse. Really sharp edges, but be careful not to overrun maximum peak currents for the transistors!

author: Zero999
author_rank: Super Contributor
timestamp: December 14, 2014, 09:42:18 pm
content: ^ That circuit will work but you need a current limiting resistor in series with the base of the transistor!

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 10:20:40 pm
content: Please, buy yourself glasses. Third sentence, second §.Read before leaving a comment.

author: Zero999
author_rank: Super Contributor
timestamp: December 14, 2014, 10:22:41 pm
content: Quote from: Yansi on December 14, 2014, 10:20:40 pmIt did skim through it but found it hard to read. It would help if you space your post out into separate paragraphs.EDIT:Which you've done: thanks!

author: Yansi
author_rank: Super Contributor
timestamp: December 14, 2014, 10:29:04 pm
content: What an unusual request.//Been there, done that. Better?