I'm having trouble with the 3.3 v PWM DC output and I need ideas for a logic level shifting solution

I have a project that uses the PWM output of the Core and displays it on an analog meter, and although the output from the Core is working correctly, I need to convert the PWM signal to a 5 volt signal (full scale on the analog meter). Here’s what I’ve tried, without success:

• I’ve tried a TXB0104 level shifter from Adafruit with a second 5 volt power supply, but the output current is too low for my application. I only need a few milliamps, and this only gave me something about half way to 5 volts (which tells me it fails under load). Under no load it measured correctly.

• I’ve tried two NPN transistors with resistors, but for some reason, the output also drops when under load. Again, it worked fine under no load.

• I used another Arduino Uno to read an output from the Core (calling 3.3 volts a logic high), and then providing a logic high from the Uno (at 5 volts) in response to each pulse. This got me closer, but I still couldn’t hit the full 5 volts on the meter. I did not put this on a scope to verify, but this seems like a clumsy way to shift the voltage.

What am I doing wrong? How are others shifting a 3.3 volt PWM signal from the Core? I have to shift four output pins.

Yea, you certainly don’t need to use option three (i.e. the 5V UNO) to do this. Should be able to make it work with the NPNs. (Can you show or describe your circuit)? Just how close to the +5v supply are you trying to get … and do you have an estimate of your load or output current?

Here is the circuit I tried to copy for the transistors:

The analog meter has a full scale deflection at 5 v DC, so I’d like to get to that value. I can use a larger supply voltage, provided the Core can also accept it as an input voltage.

The meter draws 1 mA. I have four meters, each driven by a separate Core PWM pin (pins 14-17).

Ok, well the 10k on the second stage (i.e. Q2) is what’s doing you in, so as a brute force first cut you might try reducing it … say to 470 ohms or so. This should get you a lot closer.
(Kinda inefficient though as you’re now dumping about 10ma per output in the low state).

I’ll look into seeing if there’s a device (quad buffer, etc.) with a push-pull output stage that might be a bit better. You only need a uni-directional part, and at 1ma there should be a number of gates that should drive this at a high-level output close to your +5v supply rail.

I guess you are only showing a part of your setup, since you’d need some filtering stage to turn your PWM into an analog signal.
Could provide some more background what you want to do with your signal?

But I agree with @ljd2 about the 10k, which will limit your max current to about 0.5mA.

You could use a P-channel MOSFET to switch the 5V source side, driven by an NPN to pull it down, switching it on. Here’s an example: http://i1259.photobucket.com/albums/ii554/kaj9/Schmatic1.png

I’d go with 1K to the NPN base and 4K7 as the P-channel pullup since it’s PWM and might need faster switching.

Actually @ScruffR, I’m thinking the analog meter likely already provides all the low-pass filtering probably needed, and (assuming a high enough PWM frequency) should yield a fairly accurate average level reading of the PWM output, which is what I’m assuming @Alligator has been trying to achieve.

(Your suggested circuit looks like a good possibility @CT).

True, but I’d wonder what @Alligator means with

What kind of load is it and will it function with PWM signals as intended?
The low-pass filtering of the meter (in parallel) might account for a “correct” reading, but not necessarily for the active load to work, or it might - who knows without info about the load.

Have you considered simply changing the load resistor in the meter so that it’s full scale at 3.3v instead of 5v?

I’m simply using the meter as intended (to display voltage), and trying to get the needle to map to specific spots on the meter background with different PWM outputs. The load I’m talking about is the 1 mA consumption when the Core is connected directly to the meter. However, when I’ve tried the other solutions I first mentioned above, the meter displays the wrong value (usually about half of the correct value). When I test the circuit with a digital voltmeter, it works correctly. This indicated to me that the (small) load the meter places was causing the failure by possibly drawing too much current (my guess).

I did consider changing the load resistor in the meter, and gave it quite a bit of thought. Unfortunately, due to the way this particular meter is constructed, I can’t get to the load resistor without damaging the meter. That would have been a perfect solution!

Looks like I’m getting a strange waveform out of the TXB0104 level shifter. Although it is able to keep up with the frequency of the PWM signal, it doesn’t hold the full 5 volt square wave. And this is with nothing connected except the 'scope.

The top waveform is the Core’s PWM signal, the bottom is the (supposedly logic level shifted) 5 volt TXB0104 output.

Are you still using a 10k or another resistor between +5V and your load?
Where do you get your +5V from?

What’s the internal resistance of your meter? You got a voltage divider there, I’d guess

Sorry, missed that bit

I’m thinking what you’re likely seeing here @Alligator is inductive kickback from the coil (i.e. inductor) that’s a part of your analog meter. It would be similar to what you’d see with any switching waveform driving an inductive load (speaker, solenoid, relay, etc.)

You can mitigate it (with a clamp diode perhaps), but as it’s a short duration it really should have minimal impact on the measurement you’re trying to make.

Edit: It isn’t that it’s “not holding the 5v square wave” as you say. Rather, the max voltage out of your circuit is now simply 4.40v … (i.e. you’re getting close). That extra spike you see is simply the ‘inductive kick’ when you cut the current to the coil (i.e. meter). You can read a bit more about it here. (Sorry, I was trying to find a more simplified explanation with waveforms).

@ljd2, I’d say the 4.40V on the plot actually refer to the amplitude of the spike.
Looking at the 2.00V per division at the bottom line and the plot against the grid, I’d rather read the voltage as aprox. 2.3V.

And should the “kickback” of a coil not usually happen due to the collapsing magnetic field when the driving electro dynamic force gets switched off and also with opposite polarity?

I went back to the original two-transistor level shifter. It works, provided I supply a voltage higher than 5 volts (such as 5.2 volts with a ~1.2k resistor). I’ll just have to pick a supply voltage suitable for the Core, plus this level shifting circuit. Thanks!

Ah, you’re absolutely right on the peak voltage level @Scruff … just totally overlooked this thinking about the spike (which I do think is due to the meter coil, but I’ll think about it further. Saw a similar waveform while I was PWM’ing a speaker a couple weeks back).

Anyway, glad @Alligator has got his voltage where he wants it by decreasing the second stage resistor and bumping up the voltage a bit

1 Like