AN55102 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Author: Archana Yarlagadda Associated Project: Yes Associated Part Family: CY8C21x23, CY8C21x34 ® Software Version: PSoC Designer™ 5.4 Related Application Notes: AN2041 To get the latest version of http://www.cypress.com/?rID=38367 this application note, or the associated project file, please visit ® AN55102 presents a Lithium-Ion (Li-Ion) battery charger design, with the smallest, low-cost PSoC 1 device – CY8C21x23. This application note includes a dedicated PC-based software developed to perform real time charge process monitoring and analysis. Contents 1 2 3 4 5 6 1 Introduction ...............................................................1 PSoC Resources ......................................................2 2.1 PSoC Designer ................................................2 2.2 Code Examples ...............................................3 2.3 Technical Support ............................................4 Battery Charging Method ..........................................5 Temperature Control ................................................6 Charger Hardware ....................................................7 5.1 Low Side Current Sense ..................................8 5.2 Voltage Sense ............................................... 10 5.3 Temperature Measurement ........................... 10 5.4 Self Modulator Circuit .................................... 11 5.5 LED Control ................................................... 11 Charger Firmware................................................... 12 6.1 State Descriptions.......................................... 13 6.2 State Transition Descriptions ......................... 13 6.3 Current/Voltage Control ................................. 14 Production Calibration Procedure ........................... 16 PC Utilities and Debug Information ........................ 18 Design Enhancements ........................................... 20 9.1 Higher Charge Capacity Battery Charger ...... 20 10 Multicell Battery Charger ........................................ 21 10.1 Tiered Charge Profile..................................... 21 11 Appendix A: Charger Schematic for 8-pin CY8C21123 ................................................... 22 12 Appendix B: Charger Schematic for 16-pin CY8C21223 ................................................. 23 13 Appendix C: Charger BOM for CY8C21123/CY8C21223 ....................................... 24 14 Appendix D: Firmware Flow Chart .......................... 25 Worldwide Sales and Design Support ............................. 28 7 8 9 Introduction Li-Ion batteries have the greatest capacity to volume ratio and are found in notebooks, pocket PCs, cell phones, and other cutting-edge consumer products. This application note describes a single cell Li-Ion battery charger for a 500 mAh battery using the smallest and lowest-cost chip in the PSoC family, CY8C21x23.The battery capacity and other battery parameters can easily be changed by modifying corresponding constants in the firmware to support different batteries. Multiple methods such as, self modulated voltage reference, pin multiplexing, time multiplexing of resources, and code optimization have been used to implement the design in this chip. The charger can be embedded into consumer and home appliances or industrial applications. The production level design can be implemented in an 8-pin CY8C21123 device. The development can be done in CY8C21223 to add the digital communication required for charge monitoring. www.cypress.com Document No. 001-55102 Rev. *E 1 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 2 PSoC Resources Cypress provides a wealth of data at www.cypress.com to help you to select the right PSoC device for your design, and quickly and effectively integrate the device into your design. In this document, PSoC refers to the PSoC 1 family of devices. To learn more about PSoC 1, refer to the application note AN75320 - Getting Started with PSoC 1. The following is an abbreviated list for PSoC 1: Overview: PSoC Portfolio, PSoC Roadmap Datasheets: Describe and provide electrical specifications for the PSoC 1 device family. 2.1 Product Selectors: PSoC 1, PSoC 3, PSoC 4, or PSoC 5LP. In addition, PSoC Designer includes a device selection tool. Application Notes and Code Examples: Cover a broad range of topics, from basic to advanced level. Many of the application notes include code examples. Technical Reference Manuals (TRM): Provide detailed descriptions of the internal architecture of the PSoC 1 devices. Development Kits: CY3215A-DK In-Circuit Emulation Lite Development Kit includes an in-circuit emulator (ICE). While the ICE-Cube is primarily used to debug PSoC 1 devices, it can also program PSoC 1 devices using ISSP. CY3210-PSOCEVAL1 Kit enables you to evaluate and experiment Cypress's PSoC 1 programmable system-on-chip design methodology and architecture. CY8CKIT-001 is a common development platform for all PSoC family devices. The MiniProg1 and MiniProg3 devices provide an interface for flash programming. PSoC Designer PSoC Designer is a free Windows-based Integrated Design Environment (IDE). Develop your applications using a library of pre-characterized analog and digital peripherals in a drag-and-drop design environment. Then, customize your design leveraging the dynamically generated API libraries of code. Figure 1 shows PSoC Designer windows. Note: This is not the default view. 1. Global Resources – all device hardware settings. 2. Parameters – the parameters of the currently selected User Modules. 3. Pinout – information related to device pins. 4. Chip-Level Editor – a diagram of the resources available on the selected chip. 5. Datasheet – the datasheet for the currently selected UM 6. User Modules – all available User Modules for the selected device. 7. Device Resource Meter – device resource usage for the current project configuration. 8. Workspace – a tree level diagram of files associated with the project. 9. Output – output from project build and debug operations. ® Note: For detailed information on PSoC Designer, go to PSoC Designer Specific Documents > IDE User Guide. www.cypress.com Document No. 001-55102 Rev. *E Designer > Help > Documentation > 2 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 1. PSoC Designer Layout 2.2 Code Examples The following webpage lists the PSoC Designer based Code Examples. These Code Examples can speed up your design process by starting you off with a complete design, instead of a blank page and also show how PSoC Designer User modules can be used for various applications. http://www.cypress.com/go/PSoC1Code Examples To access the Code Examples integrated with PSoC Designer, follow the path Start Page > Design Catalog > Launch Example Browser as shown in Figure 2. Figure 2. Code Examples in PSoC Designer www.cypress.com Document No. 001-55102 Rev. *E 3 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 In the Example Projects Browser shown in Figure 3, you have the following options. Keyword search to filter the projects. Create a new project (and a new workspace if needed) based on the selection. This can speed up your design process by starting you off with a complete, basic design. You can then adapt that design to your application. Listing the projects based on Category. Review the datasheet for the selection (on the Description tab). Review the code example for the selection. You can copy and paste code from this window to your project, which can help speed up code development, or Figure 3. Code Example Projects, with Sample Codes 2.3 Technical Support If you have any questions, our technical support team is happy to assist you. You can create a support request on the Cypress Technical Support page. You can also use the following support resources if you need quick assistance. Self-help Local Sales Office Locations www.cypress.com Document No. 001-55102 Rev. *E 4 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 3 Battery Charging Method Lithium based batteries use a two-stage charge profile: activation and rapid charge stages. If the battery voltage is less than 3.0 V, it means the cell is completely discharged and the battery must be activated. In the activation stage, the battery is charged with a small constant current (typically 0.05 to 0.015 CA, where CA is the nominal battery capacity) until the battery voltage reaches the desired level. The battery activation time is limited to approximately 1.5 to 3 hours, depending on battery manufacturer recommendations. If, during activation time, the battery voltage does not rise above 3.0 V, the battery cell is considered damaged. The rapid charge stage starts after the activation stage. Rapid charge consists of two modes: constant voltage and constant current. When the battery voltage is less than a specified level (typically 4.2 V, but depends on battery manufacturer specifications), the charge is executed with the constant current (about 0.5 to 1 CA, depending on the battery manufacturer recommendations). When the battery voltage reaches the specified level, the charge source switches to the constant voltage mode (4.2 V). If the charge current drops below a specified limit, the charge process terminates; the battery manufacturer recommends the users to set the rapid termination current to 0.07 to 0.2 CA. The rapid charge stage must be protected by a timeout. The constant current time is estimated to provide 100% to 120% of the battery charge because during this mode the battery is charged up to 70% to 80%. The constant voltage charge time is limited to approximately two hours, according to the manufacturer recommendations. Figure 4 depicts the Li+ battery charge profile. Table 1 contains descriptions of the charge profile parameters and default values used in this design. Note that Li+ batteries are very sensitive to the charge voltage, current, and discharge limit. Therefore, they are assembled with a built-in thermistor and protective circuit. This circuit protects the battery from over-charge and overdischarge, and limits the load and charge current to safe values. Without this circuit, the battery can explode under adverse conditions. The charge source voltage limit accuracy must be better than 1%. Figure 4. Li+ Battery Charging Profile VMAX 8 7 VFULL VBATT VRE-CH 9 6 VRS IMAX 4 IRAP 2 VACT IACT ITERM ICHARGE 5 1 3 13 tSTART 14 tACT 10 www.cypress.com tRAP 11 Document No. 001-55102 Rev. *E tTERM tVCONST 12 5 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Table 1. Example of Charge Profile Parameters and Values Marker Parameter Description Value Charging Parameters 1 IACT Activation charge current 80 mA ± 30 mA 2 IRAP Rapid charge current 500 mA ± 40 mA 3 ITERM Termination current (use average of ICH over 1 second) 60 mA ±15 mA 4 IMAX Emergency charge stop current 600 mA ± 60 mA 5 VACT Activation charge start voltage 2.0 V ± 0.1 V 6 VRS Rapid charge start voltage 3.0 V ± 0.1 V 7 VFULL Full charge voltage 4.2V ± 0.03 V 8 VMAX Emergency charge stop voltage 4.35 V ± 0.1 V 9 VRE-CH Recharge voltage 4.0 V ± 0.1 V Timing Requirements 10 tACT Time limit for battery activation period 140 min 11 tRAP Time limit for constant current rapid charge period 80 min 12 tVCONST Time limit for constant voltage charge period 120 min 13 tSTART Maximum time for battery activation (while VBATT < VACT) 20 sec 14 tTERM Minimum time for charge complete (when ICHARG ≤ ITERM) 10 sec Additional Parameters 4 15 IMIN Minimum current for battery health test 25 mA 16 VDC_Vdd Charger power supply voltage 5.2 V ± 0.2 V Temperature Control The charge process can be activated only if the battery temperature is within a specified limit. Typical temperature values are 0 °C to +50 °C. Figure 5 depicts the temperature profile. Table 2 contains descriptions of the temperature profile parameters and default values used in this design. Thermistor resistance is also used to check for the battery presence. The battery is considered disconnected when the measured thermistor resistance is greater than ROPEN. This means there is no thermistor; therefore, no battery pack is connected. A tiered current profile, with lower current at higher temperature can be supported with modifications to the software. More information is provided in the Design Enhancements section of this application note. www.cypress.com Document No. 001-55102 Rev. *E 6 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 5. Temperature Profile ROPEN 5 THOT_STOP 3 THOT_RESTART 4 No charging TBATT 2 TCOLD_RESTART TCOLD_STOP 1 Charge in process Charge in process Table 2. Temperature Related Parameters Marker 5 Parameter Description Value 1 TCOLD_STOP Stop temperature measured from battery thermistor 0 °C 2 TCOLD_RESTART Restart temperature measured from battery thermistor TCOLD_STOP + 1 °C 3 THOT_STOP Stop temperature measured from battery thermistor 50 °C 4 THOT_RESTART Restart temperature measured from battery thermistor THOT_STOP – 2 °C 5 ROPEN Thermistor resistance limit for determining open circuit 40 kΩ (-7 °C) Charger Hardware Figure 6 shows the general structure of the charger. The following abbreviations are used within the PSoC block. RS_TX: EIA-232 (RS-232) transmitter for debug purposes (uses external transceiver). It reports temperature, voltage, and current to a PC. RS_TX is used only in the debug stage and may be removed in the released product. CPU: Central processor core for implementing charge algorithms and performing charge control functions. PWM: Pulse-width modulator for driving the regulator. ADC: Single Slope analog-to-digital converter for digitizing the analog signals. AMUX: Analog multiplexers. The signal from the PWM goes to a low-pass RC-filter (R8 and C1). The output of the RC filter is a constant voltage signal proportional to the PWM duty cycle value. This output is connected to the base of the Q1 transistor. Therefore, the PWM with an RC-filter is a PWM-DAC. The NPN transistor Q1 is driven by an analog signal from the PWM DAC and regulates the battery charge current. The PWM period is set to 255 for accuracy, and can easily be adjusted in the firmware. The combination of Q2 and Q1 avoid reverse current, which can discharge the battery when it is still connected and the charger is turned off from the supply voltage. There is a 0.25 Ω resistor used as the current sensor. Other resistors form the battery interface to allow transformation of the battery current, voltage, and temperature into the signals that have a suitable voltage range for the PSoC analog inputs. www.cypress.com Document No. 001-55102 Rev. *E 7 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 6. Charger Structure Q2 Supply Vdd SERIAL_TX Current/Voltage Control RS_TX ( debug only) CPU R5 Q1 PWM R8 Li- ion battery pack C1 R20 Charge+ Vref CMP R2 Vbg 1.3V T sense Temperature Sense C2 R1 T R3 ADC Charge and PSoC GND Voltage Sense AMUX R2 R4 R9 D1 PSoC internals Charge and PSoC GND R10 Current Sense LED Control Charge and PSoC GND R 11 to R14 Supply GND To correctly implement charge algorithms, the following must be measured accurately: charge current, battery voltage, and temperature. As the voltage drops on the corresponding resistors, all parameters are measured using the ADC. To limit current flow from the battery through the interface resistors for current and voltage measurement, precision resistor dividers with large resistor values are used. 5.1 Low Side Current Sense The current measurement is on the low side as shown in Figure 7, where the current flowing out of the negative terminal of battery (Node N1 to Node N2) is measured. Figure 7. Current Sense Circuit Vref N4 Li-ion battery pack R9 iSense N3 R10 T iCharge Supply GND N2 N1 R11 to R14 www.cypress.com Document No. 001-55102 Rev. *E Battery and PSoC GND 8 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 The current shunt resistor is outside the PSoC supply voltage to maximize and keep constant voltage range for the ADC in the PSoC. This avoids the ground being at a different potential depending on the current flow into the battery. The voltage value to be measured at Node N2 is negative with respect to PSoC, which has the ground at Node N1. Thus, a reference voltage and a summing node are required to pull this to a positive value. The reference voltage is generated using the self modulator circuit described later in this document. The advantage of this approach is that the voltage is pulled to a range higher than the offset of the ADC and thus the error due to offset can be compensated. Precise accuracy of current measurement is necessary, when near the 4.2 V battery voltage. Therefore, during the general calibration procedure, when the transistor Q1 is off, measure the voltage bias on the current sense resistor and store it in nonvolatile memory. Subtract this memorized bias voltage from each measurement value during the normal charge process. The following equation depicts this measuring scheme: n ni VCh arg e ADC max V ADC max nbias n nbias Vref bias ADC max V ADC max VCh arg e I Ch arg e i Equation 1 Equation 2 Equation 3 Where, nbias is the ADC code when ICharge is zero ∆ni is the ADC code after removing the bias voltage and ADC offset voltage nADCmax is full scale ADC code and the value is equal to 1023 for a 10-bit single slope ADC VADCmax is full scale ADC voltage for the full scale ADC code ICharge is battery charge current Vref is self modulated reference voltage (1.3 V) bias is the resistive divider coefficient for Vref. (equal to 0.25 when R10 = 100 kΩ and R9 = 300 kΩ) R 10 bias R 10 R9 i Equation 4 is the coefficient to convert the current iCharge into voltage iSense (equal to 0.1875 when R10 = 100 kΩ, R9 = 300 kΩ, and R11 = 0.25 Ω) R9 R R 9 10 i R11 www.cypress.com Equation 5 Document No. 001-55102 Rev. *E 9 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 5.2 Voltage Sense The battery voltage is scaled down to the range of the ADC10 by using the resistor divider R3 and R4 shown in Figure 8. Li-ionCircuit battery pack Figure 8. Voltage Sense VBatt R3 VSense T R4 Battery and PSoC GND The scaling is such that 4.2 V, which is the most accurate measurement required, corresponds to the 1.3 V to which the ADC10 is calibrated. The VSense voltage signal is measured by the Single Slope ADC (ADC10). n nV VBatt V ADC max VADC max Equation 6 Where, VBatt is battery voltage. βV is the resistive divider coefficient (equal to 0.306 for R3 = 22.6 kΩ and R4=10 kΩ): R 4 V R 4 R3 Equation 7 To obtain accurate voltage measurements, a calibration technique is used. The PSoC’s bandgap reference voltage error and ADC gain causes a non-calibrated voltage measurement error. The calibration procedure with external voltage reference compensates for all gain errors. The single slope ADC is calibrated by modifying the capacitor value to obtain the expected counts for a bandgap voltage measurement, and this value is stored in flash. This value is used for every measurement cycle to calibrate the ADC to compensate for any gain errors or temperature variations. The complete details of calibration are given in a following section of this document. 5.3 Temperature Measurement Temperature measurement is implemented with resistor R1 and the thermistor in the battery, as shown in Figure 9. The voltage VT across the thermistor is measured with the ADC, using equations 8 and 9. The reference bias voltage Vref is obtained with a self modulator circuit that is described later. www.cypress.com Document No. 001-55102 Rev. *E 10 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 9. Temperature Measurement Li-ion battery pack VBatt Vref R1 T VT Battery and PSoC GND n nT Vref T ADC max VADC max R Equation 8 therm T R therm R1 Equation 9 The thermistor transfer function is nonlinear, but there is no need to obtain the temperature value in linear units for this design. Therefore, only the temperature thresholds during the charge must be checked. This is done by analyzing the ADC code (nT). Hysteresis is added for the lower and upper bounds of the in/out temperature range to prevent multiple triggers when the temperature is close to the preset range (see Figure 5). 5.4 Self Modulator Circuit The CY8C21x23 PSoC device does not have any analog output pins and can provide no native analog reference voltage. The self modulator circuit is formed with the comparator block and an external RC low-pass filter as shown in Figure 10. The feedback causes the comparator output to turn ON and OFF with a duty cycle. The average voltage after the low-pass filter is equal to Vbg. This technique has a pending patent and it should be used only with Cypress products. 5.5 LED Control An LED is used to indicate charger state. Because the project uses a small package with low pin count, the temperature sense and LED control are multiplexed. The drive mode of the pin is set to “HI-Z, Analog” when the temperature measurement is performed and to “Strong” high when the LED function is ON. All possible states displayed by the LED are described in Table 3. Table 3. LED States No. Charger State Led State 1 Charge (Activate, Rapid States) ON 2 Charge Complete, No Battery States OFF 3 Temperature Over Range, Battery Error BLINKING www.cypress.com Document No. 001-55102 Rev. *E 11 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 6 Charger Firmware The charger firmware consists of two parts: one is the main charging functionality and the other is intended to calibrate the charger in the factory. The main part of the firmware is built as a state machine. A diagram of the various states of the state machine is shown in Figure 11. The order of connecting and disconnecting the three battery terminals is random. The physical ordering of the signals on the connector can vary from design to design. Therefore, all the possible sequences of Battery+, Battery-, and Thermistor connections and disconnections are allowed when a battery is installed or removed. There is no ordering that results in a lockup condition, or result in false error detection. Figure 10. Self Modulator Circuit PSoC P1[1] Vbg Comparator Bus _ P0[0] Voltage Reference Global Bus + Figure 11. Charger State Diagram reset d No Battery l Initialization f Charge Complete k e g a j Battery Error i Activation j h b c Wait For Temperature j Rapid Charge www.cypress.com Document No. 001-55102 Rev. *E 12 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 6.1 State Descriptions No Battery: LED = OFF, no charge. Waits for the battery to be connected. Initialization: LED = ON. Determines the battery presence and its state. If thermistor is present but the battery voltage value is below VACT, a short time battery initialization by IACT current is used. Activation: LED = ON. Charge by constant IACT current until voltage reaches VRS. Rapid Charge: LED = ON. Constant current mode at IRAP until voltage reaches VFULL. Then changes to constant voltage until current falls below ITERM. Charge Complete: LED = OFF, done charging. Wait for the battery to be removed, or for voltage to drop below V RECH to restart charge. Battery Error: LED = BLINK and turn off charge. Error condition. Wait for the battery to be removed, or power cycled. Wait For Temperature: LED = BLINK, stop charging. Temperature is outside of the desired range limits. Wait for the temperature to return within the limits. Then move to the Initialization state. 6.2 State Transition Descriptions a) IF VACT < VBATT ≤ VRE-CH THEN Activation Current If the battery is detected and the battery is not already charged, then turn the LED on and transition to Activation. b) IF VRS ≤ VBATT < VMAX THEN Rapid Charge If the battery voltage rises above the Rapid Charge start voltage, then transition to Rapid Charge. c) IF VFULL ≤ VBATT < VMAX AND ICHARGE ≤ ITERM for tTERM seconds THEN Charge Complete If charge current falls below ITERM for tTERM seconds after the battery voltage has reached V FULL, turn off charge current and turn off status LED and transition to Charge Complete. d) IF RTHERMISTOR ≥ ROPEN THEN Wait for Battery If a battery is disconnected, then transition to No Battery. e) IF VBATT ≤ VRE-CH THEN Initialize the Charging Process If the battery voltage falls below the re-charge voltage, then transition to Initialization. f) IF VRE-CH < VBATT THEN Charge Complete If the battery is detected and is fully charged then turn off the LED and transition to Charge Complete. g) IF VBAT < VACT for tACT seconds THEN Battery Error If the battery voltage is less than VACT after tSTART seconds of activation current, then turn off charge current, BLINK LED, and transition to Battery Error. h) IF VBATT ≥ VMAX OR ICHARGE ≥ IMAX OR Constant Current Charge Duration > tRAP www.cypress.com Document No. 001-55102 Rev. *E 13 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 OR Constant Voltage Charge Duration > tVCONST THEN Battery Error When the battery voltage exceeds VMAX, turn off charge current, BLINK LED, and transition to Battery Error. If the charge current is greater than IMAX, turn off charge current, BLINK LED, and transition to Battery Error. If the constant current charge time is longer than t RAP, or the constant voltage charge mode lasts longer than tVCONST seconds, then turn off charge current, BLINK LED, and transition to Battery Error. i) IF VBATT ≥ VMAX OR ICHARGE ≥ IMAX OR after tACT seconds: VBATT < VRS THEN Battery Error When battery voltage exceeds VMAX, turn off charge current, BLINK LED, and transition to Battery Error. If charge current is greater than IMAX, turn off charge current, BLINK LED, and transition to Battery Error. If the activation mode lasts longer than t ACT seconds, then turn off the charge current, BLINK LED, and transition to Battery Error. When battery voltage exceeds VMAX and charge current is less than IMIN (indicating battery lead path is broken), then BLINK LED and transition to Battery Error. j) IF TBATT ≤ TCOLD_STOP OR TBATT ≥ THOT_STOP THEN Temperature Outrange When temperature reading from thermistor is out of range, turn off charge current, turn LED OFF, and transition to Wait For Temperature. k) IF TBATT > TCOLD_RESTART AND TBATT < THOT_RESTART THEN Resume Charging When temperature reading returns to operation range, restart charge in Initialization. l) IF RTHERMISTOR < ROPEN THEN Initialize the Charging Process If a battery is detected, then transition to Initialization. 6.3 Current/Voltage Control To build a Li+ battery charger, the regulator must be capable of regulating both charge current and voltage. This charger employs a simple adaptive regulator. The regulator operation is based on increasing the PWM duty cycle if the charge voltage or charge current is smaller than the desired value. If the charge voltage or current are greater than the desired value, the PWM duty cycle is decreased. The circuit for the current control is shown in Figure 12. The PWM output is converted into a DC voltage value by using the RC low-pass filter (LPF). This voltage, when greater than the threshold voltage of transistor Q1, along with the resistor R20, determines the current in Q1 transistor. This in turn controls the current in Q2 transistor and thereby the current into the battery. www.cypress.com Document No. 001-55102 Rev. *E 14 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 12. Regulation Circuit Li-ion battery pack Q2 Supply Vdd T R5 Battery and PSoC GND PWM output Q1 R8 C1 R20 The PNP transistor Q2 also acts as a diode, preventing the battery from discharging when no power is applied to the charger. Figure 13 illustrates the regulator operation. Figure 13. Charger Regulator Operation VBATT VBATT<VFULL +STEP ICHARGE IREG VBATT ICHARGE<IREG AND PWM pulsewidth 0..PWMmax PWMDAC VBATT>VFULL -STEP ICHARGE IREG ICHARGE>IREG OR To obtain faster current regulation, a scheme with an adaptive step regulator is used (see Figure 14). If the regulator current is greater than the charge current by the Imis1 predefined value, the regulator step is set equal to STEP1. Current differences of Imis2 and Imis3 correspond to STEP2 and STEP3, respectively. If the difference between the target charge current and the measured current is minimum (Imis3), then the PWM step is set to ‘1’. With current difference of ImisOver, STEP_OVER is used for a fast reaction to minimize current overflow. When the battery voltage rises above 4.2 V and the FConstVoltage flag is set, the regulator step is set to ‘1’ and there is no change to the step size during the constant voltage charge period. www.cypress.com Document No. 001-55102 Rev. *E 15 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 14. Adaptive Step Charge Regulator Step = STEP_OVER Ireg Imis3 Imis2 Imis1 ImisOver Step = 1 Step = 1 Step = STEP3 Step = STEP2 Ich Step = STEP1 7 Production Calibration Procedure As previously mentioned, all devices must be calibrated during the manufacturing process. Calibration is an easy procedure but needs a precise 4.20 V source, instead of a battery, connected to the charger connector. It also needs P1[1] (pin 4 of the ISSP connector) connected to ground as shown in Figure 15. After start, the charger is used to check the P1[1] pin. If P1[1] is externally pulled down, then the charger goes to calibration mode. P1[1] is connected to pin 4 of the ISSP connector and the PSoC ground is connected to pin 2 of ISSP connector (J2, see schematic in Appendix A: Charger Schematic for 8-pin CY8C21123). In this mode, transistors Q1 and Q2 are off, and the charger measures the constant 4.20 V. The voltage sense resistors (R3 and R4) are chosen such that 4.2 V is scaled down to 1.3 V. Figure 15. Setup for Calibration Vdd 1 2 Power connector 1 2 3 4 5 ISSP/Debug Connector + Battery Precision Connector T 4.20 V source - Charger The Single Slope ADC (ADC10) is calibrated with the internal bandgap voltage, which is nominally 1.3 V. Thus, scaling down 4.20 V to 1.3 V ensures accurate reading at that point. The calibration of the single slope ADC is shown in Figure 16. www.cypress.com Document No. 001-55102 Rev. *E 16 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 16. Block Diagram of Single Slope ADC Vdd RAMP Generator ENABLE ADC Vin Comparator Counter CAPVAL PWM The current into the CAPVAL is started at the start of an ADC conversion and a voltage ramp is generated. The comparator trips when the ramp voltage value reaches the input voltage. The Counter counts the time from the start of the current to the trip of the comparator. The PWM controls the ON and OFF times of the conversion. During PWM ON, the voltage ramp is on and the Counter counts. During PWM OFF, the capacitor is discharged and the answer is processed. The calibration function (ADCCAL) adjusts the value of CAPVAL and hence the slope of voltage ramp for full scale The calibration function (ADCCAL) of the ADC changes the CAPVAL capacitor value to obtain the desired ADC counts for the internal bandgap voltage. The firmware is setup to do the following: Step 1: An initial ADC counts value, as shown in Equation 10, is assigned to n niCAL Vbandgap ADC max VADC max niCAL . Equation 10 Step 2: ADC10 is calibrated with the ADCCAL function with niCAL as the counts for bandgap voltage. nV (Vsense = 4.20 V). Step 4: niCAL is increased if nV > niCAL or decreased if nV < niCAL . Step 5: Step 2 to Step 4 is repeated till nV == niCAL Step 6: niCAL is stored in flash and used as the ADC calibration point for every measurement cycle. Step 3: Vsense is measured, Step 7: The calibration function remains in an infinite NOP loop until a reset occurs. www.cypress.com Document No. 001-55102 Rev. *E 17 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 8 PC Utilities and Debug Information The charger control software monitors the charge process. The program interface is simple (Figure 17). Set the COM#, press the Start button, and then turn on the charger. The software then presents the charger state and displays graphs with charge current and voltage (see Figure 17). The default values for the software must be changed to match the profile required by clicking on the “Settings”. For the project accompanying this application note (500 mAh battery charger), the settings are shown in Figure 18. Figure 17. PC Charger Monitoring Software www.cypress.com Document No. 001-55102 Rev. *E 18 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 18. Settings Window for the Associated Project The charger can send two kinds of packets to the PC utility. Both packets are in text format and all values are hexadecimal. The first packet is an initialization packet that is sent once, after the charger is powered on. This package has a length of 22 bytes and contains the stored nonvolatile memory voltage thresholds that are set in the code. Packet details are represented in Table 4. The packet’s structure is shown in Figure 19. Table 4. Initialization Package No. Length in Bytes Reference Description 1 1 I Character ‘I’ as start marker of initialization packet 2 4 VFULL 4-digit hexadecimal value of full-charge voltage (ADC code) 3 4 VACT 4-digit hexadecimal value of activation start voltage (ADC code) 4 4 VRS 4-digit hexadecimal value of rapid start voltage (ADC code) 5 4 VMAX 4-digit hexadecimal value of emergency stop voltage (ADC code) 6 4 VRE_CH 4-digit hexadecimal value of re-charge start voltage (ADC code) 7 1 CR Character with ASCII code 13 (CR) as marker of end of packet Figure 19. Initialization Package Structure 0 ‘I’ 1 4 VFULL 5 8 VACT 9 12 VRS 13 16 VMAX 17 20 VRE-CH 21 CR The second packet is sent regularly and contains the current state of the charger battery voltage, charger current, temperature values, and errors. Using this packet, the PC utility builds charts and displays actual battery parameters. This packet has a length of 16 bytes. Packet details are represented in Table 5. The packet’s structure is shown in Figure 20. www.cypress.com Document No. 001-55102 Rev. *E 19 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 The program in the PSoC does not calculate the actual current and voltage in amperes and volts. It only looks at ADC counts and makes state machine decisions based on them. The PC utility calculates the amperes and volts for debugging purposes. Table 5. Information Packet Description No. Length in Bytes 1 1 Character with ASCII code 10 (LF) as packet start marker 1 Charger State 0 – Initialization 1 – Battery Activation 2 – Rapid Charge 3 – Charge Complete 4 – Error 5 – Temperature Outrange 6 – No Battery Charger 3 1 Errors 0 – No Error 1 – Voltage Error (VBAT ≥ VMAX) 2 – Current Error (ICH ≥ IMAX) 3 – Activation Timeout 4 – Constant Current Rapid Charge Stage Timeout 5 – Constant Voltage Rapid Charge Stage Timeout 6 – Battery Initialization Timeout 4 4 4-digit hexadecimal value of charge current (ICHARGE) ADC code 5 4 4-digit hexadecimal value of battery voltage (VBATT) ADC code 6 4 4-digit hexadecimal value of voltage drop on thermistor used for temperature control 7 1 Character with ASCII code 13 (CR) as marker of end of packet 2 Figure 20. Information Package Structure 0 LF 9 1 2 State Error 3 6 ICHARGE 7 10 VBATT 11 14 T 15 CR Design Enhancements The project accompanying this application note is for designs with no voltage feedback regulation. The current into the battery is thus limited by the power dissipation in transistor Q2. The charger in this application note is designed to support batteries with a capacity up to 500 mAh. 9.1 Higher Charge Capacity Battery Charger To charge batteries of higher capacity the options are: use an expensive PNP transistor with a higher power rating or incorporate a feedback mechanism to decrease the voltage drop across current control PNP transistor (Q2) as shown in Figure 21. In a complete system, the feedback control can be a fly-back circuit, which does the voltage regulation. www.cypress.com Document No. 001-55102 Rev. *E 20 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Figure 21. Block Diagram for Higher Current Capacity Battery Charger Voltage Regulator Current Control Li-ion battery pack DC Supply Voltage Sense Vdd Control (Zener) PSoC Temp Sense T RS_TX (UART for Debug) 10 Current Sense LED Multicell Battery Charger To implement a multicell battery charger, the Vdd to PSoC must be regulated for the entire range of voltages (all batteries discharged to fully charged). The voltage regulation across current control PNP transistor (Q2) is required to facilitate higher current flow. Figure 22. Block Diagram for Multicell Battery Charger Voltage Regulator Current Control Li-ion battery pack DC Supply Voltage Sense Vdd Regulation PSoC Temp Sense T RS_TX (UART for Debug) 10.1 Current Sense LED Tiered Charge Profile This is straight forward to implement with the current project. The state machine can be easily modified to get a different charge profile. A tiered rapid charge mode could be created that is dependent on the temperature by modifying the state machine. Since the different states are well defined in the firmware, it is easy to add or modify a few conditional statements to change the profile. About the Author Name: Archana Yarlagadda Title: Application Engineer Background: Applications Engineer in Cypress with focus on PSoC applications. Masters in Analog VLSI from University of Tennessee, Knoxville www.cypress.com Document No. 001-55102 Rev. *E 21 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 11 Appendix A: Charger Schematic for 8-pin CY8C21123 www.cypress.com Document No. 001-55102 Rev. *E 22 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 12 Appendix B: Charger Schematic for 16-pin CY8C21223 www.cypress.com Document No. 001-55102 Rev. *E 23 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 13 Appendix C: Charger BOM for CY8C21123/CY8C21223 Designator C1, C2, C3, C4, C5, C6 Value 0.1 uF Digikey PN Description Quantity PCC1762CT-ND Capacitor 0.1 uF X7R 0603 6 D1 67-1552-1-ND LED 1 DZ1 MMBZ5226B-FDICT-ND Zener Diode 1 J2 WM4203-ND ISSP Connector 5 pin 100 mil partially shrouded 1 2 pin header 1 J1 Q1 MMBT5089LT1GOSCT-ND BJT - NPN 1 Q2 568-4167-1-ND BJT – PNP 1 R1, R4 10K P10.0KHCT-ND Resistor 10K 1% 0603 2 R2 1K P1.00KHCT-ND Resistor 1K 1% 0603 1 R3 22K6 P22.6KHCT-ND Resistor 22K6 1% 0603 1 R5 100 Ohms P100HCT-ND Resistor 100 Ohms 1% 0603 1 R6 39 Ohms P39.0HCT-ND Resistor 39 Ohms 1% 0603 1 R7, R8 3K9 P3.90KHCT-ND Resistor 3K9 1% 0603 2 R9 100K P100KHCT-ND Resistor 100K 1% 0603 1 R10 300K P300KHCT-ND Resistor 300K 1% 0603 1 R11, R12, R13, R14 1 Ohms P1.0DCT-ND Resistor 1 Ohms 1/8 Watt 0805 1% 4 www.cypress.com Document No. 001-55102 Rev. *E 24 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 14 Appendix D: Firmware Flow Chart Start Init device Check for Connected Callibrator Yes Perform Charger calibration and store coeficients Permanent loop Set INITIALIZATION state Measure Vb, Ich, Tb Calculate Avrg(Ich) Send Debug Data Check for battery absent Yes (Rterm ) Set NO_BATTERY state No State NO_BATTERY Yes Charge Off Check for battery present Yes (Rterm ) Set INITIALIZATION state Start tSTART, No No State Yes Init variables INITIALIZATION Check battery temperature Yes Set WAIT FOR TEMPERATURE state Yes Set ERROR state and error code No No Check timeouts No Check Vb≤VACT Yes Charge On Set Ireg=IACT; Regulate No Check Vb ≤VRE-CH Yes No Yes Set Ireg=IACT; Regulate Start tACT, Set CHARGE COMPLETE state No State ACTIVATION Set ACTIVATION state Check battery temperature Yes Set WAIT FOR TEMPERATURE state No Check timeouts Yes Set ERROR state and error code Yes Set ERROR state and error code Yes Set ERROR state and error code No Check for voltage error Vb≥Vmax No Check for voltage error Ich≥Imax No Check rapid start condition Vb>=VRS Yes Set RAPID state Start tRAP time counter No A www.cypress.com B Document No. 001-55102 Rev. *E 25 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 A State RAPID B Yes Set Ireg=IRAP; Regulate No Check Vb>=VFULL Yes Set fConstVoltage flag Start tVCONST time No Check charge terminate condition Yes Set CHARGE COMPLETE state No Check battery temperature Yes Set WAIT FOR TEMPERATURE state No Check timeouts Yes Set ERROR state and error code Yes Set ERROR state and error code Yes Set ERROR state and error code No Check for voltage error Vb≥Vmax No Check for current error Ich>=IMAX No State CHARGE COMPLETE Yes Charge Off Yes Charge Off WAIT FOR TEMPERATURE Set INITIALIZATION state Start tACT, Temperature back to norm Set INITIALIZATION state Start tACT, No No State ERROR Yes No No State Check charge restart condition Yes Charge Off No www.cypress.com Document No. 001-55102 Rev. *E 26 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Document History ® Document Title: AN55102 – PSoC 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Document Number: 001-55102 Revision ECN Orig. of Change Submission Date Description of Change ** 2752862 YARA 08/18/2009 New application note *A 3210386 YARA 03/30/2011 1. Modified the schematic to show the 8-pin implementation 2. Added BOM for 8 pin implementation 3. Updated the project to PD 5.1 4. Updated the Title and Abstract. 5. Added a folder called Charge Control Center, which was earlier accessible through AN2267, to make this AN stand-alone. *B 3271365 YARA 06/01/2011 Document title updated as per template. *C 3510163 RJVB 01/27/2012 Schematic and block diagram updated Updated project with PD5.2 Updated template *D 3704640 DESH 08/06/2012 No change. Completing sunset review. *E 4764533 ASRI 05/14/2015 Updated Schematic diagram for CY8C21123 Added Schematic diagram for CY8C21223 Updated project with PD5.4 Updated template www.cypress.com Document No. 001-55102 Rev. *E 27 PSoC® 1 Single Cell Li-Ion Battery Charger with CY8C21x23 Worldwide Sales and Design Support Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find the office closest to you, visit us at Cypress Locations. PSoC® Solutions Products Automotive cypress.com/go/automotive psoc.cypress.com/solutions Clocks & Buffers cypress.com/go/clocks PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP Interface cypress.com/go/interface Cypress Developer Community Lighting & Power Control cypress.com/go/powerpsoc Memory cypress.com/go/memory PSoC cypress.com/go/psoc Touch Sensing cypress.com/go/touch USB Controllers cypress.com/go/usb Wireless/RF cypress.com/go/wireless Community | Forums | Blogs | Video | Training Technical Support cypress.com/go/support PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners. Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone Fax Website : 408-943-2600 : 408-943-4730 : www.cypress.com © Cypress Semiconductor Corporation, 2009-2015. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement. www.cypress.com Document No. 001-55102 Rev. *E 28