Author Topic: Smoothing PWM of a load  (Read 11968 times)

0 Members and 1 Guest are viewing this topic.

Offline MihemineTopic starter

  • Newbie
  • Posts: 3
  • Country: 00
Smoothing PWM of a load
« on: August 20, 2016, 07:44:34 pm »
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 battery
Also 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 )
« Last Edit: August 20, 2016, 09:09:22 pm by Mihemine »
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
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?

Are you serious? You are actually trying to be pedantic. This is my problem about this forum.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
Syncing the reads with the pwm is going to be nearly impossible, because it's jitter prone and the pwm runs off a different timer than the on board timer ( different timers are used because I use interrupts )

This 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
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?

Are you serious? You are actually trying to be pedantic. This is my problem about this forum.

Yes, 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
The idea is that the cap has "no" internal resistance compared to the 30+ mohms of the battery

So this can't work at all ? There is no way of using the cap to smooth out ( to an extent ) the square wave ?

I'll look into syncing the pwm and clock timers

( the idea of the circuit is to drain the batteries, so as long as I can account for all loads on the battery then it's not a problem )

If 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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
You should read this I think it applies in this situation.
https://www.eevblog.com/forum/beginners/another-must-read-for-beginners/
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
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.

Yes, 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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #10 on: August 20, 2016, 08:11:46 pm »
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.

This creates an unwanted side effect of a hot mosfet and requires the use of a heatsink for it

I edited the photo above to better illustrate the problem ( not pictured is the internal resistance of the battery )

Just use more fets in parallel to spread the heat. How much current are you trying to draw?
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #11 on: August 20, 2016, 08:15:30 pm »
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.

Yes, 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.

Thats 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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #12 on: August 20, 2016, 08:20:49 pm »
Thats 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.

But 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.
 
The following users thanked this post: Kilrah

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #13 on: August 20, 2016, 08:23:28 pm »
Thats 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.

But 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.

Never knew that. Well mines are hard at work then.
 
The following users thanked this post: Mihemine

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #14 on: August 20, 2016, 08:23:44 pm »
You should read this I think it applies in this situation.
https://www.eevblog.com/forum/beginners/another-must-read-for-beginners/

I'm trying to explain ( to myself to be able to hopefully learn something ) why my circuit pulls more current with an identical pwm frequency when a capacitor is put in parallel with my battery
Hoping for an answer, I came here ( as I said I have no background in electronics ) if this post is useless then I can delete it ( this is probably as stated an X Y problem, I'm terrible at expressing myself so I might not have said everything I should )

In 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.
 
The following users thanked this post: Mihemine

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #15 on: August 20, 2016, 08:28:40 pm »
You should read this I think it applies in this situation.
https://www.eevblog.com/forum/beginners/another-must-read-for-beginners/

I'm trying to explain ( to myself to be able to hopefully learn something ) why my circuit pulls more current with an identical pwm frequency when a capacitor is put in parallel with my battery
Hoping for an answer, I came here ( as I said I have no background in electronics ) if this post is useless then I can delete it ( this is probably as stated an X Y problem, I'm terrible at expressing myself so I might not have said everything I should )

Try 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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #16 on: August 20, 2016, 08:30:43 pm »

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.


That's exactly the answer I was looking for. Thank you! ( I see I can't delete topics, so this one will have to stay :/ )

Don't delete topics. People can learn something from reading someone else's problem.
 
The following users thanked this post: Mihemine

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19854
  • Country: gb
  • 0999
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #17 on: August 20, 2016, 08:33:30 pm »
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.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 12291
  • Country: us
Re: Calculator for capacitors allowing more current to pass in a pwm circuit
« Reply #18 on: August 20, 2016, 08:49:58 pm »
If I still want to average out my adc readings, could I stick a cap in between the measure pin and the battery ( ADC(32k internal impedance)--cap--resistor to prevent reverse current--battery, where -- are wires )

The 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.
 

Offline Aodhan145

  • Frequent Contributor
  • **
  • Posts: 403
  • Country: 00
Re: Smoothing PWM of a load
« Reply #19 on: August 20, 2016, 09:11:28 pm »
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.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19854
  • Country: gb
  • 0999
Re: Smoothing PWM of a load
« Reply #20 on: August 20, 2016, 09:19:39 pm »
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.

 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Smoothing PWM of a load
« Reply #21 on: August 21, 2016, 09:30:44 am »
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.
 
The following users thanked this post: Mihemine

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19854
  • Country: gb
  • 0999
Re: Smoothing PWM of a load
« Reply #22 on: August 21, 2016, 08:49:34 pm »
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.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf