Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:56 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Taming the ACS712

Author Message
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 06:59pm 21 Apr 2017
Copy link to clipboard 
Print this post

Over the last few months, I have been playing with a monitor for a small solar charged 12V supply.
It started out OK but then I got too involved with trying to get accurate readings from sensors that were never designed for precision.

My efforts might help others who use the ACS712 current sensors.

The ACS712 is a 5V device and with zero amps, it's output is at half VCC or 2.5V
I decided on 30A modules and wired the primary circuits so that increasing amps gives a reducing voltage output. This means that I can handle +30 amps and -11 amps without going off scale.
There should never be -ve amps on the solar side but when the AC charger is running, it will be back feeding into the battery at a maximum of 12 amps minus the load of at least 1.1 amps. That's close but not too close. The charge would only put out 12 amps while the battery is very flat and that shouldn't happen.
I wired the charger directly to the fuse panel so that the battery can be fully disconnected while having the load maintained.



I started with the two ASC712 modules for solar and load.
The readings were good for a few days then the zero amps started to wander. The output of the modules is temperature sensitive so I added a DS18B20 and did the calibration maths.
It worked, sort of, but still not happy.
The other cause of reading errors could have been fluctuation in the 5v supply to the modules or the 3.3V supply to the micromite.
A pair of 10k resistors across the 5V supply and used as a reference would eliminate both sources of error but I decided to use a third ASC712 as the zero current reference.
That worked beautifully and over a few weeks and a range of temperatures, the solar zero current was consistent as well as the base load current of the load.
Happy days! But since I had the ACS712 doing nothing, I wired it into the AC charger output.
Now the third module is used as the zero reference whenever the charger is off and the last zero is used for the time that the charger is running. The maximum run time for the charger has been set to 2 hours so for that period of time, the current readings will be off slightly but after a few weeks of monitoring, I am happy.

The code is reasonably basic. There is no LCD to admire, just a serial link to my network.
A program on my PC will eventually fetch readings periodically during the day and occasionally adjust the micromite's clock.
ON the micromite, I have 2 arrays, one for today and the other for yesterday. The day is divided into 96 15 minute intervals. Provided the PC connects every 48 hours, no data is lost. At the start of a new day, the daily stats are saved into a weekly array.

The solar regulator (a cheap ebay one) uses a slow PWM with a frequency of 10 to 25 Hz. This slow switching keeps the strain of the switching transistors but makes taking a reading awkward.
I ended up taking 100 readings over 600mS and averaging them. As well as giving a stable reading, it allowed me to record the maximum reading of the 100 samples and use that as the available solar output for the reading.

Readings are taken every 10 seconds and placed into their time-slot of the array. It is done in a way that will always have the average for that time-slot, no matter how many readings have been entered.
  Quote  SUB Doread
LOCAL n, k
BatTemp =
TEMPR(14)
readNow =
0
PVampsRaw =
0
LoadampsRaw =
0
BatVoltsRaw =
0
RefZeroRaw =
0
FOR n = 1 TO readAv
solar(n) =
PIN(26)
PVampsRaw = solar(n) + PVampsRaw
LoadampsRaw =
PIN(25) + LoadampsRaw
BatVoltsRaw =
PIN(24) + BatVoltsRaw
RefZeroRaw =
PIN(23) + RefZeroRaw
IF PVmax > solar(n) OR n = 1 THEN PVmax = solar(n)
PAUSE 5
NEXT n
RefZeroRaw = RefZeroRaw / readAv
PVampsRaw = PVampsRaw / readAv
LoadampsRaw = LoadampsRaw / readAv
BatVoltsRaw = BatVoltsRaw /readAv
IF RefZero = 0 THEN RefZero = RefZeroRaw ' this is the first reading
PVamps = (RefZero + PVZero - PVampsRaw)*1000/66
PVmaxA = (RefZero + PVZero - PVmax)*
1000/66
Loadamps = (LoadampsRaw - RefZero - LoadZero)*
1000/66
Mainsamps = (RefZero - RefZeroRaw)*
1000/66
BatVolts = BatVoltsRaw * BatVscale
IF (PVamps + LoadAmps) > 0 THEN ' charging
BatCharge = BatCharge + (PVamps + LoadAmps)*BatEff/360
ELSE
BatCharge = BatCharge + (PVamps + LoadAmps)/
360
ENDIF
IF BatCharge > 105 THEN BatCharge = 105

thisTime$=
TIME$
ThisTS =
INT(VAL(LEFT$(thisTime$,2))*4+VAL(MID$(thisTime$,4,2))/15)
IF thisTS <> oldTS THEN
' new time slot
IF thisTS = 0 THEN ' new day
FOR n = 1 TO 7
FOR k = 1 TO 6
daily(n,k) = daily(n+
1,k)
NEXT k
NEXT n
daily(
8,1) = records(oldTS,1)/4
daily(
8,2)= records(oldTS,2)/4
daily(
8,3)= records(oldTS,3)/4
daily(
8,4) = records(oldTS,4)
daily(
8,5) = records(oldTS,4)
daily(
8,6) = 0
ELSE
daily(
8,1) = daily(8,1) + records(oldTS,1)/4
daily(
8,2) = daily(8,2) + records(oldTS,2)/4
daily(
8,3) = daily(8,3) + records(oldTS,3)/4
IF daily(8,4) > records(oldTS,4) THEN daily(8,4) = records(oldTS,4)
IF daily(8,5) < records(oldTS,4) THEN daily(8,5) = records(oldTS,4)
IF daily(8,6) < records(oldTS,6) THEN daily(8,6) = records(oldTS,6)
ENDIF
oldTS = thisTS
TScount =
1
yesterday(thisTS,
1)=records(thisTS,1)
yesterday(thisTS,
2)=records(thisTS,2)
yesterday(thisTS,
3)=records(thisTS,3)
yesterday(thisTS,
4)=records(thisTS,4)
yesterday(thisTS,
5)=records(thisTS,5)
yesterday(thisTS,
6)=records(thisTS,6)
yesterday(thisTS,
7)=records(thisTS,7)
'
records(thisTS,1)=PVamps
records(thisTS,
2)=Loadamps
records(thisTS,
3)=Mainsamps
records(thisTS,
4)=BatVolts
records(thisTS,
5)=BatCharge
records(thisTS,
6)=PVmaxA
records(thisTS,
7)=BatTemp
ELSE
records(thisTS,
1)=(records(thisTS,1)*TScount +PVamps)/(TScount+1)
records(thisTS,
2)=(records(thisTS,2)*TScount +Loadamps)/(TScount+1)
records(thisTS,
3)=(records(thisTS,3)*TScount +Mainsamps)/(TScount+1)
records(thisTS,
4)=(records(thisTS,4)*TScount +BatVolts)/(TScount+1)
records(thisTS,
5)=(records(thisTS,5)*TScount +BatCharge)/(TScount+1)
records(thisTS,
6)=(records(thisTS,6)*TScount +PVmaxA)/(TScount+1)
records(thisTS,
7)=(records(thisTS,7)*TScount +BatTemp)/(TScount+1)
TScount = TScount +
1
ENDIF
readTime$=
TIME$
IF Charger = -1 THEN ' not charging from mains
IF BatVolts < 12 THEN
sendit(
1)
Charger =
TIMER
ENDIF
IF Mainsamps > 1 THEN ' charger didn't turn off
sendit(0)
ELSE ' it is safe to use the Mainsamps reading as zero.
RefZero = RefZeroRaw
ENDIF
ELSE ' we are charging from the mains
IF (TIMER - Charger) > ChargeTime THEN
' turn charge off after preset time
sendit(0)
Charger = -
1
ENDIF
IF Mainsamps < 0.5 THEN ' we are not charging
sendit(1)
ENDIF
ENDIF
END SUB


After the readings are taken and stored, the logic for controlling the AC charger is run.
The charger is controlled by RF and an Arlec switch which is not 100% reliable so I needed to check the current and if I think that there should be some charging current but there is none, resend the ON command. This test happens every 10 seconds so even if there has been an AC fail, we are not likely to spend too much time trying to turn the charger on.

Likewise when the 2 hours are up. If there is still current flowing, send an OFF command again.

So far, I have been charting the output in Excel



On the first day, the dip in the solar output is caused by the shadow from a tower. You can see the green trace of the maximum solar in the second hump of day one. The regulator was starting to limit the current as the voltage rose to 14.3V
At about 4pm the solar panel is shaded by trees. About then the transmitter was used and the load increased for a while. It normally sits on 1.1A when on standby.
At 7am on day 2, the battery voltage dipped below 12V so the AC charger (Brown trace) came on for 2 hours. Just as well because it was cloudy that day so not much solar contribution. Still enough to do a bit of regulating.
The cyan trace is the estimated remaining capacity, not something to take too seriously.



This graph shows the PWM of the solar regulator for two different conditions and the 100 readings used to record it. the full time shown is about 600mS

The full program
2017-04-22_045614_RTVmonitor.zip
The communications side is designed for a multidrop setup. All commands must start with $9 (this module) or $0 (broadcast to all modules).

JimEdited by TassyJim 2017-04-23
VK7JH
MMedit
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 07:39pm 21 Apr 2017
Copy link to clipboard 
Print this post

Very nice job Jim - looks like you've nailed it. Plenty for us all to ponder here.

Greg
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 07:46pm 21 Apr 2017
Copy link to clipboard 
Print this post

  paceman said   looks like you've nailed it.
Greg

No.
The hard part is convincing the Boss that we need a second solar panel on the eastern side of the garage roof. Where she can see it from the house.

VK7JH
MMedit
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:19am 22 Apr 2017
Copy link to clipboard 
Print this post

Hmmmm... tricky! She seemed like a very nice lady when we all met up so I think you'll have to go gently - more chocolate perhaps?
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025