Text preview for : gpmm3153-manual.pdf part of NiCd/Ni MH Battery Charger
Back to : gpmm3153-manual.pdf | Home
Application Note
Z8 Encore!® Based AA Type NiMH and NiCd Battery Charger Reference Design
AN022901-0905
ZiLOG Worldwide Headquarters · 532 Race Street · San Jose, CA 95126 Telephone: 408.558.8500 · Fax: 408.558.8300 · www.ZiLOG.com
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
This publication is subject to replacement by a later edition. To determine whether a later edition exists, or to request copies of publications, contact: ZiLOG Worldwide Headquarters
532 Race Street San Jose, CA 95126 Telephone: 408.558.8500 Fax: 408.558.8300 www.zilog.com
ZiLOG is a registered trademark of ZiLOG Inc. in the United States and in other countries. All other products and/or service names mentioned herein may be trademarks of the companies with which they are associated.
Information Integrity
The information contained within this document has been verified according to the general principles of electrical and mechanical engineering. Any applicable source code illustrated in the document was either written by an authorized ZiLOG employee or licensed consultant. Permission to use these codes in any form, besides the intended application, must be approved through a license agreement between both parties. ZiLOG will not be responsible for any code(s) used beyond the intended application. Contact the local ZiLOG Sales Office to obtain necessary license agreements.
Document Disclaimer
©2005 by ZiLOG, Inc. All rights reserved. Information in this publication concerning the devices, applications, or technology described is intended to suggest possible uses and may be superseded. ZiLOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZiLOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. Except with the express written approval ZiLOG, use of information, devices, or technology as critical components of life support systems is not authorized. No licenses or other rights are conveyed, implicitly or otherwise, by this document under any intellectual property rights. Application notes are tested with the version of ZDS II available at the time of release. Subsequent releases of ZDS II may require you to modify Application Note code to restore its function.
AN022901-0905
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
Table of Contents
List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . V List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . VI Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Salient Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Display Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Buzzer indicator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Other Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Software Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Battery charging algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Battery safety and termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Display and Control of Battery Charger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initializing the Z8 Encore!® Peripheral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 2 2 4 4 5 6 6
Hardware Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Testing the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Appendix A--References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Appendix B--Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Appendix C--Photograph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Appendix D--Schematic Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Appendix E--Bill of Material. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Appendix F--Flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Appendix G--Battery Technology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Appendix H--Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
AN022901-0905
Table of Contents
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
V
List of Tables
Table 1. References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Table 2. Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Table 3. Bill of Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
AN022901-0905
List of Tables
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
VI
List of Figures
Figure 1. Block diagram of the Battery Charger . . . . . . . . . . . . . . . . . . . . . . . . . 3 Figure 2. NiCd Battery Charging Characteristics . . . . . . . . . . . . . . . . . . . . . . . . 8 Figure 3. Schematic diagram of Z8 Encore!® Interface . . . . . . . . . . . . . . . . . . 13 Figure 4. Schematic diagram of DC-DC Step Down Converter . . . . . . . . . . . . 14 Figure 5. Schematic Diagram of Feedback Converter . . . . . . . . . . . . . . . . . . . 15 Figure 6. Schematic Diagram of Temperature Sensor . . . . . . . . . . . . . . . . . . . 16 Figure 7. Flowchart for the Main Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Figure 8. Flowchart for the ISR Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
AN022901-0905
List of Figures
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
1
Abstract
This reference design demonstrates AA type NiMH and NiCd battery charger using 28-pin Z8 Encore!® 8K Series MCU. The battery charger uses 18.432-MHz external clock. An internal reference voltage of 2 Volts is applied to the ADC peripheral for monitoring the battery voltage, battery current, and charger voltage. The battery temperature is monitored using an external I2C temperature sensor. The battery status information and battery type selection are controlled by the push button switches and monitored using an LCD display. The battery charger is a stand-alone product. It requires 9 Volts external power supply for charging the 1.2 Volts AA type NiMH and NiCd battery.
Salient Features
The salient features of the battery charger used in this reference design are as follows:
· · ·
The battery type is AA and voltage rating is 1.2 Volts. The charger can charge upto 1-4 batteries at a time. The combination of three switches perform the functions of selecting the battery type and viewing the charging status. The battery charger has following press button type function keys: Battery type selection key: Used to select the type of battery to be charged. Display info selection key: Used to select the status (battery type, battery voltage, battery current, battery temperature and charger voltage) of the battery to be displayed. Enter key: Used to enter the selection type and status for battery . Reset key: Used to reset the system.
· · · · · ·
Monitoring the battery status using LCD display. Charging and full charge indication using LED. The temperature sensor measures the temperature of each battery separately. The temperature is read continuously using I2C bus. A dynamic PWM is used for controlling the battery charging. For termination of charging at the appropriate time, the battery charging algorithm continuously monitors the battery voltage. For NiMH and NiCd battery types, the charging is done in the constant current mode with the maximum charging current equal to 500mA. The charging will
AN022901-0905
Abstract
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
2
be terminated when the battery voltage exhibits no increase in the terminal voltage (zero termination) or negative termination voltage.
Display Features
The display function performs the following:
· · · · ·
Display the battery parameters (battery type, battery voltage, battery current, battery temperature and charger voltage) during the charging process. The LCD display is used for viewing the battery charging status and battery type. Display the full battery status. Four LEDs display the following status: power on, battery charging, charger on, and battery full. The buzzer beeps and LED ON indicates the full charge status of the battery.
Buzzer indicator
The buzzer indicator indicates the full charging status of the battery by beeping sound.
Other Features
The other features of the battery charger used in this reference design are as follows:
· ·
In-circuit programming for upgrading firmware. Adjusting the battery charging using online PWM.
Hardware Details
The hardware of the battery charger, Appendix C , is built and tested with commonly available components. The main component of the hardware is Z8 Encore!® 8K Series 28-pin microcontroller. Figure 1 displays the block diagram of the battery charger. See Figure 3 of Appendix D for the schematic diagram of battery charger demo board. The demo board uses 9Vdc regulated external input power supply to drive the 5 Volts and 3.3 Volts internal supply.
AN022901-0905
Hardware Details
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
3
LCD Display (16x2)
External Power Source
GPIO
PWM
Step down (bulk) Converter
ADC ADC Z8Encore!®MCU (Z8F08) GPIO
Converter V/I, Battery Voltage Feedback
Battery Selector (Switches)
GPIO GPIO 12C
Status Indicator(LED)
Battery Bank (4No. AA Type)
I2 C Temperature Sensor (4 No.) Buzzer
Figure 1. Block diagram of the Battery Charger
The hardware consists of the following modules: DC- DC Step down converter (DC-DC converter) The PWM is an input to the DC-DC converter, which is controlled by the MCU. Depending upon the charging speed, the output of the converter usually ranges from 1.2 Volts to 3.6 Volts.This voltage is supplied to the battery. See Figure 4 of Appendix D for the schematic diagram of DC-DC converter. Feedback Module The feedback module provides the battery voltage, battery current and converter output using three channels of the operational amplifier. The I2C temperature sensor is used for reading the temperature of the battery. These readings are used for checking the safety of the battery, terminating the charging and keeping
AN022901-0905
Hardware Details
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
4
the current constant using a variable PWM. The feedback is obtained using an ADC. See Figure 5 of Appendix D for the schematic diagram of the feedback converter. Switch Selection and LED Indication Select the battery type using SW2 (B - TYPE) and the status of the battery using the switch SW3 and press SW4 (ENTER). The LED indicators D4 and D5 indicate the full charge and battery charging status, respectively. The LED D1 indicates the DC-DC converter output status. Display Module The 16x2 character LCD displays the battery information. The potentiometer RV1 controls the intensity of character and potentiometer RV2 controls the backlight of the LCD. See Figure 3 of Appendix D for the schematic diagram of the hardware interface of the display module.
Software Details
The software provided with this reference design is developed and tested on the hardware as per the schematics provided in Appendix D. This section provides the functionality of different software blocks used for battery charging. The following are the different functional blocks:
· · · ·
Battery charging algorithm Battery safety and termination Display and Control of Battery Charger Initializing the Z8 Encore!® Peripheral
Battery charging algorithm
The battery charging algorithm is a close loop constant current algorithm. The DCDC converter current is controlled by the PWM duty cycle based on the battery current feedback. The input PWM frequency of the DC-DC converter is 50KHz. If the battery is not completely charged, then the duty cycle required for maintaining the set points at the converter output is calculated by the control algorithm. The control algorithm implements proportional plus integral (PI) control to derive the PWM output based on the equation:
u ( t ) = k1 e ( t ) + k2 e ( t ) dt
AN022901-0905
Software Details
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
5
The interrupt service routine (ISR) timer is invoked every five milliseconds. The PWM value computed by the control algorithm is loaded into the PWM generators to be sent out via the output pin. The 16-bit timer PWM mode offers a programmable switching frequency based on the reload value. This flexibility allows designers to trade-off between accuracy and frequency of the PWM switching signal. The higher the frequency, lesser the reload value and lower the resolution in the pulse width variation and vice versa.
Battery safety and termination
The safety and termination threshold calculations are based on the battery parameters. To check for battery safety and termination, perform the following steps:
·
The set points for the DC-DC step-down (buck) converter voltage, the current, and the current limit are calculated. Once the one-time calculations are complete, the charger software enters into an infinite loop, which is broken only by a successful charge completion or a safety error. Inside the infinite loop, the ADC reads the actual values of the converter output voltage, the battery voltage, the current, and the temperature (temperature is measured only if the battery features a temperature sensor). The ADC measures the output voltage and the output current of the DCDC converter as a feedback to the controller. The ADC measures the voltage at the battery terminals as an input to determine the charging termination. Measurement of the output voltage, the output current, and the battery voltage are the basic measurements. For the charge termination, the current across the battery terminals should be same as the measured converter output current . For batteries featuring externally provided temperature sensors, the charger reads the battery temperature also in addition to the basic measurements. The temperature measurement is significant for safety measures. After the actual values (VOUT, VBATT, and IBATT) are known, they are checked for safety limit compliance.
· · ·
·
The safety routine is responsible for the overall safety features associated with the battery charger. The charger ensures safety by comparing the actual converter voltage, the battery voltage, and the battery temperature with the calculated thresholds. Crossing these thresholds switches off the PWM output, which turns off the converter output and terminates 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. For NiMH batteries, the battery is considered to be completely charged if the measured battery voltage stops increasing (zero V termination).
AN022901-0905
Software Details
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
6
The timer ISR also updates the charge termination variables every 10 seconds.
Display and Control of Battery Charger
Display functionality is achieved using the 16x2 character LCD display. Display information is given below:
· · · · · · · · · ·
Displays the battery type. The battery type is user selectable using a press switch. Displays the battery status (battery charging status, battery voltage, battery current, and battery temperature). Battery status display is user selectable and can be changed at any point of time. Displays the battery temperature of individual AA type batteries. It is user selectable. By default displays the battery type (NiCd) and battery voltage. Displays the battery full indication status, once the charging is complete.
Battery keys Battery type selection key: It is a press button type of key, used to select the type of battery to charge. Battery status selection key: It is a press button type of key, used to select the type of status to monitor. Enter key: It is used for entering the selection type for battery or battery status along with the selection switch. Reset key: It is used for resetting the system.
LED indicators Four different LEDs will display the various functionalities of the charger.
· · · ·
Power-on indication LED DC-DC converter output indication LED Battery charging indication LED Charging complete indication
Initializing the Z8 Encore!® Peripheral
All Z8 Encore!® peripherals are initialized from their power-on state to the required mode of operation.
AN022901-0905
Software Details
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
7
Port A pin 0,1,2 and Port C pin 2,3,4,5 are initialized as general purpose input output (GPIO) ports. These pins are used to communicate with LCD display. Port A pin 3, 4, 5 are initialized as GPIO input ports to read the status of control switches. Port A pin 6, 7 are initialized in alternate function mode(I2C) to communicate with the temperature sensor device. Port C pin 1 works in alternate function mode and supplies the PWM output for DC-DC converter. Port C pin 0 is initialized as GPIO output port to control the buzzer function. Port B pins 0,1,2 are initialized in alternate function mode (ADC) to read feedback values for battery voltage, converter voltage, and charging current. Port B pins 3,4 are initialized as GPIO output ports to indicate the status of charger on LEDs. Initialize the battery parameters stored in the variables.These battery parameters are defined in the charger.h header file.
Testing the Application
This section discusses the setup, equipments to use, and procedure to follow for testing the Z8 Encore!® based NiMH, NiCd battery charger. The test setup comprises of a Z8 Encore!® battery charger board, Appendix C , NiMH or NiCd batteries that are to be charged and a 9 Volts Vdc power supply. Procedure Follow the steps below to test the Z8 Encore!® based NiMH and NiCd battery charger:
· · · · ·
Launch ZDS ll for Z8 Encore!®. Load the NiMH or NiCd batteries to the battery charger board. Connect the batteries to be charged across the provided battery terminals (see Appendix D). Make sure that jumper JP5 is connected 1-2 position for supplying the 9 Volts for DC - DC converter. Power up the battery charger board with the 9 Volts DC supply. Download the code to the Z8 Encore!® Flash memory using the debug connector ( JP3) with the help of ZDS II-IDE, if required. The code is shipped along with the board.
AN022901-0905
Testing the Application
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
8
· · · · · · Results
Press reset key to execute the battery charger code. Select battery type by pressing switch SW2 and press SW4 for entering the selected type (default type is NiCd). Select battery voltage by pressing switch SW3 and press SW4 for entering the selected type. Observe the gradual increase in battery voltage on LCD display. When the battery is fully charged under normal circumstances, the buzzer will beep and "Battery charging complete" is displayed on the LCD display. If the temperature is above 40C, charging of the batteries will be terminated.
The test results for the Z8 Encore!® based NiCd battery charger is shown in the figure below. These readings are obtained using single NiCd AA-type battery (700mAh) at 300mA charging rate.
1600
-ve termination
Battery voltage (mv)
1500 1400 1300 1200 1100 1000 1 11 21 31 41 51 61 71 81
Time (minutes)
Figure 2. NiCd Battery Charging Characteristics
AN022901-0905
Testing the Application
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
9
Summary
This reference design discusses NiCd and NiMH battery charger implementation using Z8 Encore!® F08 MCU. The battery charger software accompanying this reference design provides fast charging algorithm. Fast recharge is possible due to the monitoring of charging parameters rendered by the 10-bit accuracy of the ADC. This charging mechanism facilitates the accurate termination of charging. Therefore, over-charging is prevented, resulting in a longer battery life. Pulse width modulation technique facilitates an accurate DC-DC converter (buck) implementation with excellent line/load regulation.
AN022901-0905
Summary
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
10
Appendix A--References
More details about the Z8 Encore!® battery charger can be found in the table below. Table 1. References Topic Document Name Source ® Z8 Encore! F08 Product Specification: Z8 Encore!® Series Product Documents PS0225.pdf Specification
AN022901-0905
Appendix A--References
Z8
Encore!® Based
Application Note AA Type NiMH and NiCd Battery Charger Reference Design
11
Appendix B--Glossary
Definitions for terms and abbreviations used in this Application Note that are not commonly known are listed in table below.
Table 2. Glossary Term/Abbreviation Definition
ADC ISR Nicd NiMH MAh PI PWM
Analog to Digital Converter Interrupt Service Routine Nickel cadmium Nickel Metal Hydride milli-Ampere-hour : The unit of battery capacity Proportional plus Integral Pulse Width Modulation
AN022901-0905
Appendix B--Glossary
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design
12
Appendix C--Photograph
Appendix C provides the photograph of the NiMH and NiCd battery charger hardware.
AN022901-0905
Appendix C--Photograph
Z8
Encore!®
Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design 13
Appendix D--Schematic Diagrams
Appendix D provides the schematic diagrams for NiMH and NiCd battery charger.
TP 6
9V
Z8 Encore! Interface
U1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 PWR JACK 1 PB 0/A NA1 3 PB 1/A NA2 2 PB 2/A NA3 PB 3/LE D1 U8 PB 4/LE D2 P1 VDD
1
F1 D7 RX E160 S2G
U7 LM780 5C/T O220/0.5A 1 IN OUT 3
VCC
PC0/B Z SCL SDA RE SET VDD
PC0/T 1IN PA 6/S CL PA 7/S DA RE SET VS S XIN XOUT VDD PC5/MISO PC4/MOSI PC3/S CK PC2/S S PA 0/T 0IN PA 1/T 0OUT
PB 0/A NA0 PB 1/A NA1 PB 2/A NA2 PB 3/A NA3 PB 4/A NA4 VREF AV SS AV DD DB G PC1/T 1OUT PA 5/T XD0 PA 4/RXD0 PA 3/CTS0 PA 2/DE0
2
G ND
C4 C30 0.1uF + C3 0.1uF
+ C5 100uF/16V 1 TP 7 GND
47uF/16V
DB G PC1/T 1OUT PA 5/S W4 PA 4/S W3 PA 3/S W2 VCC 3 1 U8 VIN VOUT GND 2 VDD
Z8F0822
LT108 6-3.3/T O220
R13 680E
0.1uF VCC 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 LCD Displ ay
2
D6 LED RED
C6
+ C7
100uF/16V
3
Y1 18.432MHz R11 1M C1 18pF C2 18pF
Gnd Vcc FNC RS /WR /RD DX 0 DX 1 DX 2 DX 3 DC2 DC3 DC4 DC5 2
2
VR1 10k U9 4 GND GND VCC RE SET 3
VDD R14
1
100K 1 VCC 1 VR2 10k TP 3 DS 1233A-15/S OT23 3.3V 1 1 VDD TP 4 SW1 GND C8 0.01uF 1 TP 1 5.0V TP 2 GND 2 RE SET VCC
3
RESET
1
C9 0.1uF
C10 0.1uF
C11 0.1uF
C12 Ti tl e 0.1uF Si ze A Date: Document Number Saturd ay, Ju ly 23, 2 005 Sheet 1 of 1 Rev
Figure 3. Schematic diagram of Z8 Encore!® Interface
AN022901-0905 Appendix D--Schematic Diagrams
1
J1
Application Note Z8 Encore!® Based AA Type NiMH and NiCd Battery Charger Reference Design 14
JP5 3 2 1 3 2 1 R3 1K R34 18E IRF9540 Q1 D2 L1 Q2 2N2222
2
VCC
9V
DC-DC Step Down Converter
HE ADE R 3 TP 5 PWM Test P oint
1
V_out(+) V_out(-) R37
R1 PC1/T1 OUT 3.3K
1 1
3
3
2
120uH D3 MB R360
MB R360
3.3E/0.5W C13 100uF/16V
C14 100uF/16V
R4 470E R5 79E D1 LED RE D R6 R7 C15 10E 10E BT 1
(+) V_batt(+) BA TTE RY Hol der (4 AA Type) (-) V_batt(-)
R2 2.2K
Rsense
0.1uF 10E 10E I_out(+) I_out(-)
LED Indicator Port
VDD
R12 R33
R8 560E
R9 560E
D4 LED GREEN
D5 LED RE D
PB 3/LE D1 PB 4/LE D2 Ti tl e Si ze A Date: Document Number Saturda y, Jul y 23, 20 05 Sheet 1 of 1 Rev
Figure 4. Schematic diagram of DC-DC Step Down Converter
AN022901-0905
Appendix D--Schematic Diagrams
Application Note Z8 Encore!® Based AA Type NiMH and NiCd Battery Charger Reference Design 15
C16 R18 0.1uF 1K C17 0.1uF 1K
Feedback Circuits
R23
11
I_out(-)
1K R16 10 1K R17 1K R15 9
1K 8 R19 V_batt(-) PB1/ANA2 Battery Current V_batt(+) R21 1K C29 10uF/16V R22 1K 3 10K R20 2
11
LM324 U6C
LM324 U6A 1
PB0/ANA1 Battery Voltage
I_out(+)
4
VCC
4
C18 VCC R27 1K
2K V_out(-) V_out(+) R25 2K R26 1K 5 C19 100uF/16V C20 0.1uF C21 0.1uF R24 6
11
4
DBGINTERFACE
R36 VDD JP3 1 3 5 2 4 6 DBG
R35 10K
RESET DBG
0 Ohm
HEADER 3X2
Note: 1. R14 - R30 all 1% MFR. 2. Signal, Digital, and Power Grounds are connected on the evaluation board.
Ti tle Si ze A Date: Document Number <Doc> Saturday, July 23, 2005 Sheet 1 of Rev <RevCode> 1<br><br>Figure 5. Schematic Diagram of Feedback Converter<br><br>AN022901-0905<br><br>Appendix D--Schematic Diagrams<br><br>+ VCC 0.1uF LM324 U6B 7 + VCC<br><br>+<br><br>PB2/ANA3 Converter Output Voltage<br><br>Application Note Z8 Encore!® Based AA Type NiMH and NiCd Battery Charger Reference Design 16<br><br>Temperature sensor<br>R3 9 R3 8 VDD 10k 10k SDA SCL 1 2 3 R3 2 330E U2 SDA GND SCL MA X662 5 Vs ADD OT 6 5 4 1 2 3 U4 SDA GND SCL MA X662 5 R2 8 U3 1 2 3 SDA GND SCL MA X662 5 Vs ADD OT 6 5 4 1 2 3 U5 SDA GND SCL MA X662 5 Vs ADD OT 6 5 4 PC0/B Z 1K 1 1 Vs ADD OT 6 5 4 2 VCC<br><br>1<br>BZ1 BUZZER PB2130UL100A 3 Q3 2N2222 2<br><br>1<br><br>VDD<br><br>Switchs for Battery Selection<br>VDD R2 9 10K SW2 SW3 R3 0 10K R3 1 10K SW4 PA 4/S W3 C2 2 0.01uF C2 3 0.01uF PA 5/S W4 C2 4 0.01uF C2 5 0.1uF C2 6 0.1uF C2 7 0.1uF C2 8 0.1uF<br><br>PA 3/S W2<br><br>Select Battery Type<br><br>Select Battery status<br><br>Enter Selection<br><br>Ti tle <T itle> Si ze A Da te: Do cume nt Number <Doc> Sa turday, Jul y 23, 2005 Sh eet 1 of 1 Re v <RevCode><br><br>Figure 6. Schematic Diagram of Temperature Sensor<br><br>AN022901-0905<br><br>Appendix D--Schematic Diagrams<br><br>2<br><br>3<br><br>2<br><br>Z8<br><br>Encore!®<br><br>Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design<br>17<br><br>Appendix E--Bill of Material<br>Appendix E provides the Bill of Material for NiMH and NiCd Battery Charger<br>Table 3. Bill of Material<br>Item 1 2 3 4 5 Quantity 1 1 2 1 17 Reference BT1 BZ1 C2,C1 C3 C4,C6,C9,C10,C11,C12,C15,C 16,C17,C18,C20,C21,C25,C26 ,C27,C28,C30 C5,C7,C13,C14,C19 C8,C22,C23,C24 C29 D1,D5,D6 D2,D3 D4 D7 F1 JP3 JP5 J1 L1 P1 Q1 Q2,Q3 R1 R2 Part Lead PB2130UL100A 18pF 47uF/16V 0.1uF Type Package Battery Holder(4-AAPTH Buzzer PTH Capacitor 805 Capacitor 2220 Capacitor 805 Manufacturer<br><br>6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23<br><br>5 4 1 3 2 1 1 1 1 1 1 1 1 1 2 1 1 12<br><br>100uF/16V 0.01uF 10uF/16V LED MBR360 LED Rectifier RXE160 HEADER 3X2 HEADER 3X1 BOX Header 16x1 120uH S-G9312 #01 IRF9540 2N2222 3.3K 2.2K<br><br>Capacitor Capacitor Capacitor Red SCHOTTKY Green S2G FUSE L Type Straight Header Inductor Power Jack MOSFET NPN transistor Resistance<br><br>2220 805 2220 805 PTH 805 S2G PTH PTH PTH PTH PTH PTH TO-220 SOT23 805 805 805<br><br>R3,R12,R15,R16,R17,R18, 1K R20,R21,R22,R23,R26,R27<br>R4 R5 R7,R6 R8,R9 R11 R13 R14 470E 79E 10E 560E 1M 680E 100K 10K<br><br>Resistance Resistance Resistance Resistance Resistance<br>Resistance Resistance Resistance Resistance Resistance<br><br>24 25 26 27 28 29 30 31<br><br>1 1 2 2 1 1 1 7<br><br>805 805 805 805 805 805 805 805<br><br>R19,R29,R30,R31,R35,R38 ,R39<br>RV1,RV2<br><br>32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54<br><br>2 2 1 1 1 1 4 1 1 4 1 1 1 1 1 1 4 3 1 1 3 4 1<br><br>10k<br><br>R24,R25, 2k R32 330E R34 18E R36 0E R37 3.3E/ 1/2W SW1,SW2,SW3,SW4 SPST TP1,TP2,TP3,TP4,TP6,TP7 40x1 U1 Z8F0822SJ020SC U2,U3,U4,U5 MAX6625RMUT U6 LM324 U7 LM7805 U8 LT1086-3.3 U9 DS1233A-15 Y1 18.432MHz LCD Module HDM16216L-B-L30S Plastic PCB Base with screw for mounting LCD module Screw set for titening the TO220 pack with PCB and heat sink Fevibond(only one NO.) for pasting battery holder P1(Matching connector for J1in LCD module Header 16X1 Straight Q1,U7,U8 Heat sink BMH1,BMH2,BMH3,BMH4 PCB Holder PCB Battery charger PCB<br><br>multiturn variable resistance Resistance Resistance Resistance Resistance Resistance micro switch Header MCU Temp. sensor Op-Amp Regulator Regulator 3.3V EconoReset Crystal LCD Display<br><br>PTH 805 805 805 0805 PTH PTH PTH SOIC SOT23-6 SOIC-14 TO220 TO220 SOT23 Half CAN Module<br><br>Zilog<br><br>Hantronix<br><br>PTH TO220<br><br>AN022901-0905<br><br>Appendix E--Bill of Material<br><br>Z8<br><br>Encore!®<br><br>Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design<br>18<br><br>Appendix F--Flowcharts<br>The main battery-charging routine is illustrated in Figure 7.<br><br>Start<br><br>Initialize the Peripherals<br><br>Calculate safety limits and thresholds for charging and termination<br><br>Read feedback values for battery voltage, converter voltage, charging current and battery temperature<br><br>Within safety Within Safety Limits? limits?<br><br>No<br><br>Yes<br><br>Is the battery charged?<br><br>Yes<br><br>Terminate No<br><br>Calculate the duty cycle<br><br>Figure 7. Flowchart for the Main Routine<br><br>AN022901-0905<br><br>Appendix F--Flowcharts<br><br>Z8<br><br>Encore!®<br><br>Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design<br>19<br><br>The ISR Routine of the battery charger is illustrated in Figure 8.<br><br>Start ISR<br><br>Reload PWMvalue<br><br>Update charge termination data every10 sec<br><br>Return from ISR<br><br>Figure 8. Flowchart for the ISR Routine<br><br>AN022901-0905<br><br>Appendix F--Flowcharts<br><br>Z8<br><br>Encore!®<br><br>Application Note Based AA Type NiMH and NiCd Battery Charger Reference Design<br>20<br><br>Appendix G--Battery Technology<br>Battery Technology The four popular battery types (NiCd, NiMH, SLA, Li-Ion) possess different charging and discharging characteristics.The battery life and performance critically depends upon the battery charging mechanism.Therefore, batteries must be charged in a proper mechanism. The charging must terminate at the appropriate time as overcharging of the battery invariably results in poor performance and can also damage the battery. Different batteries require different charge termination techniques as they behave differently while approaching the full charge state. While charging, batteries exhibit the marked rise in voltage above the rated battery voltage.The NiCd and NiMH rechargeable battery types are briefly discussed below. Nickel Cadmium (NiCd) NiCd batteries are used in camcorders, walkman and in other consumer portable equipments. The single-cell voltage for NiCd batteries is 1.2 Volts. These batteries are charged using the constant current charging method. While charging, as the voltage crosses the full charge point, the current gradually drops.This current drop is approximately 15mV per cell in the battery. This current drop is recognized as full charge condition resulting in the termination of the charge. This termination mechnanism is known as - V termination). The battery voltage rises to 1.65 Volts per cell during charging. The main disadvantage of the NiCd battery is that it must be discharged periodicallly to protect the performance. This phenomenon is known as memory effect. Nickel Metal Hydride (NiMH) NiMH batteries exhibit high power density compared to the NiCd batteries.The per cell voltage of the NiMH bettery type is 1.2 Volts which is similar to NiCd batteries. NiMH batteries are charged with constant current charging method. While charging, the voltage drop is not as low as compared to NiCd batteries. Therefore, - V charge termination is not recommended. Instead of the drop in cell voltage, the battery tends to stabilize after a small drop.This flat region is the indication for full battery charging. This termination mechanism is known as zero V termination. NiMH batteries do not suffer with memory effect as compared to NiCd batteries. As a result, they replace NiCd batteries in devices such as cell phones. The increase in price is justified by the reduction in weight and absence of memory effect.<br><br>AN022901-0905<br><br>Appendix G--Battery Technology<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>21<br><br>Appendix H--Source Code<br>Appendix H provides a listing of all the source code associated with the application described in this document. The code files in this section are listed merely to assist the reader, and are intended only for the purpose of review. Copying these code listings from this document for actual use can result in compilation errors, and is therefore strongly discouraged. To use properly-formatted code for your development work, please refer to the source code file that is a companion to this document. Note: The code files in this section are listed merely to assist the reader, and are intended only for review process. Copying these code listings from this document for actual use can result in compilation errors, and is therefore strongly discouraged. To use properly-formatted code for your development work, refer to the source code file in the document.<br>/********************************************************** * File :main.c * Description :this is the main file of the project. * * Copyright 2005 ZiLOG Inc. ALL RIGHTS RESERVED. * * The source code in this file was written by an * authorized ZiLOG employee or a licensed consultant. * The source code has been verified to the fullest * extent possible. * * Permission to use this code is granted on a royalty-free * basis. However users are cautioned to authenticate the * code contained herein. * * ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE. **************************************************************/ #include <stdio.h> #include <ez8.h> #include "Battery_Charger.h" #include "LCD_API.h" #include "I2C.h" int display_timer = 0, pwm_update_timer = 0, eoc_update_timer = 0; int new_pwh = 0, new_pwl = 0, timer_count=0; int eoc_value = 0, last_eoc_value = 0; unsigned char battery_type,SwitchSW3flgON,SwitchSW2flgON; unsigned char status=0,RedLEDFlg=0,GreenLEDFlg=0,BuzzerONFlg=0,Read_Feedback_flg=0;<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>22<br><br>unsigned char safety_flgON=0,Termination_flgON=OFF; extern int average_value[CHANNELS+1]; unsigned int current_ms=0; unsigned char current_temp0,current_temp1,current_temp2,current_temp3; /////////////for testing///////////// // unsigned char store_battery_voltage[100]=0;// for testing<br>// unsigned char reading_counter=0; //////////////////////////////////// void main() {<br><br>status = 0; Init_Port(); Init_Timer(); Init_LCD(); init_I2C(); Init_ADC(); battery_type = NICD; select_parameters(battery_type); ADCCTL |= 0x80; EI(); while (1)<br>{<br><br>// Enable Interrupts<br><br>if(Read_Feedback_flg==ON)<br>{ Read_Feedback_flg==OFF; Upload_Feedback(); if(safety_flgON==ON) {<br><br>check_for_safety();<br>if(Termination_flgON==ON)<br><br>// Ensure safe // operation. // Find whether // further charging is<br><br>check_for_termination(battery_type); required.<br>safety_flgON=OFF; } } if(status != CHARGING_COMPLETE) { Read_Battery_Temp(); Read_Switch(); Write_LED(); Display_Battery_Parm(); }<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>23<br><br>else { Write_LED(); delayms(12000); PCOUT &= BUZZER_OFF; while (1); } } } /* ****************************************************************************** ** End of File ****************************************************************************** */ #include <eZ8.h> #include <sio.h> #include <stdlib.h> #include "Battery_Charger.h" int gain[4] = {1, 1, 1, 1}; // Tbatt-gain0 = 1; Vbatt-gain1 = 5; // Iout-gain2 =1; Vout-gain3 = 10 int Vbatt_max, Vout_max, flag_test, neg_th, zero_th, abs_th; int type, Vset, Iset, Ilim; int average_value[CHANNELS + 1] = 0; int adc_value[CHANNELS + 1] = 0; int old[CHANNELS + 1]; int error[2] = {0,0}; int Vpwm = 0x0160; char data_ready; extern unsigned char current_temp0,current_temp1,current_temp2,current_temp3; extern int eoc_value, last_eoc_value; extern int new_pwl, new_pwh; extern int battery_type; extern unsigned char status; /* ****************************************************************************** ** ** Routine : select_parameters ** Parameters : None ** Return : Nothing ** ** Purpose: ** This routine selects battery voltage and capacity parameters for the ** charger. ** In a commercial product these can be entered from a keyboard. The values ** are defined in charger.h and the user will have to change the same if the ** battery selected is of different voltage and capacity. ******************************************************************************<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>24<br><br>*/ void select_parameters(int type) { int Vbatt,Ibatt; if (type == NICD) { Vbatt = VBATT_NICD; // Voltage milivolts Ibatt = IBATT_NICD; // Capacity miliamperehours } else if (type == NIMH) { Vbatt = VBATT_NIMH; // Voltage milivolts Ibatt = IBATT_NIMH; // Capacity miliamperehours } Vbatt = Vbatt / gain[1]; // Converted to 0-2000 range Ibatt = Ibatt / gain[2]; // Converted to 0-2000 range Vset = Vset / gain[3]; // Converted to 0-2000 range Vbatt = ((long)Vbatt << 10) / 2000;// scaled to 10 bit ADC Ibatt = ((long)Ibatt << 10) / 2000;// scaled to 10 bit ADC Vset = ((long)Vset << 10) / 2000;// scaled to 10 bit ADC // --------------------------Vout_max = 160 * (Vset); Vbatt_max = 160 * (Vbatt /100); flag_test = (Vbatt * 2) ; // --------------------------// // // // Define termination thresholds 2% of Battery rating for NiMH termination.<br><br>// // // // // //<br><br>Defined for dc-dc converter output. The max out of 4 types is 60% over the rated voltage. Used to avoid false, early termination in NiCd and NiMH.<br><br>zero_th = (Vbatt / 100) * 2; zero_th =0; abs_th = (Vbatt / 100) * 5;<br><br>// 5% of Battery rating for SLA // and Li-Ion termination.<br><br>} /* ****************************************************************************** ** ** Routine : read_feedback_values ** Parameters : None ** Return : Nothing ** ** Purpose: ** In the read-feedback_values routine: ** Four Analog channels are converted to Digital data. ** The ADC data is stored arbitrarily from RAM location 0xDE0.<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>25<br><br>** The RAM location must exclude 0xF00-0xFFF address space. ** The ADC data is passed through a digital low pass filter. ** The final data is stored in the array average_value. ** ****************************************************************************** */ void read_feedback_values() { long i; static int channel; /* // Check if the data is ready, read data at appropriate loacation // if data for last channel is read then set fresh_data flag // start conversion for next channel */ if (!(ADCCTL & 0x80))// Check if the ADC data is available { // ADC data available adc_value[channel] = new_getvalue();// Read ADC data - adjusted average_value[channel] = ((3 * adc_value[channel])+(2 * old[channel]))/10; // Low pass filter old[channel] = adc_value[channel]; // Preparing for low pass filter // Implement ADC channel sequence 0 - 1 // 2 - 0 if (channel == CHANNELS) { // This is the last channel data_ready = 1; // All channels are having a new // value channel = 0; // Start from the beginning // channel } else { channel++; // Next Channel } // Proper channel is selected ADCCTL &= ~(0x0F); // Clear the lower nible for // loading the new channel ADCCTL |= (char)channel;// Load the channel in the ADC // control register ADCCTL |= 0x80; // Start Conversion for the new // channel } else { // Conversion in progress, skip } }<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>26<br><br>/* ****************************************************************************** ** ** Routine : check_for_safety ** Parameters : None ** Return : Nothing ** ** Purpose: ** This routine checks whether the battery voltage and converter ** output voltage are within the safety limits. ** ****************************************************************************** */ void check_for_safety() { if(average_value[0]>Vbatt_max) // Compare actual batery voltage with max // limit for Vbatt. { T1CTL &= 0x7F; // Actual battery voltage higher than // threshold - disable PWM output. DI(); // Disable further action. } if(average_value[2]>Vout_max) // Compare converter output voltage with // max limit of Vout. { T1CTL &= 0x7F; // Actual output voltage higher than // threshold - disable PWM output. DI(); // Disable further action } // ----------------------------- // Code for thermal safety can be added // here. } /* ****************************************************************************** ** ** Routine : check_for_termination ** Parameters : None ** Return : int ** ** Purpose: ** This routine contains code for terminating different ** types of batteries. The algorithms available are ** Negative delta V algorithm for NiCd batteries, ** Zero delta V algorithm for NiMH batteries, and ** Absolute V algorithm for SLA and Li-Ion batteries. **<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>27<br><br>****************************************************************************** */ void check_for_termination(int type) { static unsigned char count = 0; // for NiMH zero delta V termination static int max = 0; // for NiCd neg delta V threshold int diff = 0; // for NiCd neg delta V threshold int difference; // for SLA and Li-Ion termination // // // // // // Charging for the NiCd batteries is terminated using -ve delta V technique. This is done by detecting a "hump" after the battery has attained some charge,to avoid false triggering.<br><br>if((average_value[0]>flag_test)||((eoc_value - last_eoc_value) < zero_th)) // zero_th is 2% of battery rating. // Check if Battery voltage is near // full charge. { // This avoids false early // termination. count = count + 1; // Mark the occurances. if(count>4) // Avoiding spurious equalities. { T1CTL &= 0x7F; // terminate - disable PWM output. status = CHARGING_COMPLETE; // Termination flag set, used in main() } }<br><br>if((current_temp0>40)||(current_temp1>40)||(current_temp2>40)||(current_temp3> 40)) { T1CTL &= 0x7F; // terminate - disable PWM output. status = CHARGING_COMPLETE; // Termination flag set, used in main() } } /* ****************************************************************************** ** ** Routine : calculate_pwm_value ** Parameters : None ** Return : Nothing<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>28<br><br>** ** Purpose: ** The calculate_pwm_value routine monitors the battery status ** and decides the charging type. It further calculates the ** pwm values required for next cycle in control loop. ** ****************************************************************************** */ void calculate_pwm_value(int type) { int new_pw; error[0] = Iset - (average_value[1]); // Find present error. Vpwm = Vpwm - ((error[0])/10 - (error[1])/20); // stable, best till now error[1] = error[0]; // store present error as // last error. // Reload corresponds to Vin// 100% duty cycle. new_pw = (Vpwm * RELOAD)/VIN; // So, calculate new_pw to // correspond to Vout. new_pw=abs(Vpwm); if(new_pw new_pw if(new_pw new_pw >= 0x0170) = 0x016F; <= 0x0008) = 0x0008;<br><br>// Encapsulate so that half // the value is not loaded in // ISR new_pwl = new_pw & 0x00FF; // convert the new_pw in PWM register // format - L new_pwh = (new_pw >> 8)&0x00FF; // convert the new_pw in PWM register // format - H // -------------------------------------------} /* ****************************************************************************** ** ** Routine : new_getvalue ** Parameters: None ** Return : int ** ** Purpose: ** This function gets the value from the ADC HI-Lo registers and then ** concatenates it into a single integer value. This value is returned ** to the calling function. ** ******************************************************************************<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>29<br><br>*/ int new_getvalue(void) { int ADCvalue=0, valueH=0, valueL=0; /* In single shot conversion the ADC is 11-bits and in 2's complement format. ADHR holds higher 8-bits and ADLR holds lower 3-bits in bits 7-5 */ valueH = ADHR; valueH &= 0x00FF; valueH = valueH << 3; valueH &= ~(0x07); valueL = ADLR; valueL = valueL >> 5; valueL &= 0x07; ADCvalue = valueH | valueL; // // // // // // // // // // // // valueH is an int - Is this required? Make space for the three least significant bits. Mask all undefined bits. Read LSbyte from ADC data Low register Position least significant bits at D0-D2 positions. Mask all undefined bits. Form the 10-bit ADC value. This is raw ADC data<br><br>return (ADCvalue); } /* ****************************************************************************** ** End of File ****************************************************************************** */ /* *********************************************************** * File : Auxiliary.c * Description : this has auxiliary function of battery charger. * * Copyright 2005 ZiLOG Inc. ALL RIGHTS RESERVED. * * The source code in this file was written by an * authorized ZiLOG employee or a licensed consultant. * The source code has been verified to the fullest * extent possible. * * Permission to use this code is granted on a royalty-free * basis. However users are cautioned to authenticate the * code contained herein. * * ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE.<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>30<br><br>**************************************************************/<br><br>#include <eZ8.h> #include "Battery_Charger.h" #include "I2C.h" #include "define.h" #include "LCD_API.h"/* Header file */ #define TRUE0x01 #define FALSE0x00 unsigned char i2c_shiftreg, i2c_error; unsigned char temp_low_byte,temp_high_byte; unsigned char BT_temp[4]={0,0,0,0}; unsigned char CountBatType=0,CountBatStatus=0; unsigned char SW2LCDflg=OFF,SW3LCDflg=OFF,Enterflg=OFF,SW2Keyflg=OFF; unsigned char flg; extern unsigned char battery_type; extern unsigned char status,RedLEDFlg,GreenLEDFlg,BuzzerONFlg,SwitchSW3flgON,SwitchSW2flgON; extern unsigned char current_temp0,current_temp1,current_temp2,current_temp3; unsigned char DisplayBatType,DisplayBatStatus,CountBatSet,status_type; extern int average_value[CHANNELS+1]; unsigned char *pstring0, *pstring1, *pstring2, *pstring3; unsigned charstring0[]="BAT-T0 C "; unsigned charstring1[]="BAT-T1 C "; unsigned charstring2[]="BAT-T2 C "; unsigned charstring3[]="BAT-T3 C "; unsigned char *bvstring, *bcstring, *cvstring; unsigned charstringbv[]="BAT-V mv "; unsigned charstringbc[]="BAT-C ma "; unsigned charstringcv[]="CHR-V mv "; void bin_to_ascii1(unsigned char, unsigned char *); static void bin_to_ascii1ong(unsigned int c, unsigned char *buff); unsigned char readtemp(unsigned char SensorAdd,unsigned char *I2Cstatus) { unsigned char temp1; unsigned char data; i2c_shiftreg = SensorAdd; // The MAX6625 is at I2C slave address // 0x90 I2C_start (); // I2C Start I2C_Set_NAck (); // Set the No Acknowledge(NACK) bit,this // is sent after receiving the // last byte.In a single byte read ,the // NACK is sent after receiving one byte I2C_write_byte (i2c_shiftreg); // EEPROM Address; Write<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>31<br><br>temp1 = I2C_tdre_ack(); if(temp1 == FAIL) { *I2Cstatus = FAIL; return; } i2c_shiftreg=(SensorAdd+1); I2C_start (); I2C_Set_NAck ();<br><br>// // // // // // //<br><br>Check if the transmit buffer is empty / and checks if NCKI bit is set The transaction is discontinued if NCKI is SET after sending a byte of data.This is like checking if the slave has acknowledge the receipt of "EEPROM_Write_Control_Word"<br><br>// // // // //<br><br>I2C Start Set the No Acknowledge(NACK) bit,this is sent after receiving the last byte.In a single byte read ,the NACK is sent after receiving one byte Load LSB EEPROM Address<br><br>I2C_write_byte (i2c_shiftreg);// temp1 = I2C_tdre_ack(); if(temp1 == FAIL) { *I2Cstatus = FAIL; return; } I2C_Receive_Data_Full (); // data = I2C_read_byte (); // I2C_stop (); // return data;<br><br>wait for receive data EEPROM Read data I2C Stop<br><br>} /*************************************************************** * Battery tamperature functon ****************************************************************/ void Read_Battery_Temp(void) { unsigned char temp; pstring0 = string0; pstring1 = string1; pstring2 = string2; pstring3 = string3; BT_temp[0] = readtemp(BT0_TEMP, (unsigned char *)temp); /* Read the I2C temp sensor 0 */ current_temp0=(BT_temp[0]-10); bin_to_ascii1(current_temp0,(unsigned char *)pstring0); BT_temp[1]= readtemp(BT1_TEMP, (unsigned char *)temp);/* Read the I2C temp sensor 1 */ current_temp1=(BT_temp[1]-10); bin_to_ascii1(current_temp1,(unsigned char *)pstring1);<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>32<br><br>BT_temp[2]= readtemp(BT2_TEMP, (unsigned char *)temp);/* Read the I2C temp sensor 2 */ current_temp2=(BT_temp[2]-10); bin_to_ascii1(current_temp2,(unsigned char *)pstring2); BT_temp[3]= readtemp(BT3_TEMP, (unsigned char *)temp);/* Read the I2C temp sensor 3 */ current_temp3=(BT_temp[3]-10); bin_to_ascii1(current_temp3,(unsigned char *)pstring3); } /*************************************************************/ void SW_delay(void) { int i; for(i=0;i<=32000;i++); } /*************************************************************/ void Read_Switch(void) { unsigned char SWON; SWON = PAIN | 0xC7; if(SW2==SWON) { DisplayBatType=TRUE; SW2LCDflg=OFF; if(SW2LCDflg!=ON) { LCD_clear(); LCD_setposition(0,0); LCD_prints("SELECT BATTERY"); SW2LCDflg=ON; } if(CountBatType==0x00) { SWON = 0xFF; battery_type=NICD; CountBatType=0x01; LCD_setposition(1,0); LCD_prints("TYPE Nicd"); } else if(CountBatType==0x01) { SWON = 0xFF; battery_type=NIMH; CountBatType=0x00;<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>33<br><br>LCD_setposition(1,0); LCD_prints("TYPE NiMH"); } SW_delay(); SwitchSW2flgON=TRUE; SwitchSW3flgON=FALSE; Enterflg=OFF; } if(SW3==SWON) { DisplayBatStatus=TRUE; SW3LCDflg=OFF; if(SW3LCDflg!=ON) { LCD_clear(); LCD_setposition(0,0); LCD_prints("SELECT DISP INFO"); SW3LCDflg=ON; } if(CountBatSet==0x00) { status_type=BATTERY_TYPE; CountBatSet=0x01; LCD_setposition(1,0); if( CountBatType==0x01) LCD_prints("BATTERY Nicd"); else LCD_prints("BATTERY NiMH"); } else if(CountBatSet==0x01) { status_type=BATTERY_VOLT; CountBatSet=0x02; LCD_setposition(1,0); LCD_prints("BATTERY VOLT"); } else if(CountBatSet==0x02) { status_type=BATTERY_CURRENT; CountBatSet=0x03; LCD_setposition(1,0); LCD_prints("BATTERY CURRENT"); } else if(CountBatSet==0x03) { status_type=BATTERY_TEMP; CountBatSet=0x04; LCD_setposition(1,0);<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>34<br><br>LCD_prints("BATTERY TEMP"); } else if(CountBatSet==0x04) { status_type=CHARGER_VOLT; CountBatSet=0x00; LCD_setposition(1,0); LCD_prints("CHARGER VOLT"); } SW_delay(); SwitchSW3flgON=TRUE; SwitchSW2flgON=FALSE; Enterflg=OFF; } if(SW4==SWON) { LCD_clear(); if(DisplayBatType==TRUE) { LCD_setposition(0,0); LCD_prints("BATTERY SELECTD"); } if(DisplayBatStatus==TRUE) { LCD_setposition(0,0); LCD_prints("STATUS SELECTD"); } SwitchSW3flgON=FALSE; SwitchSW2flgON=FALSE; DisplayBatType=FALSE; DisplayBatStatus=FALSE; Enterflg=ON; flg=FALSE; delayms(100); } } /**********************************************************************/ void Display_Battery_Parm(void) { char count_battery=0; pstring0 = string0; pstring1 = string1; pstring2 = string2; pstring3 = string3; bvstring = stringbv; bcstring = stringbc;<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>35<br><br>cvstring = stringcv; if(Enterflg==ON) { if(Status_type==BATTERY_TYPE) { if(battery_type==NICD) { if(flg!=TRUE) { LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY TYPE"); flg=TRUE; } LCD_setposition(1,0); LCD_prints("Nicd"); } if(battery_type==NIMH) { if(flg!=TRUE) { LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY TYPE"); flg=TRUE; } LCD_setposition(1,0); LCD_prints("NiMH"); } } if(status_type==BATTERY_VOLT) { if(flg!=TRUE) { LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY VOLT"); flg=TRUE; } LCD_setposition(1,0); LCD_prints(stringbv); } if(status_type==BATTERY_CURRENT) { if(flg!=TRUE)<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>36<br><br>{ LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY CURRENT"); flg=TRUE; } LCD_setposition(1,0); LCD_prints(stringbc); } if(status_type==BATTERY_TEMP) { if(count_battery==BT0) { if(flg!=TRUE) { LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY TEMP"); flg=TRUE; } LCD_setposition(1,0); LCD_prints(pstring0); count_battery++; delayms(150); } if(count_battery==BT1) { LCD_setposition(1,0); LCD_prints(pstring1); count_battery++; delayms(150); } if(count_battery==BT2) { LCD_setposition(1,0); LCD_prints(pstring2); count_battery++; delayms(150); } if(count_battery==BT3) { LCD_setposition(1,0); LCD_prints(pstring3); count_battery++; delayms(50); } } if(status_type==CHARGER_VOLT)<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>37<br><br>{ if(flg!=TRUE) { LCD_clear(); LCD_setposition(0,0); LCD_prints("CHARGER VOLT"); flg=TRUE; } LCD_setposition(1,0); LCD_prints(stringcv); } delayms(100); } }<br><br>/********************************************************************/ void Write_LED(void) { if ( status == CHARGING_COMPLETE) { PBOUT|=GREEN_LED_OFF; PBOUT&=RED_LED_ON; Buzzer_ON(); RedLEDFlg=TRUE; } else { PBOUT&= GREEN_LED_ON; PBOUT&= RED_LED_OFF; PCOUT &= BUZZER_OFF; GreenLEDFlg=TRUE; BuzzerONFlg=FALSE; } }<br><br>// Termination flag set, // battery charging LED indication Off // battery full charge indicator On<br><br>// battery charging in progress indicator<br><br>/**********************************************************************/ void Buzzer_ON(void) { LCD_clear(); LCD_setposition(0,0); LCD_prints("BATTERY CHARGING"); LCD_setposition(1,0); LCD_prints("COMPLETE"); PCOUT |= BUZZER_ON; BuzzerONFlg=TRUE;<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>38<br><br>} /**********************************************************************/ void Upload_Feedback(void) { unsigned int current_average_value; bvstring = stringbv; bcstring = stringbc; cvstring = stringcv; current_average_value=(average_value[0]<<1); bin_to_ascii1ong(current_average_value,(unsigned char *)bvstring); current_average_value=(average_value[1]>>1); bin_to_ascii1ong(current_average_value,(unsigned char *)bcstring); current_average_value=(average_value[2]<<2); bin_to_ascii1ong(current_average_value,(unsigned char *)cvstring); } /************************************************************************* * This will convert the binary value c into it's ascii representation * in hex. It will append the two ascii characters at the end of *buff * If you want to save it at the start of buff, make buff[0]='\0'; * This function will also null terminate the string. **************************************************************************/ static void bin_to_ascii1(unsigned char c, unsigned char *buff) { unsigned charh,k; /* read temperatur binary to ASCII conversion*/ for(h = 0;c >= 100;c -= 100,h++); for(k = 0;c >= 10;c -= 10,k++); *(buff+8) = ('0'+(c & 0x0f)); *(buff+7) = ((k & 0x0f) + '0'); *(buff+6) = ((h & 0x0f) + '0'); if(*(buff+6) == '0') { *(buff+6) = ' '; if(*(buff+7) == '0') { *(buff+7) = ' '; } } } /*****************************************************************/<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>39<br><br>static void bin_to_ascii1ong(unsigned int c, unsigned char *buff) { unsigned charh,k,l; /* read temperatur binary to ASCII conversion*/ for(l = 0;c >= 1000;c -= 1000,l++); for(h = 0;c >= 100;c -= 100,h++); for(k = 0;c >= 10;c -= 10,k++); *(buff+9) = ('0'+(c & 0x0f)); *(buff+8) = ((k & 0x0f) + '0'); *(buff+7) = ((h & 0x0f) + '0'); *(buff+6) = ((l & 0x0f) + '0'); if(*(buff+6) == '0') { *(buff+6) = ' '; if(*(buff+7) == '0') { *(buff+7) = ' '; if(*(buff+8) == '0') { *(buff+8) = ' '; } } } } / ****************************************************************************** *** ** End of file ****************************************************************************** ***/ /* *********************************************************** * File : initialize.c * Description : this file has initialization function of the project. * * Copyright 2005 ZiLOG Inc. ALL RIGHTS RESERVED. * * The source code in this file was written by an * authorized ZiLOG employee or a licensed consultant. * The source code has been verified to the fullest * extent possible. * * Permission to use this code is granted on a royalty-free * basis. However users are cautioned to authenticate the * code contained herein.<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>40<br><br>* * ZiLOG DOES NOT GUARANTEE THE VERACITY OF THE SOFTWARE. **************************************************************/ #include <stdio.h> #include <ez8.h> #include "Battery_Charger.h" unsigned char delaytwominute=0,delay30minute=0; extern int average_value[CHANNELS + 1]; extern int adc_value[CHANNELS + 1]; extern int old[CHANNELS + 1]; extern int max; extern int battery_type; extern int Vset, Iset, Ilim; extern int eoc_value, last_eoc_value; extern int eoc_update_timer; extern unsigned char Read_Feedback_flg, safety_flgON,status,Termination_flgON; extern int new_pwl, new_pwh,timer_count; extern unsigned int current_ms;// Increment count //////////// for resting//////////// // extern unsigned char store_battery_voltage[]; // for testing // extern unsigned char reading_counter; //////////////////////////////////// void Init_Timer(void) { // ---------------------------------------------------------// Initialize timer 0 SET_VECTOR(TIMER0, isr_timer0); // Set interrupt service routine ISR for // timer0 T0H = 0x00; // Timer High T0L = 0x00; // Timer Low T0RH = 0x5A; // Reload Compare High and Low - from // 0x5A00 // to 0x3600 T0RL = 0x00; // from 5ms to 10 mS and from 20MHz to // 5.5296MHz T0CTL = 0x11; // Timer Control#00010001b // | ||_|_______ continuous mode of operation // |_|__________ divide by 4 Prescale // Set Timer0 as Level2 (Nominal) priority interrupt IRQ0ENH |= 0x20; // IRQ0 Enable High for Timer0 IRQ0ENL &= 0x00; // IRQ0 Enable Low T0CTL |= 0x80; // Enable timer0. // ------------------------------------------------// Initialize timer 1 // Initialize Timer 1 in continuous PWM // mode with prescale = 1<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>41<br><br>T1CTL T1RH T1RL T1PWMH T1PWML<br><br>= 0x03; = 0x01; = 0x70; = 0x01; = 0x00;<br><br>// // // // // // //<br><br>PWM mode, Prescale 1, not enabled. RELOAD High RELOAD Low 0x0170 = 50KHz at 18.432MHz sysclk PWM High PWM Low Define destination address for ADC-DMA<br><br>T1CTL<br><br>|= 0x80;<br><br>/********************/// Enable timer, // rest same.<br><br>} void Init_ADC(void) { ADCCTL = 0x10; } void Init_I2C(void) { I2CBRH = 0x03; I2CBRL = 0x99; I2CCTL = 0x80; } void Init_Port(void) { unsigned int RAM_Location; int i;<br><br>// ADC initialization // Internal Vref, Single Shot, Analog // channel 0, not enabled<br><br>PAADDR = ALT_FUN; PACTL |= 0xC0;<br><br>// // // // // // // // // //<br><br>Initialize PORTA I2C alternate function Port C alternate function -(I2C Mode) - Selecting Alternate Function for PA6(SCL),PA7(SDA) Initialize PORT A GPIO FOR LCD function, Buzzer function Port C data direction PC2,PC3,PC4,PC5 output, rest input.<br><br>PCADDR = DATA_DIR; PCCTL = 0x00;<br><br>PAADDR = DATA_DIR; PACTL |= 0xF8;<br><br>// Initialize PORT C GPIO FOR LCD function // Port A data direction // PA0,PA1,PA2 output, rest input. // // // // Initialize PORT A GPIO FOR switch function Port S data direction PA3,PA4,PA5 input, rest unchanged.<br><br>PAADDR = DATA_DIR; PACTL |= 0x28;<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>42<br><br>// Initialize PORT B GPIO FOR LED function PBADDR = DATA_DIR; // Port B data direction PBCTL &= 0x07; // PB3,PB4 input, rest unchanged. PBADDR = HIGH_DRIV; PBCTL |= 0x18; PBOUT =0xFF; // Initialize PORTB ADC alternate function PBADDR = ALT_FUN; // Port B alternate function PBCTL |= 0x07; // - PB0,PB1,PB2, = ADC Inputs // Initialize PORTC PWM alternate function PCADDR = ALT_FUN; // Port C alternate function PCCTL |= 0x02; // - PC1 = Timer 1 output Iset = DC_DCI*2; Vset = 300; }<br><br>// 300 corresponds to 3000mV output.<br><br>/* ****************************************************************************** ** ** Routine : isr_timer0 ** Parameters : None ** Return : int ** ** Purpose: ** This is the ISR for the battery charger. ** It updates the duty cycle every 10 miliseconds. ** It updates the fullcharge test values every 10 seconds. ** ****************************************************************************** */ #pragma interrupt void isr_timer0() { DI(); current_ms++ ; // Increment count for LCD delay timer_count++; if(status!= CHARGING_COMPLETE) { if(timer_count==5) { eoc_update_timer = eoc_update_timer + 1; // condition for // updating termination // values<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>43<br><br>Read_Feedback_flg=ON; timer_count=0; read_feedback_values(); calculate_pwm_value(battery_type); T1CTL &= 0x7F; // Disable timer for // modifications T1PWMH = new_pwh; // PWM High T1PWML = new_pwl; // PWM Low //////////// for testing////////// // T1PWMH = 0x00; // PWM High for testing // T1PWML = 0x50; // PWM Low fpr testing /////////////////////////////////// T1CTL |= 0x80; // Enable timer, rest same. } if (eoc_update_timer == 5000) // Store end_of_charging // every 10 seconds { // values last_eoc_value = eoc_value; // update last value eoc_value = average_value[0]; // update present value eoc_update_timer = 0; // Reset every 10 // seconds safety_flgON=ON; if (delay30minute >=12) Termination_flgON=ON; delaytwominute++; delay30minute++; /////////////////testing code//////////////// // store_battery_voltage[reading_counter++]=average_value[0]; // delaytwominute=0; ///////////////////////////////// } } else { T1CTL &= 0x7F; T1PWMH = 0x01; T1PWML = 0x69; T1CTL |= 0x80; } EI();<br><br>// // // //<br><br>Disable timer for modifications PWM High PWM Low Enable timer, rest same.<br><br>} /* ****************************************************************************** ** End of File ****************************************************************************** */ /* *********************************************************<br><br>AN022901-0905<br><br>Appendix H--Source Code<br><br>Z8<br><br>Encore!® Based<br><br>Application Note AA Type NiMH and NiCd Battery Charger Reference Design<br>44<br><br>* File : i2c.c * Description : To Generate the APIs (Application programme interface) * for I2C hardware of Z8ENCORE Microcontroller. * This program implements the APIs and the relevent * functions of individual API are Commented out. * This API can be directly used to control the I2C functionality. * * Copyright 2005 ZiLOG Inc. ALL RIGHTS RESERVED. * * The source code in this file was written by an * authorized ZiLOG employee or a licensed consultant. * The source code has been verified to the fullest * extent possible. * * Permission to use this code is granted on a royalty-free * basis. However users are cautioned to authenticate the * code contained herein. * * ZiLOG DOES NOT GUARAN<br/><br/><br/>
<!-- Ezoic - Search Break Responsive - top_of_page -->
<div id="ezoic-pub-ad-placeholder-110">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Preview Manual Leaderboard Responsive -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-2156279550025329"
data-ad-slot="6566435862"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
<!-- End Ezoic - Search Break Responsive - top_of_page -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-2001630-7"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-2001630-7');
</script>
</body>
</html>