English
Language : 

SM3320-BATT-EV-NOPB Datasheet, PDF (14/21 Pages) Texas Instruments – AN-2121 SolarMagic™ SM3320-BATT-EV Charge Controller Reference Design
Microcontroller Program Code
www.ti.com
14.1 Function: check_lead_acid()
This function senses the battery voltage through the microcontroller’s A/D converter. The A/D conversion
is needed because the current limiting circuit in hardware acts on the voltage sensing line of the
SM72442. Therefore, when the system is running in high current mode, the voltage sensed by the
SM72442 is not the battery voltage. If the current limitation is not necessary, such as panels with limited
power capabilities, the voltage used by the check_lead_acid() function could be changed to the value
recovered from the SM72442 through I2C instead of using the microcontroller’s ADC.
This function verifies the state of the battery by sensing its voltage and returns an 8 bit number related to
the state of the battery:
• 0: No change
• 1: Battery reached the full State Of Charge voltage
• 2: Battery voltage is low
• 3: Battery voltage is too low or battery damaged/disconnected
• 4: Battery voltage is above the acceptable value: battery damaged or disconnected
• 5: Battery voltage has reached above 13.6V. This is usually due to the lower limit on the duty cycle of
the buck converter. When the battery stays in floating charge state for too long, the converter will keep
pumping a minimum current into the battery which could result in an increase of the battery voltage
beyond the desired floating charge voltage range.
• 6: Battery voltage has returned to an acceptable value
States 5 and 6 correspond to the state of charge of the battery after it has reached it's floating charge
state value of 13.5V. When “5” is returned by this function, the program will completely cut the charge into
the battery (by issuing a reset to the SM72442 via PORTB of the microcontroller). When “6” is returned by
this function, the program will re-enable the floating charge into the battery by releasing the reset on the
SM72442.
14.2 Function: Main()
The “Main” function calls the” Init()” function, which simply initializes the variables and the registers. The
program then enters an infinite while-loop in which the values of the sensed voltages and current are
recovered from the SM72442 through I2C. The function “check_lead_acid()” is called and returns a value
based on the voltage of the battery. The “Main” function uses this value to modify the behavior of the
system. The following lists the values returned from the “check_lead_acid()” function the corresponding
action the “Main” function will take:
• 1 (fully charged battery): The floating charge voltage setpoint will be sent to SM72442 through I2C
• 2 (heavily discharged battery): Trickle charge will be applied
• 3 (battery voltage too low): System shuts down by keeping the SM72442 in reset mode (bit RB2 set)
• 4 (battery voltage too high): System shuts down by keeping the SM72442 in reset mode (bit RB2 set)
• 5 (battery voltage slightly high in floating charge): System shuts down by keeping the SM72442 in
reset mode (bit RB2 set) and hysteresis flag set
• 6 (battery voltage dropped below 13V after hysteresis flag set): Re-enable SM72442, hysteresis flag
reset
The Main function also resets the watchdog timer once every iteration of the while-loop.
14.3 Function: get_i2c_data
This function reads the sampled voltage of pin AIIN(19), AVIN(15), AIOUT(21), and AVOUT(17) of the
SM72442. The data is fetched through the I2C channel. The function updates the global variable “outval”
which is an array of unsigned 16 bit integers. The data only occupies 10bits of each integer (full
scale=1023).
• outval[0] = input current
• outval[1] = input voltage
• outval[2] = output current
• outval[3] = output voltage
14
AN-2121 SolarMagic™ SM3320-BATT-EV Charge Controller Reference
SNOSB76C – December 2010 – Revised May 2013
Design
Submit Documentation Feedback
Copyright © 2010–2013, Texas Instruments Incorporated