Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Average current for a square wave

Status
Not open for further replies.

Overclocked

Member
Its been a while since Ive used calculus, but I have realized I need to use it for this. I am measuring the current consumed by a bluetooth module (HC05) by using a small resistor that then goes to a O-Scope. The scope is measuring the voltage across the resistor, from there I can use Ohms law to get the current consumed by the module.

Ive broken it up into blocks (its a square wave). I figured if I measure the voltage of that certain block, and then divide by the resistance, I can get current consumed in that period. From there I (think) I would divide Current by time to get average current. Correct me if Im wrong on this.

My Data: For a period of 4mS The measuring resistor has 66mV across it. For 5mS the measuring resistor has 214mV across it. Total ON time of the signal is 9mS. Off time is 116mS. Period time is 0.125 seconds. My Resistor is 5 Ohms. The current consumed in those periods is 13.2mA and 42.8mA respectively. Am I correct in adding them both together and then dividing by total time? Or should I divide each current by its respective period and then add?

I get 12mA Average if I do the math out.
 
[(13.2mA*4ms) + (42.8mA*5ms)]/125ms = (52.8e-6As + 214e-6As)/125ms = 266.8e-6As/125e-3s = 2.1344e-3A = 2.1344mA

98.gif
 
Hi,

I get the same.

Also, defining a function to mimic the currents i get:
I1=66/5
I2=214/5
f1(t)=(t<4)
f2(t)=(t>4)
f3(t)=(t=4)
f4(t)=(t<9)
f5(t)=(t=9)
f(t)=f1(t)*I1+f2(t)*f4(t)*I2+f3(t)*(I1+I2)/2+f5(t)*I2/2
Aavg=Avg(f(u),u,0,125,250)
Aavg=2.1344

Although in real life the current levels are sequential, they can also be concurrent:
I1=66/5
I2=214/5
f1(t)=(t<4)
f2(t)=(t>0)
f3(t)=(t=4)
f4(t)=(t<5)
f5(t)=(t=5)
f(t)=f1(t)*I1+f2(t)*f4(t)*I2+f3(t)*(I1+I2)/2+f5(t)*I2/2
Aavg=Avg(f(u),u,0,125,250)
Aavg=2.1344

BTW Avg() finds the average of the function 'f'.
 
either way works out the same.
(4 * 13.2+ 5 * 42.80 )/9=29.6 mA average for 9ms when ON
for total cycle period of 125mS thus Duty cycle , D= 9/125 = 7.2%
Total average current = 29.6 *D = 2.13 mA
 
Awesome!

Probably a very simple question: Is the average current what gets drawn from the power source (be it a battery or other power source)?
 
Hi,

What really gets taken from the power source is energy. Energy is the current times the voltage over time. The RMS current is a good thing to know too.
For a battery, the ampere hours makes the most difference in the run time. For a changing load current it is more complicated, but if it is a set of rectangular waves like you have it's a lot simpler.
If you have 2 amps for 1 hour and then 1 amp for two hours, the total ampere hour load is 2*1+1*2=4 ampere hours. If you have 2 amps for 1 hour and 1 amp for two hours (again) but this time have in addition 2 hours with no current draw, then the ampere hour draw is still 2*1+1*2=4 because now we dont count the off time. This is important when something runs off of a battery. This is an approximation that is valid if the current levels are not too much different than the 20 hour discharge ampere hour rating of the battery.
 
the power on a square wave is a function of frequency and most of all the rise and fall time. There is where the power is greater while zero some power butat mid point is the greatest and the slower the rise and fall the greater the power.
 
Hi,

What really gets taken from the power source is energy. Energy is the current times the voltage over time. The RMS current is a good thing to know too.
For a battery, the ampere hours makes the most difference in the run time. For a changing load current it is more complicated, but if it is a set of rectangular waves like you have it's a lot simpler.
If you have 2 amps for 1 hour and then 1 amp for two hours, the total ampere hour load is 2*1+1*2=4 ampere hours. If you have 2 amps for 1 hour and 1 amp for two hours (again) but this time have in addition 2 hours with no current draw, then the ampere hour draw is still 2*1+1*2=4 because now we dont count the off time. This is important when something runs off of a battery. This is an approximation that is valid if the current levels are not too much different than the 20 hour discharge ampere hour rating of the battery.

I get what your saying. Its not the off time that matters, its the on time. So to reduce current consumption, I either have to reduce the amount of time its On and/or the amount that it consumes during that period, by reducing its output power. There are commands for these modules but their descriptions are quite lacking. I also tested them without sending anything, so the consumption will probably be different.

In their final application though (A data logger-I will be posting about it soon) they only transmit data once per minute. Its only logging temperature, so I could even get away with once every 5 minutes.

ADD: I took some more measurements. It seems that when I receive data (or send), current consumption goes up quite a bit (obvious!). I found that my scope actually has a averaging function, so I used that. 103mV for 5 seconds as an on time, then it goes back down to idle current and follows the above wave function in my original post. I sent it a "packet" consisting of 5555 (so, 4 Bytes?)

So doing out the math it consumes 20mA in that time frame. It will only be on once a minute or once per 5 minutes. If I use it once per minute, then that averages around 2mA (rounded). But realistically, do I really need to know temperature every minute?
 
Last edited:
Hi,

Depends what you are monitoring it for. For my fridge, i have it report every 10 minutes. Batteries last 2 years.
 
Just to monitor outside temp. Around here its been getting to be around 90-95F in the summer and -10F in the winters. It will have a solar panel recharging the battery. I will be using a LiFePO4 1500mAh battery because it can survive those extreme temperatures (Plus, I have them just sitting around-Might as well use them). It will also monitor battery voltage and solar voltage once per hour. Ive been thinking about adding more, like humidity, a gas sensor, and possibly a light sensor, but I know a solar panel can also double as a light sensor as well. Software is pretty much complete, and Im on the 2nd revision for the PCB.
 
Hi,

Just out of curiosity, is that range much outside the range you normally have seen in the past?

My power source is made of two AA cells in series, alkaline. They can last so long because i made the sensor high impedance (so it doesnt have to be turned on and off, but you can do that too) and the uController goes to sleep when not making a measurement. With the very low power controllers these days you can run for a long time on batteries, as long as the sensors and other loads dont have too much average current drain. You can shut them down too when not needed with a simple MOSFET circuit.

The monitor i bought from the store a long long time ago used up two AA cells every two to three months. I got tired of changing the dang batteries :)
 
In thepast few years, yes. We've had warm winters in the past where it hasnt gotten above 20 degree's (F). In the summer it was 100+ in those years. We seem to be in a mild summer period, but the winters have become brutally cold with large amounts of snow.

The sensor I'm using only consumes micro amp's, so its not of concern. My main worry is the transmitter, because its consumes so much. Wonder if I increase the bit rate if it will decrease the time its receiving or transmitting. The other issue is if I want to measure the battery voltage and solar voltage. If I am directly powering them from a battery, I will need a voltage divider and a stable voltage reference for the ADC. PICs have a internal voltage reference, but its not accurate enough. The voltage divider presents a problem since it will always draw current.

I've thought of using AAs, but I can't think of any other use for these LiFePO4 batteries, so that's the reason I'm using them. I have 1500mAh's and 3000mAh on hand (2 of each).
 
The voltage divider presents a problem since it will always draw current.
It doesn't have to. You could use an NMOSFET to switch it off when the micro is asleep.
 
In thepast few years, yes. We've had warm winters in the past where it hasnt gotten above 20 degree's (F). In the summer it was 100+ in those years. We seem to be in a mild summer period, but the winters have become brutally cold with large amounts of snow.

The sensor I'm using only consumes micro amp's, so its not of concern. My main worry is the transmitter, because its consumes so much. Wonder if I increase the bit rate if it will decrease the time its receiving or transmitting. The other issue is if I want to measure the battery voltage and solar voltage. If I am directly powering them from a battery, I will need a voltage divider and a stable voltage reference for the ADC. PICs have a internal voltage reference, but its not accurate enough. The voltage divider presents a problem since it will always draw current.

I've thought of using AAs, but I can't think of any other use for these LiFePO4 batteries, so that's the reason I'm using them. I have 1500mAh's and 3000mAh on hand (2 of each).

Hi again,

Yes you can increase the bit rate to decrease transmit time, as long as you dont loose reliability of the transmission.

As i said back in post #11, if you use a MOSFET to turn off what you dont need you can save a lot of power. This includes the external voltage reference, and if the divider is connected to the output of that then that turns off too.

Just to round things a little, if you transmit every 17 minutes with a 1 second transmit time you reduce the average transmit current to one one-thousandth of the instantaneous current. So if the transmit current is 100ma, the average over 17 minutes will be 100ua. 100ua draws down a 2000mAhr battery in about 20,000 hours (twenty thousand hours) which is about 833 days. If you double the transmission rate to every 8 minutes, this time will halve, but will still be more than 400 days which is over a year.
This assumes you shut down everything during sleep using a mosfet or other device. If you are using a voltage reference chances are you can even use a bipolar and that makes up a pretty simple and reliable circuit (maybe one or two resistors and one tiny transistor).
 
Last edited:
Hello again,

Please note that i made a couple typos in the previous post. It originally read that if you transmit every 17 seconds with a 1 second transmit time the average current falls to 1/1000 (one one-thousandth) of the transmit current, but really it should have read "if you transmit every 17 minutes with a 1 second transmit time", not every 17 seconds. Obviously 17 seconds 'off' time isnt long enough when the transmit time is 1 second, it has to be about 17 MINUTES with 16 minutes 39 seconds 'off' time and 1 second 'on' time (slightly less than 17 minutes total time). That's a long time to stay off, but for some measuring purposes that is ok.
The typos have been corrected.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top