Voltage level shifter

Thread Starter

akis02

Joined Apr 30, 2011
57
Hello

I have just only started with MCUs and have been experimenting with a Arduino Nano which is a ATmega328P chip.

I have done this simple experiment. I set an output pin of the MCU to go on and off 5 times a second. It drives an LED drawing around 3mA. The MCU is powered by 5V.

I also have a simplistic op-amp circuit with Vcc=12V and Av=10 which drives a LED drawing also 3-5mA. The op-amp is driven by the same MCU pin that drives the LED.

I connect the scope on the MCU output pin and also the op-amp's output pin. Both show a perfect square wave in perfect unison.

Looking closer however the MCU's output pin has a rise time of around 30-40ns. The op-amp has a hysteresis of around 100ns and a rise time of around 1200ns (including the hysteresis).

Obviously this may be considered too slow, so I changed the op-amp for a fast one (LM6172/LT1361) and tried the same experiment. Now the op-amp's rise time is around 90ns, which is very much nearer the MCU.

I am therefore quite satisfied that this simple op-amp circuit works quite well, and I can use it to marry the MCU's digital voltages from 0V to 5V to my analogue circuit, in this case 0V to 12V. To make sure I get real 0V from the op-amp I feed it a negative supply, and I do not much care if I do not reach the 12V perfectly.

Now it appears that this is not the way to do it. Apparently a comparator is a much better choice, and op-amps, apparently, make for very poor comparators.

I am not sure, because the LM293 which I happen to have in my drawer, has an open collector output. How is it supposed to source current? Just does not make sense. Secondly, would the LM293 be faster than my super-fast slew rate op-amp? I also doubt it.

Could someone please explain to me why my op-amp solution is a poor choice and why I would need Schmitt triggers, comparators, hex inverters and so on?

Many thanks!
 

MrChips

Joined Oct 2, 2009
30,706
Comparators usually come with an uncommitted output (open collector) so that you can sink any source voltage. To use with a resistor as a load, simply connect one end of the resistor (1k-10kΩ) to the output while pulling up the other end to your power source (2-36V).
 

ericgibbs

Joined Jan 29, 2010
18,766
hi akis,
It would be helpful if you explained what your target specification is for the LED project.

Why do you need to switch an LED so 'fast' and whats the spec' of the LED's
E
 

Thread Starter

akis02

Joined Apr 30, 2011
57
The LED is just an example to prove I can source and sink a moderate amount of current.

Think of the 555's output - it is push-pull and allows you to source or sink up to 200mA.

OK I am not going to need 200mA, but my current 555 switches on and off (sources and sinks) 2 pairs of SSRs, at 12mA each pair, and also drives another circuit a few mA there too.

Now I am thinking of replacing the 555 with an MCU, using one or more of the output pins to replace the 555's output pin.

But I need to translate the voltage levels from 5V for the MCU to 12V (or whatever) for the 555.

So I need to be able to source + sink around 20mA each direction, just like the 555 does. And of course I do not want one million extra components.

A friend of mine suggested a Schmitt trigger but I read about it and that is for when the input waveform is not a square wave. Here the MCU produces fantastic square waves, so I do not think I need a Schmitt.

Wikipedia says comparators are the way to go, and slags off op-amps, but I am not sure why. The comparator can only sink, not source, I do not think it is any quicker either. I just must be missing something with those comparators.
 

BobTPH

Joined Jun 5, 2013
8,804
Driving an SSR is just like driving an LED, you should not need 12V, the 5V output from the micro should be perfectly okay. Can you show us a datasheet for the SSR?

Bob
 

ErnieM

Joined Apr 24, 2011
8,377
Ditto what Bob says. It may be (and probably is) that a simple NPN transistor and a pair of resistors is all you need to drive the SSR (assuming SSR stands for Solid State Relay).
 

Thread Starter

akis02

Joined Apr 30, 2011
57
I can drive the SSRs with 5V, all I need is the right mA through their LEDs. I may also be able to drive other parts of my circuit using the 5V of the MCU rather than the "12V" of the 555 after making necessary mods. I say "12V" because the 555 never really reaches the Vcc, it's about 1.3V lower, but that's by the by.

However my initial query arose from the need to remove a 555 from a circuit and replace it with an MCU. The idea is that I will get the MCU to do many more things in the future. So trying to "bolt on" the MCU in place of the 555, the first hurdle is "oh, I need 12V pulse but I only get 5V from the MCU - how can I convert it?".

So I devised the very simple non-inverting, op-amp amplifier, that connects to the output pin of the MCU and gives out a pulse almost 100% equivalent to that of the 555. One op-amp can do two output pins, a quad op-amp can do 4 pins. In terms of space/pin count this seems to be very good.

Thus my question is a very general one, as per title, I am devising a general purpose, voltage level shifter, unless there is a better term for this, and a friend of mine has indicated the use of Schmitt triggers, comparators (for extra speed) and so on. I just cannot see why/how my simple non-inverting op-amp can be beaten in performance or component/pin count or any other measure by a comparator or by a Schmitt trigger. So I asked here:)

So supposing you were pulling a 555 out of a circuit, and replacing it with an MCU, and you had absolutely no idea what the pin 3 of the 555 was used for, downstream, so you wanted to be as compatible as possible, you too would be using a level shifter. The questions is what would you use. An op-amp like my idea? A Schmitt trigger? Some sort of comparator?
 

MrChips

Joined Oct 2, 2009
30,706
No, no, no.

You don't put a driver on the output unless you know what you are driving.
If you want to give it a general purpose output, put an NPN BJT (e.g. 2N3904) with open collector (nothing connected at the collector).

Or leave the MCU output pin uncommitted but put pads for a series resistor feeding the base of the NPN BJT.

If you want to drive multiple outputs consider using ULN2003 or ULN2803 transistor array.
 

to3metalcan

Joined Jul 20, 2014
260
akis, you're presuming the need to both sink/source current...driving an LED only requires one or the other. If you want to drive two LED's in alternation, you might need to do both, but otherwise you're over-specing the wrong feature.

A comparator with hysteresis is designed to go rail-to-rail as fast as possible, uses a low component count, and it's CHEAP. That's the advantage vs. typical op amps. A super-fast rail-to-rail op amp might be able to compete, but it's kind of a wasted part in this application.
 

Thread Starter

akis02

Joined Apr 30, 2011
57
Yes the 555 drives SSRs on both sides of the pulse. It also drives other circuitry on both sides of the pulse but with less current requirements.

I want to do a "555 replacement" which means I want to emulate the 555's push-pull output with source and sink capability. The MCU has the precise same output but with lower voltages. Ideally I should be able to drop in this in place of the 555 and noone should tell the difference. This is something we do very regularly in software, take on e module out replace with another that presents the same interface, I do not know why there has been so much resistance here with people suggesting I modify everything else instead to make it fit the MCU.

I have tried a few solutions and it seems the super-fast op-amps have excellent rise times but poor fall times and some distance from the positive rail. A comparator (LM2903) plus a push-pull transistor stage is much slower to rise than the fastest op-amps, but has decent fall times and it stays within 800mV off of the rails. A cheap op amp (MC33072) has slow rise times and slow fall times but has 8 pins less than the comparator solution. I must also mention the solution involving an NPN transistor switch followed by a push-pull stage, the problem there is the NPN transistor takes too long to switch off once it is on, and because it is inverting, the rise times are awful.

None of it matters anyway, because the measured times are in 100s of ns but the waves are in 100s of ms. But it is good to have run all this experiments and observe the rise and fall times on the scope.

In the end I will go for component count + cost, and the 50p MC33072 seems to be the ticket.
 

ErnieM

Joined Apr 24, 2011
8,377
Ideally I should be able to drop in this in place of the 555 and noone should tell the difference. This is something we do very regularly in software, take on e module out replace with another that presents the same interface, I do not know why there has been so much resistance here with people suggesting I modify everything else instead to make it fit the MCU.
Hardware is not software. There may be little difference in one routine that uses 5 instructions over another that uses 50 instructions, but there is a huge difference in a circuit that uses 45 more parts then some other.

The "resistance" here has been in the lack of any sort of specfication on your end. The SSR is still some undefined element, the absolute need for a '555 element is also not defined.

Heck, if you are so set on keeping a '555 like interface then just drive a '555 from the micro. 555's don't have to be used as a timing element, they have a comparator inside that can differentiate signals of 0 and 5V, plus that hefty driver on the output.

Just don't expect anyone to suggest a design based upon a wish to use certain parts.
 

BobTPH

Joined Jun 5, 2013
8,804
Heck, if you are so set on keeping a '555 like interface then just drive a '555 from the micro. 555's don't have to be used as a timing element, they have a comparator inside that can differentiate signals of 0 and 5V, plus that hefty driver on the output.
Yep, lowest parts count to make a 555 equivalent to drive a black box.

Bob
 
Top