PDA

View Full Version : PWM to 0-5V



tallen
- 28th April 2010, 20:37
I am using the PWM command to create a 0-5V output that corresponds to 0-100% on my display. The Pic Pin has a RC filter 10K and 1uf cap into a rail to rail op amp. The op amp is powered off of the 5V supply that powers the PIC. I can only get about 4.5V out of the op amp when the cout is at 100. Is there a better way to do this or am i missing something?

' b1 varies from 0-100 which is converted to 0-255

Normal:
if sw1 = 1 then up
if sw2 = 1 then dwn
if sw3 = 1 then foff
if sw4 = 1 then fon
lx = b1
d1 = ((b1*100)/39)
pwm out,d1,100
call display
pause 250
goto normal

Thanks,

Terry

Charles Linquis
- 29th April 2010, 02:24
You will have to use two resistors to give the op amp a gain of greater than 1.
A 1K resistor from the output to the (-) input and a 4.7K resistor from the (-) input to GND should do it.

LinkMTech
- 29th April 2010, 17:02
My initial circuit did the same thing until I switched from a TI chip to a MIC7300YM5 TR. I think the output load was too much for it and could only source to 4.35V.
My PWM filter is a 39K with a 0.1uF to GND and the op amp is just configured as a buffer to give me the full 0 to 5V swing.

LinkMTech
- 29th April 2010, 18:14
Oops! Took too long to edit. Wanted to include partial schematic for clarity.
Don't recall actual PWM frequency but running PIC on IOSC set to 8MHz.

Gusse
- 29th April 2010, 19:49
Oops! Took too long to edit. Wanted to include partial schematic for clarity.
Don't recall actual PWM frequency but running PIC on IOSC set to 8MHz.

This not really solution for your problem but why you have so big RC time constant for filter?
PWM cycle time for 8MHz is ~2.5ms.


39kOhm and 100nF:
4358

How about something like this or in that range?
10kOhm and 10nF
4359

BR,
-Gusse-

tallen
- 29th April 2010, 20:45
adding the 1k and 4.7K resistors to the op amp to give it some gain, did not seem to help. I only have one rail to rail op amp here it is a lmc 6482 form national.

I'm using a PIC 16F716 @ 4mhz. I just used the RC filter that was used in the example on page 120 of the PBP book. That was what they were using for ther PWM Out Example.

Thanks,

Terry

LinkMTech
- 29th April 2010, 21:26
This not really solution for your problem but why you have so big RC time constant for filter?
PWM cycle time for 8MHz is ~2.5ms.


39kOhm and 100nF:
4358

How about something like this or in that range?
10kOhm and 10nF
4359

BR,
-Gusse-

Hi Gusse,
It was a choice between really fast response or a steady output to replace a resistor network and switch. This app. didn't need the speed but really good filtering.

Terry,
It looks like the LM6482 should work for you. Taken from data sheet:


3.0 RAIL-TO-RAIL OUTPUT
The approximated output resistance of the LMC6482 is
180Ω sourcing and 130Ω sinking at VS = 3V and 110Ω
sourcing and 80Ω sinking at Vs = 5V. Using the calculated
output resistance, maximum output voltage swing can be
estimated as a function of load.

Unless... your output load is 1K then that would explain your 0.5V loss.

tallen
- 29th April 2010, 22:09
I will keep working on it. The only load I have on it now is a volt meter. It is powered for the 5V Rail.

Thanks,

Terry

Gusse
- 30th April 2010, 08:03
I understood wrong, so you want to create adjustable voltage output with buffer (OP-amp)?

Even with your heavy filtering, you'll have a nasty ripple on PWM out (= OP amp input). If you add diode (cathode to OP amp) in front of RC-filter, the you'll get rid of pull-down effect of PWM. This will require additional pull-down resistor (after RC) to sink current when you want to reduce voltage (= decrease PWM duty cycle). Also d1 function will need some re-tuning.

Can you measure what is input voltage to OP amp? If that PIC output is 5V then problem is in your OP amp.

BR,
-Gusse-