Getting 0-5V with PWM

Hi,
I’m trying use the PWM to generate a varying voltage from 0 to 5V which I want to display on an analog volt meter.
After seeing that the vcc voltage on the board is lowered to ~4.8 I decided to try and use a transistor instead.
So I’m a 7805 to generate my 5V and I see that also with the circuit powered it’s giving out 5V.
I’m using a BC547 (NPN) transistor with the base hooked up to the PWM pin, the collector to the 5V and emitter to gnd.
I still can’t get the full range of 5V - how do I calculate which resistors to add in? Am I mistaken in the way I’ve built the circuit?
Any help would be appreciated.

Elan

PWM.JPG

To smooth PWM to DC, the drive must be symmetrical. What you've done here is change the relatively symmetrical output of the Arduino to a highly assymetrical drive.

IE, it pulls high with a resistor (you don't give a value) but pull low with a very low impedance saturated BJT. And there is no smoothing capacitor, so of course all your meter gets is the same old PWM that came out of the Arduino, except now the On cycle is rather weak, and the Off cycle is essentially a dead short.

Why not connect whatever 5V source you have on the transistor to the Arduino 5V line instead of whatever is powering the Arduino now? If it is USB, many computers don't put out full 5V on the USB ports.

Then you need an RC network, or two, to smooth the PWM to DC. The corner frequency needs to be much lower than the PWM frequency, which is about 490Hz. I suggest at least 1/10th, better 1/20th.

However - this is an analog voltmeter, it should smooth out 490Hz by its inertia. Does it have a calibration pot? Why not just adjust it so 100% duty cycle is full scale and forget all the rest?

Check what Nick Gammon did http://www.gammon.com.au/forum/bbshowpost.php?id=11395

Hi,

polymorph: Why not connect whatever 5V source you have on the transistor to the Arduino 5V line instead of whatever is powering the Arduino now? If it is USB, many computers don't put out full 5V on the USB ports.

I have. The output of the 7805 is feeding both the Arduino and the transistor.

I don't think the shaping of the pwm is all that important to me. What I'm trying to do is build a clock and use the meter as a digits display. For that I'm mapping the seconds value to a pwm value using:

analogWrite(secondsMeter,map(seconds,0,60,0,255));

Because the mapping is uniform across the 0-255 range I'd like the needle on my meter to move from 0 to 5. Although my regulator is outputing 5v the Vcc on the Arduino is just lower than that at 4.8-4.9 so I was hoping that by using the transistor rather than hooking the meter straight the pin I'd be able to go through the whole range. That's also why I don't think smoothing of the PWM to nicer DC value is so important. Am I wrong in my thinking here?

Sure, with an analog meter, you don't really need to smooth the PWM.

Are you not able to recalibrate the meter?

Am I wrong in my thinking here?

Yes you need to smooth it. Simply hoping that the mechanical inertia will smooth the signal for you will not work.

Grumpy_Mike:
Yes you need to smooth it. Simply hoping that the mechanical inertia will smooth the signal for you will not work.

My problem is not the meter itself. It shows the correct value from the output.
My problem is that I can only get to a max output of 4.8 rather than the 5v I want.

Maybe I need to use a higher voltage and couple a transistor with a voltage divider somehow

My problem is that I can only get to a max output of 4.8 rather than the 5v I want.

You will not see 5V while it is pulsing without smoothing.

If you want to be able to trim this then you simply put the collector resistor up to a higher voltage. You could even put it to the wiper of a pot that is going from ground to some higher voltage than 5V and then adjust the pot until you get the right voltage but USE SMOOTHING.

I doubt an analog meter is going to show pulsing at 490Hz. I have used analog meters for a very long time, I don't recall seeing smoothing capacitors in the AC circuits on them, and that is only 60Hz. In fact, on AC, if you add a capacitor to an analog VOM, the meter will now inaccurately report the peak voltage.

Anyway, I don't know of any analog panel meter or VOM that will respond quickly enough to move for a 490Hz signal.

the meter will now inaccurately report the peak voltage.

That is EXACTLY the point. The OP needs to read the peak value not the RMS value.

No, he wants to read the average of a PWM output. He could do so using a lowpass filter and buffer amplifier, or he could just connect the meter and allow the intertia of the movement to smooth PWM to a static needle position. No capacitor required.

To read the peak, he’d need a diode and capacitor. But the peak would always be 4.8V - 0.7V or 4.1V.

just connect the meter and allow the intertia of the movement to smooth PWM to a static needle position.

Well you might but I would not.

An entire industry disagrees with you. Page 44 of the good old Simpson 260 VOM (page 23 of the PDF) has the schematic. No smoothing capacitor when using the ACV range.

http://www.simpson260.com/downloads/simpson_270-4_user_manual.pdf

Same with the 160:

http://www.simpson260.com/downloads/simpson_160_schematic.pdf

Some other brands:

In VU and dB-spl meters, capacitors are added to slow the response time of the meter.

In any case, what I said about peak readings still stands.

An entire industry disagrees with you.

Oh come off it, do not be so silly.

So how many of those circuits are for a clock indicated on an analogue meter?

Top circuit. What do you think C2 is?

What about average vs peak? I think he wants the average, not the peak.

Anyway, where is the OP in all this?