Monitor current: Charge & Discharge with only a PICAXE

mrburnette

Senior Member
No instrumentation amplifier... no OpAmp... no virtual ground. The caveat is that the PICAXE must be powered by battery or on a DC-DC isolated regulator separate from the power generator/battery source that drives the primary load.

The general approach to measuring +/- current (charge/discharge) is to put the current shunt in front of a dual-rail OpAmp or instrumentation amp. Then the +/- voltage swing across the shunt can be offset to a positive voltage with reference to ground (the AD ground.) But with a little thought you can do this fairly easily with just 3 resistors and the shunt.

PICAXE 08M2+ code for mVolt output
Code:
; by M. Ray Burnette 20120828
;
#Picaxe 08M2				; PICAXE 08M2+ used in prototype
#Terminal 4800
;#no_data

Symbol ADval = w0				; b1:b0
Symbol VMINUS_0V_VPLUS_FVR = %011	; Page 28, Man#2
Symbol Channel = 4			; 08M2 Physical PIN#3, Port C.4

LET ADCsetup = %0000000000010000	; Channel 4 == C.4 / Page33, Man#2

Do
  fvrsetup FVR1024	; set FVR as 1.024V reference = 1mV / step
  ADCconfig VMINUS_0V_VPLUS_FVR
  
  Pause 1000
  ReadAdc10 Channel, ADval	; AD value
  sertxd("=",#ADval, , " mV",CR, LF)
Loop


For home made shunts, a reference: AWG

The SPICE code for http://www.falstad.com/circuit/ so that you can play around with different values of resistors for any specified (home made) shunt. Use standard resistor values: standard resistors

Code:
$ 1 5.0E-6 58.6985430941709 82 5.0 50
r 400 240 496 240 0 1.0E8
c 400 240 400 320 0 1.0E-10 0.34928718214492827
g 400 320 400 336 0
w 496 240 544 240 0
w 304 240 400 240 0
r 304 240 304 144 0 10000.0
r 304 240 304 320 0 10000.0
g 304 320 304 336 0
R 304 144 304 112 0 0 40.0 5.0 0.0 0.0 0.5
c 496 240 496 320 0 1.0E-12 0.3492871821449275
g 496 320 496 336 0
x 422 211 561 217 0 24 Arduino ADC
r 176 240 304 240 0 1000.0
w 176 240 144 240 0
r 144 240 144 288 0 0.16185
i 144 288 144 352 0 -0.5
w 144 240 112 240 0
w 112 240 112 352 0
w 112 352 144 352 0
w 144 288 224 288 0
w 224 288 224 320 0
g 224 320 224 336 0
x 323 118 441 122 0 15 DC-DC generated
o 3 64 0 35 0.625 9.765625E-5 0 -1
My shunt was made from 5 feet of #25AWG and resulted in the
Rs = 0.16185 Ohms. My voltage divider was made from two 10K resistors and the feed resistor to the shunt was valued at 1K. The SPICE above will produce the tested circuit.

The table below shows +/- 1A values and a 100mA step from +500mA to -500mA. Note the linearity is pretty good, averaging 11 steps per 100mA. Just stick this into a SELECT CASE and provide whatever kind of readout or LED illumination you need. Using my example and shunt, the current resolution is 11mA... probably good 'nuff for lots of needs.


+/- mA ............PICAXE_AD ...........mV_Delta
+1000 .................. 528
+900
+800
+700
+600
+500 .................. 471 .................. 11
+400 .................. 460 .................. 11
+300 .................. 449 .................. 11
+200 .................. 438 .................. 12
+100 .................. 426 .................. 11
00 .................... 415 .................. 0
-100 .................. 403 .................. 12
-200 .................. 392 .................. 11
-300 .................. 381 .................. 11
-400 .................. 370 .................. 11
-500 .................. 359 .................. 11
-600
-700
-800
-900
-1000 .................. 302
Please note that I generalized the PICAXE AD input as approximately 100M Ohm...the capacitors really do not come into play in this example. As for the primary load circuit, the battery and generator are not shown but a current source is defined where values can be positive or negative to represent the generator/alternator and battery and device current load.

For a larger +/- 50A project:

View attachment 12141
View attachment 12142
 
Top