Smoothing PWM of a load - Page 1
Forum section: electronics / projects

author: Mihemine
author_rank: Newbie
timestamp: August 20, 2016, 07:44:34 pm
content: Hello,Hoping to be clear, I'll try and elaborate as much as possible, so this might be long :I am searching to discharge a lithium battery. It is put across a load of 2.4 ohms. To control the current pulled via a micro controller to 1a I use a pwm signal, essentially averaging the current switching between 1.375 and 0 amps flowing ( at a nominal of 3,3v ) so a theoretical duty cycle of 72.7% at 3.3v would put a load of 1a on the source. Using PID I controll the duty cycle depending on actual voltage of the batt and the known resistance, this duty cycle is provided by a micro controlling a Nchannel fet ( placed after the load resistor ) as such :C2 smooths voltage to adc, R2 prevents the battery reverse powering the micro, C1 was supposed to smooth the voltage pulled from the battery ( see below why this doesn't work )This works in practice because all the leads are very short and thick, but now comes the problem : It would be better to filter the output for the battery and for the micro that reads the voltage of the battery ( otherwise it might read 3.465 and a micro second later 3.452, although this is fixed by filtering the line going to the ADC ).Now, adding a capacitance of 1000µF in between the battery and ground makes the amount of current go straight up. I understand why, when the mosfet is off the battery is charging the cap and when it's on a higher voltage is maintained so more current can pass in the same amount of time, this also explains the smaller delta V.But what equations would allow me to know and calculate the current flowing with the cap ? This is a very complex problem to solve myself ( I have no background in electronics whatsoever ), I get that load resistance, battery internal resistance, battery voltage and capacitance all play in, but what equations do I use ( I searched all day :p )This is more of a quest for personnal knowledge than actually using it in practice, because I really don't have to put the cap across the batteryAlso to be noted pwm frequency is at 500hz, and I'll bump it up to 31kHz later to be able to use a smaller cap once I get the maths because 1000µF is way to big, I'l hoping to use ~22µF-88µF.Thank you for all help !---->> Thanks to the people in the posts bellow, the answer is that the capacitor allows current to flow through itself ( this post has been edited a few times )

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 07:52:04 pm
content: When you say "put a capacitor in between the battery and the ground" I assume you mean to put the capacitor in parallel with the battery?Now the problem you have is that a capacitor by itself cannot filter anything. A capacitor can only act as a filter if it is combined with a resistor or an inductor. Inductors are big and heavy, and thus rarely used for power filtering. Resistors sap power and make the circuit inefficient, so they are rarely used either.In short, capacitors and PWM do not go together well, and you should not use the capacitor.Instead, when you want to measure the battery voltage, synchronize the voltage measurement with the PWM so you always measure the battery voltage at the same point in the cycle, and then apply digital filtering to the actual measurement to remove unwanted noise.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 07:57:41 pm
content: No, that resistor is not part of the filter.If you put a "perfect" capacitor in parallel with the battery then the capacitor voltage will always equal the battery voltage and the capacitor will do nothing.However, current will flow from the battery into and out of the capacitor, and this current will be additional to any current already in the circuit. This additional current will have to flow through the internal resistance of the battery and through the wires between the battery and the capacitor, and this will produce an unwanted power drain.Really, you don't want the capacitor.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 07:57:45 pm
content: Quote from: IanB on August 20, 2016, 07:52:04 pmAre you serious? You are actually trying to be pedantic. This is my problem about this forum.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:00:19 pm
content: Quote from: Mihemine on August 20, 2016, 07:54:27 pmThis problem is yours to solve. You can use the PWM timer as the master clock and derive the read time for the battery voltage from the same clock. It is merely a programming/design problem.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:02:35 pm
content: Quote from: Aodhan145 on August 20, 2016, 07:57:45 pmYes, I'm being pedantic because there is a whole other part of the circuit that is not shown controlling the PWM signal. This also could have a "ground", and now it matters which ground we are talking about.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:05:34 pm
content: Quote from: Mihemine on August 20, 2016, 08:01:15 pmIf you put a capacitor in parallel with a voltage source, the capacitor voltage will always equal the source voltage. The capacitor can do nothing except drain extra power from the system.To properly smooth out the voltage requires the use of a voltage converter topology, like a buck converter, and these circuits always use an inductor as an energy storage device. This is likely more complicated than you need.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:06:19 pm
content: What about putting a filter on the PWM to make a DAC, then using this with an opamp to put the nfet in its linear range to adjust the current flow and use a shunt for feedback.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:08:42 pm
content: You should read this I think it applies in this situation.https://www.eevblog.com/forum/beginners/another-must-read-for-beginners/

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:10:20 pm
content: Quote from: Aodhan145 on August 20, 2016, 08:06:19 pmYes, I imagine this could work, but don't you now need a special power FET that is rated for linear operation? Also you need heat sinking to handle the power dissipation.Most battery conditioning and measuring systems that I have seen just PWM the battery current and integrate the pulses.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:11:46 pm
content: Quote from: Mihemine on August 20, 2016, 08:08:25 pmJust use more fets in parallel to spread the heat. How much current are you trying to draw?

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:15:30 pm
content: Quote from: IanB on August 20, 2016, 08:10:20 pmThats why I like to keep broken motherboards around, they are full of logic level mosfets capable of draining ~60A. They are normally high power as they are part of the buck circuitry to the CPU which needs ~100W.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:20:49 pm
content: Quote from: Aodhan145 on August 20, 2016, 08:15:30 pmBut that is not what I am saying. A MOSFET that can handle 60 A in a switching configuration cannot necessarily handle anything like 60 A if forced into the linear range for analog current regulation. Linear control requires a special design to avoid hot spots on the die and such high power MOSFETS are rare and expensive.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:23:28 pm
content: Quote from: IanB on August 20, 2016, 08:20:49 pmNever knew that. Well mines are hard at work then.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:23:44 pm
content: Quote from: Mihemine on August 20, 2016, 08:14:21 pmIn this instance, you could start out by explaining the purpose of your circuit (to measure the capacity of the battery by draining it in a controlled manner). Then explain how you are going about this.In this particular case you definitely don't want to "interfere" with the battery by putting a capacitor across it, as you will likely upset your measurements.As to why the circuit pulls more current, the combined battery and capacitor will have a lower AC source impedance than the battery alone, therefore when you apply a particular PWM load to it (which has a heavy AC component), you will effectively be able to draw more current from the battery.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:28:40 pm
content: Quote from: Mihemine on August 20, 2016, 08:14:21 pmTry measure the current from the battery before the cap and then separately between the resistor and the mosfet. You should see a difference as some current is flowing through the cap.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 08:30:43 pm
content: Quote from: Mihemine on August 20, 2016, 08:28:05 pmDon't delete topics. People can learn something from reading someone else's problem.

author: Zero999
author_rank: Super Contributor
timestamp: August 20, 2016, 08:33:30 pm
content: Why are you using PWM at all?If the idea is to discharge a battery, then a constant current sink is what you need, not PWM.

author: IanB
author_rank: Super Contributor
timestamp: August 20, 2016, 08:49:58 pm
content: Quote from: Mihemine on August 20, 2016, 08:38:21 pmThe capacitor should not be in series like that, it should be across the ADC terminals. You would be looking to create a low pass RC filter between the measurement source (battery) and the ADC.

author: Aodhan145
author_rank: Frequent Contributor
timestamp: August 20, 2016, 09:11:28 pm
content: Put a shunt in with an instrumentation amplifier to get current feedback so then you can adjust the PWM till it draws the amount of current you want.

author: Zero999
author_rank: Super Contributor
timestamp: August 20, 2016, 09:19:39 pm
content: Use this circuit.If the MCU runs off 3V, rather than 5V, then use 33k for R1 R2.If the op-amp needs to run off the battery or 3V, then use the MCP601 or MCP602.

author: Kalvin
author_rank: Super Contributor
timestamp: August 21, 2016, 09:30:44 am
content: For the controllable discharge current, a simple solution would be to use four fixed resistors, for example. Each resistor will be enabled/disabled by a MOSFET. Your microcontroller would need 4 GPIO-lines to control the MOSFETS instead of 1 GPIO line you have now. When the resistors are binary-weighted, you can get 16 different current levels with 4 resistors. No PWM required and no problems with the voltage measurement. You just need to calculate the worst-case power dissipation for each of the resistors in order to figure out which resistors require highest power rating.

author: Zero999
author_rank: Super Contributor
timestamp: August 21, 2016, 08:49:34 pm
content: The power needs to be dissipated somewhere.How about dissipating some of it in the resistor and some of it in the MOSFET?The PWM could be filtered before the MOSFET and the voltage across the load resistor monitored by the MCU, which can adjust the PWM to achieve the desired current draw.