rem Solar Meter.bas for the device with the modified alarm clock and optionally rem for the Secure Digital Writer with some provisions for its LCD display rem Turn on the SD chip and wait for the red light to go out before booting this. rem Stop this program or disconnect before turning off the SD chip to ensure that rem the file is closed. rem Recording is once per clock movement (which may be more than 1 "second") rem This program measures volts and current. rem Viewed from the front (clock) end, connect the load -ve to the center terminal. rem Connect the negative (current) input to the left terminal, rem and the positive (voltage) to the right. rem The marked end of the programming/output adapter goes to the rear. rem The red wire of the clock connector goes to the left. rem DC use (solar cell panel output or small rechargable battery capacity): rem The clock advances 1 minute per milliampere-hour in low range, (5.1-ohm shunt) rem with jumpers on right-hand front header and the left rear header (only) rem Low range Scale Factor is Milliamperes = 0.1243 * reading - 0.3 rem Low range increment/count = 483 rem The clock advances 1 minute per 5 milliampere-hours in high range (1& 5.1-ohm shunts) rem with jumper on left-hand front header only rem High range Scale Factor is Milliamperes = 0.7352 * reading + 0.7 rem High range increment/count = 408 rem Increase voltage for shunt drop: millivolts = 0.6137 * reading + 2 rem Voltage Scale Factor is Volts = 0.02 * reading + 0.014 rem When used with the AC current sensor, both internal shunts rem (left-hand headers) are un-jumpered since the AC sensor has its own shunt, rem but the right rear header is jumpered. rem The AC sensor has a range connector for the right front jumper. rem The clock advances 1 minute per 1 watt-hour in the 1-amp low range @ 115 V rem The clock advances 1 minute per 10 watt-hours in the 10-amp high range @ 115 V rem Low range Scale Factor is amperes = (reading - 3)/846, increment/count = 441 rem High range Scale Factor is amperes = (reading - 5)/84 increment/count = 438 rem This code uses 255 bytes! #picaxe 14M #COM 1 'Input ports symbol Flux = 0 'Port for negative current measurement symbol Onesec = INPUT1 'Port for 18 ms pos pulse every sec from clock symbol Volts = 4 'Port for positive voltage measurement 'Output ports symbol Coil1 = 1 'Port for yellow wire coil end in 4-post header symbol Coil2 = 2 'Port for brown wire coil end in 4-post header symbol LED = 4 'Port for green LED, lights when high 'Constants symbol StartDelay = 1500 'Initial delay to help re-program symbol PulseLen = 27 'Millisconds for the coil pulses, was 27 symbol HighCount = 1020 'More is too much current or voltage symbol MinCurrent = 10 'Currents less are not accumulated symbol Interpulse = 200 'Milliseconds between coil pulses 'Variables symbol RecordFlag = bit0 'Used to ensure enough time for opening the file. symbol CoilPolarity = bit1 'Alternate coil pulses must be of opposite polarity symbol VoltFlag = bit2 'Flag to TransmitValue send voltage, not current symbol Iter = b1 'General byte variable symbol Div = b2 'Used only in serial output symbol ByteCount = b3 'Used only in serial output symbol CurrentInc = b4 'Either Count60MA or Count300MA symbol Divider = w3 'Used only in serial output symbol Watt_Sec = w4 'Watt-second count symbol DECdata = w5 'Multi-use scratchpad variable symbol CurrentCount = w6 'Accumulated current-time count rem File Number, increments each boot EEPROM 0,(11) init: HIGH Coil1 'Drive off HIGH Coil2 'Drive off HIGH LED 'Pulse LED to show power on LET Iter = Pin2 + 2 * pin3 'To get the right current increment LOOKUP Iter,(183,108,141,138),CurrentInc 'Add 300 to use a byte for CurrentIncs LET CurrentCount = 0 READ 0,ByteCount 'Increment the File number each re-boot LET ByteCount = ByteCount + 1 WRITE 0,ByteCount pause StartDelay setfreq m8 sertxd (#CurrentInc) LOW LED stop main: 'Executed once per second. READADC10 Flux,DecData IF DecData < MinCurrent THEN phase 'Minor values due to offset to be not counted LET CurrentCount = CurrentCount + DecData IF RecordFlag=0 THEN NoRecord 'Skip unless the file is open LET VoltFlag = 0 'Current measurement first GOSUB TransmitValue READADC10 Volts,DecData 'Read voltage input LET VoltFlag = 1 'Voltage and count recording, close file LET DecData = 2*DecData + 1 'Voltage in 10s of mv GOSUB TransmitValue LET RecordFlag = 0 NoRecord: DO WHILE CurrentCount > 450 'Pulse coil for each charge increment IF RecordFlag = 0 THEN 'To ensure opening the file only once READ 0,ByteCount 'use as scratch pad variable SETFREQ m8 'Open the file, then overwrite it on the display rem SERTXD ("O 1 A /W",#ByteCount,".CSV",13,$FE,$80,13) SETFREQ m4 ENDIF GOSUB PulseCoil 'Wont be more than three per second LET CurrentCount = CurrentCount - CurrentInc - 300 LET Watt_Sec = Watt_Sec + 1 LET RecordFlag = 1 LOOP phase: 'Wait for the one sec pulse from the clock PAUSE 9 'This delay is critical to avoid main executing twice. IF Onesec = 0 THEN phase GOTO main end PulseCoil: 'Each pulse moves the second hand 1 "second" HIGH LED IF CoilPolarity = 0 THEN 'Alternate calls reverse the coil polarity LOW Coil1 pause PulseLen 'Critical and empirically determined HIGH Coil1 LET CoilPolarity = 1 ELSE LOW Coil2 pause PulseLen HIGH Coil2 LET CoilPolarity = 0 ENDIF PAUSE Interpulse 'Critical and empirically determined LOW LED RETURN TransmitValue: 'DecData is current then voltage. SETFREQ m8 LET ByteCount = 6 GOSUB ConvertDec SERTXD (",") IF Voltflag = 1 THEN 'Then transmit the count and finish up LET DecData = Watt_Sec LET ByteCount = 10 GOSUB ConvertDec SERTXD (13,10,$FE,$C0,13) PAUSE 100 SERTXD ("C 1",13) ENDIF SETFREQ m4 RETURN ConvertDec: 'Uses fewer bytes than 40-byte BINTOASCII SERTXD ("W 1 ",#ByteCount,13) 'and one less variable byte LET Divider = 10000 FOR Iter = 0 TO 4 'Always 5 digits. div = Decdata / Divider DecData = DecData // Divider SERTXD (#div) LET Divider = Divider/10 NEXT RETURN