' ========================================================================= ' File: powercontrl.bs2 ' ' Controls the shutdown and power of a power supply connected to the stamp ' Also controls the charging a batteries attached to the stamp ' ' {$STAMP BS2} ' ========================================================================= power CON 0 relay CON 15 batteryIn CON 13 mainsin var in14 chargeMode var bit chargeTime var word feedbacklight con 8 a var byte dataIn var word lastData var word ' ------------------------------------------------------------------------- Main: debug "just turned on" , CR 'setup stuff a bit low batteryIn gosub keepon gosub ionloop goto main END keepon: debug "keeping the power on", CR high power 'keep the shutdown pin of the power supply high high feedbacklight low relay pause 2000 retur ionloop: FOR a = 0 TO 100 ' debug "I'm on and running ",dec a, cr 'debug "pin 14 is :" ,dec mainsin, cr pause 500 debug "in the loop", cr next goto turnoff return turnoff: debug "about to turn myself off or chargeCheck" ,cr if mainsin = 1 then chargeCheck low power ' no power so just turn off debug "should be powering off", cr 'pause 1000 goto main return startCharge: debug "start to charge", cr chargemode = 1 high relay low batteryIn 'do the check on battery voltage in low batteryIn pause 100 rctime batteryIn,0,dataIn debug "dataIn = ", dec dataIN, cr low batteryIn lastdata = dataIN goto chargeCheck return endCharge: debug "stopping the charge", cr if chargemode = 0 then main 'make sure we haven't already done this chargeTime = 0 chargemode = 0 low relay low power debug "relay and shutdown power pin should be low", cr pause 10000 goto main return chargeCheck: if mainsin = 0 then endCharge if chargemode = 0 then startCharge 'Check to see if we have been charging for more than 15 hours(which equals 900 sec (approx)) if chargeTime > 900 then endCharge 'so we are in chargeing mode debug "currently chargeing but I'm going to sleep",cr debug "charge time is ", dec chargeTime, cr chargeTime = chargeTime + 1 'increase the charge time 'pause for roughly 1 minutes '1000 pause = 1 sec pause 60000 'pause 1000 'do the check on battery voltage in low batteryIn pause 100 rctime batteryIn,0,dataIn debug "dataIn = ", dec dataIN, cr low batteryIn if dataIN > (lastdata + 1) then endCharge lastdata = dataIN goto chargeCheck return