PWM to DC - RC filter maths? - Page 1
Forum section: electronics / beginners

author: alxpowa
author_rank: Newbie
timestamp: February 09, 2012, 02:31:16 am
content: 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 goodAll values are on the schematics, and they are the one suggested.thanks for your help!Alex

author: amspire
author_rank: Super Contributor
timestamp: February 09, 2012, 02:54:37 am
content: 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

author: alxpowa
author_rank: Newbie
timestamp: February 09, 2012, 03:56:17 am
content: 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

author: vk6zgo
author_rank: Super Contributor
timestamp: February 09, 2012, 03:57:08 am
content: 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!

author: amspire
author_rank: Super Contributor
timestamp: February 09, 2012, 05:28:43 am
content: Quote from: alxpowa on February 09, 2012, 03:56:17 amYou 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.

author: alxpowa
author_rank: Newbie
timestamp: February 09, 2012, 05:38:28 am
content: 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.

author: amspire
author_rank: Super Contributor
timestamp: February 09, 2012, 05:50:46 am
content: Quote from: alxpowa on February 09, 2012, 05:38:28 amYou 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.

author: vk6zgo
author_rank: Super Contributor
timestamp: February 09, 2012, 08:27:55 am
content: 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.

author: Zero999
author_rank: Super Contributor
timestamp: February 09, 2012, 12:08:07 pm
content: 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.

author: alxpowa
author_rank: Newbie
timestamp: February 09, 2012, 09:56:15 pm
content: 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 thatC4: I'd try 0,1uF for a time constant of 1ms which would correspond to my PWM frequency of 1kHzI 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?

author: electrode
author_rank: Regular Contributor
timestamp: February 09, 2012, 10:01:02 pm
content: If you go the op-amp route, this may be of some assistance:http://ww1.microchip.com/downloads/en/appnotes/00538c.pdf

author: Zero999
author_rank: Super Contributor
timestamp: February 12, 2012, 10:43:33 pm
content: Quote from: alxpowa on February 09, 2012, 09:56:15 pmCorrect.QuoteThat'll be fine.QuoteThat 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.QuoteThat will give far too much ripple, try building or even simulating it.

author: alxpowa
author_rank: Newbie
timestamp: February 13, 2012, 11:19:54 pm
content: QuoteYeah, 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.