Author Topic: PWM to DC - RC filter maths?  (Read 12360 times)

0 Members and 1 Guest are viewing this topic.

Offline alxpowaTopic starter

  • Newbie
  • Posts: 5
PWM to DC - RC filter maths?
« on: February 09, 2012, 02:31:16 am »
Hi!


I'm using one of TI's DSC (TMS320F28069) to control a little tracked robot I'm making. I want to use the DSC because I know it well, I wrote most of the libs and it's kinda powerful (for this use at least).


I chose the sabertooth 2x5 motor controller which has many way to be used. I want to control it with a PWM output from my DSC.

Question is, I'm trying the manufacturer's values in NI Multisim 11 to simulate the result of their RC filter and it doesn't seem to work so well. I attached a draft of my output circuit.

Since I'm not so good, I'd like a little help to understand this kind of circuit. My knowledge of analog is restricted and I don't want to mess up. Plus, understanding better what I'm doing is always good :P

All values are on the schematics, and they are the one suggested.

thanks for your help!


Alex
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #1 on: February 09, 2012, 02:54:37 am »
Your circuit will not work well as the capacitor has a 10K pull down resistance and a 20K pull up resistance. To convert PWM into an accurate DC voltage, you a single resistance.

If the TSC has cmos outputs that allows the outputs to go from rail-to-rail, you could have a 100K resistor into a capacitor followed by an amplifier.

Otherwise you can use a 74hc4053 multiplexer gate as a 3v3 logic to 0V/5V switch followed by a 10K resistor and a capacitor.

Richard
 

Offline alxpowaTopic starter

  • Newbie
  • Posts: 5
Re: PWM to DC - RC filter maths?
« Reply #2 on: February 09, 2012, 03:56:17 am »
I am not sure I understand what you said? Should I remove the 1k pull down resistor at the gate of the mosfet or the pull at the drain?

Yes the DSC has CMOS output (see attachment). I don't have an OP on me now, so I can't just make a RC circuit at the outputs after my transistor? I thought it could be this easy :P

 

Online vk6zgo

  • Super Contributor
  • ***
  • Posts: 7705
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #3 on: February 09, 2012, 03:57:08 am »
The RC time constant of your network is too short.
The value of t=RC needs to be  5x  (or greater  than) the period of the waveform you are feeding it with.
Try increasing the value of C.
As you are modelling it,you can play around with various values & configurations.

PS:Keep the two 10k resistors,& just play with the C.
     Yes,it is easy,people do it every day!
« Last Edit: February 09, 2012, 04:00:35 am by vk6zgo »
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #4 on: February 09, 2012, 05:28:43 am »
I am not sure I understand what you said? Should I remove the 1k pull down resistor at the gate of the mosfet or the pull at the drain?

Yes the DSC has CMOS output (see attachment). I don't have an OP on me now, so I can't just make a RC circuit at the outputs after my transistor? I thought it could be this easy :P

You cannot use a single FET and a resistor to shift the level to 5V. The problem is the FET has near 0 ohms when it is pulling down. The 10K resistor has 10K Ohms when it is pulling up. You need an active pullup like another FET. Just like the DSC output stage.

If you use your circuit, here is what will happen:

0% duty PWM cycle:- 0V out.  That sounds good.
100% PWM duty cycle:- 5V out. Sounds good too.
50% PWM duty Cycle:- 1.66666V out>  Wanted 2.5V, so a big FAIL.

The 74hc4053 is a fairly common IC that can be used to shift levels.  The multiplexer inputs are connected to +5V and 0V, and the multiplexer is switched by the DSC output.  The multiplexer output will be either 5V or 0V.

And vk6zgo is right about the time constant. The longer the time constant, the less ripple will be in the output voltage, but the slower it will change when you change the PWM duty cycle.  So you need to find the best compromise.

Richard.
 

Offline alxpowaTopic starter

  • Newbie
  • Posts: 5
Re: PWM to DC - RC filter maths?
« Reply #5 on: February 09, 2012, 05:38:28 am »
Thanks you two!

That's a lot clearer! I'll try some things.

But if I used a typical bipolar transistor instead of the FET, I wouldn't have that problem right? It's just a little more work to find the values of Rb and Rc.
 

Offline amspire

  • Super Contributor
  • ***
  • Posts: 3802
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #6 on: February 09, 2012, 05:50:46 am »
But if I used a typical bipolar transistor instead of the FET, I wouldn't have that problem right? It's just a little more work to find the values of Rb and Rc.
You will have the same problem with a transistor, but worse as a FET does this kind of task better then a transistor. If you do not have a two FETs with one switching to 0V and one switching to 5V, you will have a non-linear output. The DSC output has two fets. The 74hc4053 has two FET-based switches.
 
Your circuit only has one switching device, so it will not work. A pull up resistor cannot replace a second FET.
« Last Edit: February 09, 2012, 06:05:50 am by amspire »
 

Online vk6zgo

  • Super Contributor
  • ***
  • Posts: 7705
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #7 on: February 09, 2012, 08:27:55 am »
Most such circuits I have seen never use the two extremes ,& operate around a "sweet spot" in mid-range.
They usually have a feedback circuit to tell the controller exactly what state the resultant function has reached.
These were RF drive control systems for radio transmitters,or similar devices, not robots,which may need the extreme range.
 
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19975
  • Country: gb
  • 0999
Re: PWM to DC - RC filter maths?
« Reply #8 on: February 09, 2012, 12:08:07 pm »
If can be done with a single transistor as long as the pull-up resistor is insignificant compared to the low pass filter's impedance.

What impedance is the low pass filter driving?

If it's high (<10M) it should be easy.

Make R4 as low as you possibly can without drawing too much current or making the MOSFET's on resistance significant, in this case 1k will probably so and make R5 as high as possible without making the load impedance significant: 100k will do as long as the load is 10M of more. Now set the capacitor to a suitable value which depends on how much ripple is acceptable, I'd go for 1uF for a ripple of 6.2mV.

If you need better performance then I'd recommend an op-amp active filter which will give a higher input and lower output impedance and a sharper cut-off frequency with less ripple. If you don't have a negative voltage available you'll need a single supply op-amp and if you don't have a higher positive voltage than 5V you'll need a rail-to-rail op-amp.
 

Offline alxpowaTopic starter

  • Newbie
  • Posts: 5
Re: PWM to DC - RC filter maths?
« Reply #9 on: February 09, 2012, 09:56:15 pm »
So I understand:

R4 must be the lowest without making the Rds ON resistance of the Mosfet significant. (Significant would mean more than 1% or so)
R5 must be the highest without making the load impendance significant.
C4 must be adjusted for the fastest transition with the least ripple.

I found out that the output signal fed's impendance must be max 10k ohms for better operation. My Rds On is max 5 ohms (1.2 typical) so I'll try using:

R4: Rds ON *100 = 5 * 100 = 500 ohms (approx)
R5: manufacturer said it should be max 10k, so I'll use that
C4: I'd try 0,1uF for a time constant of 1ms which would correspond to my PWM frequency of 1kHz

I should receive my parts soon from digikey. If it doesnt work well enough, I'll go directly with a DAC. I just didn't want so much to mess with I2C/SPI.

EDIT: well, just read that the RC constant should be around 100x my PWM period... So I'll need a larger capacitor, but won't the DC voltage be slow to change?

« Last Edit: February 09, 2012, 09:59:35 pm by alxpowa »
 

Offline electrode

  • Regular Contributor
  • *
  • Posts: 141
  • Country: au
Re: PWM to DC - RC filter maths?
« Reply #10 on: February 09, 2012, 10:01:02 pm »
If you go the op-amp route, this may be of some assistance:
http://ww1.microchip.com/downloads/en/appnotes/00538c.pdf
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19975
  • Country: gb
  • 0999
Re: PWM to DC - RC filter maths?
« Reply #11 on: February 12, 2012, 10:43:33 pm »
So I understand:

R4 must be the lowest without making the Rds ON resistance of the Mosfet significant. (Significant would mean more than 1% or so)
R5 must be the highest without making the load impendance significant.
C4 must be adjusted for the fastest transition with the least ripple.
Correct.

Quote
I found out that the output signal fed's impendance must be max 10k ohms for better operation. My Rds On is max 5 ohms (1.2 typical) so I'll try using:

R4: Rds ON *100 = 5 * 100 = 500 ohms (approx)
That'll be fine.
Quote
R5: manufacturer said it should be max 10k, so I'll use that
That won't work very well, the load impedance is too low whgich will load it too much. You'll need to use a higher value for R5 and a buffer.
Quote
C4: I'd try 0,1uF for a time constant of 1ms which would correspond to my PWM frequency of 1kHz
That will give far too much ripple, try building or even simulating it.
 

Offline alxpowaTopic starter

  • Newbie
  • Posts: 5
Re: PWM to DC - RC filter maths?
« Reply #12 on: February 13, 2012, 11:19:54 pm »
Quote
That will give far too much ripple, try building or even simulating it.

Yeah, I finally was able to simulate it correctly in Multisim to see constant result, didn't pick the right tool.
I used R4 = 500 ohms and R5 = 100k ohms with a 1uF Cap and it worked pretty well. Actually, I wouldn't even need the buffer if it wasnt the 10k impendace needed by the input. The only thing is that I lose almost 1,5V when it saturates (0,75 to 4,25 instead of 0-5), but it's probably because it's a cheap OP AMP.

I used an op-amp with direct feedback (used LM741, first that came to mind). Later I noticed I mindlessly  tied it's V- to my GND and it works even though it's supposed to be a negative voltage... Is there a mistake in the simulation? (printscreen included).

But if it really works this way, I'll be very happy since it's pretty easy. And I learned that each parameter of the filter (frequency, RC values, etc.) are very sensible. If I put my frequency at 10k it doesnt work anymore.
« Last Edit: February 13, 2012, 11:50:51 pm by alxpowa »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf