Firmware description
PIC microcontroller firmware description
The PIC microcontroller program is written in assembler using the Parallax-like macro (included in the package). The program structure is quite simple because it is based on a periodic interrupt with 5msec period. This basic tic allow the processor to sample the two analog inputs (voltage and current) that are read in a 15-bit format at each tic. The processor works on a cycle time of 100 msec. In this cycle the first 16 (5 msec * 16 = 80 msec) slots are for analog reading and for low noise signals conditioning. After this phase, when the cycle is at 80 msec, the serial parameters are sent out. After 2 slots, at 95msec from the start of the cycle, the processor executes the finite state machine for the local management (if enabled).
The charge/discharge state machine has a simmetrical functioning, because there are the same states for charging or discharging the batteries:
Charge/discharge state machine
State 0: in this state the zero current output is sampled in order to minimize the offset errors, and the target current for fast charging or discharging is calculated recalling the value from the table with the enabled profile. The machine goes to the state 1 after about 20 seconds.
State 1: In this state the machine enables the fast (high current charge or discharge) checking at each cycle if the phase is finished. The machine goes to the next state if: (in charge) the timeout period has expired or the delta voltage from the peak has been reached or (in discharge) the cut-off voltage is above the actual pack voltage.
State 2: The state 2 is the battery recovery, with a small pause for battery cooling and at the same time a re-zero sampling for the zero current and calculation for slow current charging/discharging.
State 3: The state 3 is completely equivalent to the state 1 but with a different (lower) target current .
State 4: The state 4 is the finish of the charging or discharging, with a small final cooling, then a pause for next start.
Program initialization
The program when starts reads the switches status for next operation scheduling and recall from the EEPROM memory the right charge/discharge profile.The profiles if the EEPROM was not yet written are entered and saved at the right places. The two PWMs (for charge and discharge) are enabled. The serial port is initialized for 9600,N,8,1 operations.
Remote control management
In this mode the charger is completely slave of the host computer that sends all the operative commands and reads the values for batteries current and voltage. The charger in this case is only an output peripheral for the serial commands. The commands are received, decoded, checked for consistency and enabled directly in the interrupt routine: the command lets the user to control all the charger functions from the mosfet driving to the led state.
Comments ::
© 2004 Seven-Segments
All content on this website
(including text, photographs, resource files, and any other original works),
unless otherwise noted, is licensed under a
Creative Commons License