Author Topic: Level converting problem  (Read 7429 times)

0 Members and 1 Guest are viewing this topic.

Offline FrankTTopic starter

  • Regular Contributor
  • *
  • Posts: 176
  • Country: au
Level converting problem
« on: December 13, 2014, 10:08:39 pm »
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?


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Level converting problem
« Reply #1 on: December 13, 2014, 11:52:33 pm »
Quote
7407 (OC driver)

that'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.
================================
https://dannyelectronics.wordpress.com/
 

Offline FrankTTopic starter

  • Regular Contributor
  • *
  • Posts: 176
  • Country: au
Re: Level converting problem
« Reply #2 on: December 14, 2014, 12:12:14 am »
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
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #3 on: December 14, 2014, 12:17:02 am »
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.
« Last Edit: December 14, 2014, 12:24:01 am by Yansi »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Level converting problem
« Reply #4 on: December 14, 2014, 12:27:08 am »
Quote
I need a quick and dirty fix

The 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.
================================
https://dannyelectronics.wordpress.com/
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #5 on: December 14, 2014, 12:30:06 am »
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
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Level converting problem
« Reply #6 on: December 14, 2014, 03:42:48 am »
For high speeds this will help

http://www.wvshare.com/product/74LVC8T245-Board.htm

I believe they have an ebay store:
http://www.ebay.com/itm/74LVC8T245-Bus-Transceiver-Module-Development-Board-with-TTL-Voltage-Translation-/261245515841

If 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.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #7 on: December 14, 2014, 12:23:40 pm »
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 :-)
 

Offline FrankTTopic starter

  • Regular Contributor
  • *
  • Posts: 176
  • Country: au
Re: Level converting problem
« Reply #8 on: December 14, 2014, 07:21:22 pm »
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
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #9 on: December 14, 2014, 07:26:56 pm »
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.

« Last Edit: December 14, 2014, 07:39:01 pm by Yansi »
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #10 on: December 14, 2014, 08:29:05 pm »
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!
« Last Edit: December 14, 2014, 10:31:39 pm by Yansi »
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Level converting problem
« Reply #11 on: December 14, 2014, 09:42:18 pm »
^ That circuit will work but you need a current limiting resistor in series with the base of the transistor!
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #12 on: December 14, 2014, 10:20:40 pm »
Please, buy yourself glasses. Third sentence, second §.  >:D

Read before leaving a comment.
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Level converting problem
« Reply #13 on: December 14, 2014, 10:22:41 pm »
Please, buy yourself glasses. Third sentence, second §.  >:D

Read before leaving a comment.
It 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!  :-+
« Last Edit: December 14, 2014, 10:36:23 pm by Hero999 »
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Level converting problem
« Reply #14 on: December 14, 2014, 10:29:04 pm »
What an unusual request.  :-//

//Been there, done that. Better?
« Last Edit: December 14, 2014, 10:32:04 pm by Yansi »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf