Reference Design
Buck Converter Battery Charger
Using the Z8F042A MCU
RD001302-0814
Overview
This document describes a Z8 Encore! XP-based Buck Converter Battery Charger reference design that employs Zilog’s Z8F042A MCU to control a step-down DC-DC converter (also known as a buck converter) that acts as a regulated power source. This buck
converter battery charger hardware is capable of regulating charger output in a number of
modes, such as constant voltage, constant current, or constant voltage with a current limit.
The charger can be viewed as a complete control system. The type and capacity of the battery determines the mode of operation of the battery controller – namely, a constant current source or a constant voltage source. The voltage (VSET) and current (ISET) setpoints
are also determined by the type and capacity of the battery. All battery control loop operations can be controlled by the user via the Z8F042A MCU’s UART block, and feedback is
provided in the HyperTerminal console. Additionally, LEDs provide a visual status of the
charging process.
Note: The source code file associated with this reference design, RD0013-SC01.zip, is available
free for download from the Zilog website. This source code has been tested with version
5.0.0 of ZDS II for Z8 Encore! XP MCUs. Subsequent releases of ZDS II may require you
to modify the code supplied with this reference design.
Features
The key features of this buck converter battery charger are:
•
Z8F042A MCU featuring a highly accurate Sigma-Delta ADC
•
Buck converter with proportional/integral controlled constant current and voltage
•
Differential ADC for current measurements
•
Complete programmability
•
Current/voltage control independent of user input
•
UART-controlled operation
•
In-circuit programming for upgrading or modifying firmware
Potential Applications
This Buck Converter Battery Charger reference design can be used to develop a number of
applications; the brief list below offers a few ideas.
RD001302-0814
Page 1 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
•
Security systems
•
Information systems
•
Warning systems
Discussion
The Buck Converter Battery Charger reference design consists of a buck converter controlled by a Z8F042A MCU, plus circuitry to provide feedback signals to the MCU.
To save memory resources, the provided UART does not implement the stdio.h libraries. Instead, a simple UART using only integer values is used. As a result of this implementation, the user is asked to enter values from 10 to 40, representing values from 1.0 to
4.0, respectively, for a set voltage and set current.
An external voltage source 5 V or 15 V, or USB can be used to supply the operating voltage.
The USB 2.0 port current limit is 500 mA.
When the MCU is powered up and if a battery was detected, the MCU will start charging
the battery by generating the PWM pulses to the buck converter to the initial current and
voltage settings as determined in the Userinput.h header file, until the user enters the
desired values.
The charge process is executed in the background and controlled via a timer0 interrupt service routine to alternate between current and voltage ADC channel sampling, keeping the
UART as a foreground task in the main function. The PI then uses the sampled ADC
information from the voltage and current samples to adjust the PWM for the battery charging process.
During the charging process, the MCU measures battery charge current as a voltage drop
across R4, a 1 Ohm resistor, in series with the battery and adjusts duty cycle of PWM to
the buck converter to keep this voltage drop in respect with a battery-charging curve
which is determined by the battery chemistry.
When the battery charge current reaches the voltage charge threshold, the MCU decreases
charging current and starts monitoring battery voltage.
While the battery is charging, the red LED is on and the green LED is off. When the
charging process is completed, the red LED is turned off and the green LED is turned on
and a message to the hyper-terminal (GUI) indicates battery charge is completed. The
buck converter off, but the PI control loop keeps monitoring the battery voltage and
refreshes the charge, if necessary. The charging process can be stopped by the user at any
time.
Components and MCU Peripherals
Switching MOSFET Q1 with 3 A current limit and low power MOSFET Q2 used as level
shifter for Q1.
RD001302-0814
Page 2 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Switching MOSFET Q1 with Inductor L1, capacitors C11, C12, C13, and diode D1 forms
buck converter circuitry.
Resistive dividers R6/R9 and R7/R10 provide battery voltage/current measurement points
for MCU ADC circuitry.
Capacitors C14, C15 may be used as HF filters, if switching noise affects ADC conversion.
Capacitors C1 - C10 are input filter. Divider R2/R5 provides measurement point for input
voltage.
LEDs D2 (red) and D3 (green) are used as indicators to reflect battery charge state and
fault conditions.
Evaluation board assumes follow MCU ports assignment:
•
Analog inputs (ADC):
– PB0/ANA0 - Thermistor Voltage (Single-ended mode)
– PB3/ANA3 - Input Voltage (Single-ended mode)
– PC0/ANA4 - Buck Converter Output Voltage (Single-ended mode)
– PC1/ANA5 - Battery Voltage (Single-ended mode)
– PC0/ANA4 - PC1/ANA5 - Battery Current (Differential Mode)
•
Digital outputs:
– PA7/T1out: PWM pulses
– PA1: Red LED D2
– PA2: Green LED D3
The Board features two power source options. It can be powered by connecting USB (B)
connector J1 to the USB port of the development PC using the USB A to USB (B) cable
included in the Kit. The other option is to connect a female plug to an external 6 VDC
source with at least 300–400mA of current to external power supply connector J3. A
drawing of an optional external power supply plug is shown in Figure 1.
Figure 1. Female Plug
RD001302-0814
Page 3 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Legend
A = 5.5 mm
B = 2.1 mm
C = 8.8 mm or longer
Figure 1. Female Plug
When the Board is powered via a USB connection, communication with the development
PC can be established through the FT232RL chip (U1) to provide a USB-to-serial interface. The UART0 block of the Z8F042A MCU is connected to this chip.
An on-board USB power distribution switch (U6) provides overcurrent protection in the
event of a short or if a device is connected to the Board that requires more than 500 mA
@3.3 V. If either condition occurs, LED D4 will illuminate.
The battery must be connected to terminals Vbat+ and Vbat–.
The Battery Charger Reference Board, shown in Figure 2, features two IXYS MOSFETs.
MOSFET Q1 exhibits a 3A current limit; the low-power MOSFET Q2 is used as a level
shifter for Q1. The buck converter circuit consists of MOSFET Q1, inductor L1, capacitors C11, C12 and C13, and a diode. Resistor R4 is used as a battery current sense resistor,
and resistive dividers R6/R9 and R7/R10 provide the battery voltage/current measurement
points for the Z8F042A MCU’s ADC inputs.
RD001302-0814
Page 4 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Figure 2. The Buck Converter Battery Charger Reference Design Module
RD001302-0814
Page 5 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Battery Charger Hardware
The battery charger hardware is built and tested with commonly available components.
The main hardware component of this implementation is a Z8 Encore! XP-based F042A
20-pin microcontroller. Figure 3 displays a block diagram of the battery charger; see
Appendix C. Schematic Diagrams on page 26 for a schematic illustration of the Battery
Charger Reference Board.
HyperTerminal
UART
PWM
External Power Source
Step-Down Converter
Z8F042A MCU
ADC
V/I Converter
Battery Feedback
Status Indicator LED
Battery
Figure 3. Buck Converter Battery Charger Block Diagram
Z8F082A Series Flash MCUs
The Z8F042A MCU used in this reference design is a member of the Z8F082A Series of
Z8 Encore! XP Flash MCUs; it is a 4 KB version of the Z8F082A MCU. Z8F082A Series
MCUs offer the following features:
•
20 MHz eZ8 CPU
•
1 KB, 2 KB, 4 KB, or 8 KB Flash memory with in-circuit programming capability
•
256 B, 512 B, or 1 KB register RAM
•
Up to 128 B nonvolatile data storage (NVDS)
•
Internal precision oscillator trimmed to ±1% accuracy
•
External crystal oscillator, operating up to 20 MHz
•
Optional 8-channel, 10-bit analog-to-digital converter (ADC)
•
Optional on-chip temperature sensor
RD001302-0814
Page 6 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
•
On-chip analog comparator
•
Optional on-chip low-power operational amplifier (LPO)
•
Full-duplex UART
•
The UART baud rate generator (BRG) can be configured and used as a basic 16-bit timer
•
Infrared Data Association (IrDA)-compliant infrared encoder/decoders, integrated
with the UART
•
Two enhanced 16-bit timers with capture, compare and PWM capability
•
Watchdog Timer (WDT) with dedicated internal RC oscillator
•
Up to 20 vectored interrupts
•
6 to 25 I/O pins depending upon package
•
Up to thirteen 5 V-tolerant input pins
•
Up to 8 ports capable of direct LED drive with no current limit resistor required
•
On-Chip Debugger (OCD)
•
Voltage Brown-Out (VBO) protection
•
Programmable low battery detection (LVD) (8-pin devices only)
•
Bandgap generated precision voltage references available for the ADC, comparator,
•
VBO and LVD
•
Power-On Reset (POR)
•
2.7 V to 3.6 V operating voltage
•
8-, 20- and 28-pin packages
•
0°C to +70°C and –40°C to +105°C for operating temperature ranges
FT232RL USB-to-Serial UART Interface
The FT232RL (U1) device is a USB-to-serial UART interface between a host PC and the
Z8F042A MCU with an optional clock generator output. In addition, asynchronous and
synchronous bit-bang interface modes are available. USB-to-serial designs using the
FT232RL device have been further simplified by fully integrating external EEPROM,
clock circuit and USB resistors onto the device. Its inputs are connected to the USB connector J1, and its outputs are connected to the Z8F042A MCU’s UART serial communication ports PA4 and PA5.
U3
U3 is a 3.3 V voltage regulator for the Z8F042A MCU and the debug connector.
RD001302-0814
Page 7 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Buck Converter
In general, a buck converter consists of an inductor, two switches, a transistor and a diode
to control the inductor. The PWM alternates between connecting the inductor to a source
of voltage to store energy in the inductor, and discharging the inductor into the load.
In this reference design, the PWM is an input to the buck converter which is controlled by
the MCU at an 80 kHz variable-PWM duty cycle. Depending on the charging speed, the
output of the converter usually ranges from 1 V to 4 V; this voltage is supplied to the battery. Both the feedback charge current and charge voltage are controlled by the PI loop.
R2 and R5 form a voltage divider on the input of the buck converter. The ratio of input
voltage and battery voltage (Vbat) is used to determine the start-up duty cycle.
Differential Voltage Divider Circuit
The Differential Voltage Divider Circuit/Feedback Module provides battery voltage, battery current, and converter input using three ADC inputs. These feedback readings are
used for constant current charging/voltage charging with a PI control loop, and to terminate the charging process. The constant current charging is applied using a differential
resistor network. During the constant current charge, the differential voltage drop across a
sense resistor is held constant, therefore the battery charge current is constant. The battery
charging process can be monitored via UART and the GUI (HyperTerminal).
Temperature Circuit
A temperature (thermistor) circuit consists of resistors R11 and R12. If the battery features
a temperature sensor, then this part of the circuit monitors the voltage drop across voltage
divider R11, R12. The thermistor is parallel t
o R12; its voltage drop determines the voltage drop across R12. As a result, the software
acts upon this voltage drop threshold.
LED Indicators
Three different LEDs display the various functionalities of the charger:
•
Overcurrent indication LED D4
•
Battery charging indication LED D2
•
Charging complete indication LED D3
The red LED (D2) indicates when a battery charge is in progress; it illuminates the green
LED (D3) when the charging process is complete. The Reference Board uses a 4.5 V to
15 V DC regulated external input power supply to drive the 5 V and 3.3 V internal supply.
Battery Charger Software
The software provided with this reference design is developed and tested on the hardware
per the schematic diagram shown in Figure 12 on page 26. This section describes the functionality of this reference design’s different software blocks used for battery charging.
RD001302-0814
Page 8 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
For additional details about this software, refer to the demo firmware contained in the
RD0013-SC01.zip file, which includes the following files:
•
Main.c
– Variable declarations
– Initialization of peripherals
– UART control
•
Control.c
– Timer0 interrupt service routine (control loop for constant current/voltage charge)
– PWM duty for battery charging
– Constant current PI feedback loop
– Constant voltage PI feedback loop
– UART transmit function
– UART receive function
•
Initialization.c
– WDT initialization
– Input/Output pin initialization
– UART initialization
– ADC initialization
– Timer0 initialization
– PWM initialization
•
UserInput.h
– User input parameters for the PI control loop
•
Main.h
– Function body declarations
– External variable declarations
– Constant definitions
– Structure declarations
Battery Charger Algorithm
The battery charging process is a PWM PI-controlled, closed-loop algorithm based on battery current and voltage feedback. The input PWM frequency of the buck converter is
80 kHz. If the battery is not completely charged, then the duty cycle required for maintaining the setpoints at the converter outputs is calculated by the control algorithm. The control algorithm implements a Proportional, Integral (PI) loop to derive the necessary PWM
duty cycle based on the following equation:
u(t) = k1 * e(t) + k2 * e(t)dt
RD001302-0814
Page 9 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
In this equation, K1 is the proportional constant coefficient, K2 is the integral constant
coefficient, and e(t) is the error between the set value and the actual value as a function of
time.
The coefficients are determined empirically based on system response because they are
contingent upon reactive/complex load conditions, which may vary. These coefficients
should be chosen such that smooth convergence to a current setpoint and a voltage setpoint is achieved.
If UART is enabled, then the current setpoint and voltage setpoint can be entered in
HyperTerminal. If UART is not selected, then these voltage and current values must be
entered in the UserInput.c file.
The interrupt service routine (ISR) timer is invoked every 100 µs (at 10 kHz). The PWM
value computed by the control algorithm is loaded into the PWM generators to be transmitted via the output pin. The 16-bit timer’s PWM Mode offers a programmable switching
frequency based on the reload value; this flexibility allows a trade-off between accuracy
and the frequency of the PWM switching signal. The higher the frequency, the lower the
PWM Register reload value and resolution of the PWM; the converse is also true.
The firmware heuristic is designed such that only UART code is executed in the main infinite loop. Timer0 is the main control engine, configured for interrupts at 10 kHz intervals
to change the ADC channels, if the ADC data is ready, and to determine whether the current control or the voltage control PI loop is required.
Battery Safety and Charge Termination
For safe operation, termination threshold calculations must be based on battery parameters. The setpoints for the DC-DC step down (buck) converter voltage, the current, and the
current limit are calculated. When the one-time calculations are complete, the charger
software enters into an infinite loop which is terminated by a successful charge completion
or safety error.
Inside the Timer0 loop, the ADC reads the actual values of the converter output voltage,
the battery voltage, and the current. The ADC measures the output voltage/current output
of the buck converter as feedback to the controller.
The ADC performs a basic measurement of output voltage, output current, and battery
voltage at the battery’s terminals as an input to determine charge termination. To make
this determination, the current across the battery terminals must be the same as the measured converter output current.
This safety routine is responsible for the overall safety features associated with a battery
charger. The charger ensures safety by comparing the actual converter voltage and the battery voltage with calculated thresholds. Crossing these thresholds switches the PWM output off, which turns off the converter output and terminates the charging functions. Such
termination protects the batteries in case of a device failure. If all of the actual values are
within limits, the battery is tested for full charge.
RD001302-0814
Page 10 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Initializing the Z8 Encore! XP Peripherals
All Z8Encore! peripherals are initialized from their power-on states to their required
modes of operation via the following ports:
•
Port A, bits 1 and 2 are used for the status LEDs
•
Port A, bits 4 and 5 are the UART transmit and receive pins to communicate with HyperTerminal
•
Port B, bit 3 is used for single-ended input voltage mode
•
Port C, bit 0 and 1 are the battery charge voltage pins
•
PA 7 is configured to generate the 80 kHz PWM frequency for the buck converter
Kit Contents
The tools used to build this reference design are:
•
Buck Converter Battery Charger Design Module
•
USB cable, Type A to B
•
Buck Converter Battery Charger Reference Design Flyer (FL0144)
Required Items Not Supplied
•
USB Smart Cable (Zilog PN: ZUSBSC0001ZACG)
•
3.7 V lithium-ion battery
Software Installation
This project requires the ZDS II – Z8Encore! Integrated Development Environment.
Observe the following procedure to download and install the ZDS II software.
1. Download the latest version of ZDS II for Z8 Encore! from the Downloadable Software category in the Zilog Store.
2. Run the software installation file and follow the on-screen instructions to install ZDS II.
Viewing and Rebuilding the Battery Charger Software
The source code/project is provided in this kit so that users can be familiar with the Buck
Converter Battery Charger reference design. However, users are not expected to modify or
change any parameters.
1. If you have not downloaded the software for this reference design, refer to the paper
insert that was included in your kit (Document Control Number FL0144), and follow
the 3-step software download instructions contained on it.
RD001302-0814
Page 11 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
2. Launch the ZDS II – Z8 Encore! application by navigating via the following default
path:
Start → Programs → Zilog ZDS II_Z8Encore!_ →
ZDSII_Z8Encore!
3. From the File menu, select Open Project. The Open dialog box appears.
4. Browse to the src folder which, by default, is located in the following path:
\ZRD0013CHRGZRD_
5. Select the Applications.zdsproj file from the src folder, and click Open to display the initial ZDS II program screen. To view the source files, double-click the Project Files folder on the left side of the IDE interface. Double-click an individual file to
open the file in the ZDS II file editor.
6. Click the Rebuild All toolbar icon, which is highlighted in red in Figure 4.
RD001302-0814
Page 12 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Figure 4. Build Mode Configuration
7. When the rebuild is complete, a Build succeeded. message will appear, as highlighted in Figure 5.
RD001302-0814
Page 13 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Figure 5. A Successful Build
Note: The output checksum shown in Figure 5 is for reference only and may not display the
same results at the time of release.
RD001302-0814
Page 14 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Running the Demo
Observe the following procedure to set up your reference design and host PC to run the
demo/application software.
1. Connect a 3.7 V Lithium Ion battery to the Battery Charger Reference Module across
Vbat– and Vbat+ terminals.
2. Connect a USB Smart Cable to J2 of the Reference Module and host PC USB port.
See Appendix A. Installing the USB Smart Cable Driver on page 21 for assistance, if
required.
3. Ensure that the S1 shunt is ON, and slide switch S5 to the USB position. Figure 6 indicates the locations of S1 and S5 on the Module.
Figure 6. Shunt and Switch Locations on the Battery Charger Reference Module
4. Connect the included USB Cable Type A to B to J1 and to the host PC’s USB port. If
necessary, see Appendix B. Installing the FTDI USB-to-UART Driver on page 24.
5. In your terminal emulation application, select the COM port assigned to the USB-toserial cable, and modify the settings to reflect an 57600, 8, N, 1, N configuration, as
shown in the Tera Term example in Figure 7.
RD001302-0814
Page 15 of 27
Buck Converter Battery Charger Using the Z8F042A MCU
Reference Design
Figure 7. Configuring the Serial Communication Settings
6. Launch ZDS II for Z8 Encore!. If you have not yet installed ZDS II, return to the Software Installation section on page 11.
7. From the File menu in ZDS II, select Open Project, and navigate to the following filepath: