; CHARGER.CONF V0.02

; This configuration file acts both as a basic setup of
; the BatMods and the documentation for itself
; comments start with ';'
;
; A array is denoted by a .1 - .(maxindex)
;
; NOTE THAT THIS IS BETA CODE!
; USE AT YOUR OWN RISK!


PWM_SEED=100 ; sets the value the PWM will start out at 
	   ; when charging enables

MY_NET_ADDR=1 ; sets the network address of this charger
		; LEAVE THIS AT ONE - SEE THE EMAIL THIS FILE CAME WITH!

LAST_ERROR=0 ; resets the last error storage byte
LAST_MESSAGE_SIZE=0 ; resets the last message size debug counter
NUM_SAMPLES=10 ; sets the number of samples to take on a poll() event
		; beware - too high a number here and the charger
		; will be too busy polling to do anything useful,

NUM_VF=10	; sets the number of voltage-to-frequecy (hv) samples
		; see warning on NUM_SAMPLES

DLY_VF=4	; sets the number of ticks to count() for when
		; sampling the voltage to frequency converter
		; beware, this number affects hv calibration
		; if you change it, you must rerun calibrate_hv

DIV_VF=1	; sets the number the output of count() is divided by
		; beware: setting it to zero may make bad things happen
		; see also the warnings on DLY_VF


DL_LOCK=0	; I don't know what it's for either
		; it's defined in the code and then never used
		; but I'm too lazy to go remove it
		
		; maybe we'll use it later?
		; for the bootloader or something?

PWM_FREQ=5000	; sets the frequency the PWM outputs to throttle the BatMod
		; please use a little common sense here

PWM_OFFSET=140	; sets the turn-on threshhold of the PWM
		; increase this number (and ajust PWM_SEED accordingly)
		; if your BatMod won't make enough volts

AVG_NUM=10	; controls the number of samples to keep in the running avg
		; note that if this is the same or less than NUM_SAMPLES
		; the effect is that the only sensor results that
		; are reflected are the most recent ones
		; 
		; contrawise, if this number is too big
		; it will take a long time for the charger
		; to react to anything

CONFIG_LOCKED=69; the software lock
		; this has the following magic values:

		; 55 = allow writing a block to eeprom for uploading bootloader
		; 121 = allow executing a bootloader
		; 42 = allow manual commanding of PWM levels
		; 69 = normal operation
		; 
		; any value besides 69 will result in some of the config
		; options being reset to default levels
		; whenever the board reboots
LAST_ERRNO.1=0  
LAST_ERRNO.2=0  ; this array contains the last two reported errors

MAX_WATTS=200	; this sets the most watts the charger will ever make
MAX_VOLTS=17.00 ; this sets the most volts teh charger will ever make
MAX_AMPS=15.00	; this sets the most amps the charger will ever make
MAX_CHG_TEMP=1 ; this number is backwards
		; meaning whenever the charger sensor falls below this level
		; charging will be terminated
		; suggested default is 45

MAX_BATT_TEMP=120	

PHASES_ENABLED=5 ; this number is a mask
		;so
		; 1 = ?
		; 2 = phase 1 enabled
		; 4 = phase 2 enabled
		; 8 = phase 3 enabled
		; 16 = phase 4 enabled
		; 32 = phase 5 enabled
		; 64 = phase 6 enabled
		; 128 = phase 7 enabled
	
		; add 'em togeather to get the mask you want

SCALE_BACK_CHG_TEMP=49 ; see MAX_CHG_TEMP - when the sensor reports below this
			; number (but above MAX_CHG_TEMP) the charger will
			; throttle back

CHARGE_INHIBIT_ERRNO_MASK=0	
		; this value is a mask
		; the following errors are defined
		; 1 = charger too hot
		; 2 = charger too cold (or sensor failed)
		; 4 = uncommanded charging
		; 8 = battery over voltage (MAX_VOLTS)
		; 16 = battery under voltage (MIN_VOLTS)
		; 32 = battery over temp (MAX_TEMP)
		; 64 = battery under temp (MIN_TEMP)
		; 128 = VESTA board has crashed and rebooted
		;
		; any errno that matches this mask will inhibit 
		; charging. Because you have no way to communicate
		; with the network right now, set this value to zero

TIMEOUT_MINUTES=60
		; when the VESTA board has been idle for this 
		; many minutes, it will go to sleep
		
		; note that a sleeping board
		; can not process a network event immediately
		; or report undervolts and the like

SLEEP_SECONDS=60
		; when a VESTA board has been idle for TIMEOUT_MINUTES
		; it will go to sleep
		
PHASE_CHARGE_VOLTS.1=14.70
PHASE_CHARGE_VOLTS.2=16.80
PHASE_CHARGE_VOLTS.3=14.00 ; for each phase, sets a constant voltage limit
PHASE_CHARGE_VOLTS.4=14.00
PHASE_CHARGE_VOLTS.5=14.00
PHASE_CHARGE_VOLTS.6=14.00
PHASE_CHARGE_VOLTS.7=14.00

PHASE_CHARGE_AMPS.1=10.00
PHASE_CHARGE_AMPS.2=2.00
PHASE_CHARGE_AMPS.3=2.5 ; for each phase, sets a constant current limit
PHASE_CHARGE_AMPS.4=0
PHASE_CHARGE_AMPS.5=0
PHASE_CHARGE_AMPS.6=0
PHASE_CHARGE_AMPS.7=0

; ignore these lines and use the parsed version below for easier setting
; of time

;PHASE_CHARGE_TIME_LO.0=15 ; low order byte, seconds (this is half a hour)
;PHASE_CHARGE_TIME_LO.1=16 ; low order byte, seconds
;PHASE_CHARGE_TIME_LO.2=15 ; low order byte, seconds

;PHASE_CHARGE_TIME_HI.0=7 ; high order byte, seconds (this is half a hour))
;PHASE_CHARGE_TIME_HI.1=15 ; high order byte, seconds (this is a hour))
;PHASE_CHARGE_TIME_HI.2=7 ; high order byte, seconds (this is half a hour))

PHASE_CHARGE_TIME.1=28800	; charge time in seconds
PHASE_CHARGE_TIME.2=3600	; charge time in seconds
PHASE_CHARGE_TIME.3=1800	; charge time in seconds
PHASE_CHARGE_TIME.4=1800	; charge time in seconds
PHASE_CHARGE_TIME.5=1800	; charge time in seconds
PHASE_CHARGE_TIME.6=1800	; charge time in seconds
PHASE_CHARGE_TIME.7=1800	; charge time in seconds

PHASE_CHARGE_FLAGS.1 = 0
PHASE_CHARGE_FLAGS.2 = 9
PHASE_CHARGE_FLAGS.3 = 13
PHASE_CHARGE_FLAGS.4 = 13
PHASE_CHARGE_FLAGS.5 = 13
PHASE_CHARGE_FLAGS.6 = 13
PHASE_CHARGE_FLAGS.7 = 13

		; these flags are again a mask (add 'em togeather)
		; and they are as follows
		; 1 = chg_flag_shutdown, stop charging at the end of this phase
		; 2 = chg_flag_temp_comp, use temp compensation
		; 	(see the file temp_comp_explained)
		; 4 = chg_flag_didt - if didt starts going up instead of down
		;	end this phase
		;
		; 8 = chg_flag_charged - at the end of this phase, set
		; the charged system bit
		;
		; this means the charger will not resume charging until
		; the voltage reaches CLEAR_CHARGED_THRESH (going down)
		;

		; below are the LIMITS
		; these are different from the settings in that
		; they cause the charger to change phases,
		; whereas it will just servo to try and meet the settings

PHASE_CHARGE_VOLTS_LIMIT_LO.1=0
PHASE_CHARGE_VOLTS_LIMIT_LO.2=0
PHASE_CHARGE_VOLTS_LIMIT_LO.3=0
PHASE_CHARGE_VOLTS_LIMIT_LO.4=0
PHASE_CHARGE_VOLTS_LIMIT_LO.5=0
PHASE_CHARGE_VOLTS_LIMIT_LO.6=0
PHASE_CHARGE_VOLTS_LIMIT_LO.7=0
		
		; skip to the next phase if voltage falls below the limit
		; set here

PHASE_CHARGE_VOLTS_LIMIT_HI.1=14.5
PHASE_CHARGE_VOLTS_LIMIT_HI.2=14.9
PHASE_CHARGE_VOLTS_LIMIT_HI.3=15.5
PHASE_CHARGE_VOLTS_LIMIT_HI.4=15.5
PHASE_CHARGE_VOLTS_LIMIT_HI.5=15.5
PHASE_CHARGE_VOLTS_LIMIT_HI.6=15.5
PHASE_CHARGE_VOLTS_LIMIT_HI.7=15.5
		
		; skip to the next phase if voltage falls below the limit
		; set here

PHASE_CHARGE_AMPS_LIMIT_LO.1=1.0
PHASE_CHARGE_AMPS_LIMIT_LO.2=0
PHASE_CHARGE_AMPS_LIMIT_LO.3=0
PHASE_CHARGE_AMPS_LIMIT_LO.4=0
PHASE_CHARGE_AMPS_LIMIT_LO.5=0
PHASE_CHARGE_AMPS_LIMIT_LO.6=0
PHASE_CHARGE_AMPS_LIMIT_LO.7=0
		
		; skip to the next phase if amperage falls below the limit
		; set here

PHASE_CHARGE_AMPS_LIMIT_HI.1=0
PHASE_CHARGE_AMPS_LIMIT_HI.2=0
PHASE_CHARGE_AMPS_LIMIT_HI.3=0
PHASE_CHARGE_AMPS_LIMIT_HI.4=0
PHASE_CHARGE_AMPS_LIMIT_HI.5=0
PHASE_CHARGE_AMPS_LIMIT_HI.6=0
PHASE_CHARGE_AMPS_LIMIT_HI.7=0
	
		; skip to the next phase if amperage goes above the limit
		; set here

PHASE_CHARGE_TEMP_LIMIT_LO.1=0
PHASE_CHARGE_TEMP_LIMIT_LO.2=0
PHASE_CHARGE_TEMP_LIMIT_LO.3=0
PHASE_CHARGE_TEMP_LIMIT_LO.4=0
PHASE_CHARGE_TEMP_LIMIT_LO.5=0
PHASE_CHARGE_TEMP_LIMIT_LO.6=0
PHASE_CHARGE_TEMP_LIMIT_LO.7=0

		; skip to the next phase if temp goes below the limit set here
		; note that '0' is reserved to mean 'no limit'
		; try setting it to 1 if you want to stop
		; 31 degrees below where water freezes
		
		; (et cetera)

PHASE_CHARGE_TEMP_LIMIT_HI.1=0
PHASE_CHARGE_TEMP_LIMIT_HI.2=0
PHASE_CHARGE_TEMP_LIMIT_HI.3=0
PHASE_CHARGE_TEMP_LIMIT_HI.4=0
PHASE_CHARGE_TEMP_LIMIT_HI.5=0
PHASE_CHARGE_TEMP_LIMIT_HI.6=0
PHASE_CHARGE_TEMP_LIMIT_HI.7=0

		; skip to the next phase if temp goes above te limit set here
		; see notes on LIMIT_LO

;VOLTS_M=0
;VOLTS_C=0
;VOLTS_B=0
;AMPS_M=0
;AMPS_C=0
;AMPS_B=0
;VOLTS_HV_M=0
;VOLTS_HV_C=0
;VOLTS_HV_B=0
; these are all special calibration values
; noramlly you will set them with the calibration routines
; calibrate_volts
; calibrate_amps
; calibrate_hv
;
; this is just included in case you need a fast way to rough cal a board
; the function read_calibration will print out these values
; if you want them

; here's a example of loading the temp compensation table 
; through the config file - lee, take note! I may not have time to write
; a parser for your file format!
;

TEMP_LOOKUP.119 = 80
TEMP_LOOKUP.120 = 80
TEMP_LOOKUP.121 = 80
TEMP_LOOKUP.122 = 80
TEMP_LOOKUP.123 = 80
TEMP_LOOKUP.124 = 80
TEMP_LOOKUP.125 = 81
TEMP_LOOKUP.126 = 82
TEMP_LOOKUP.127 = 83
TEMP_LOOKUP.128 = 84
TEMP_LOOKUP.129 = 85
TEMP_LOOKUP.130 = 86

;TEMP_LOOKUP.(0-255)=(temp) - this is how you map
; temp sensor A/D values into real world temps
;
;TEMP_COMP.(0-255)=(volts)
; this is how you apply corrections for voltage
; based on temp comp (if the right CHARGE_PHASE_FLAG is set)
;
; note that the value here is thousandths of a volt
; and that it is ADDED to the REPORTED VOLTAGE OF THE OPTIMA
; 
; this means to make it so at ten degrees F, the charger would switch
; off a tenth of a volt later, you would use a NEGATIVE number
;
; i.e.
; TEMP_COMP.10=-100
; note also that the subscript is binary
; so -40 degrees = 0, 0 degrees = 40, 40 degrees = 80, etc

TURN_ON_BALANCE_HV=0	; this is the HV voltage at which we go to the phase below
TURN_ON_BALANCE_PHASE=0

TURN_ON_CHARGE_HV=310	; this is the HV voltage at which we go to the phase below
TURN_ON_CHARGE_PHASE=1

TURN_OFF_CHARGE_HV=240	; this is the voltage at which we will turn off the charger
			; if it is set

			; note that if this is below the balance voltage
			; the charger will immediately hop to balance mode

TURN_OFF_BALANCE_HV=0 ; this is the voltage at which we will turn off auto
			; balance if it is engaged
			; note that this and charge can
			; interact in strange ways

BALANCE_NUM_BATTERIES_PHASE=0 ; ask lee. it was his idea
BALANCE_NUM_BATTERIES=25	; ask lee. it was his idea

CLEAR_CHARGED_THRESH=12.8	; at this voltage, we will clear
				; the charged bit, causing the charger
				; to resume automatic charging

				; please note that the DIDT routines
				; are only suitable for charge phases
				; that should start out at their
				; maximum amps, and slowly scale down

DIDT_WINDOW=100			; ignore didt for this many seconds
				; (gives the charger a chance to stablize)

DIDT_UP_LIMIT=5			; allow the DIDT to raise this many times
				; (or stay raised for this many minutes)
DIDT_CLIMB=1

BEEP_ON_NET_TIMEOUT=1		; debugging feature

BAUD_LOCKED=69			; if this is not 69
				; all reboots will return BAUD to 9600

BAUD=9600			; set the baud rate the charger will respond to
				; requires a reboot to take effect
				;
				; note that if this is not 9600, reloading
				; the software on the VESTA with the IDE
				; may prove challenging

MIN_VOLTS=6.0			; voltage below which a undervolt 
				; error will be recorded

MIN_BATT_TEMP=0			; batt temp below hwich 
				; a error will be recorded
				; (see the notes about batt temps elsewhere)

MIN_CHG_TEMP=100		; sensor value above which a 
				; fault will be recorded
