Detection circuit for battery of single-chip microcomputer and single-chip microcomputer
By designing a battery detection circuit including MOS tubes and resistors in a microcontroller, using a single GPIO to realize battery voltage and power detection, the problems of large power consumption and high IO resource occupation in the existing technology are solved, and low power consumption and high Accurate power detection.
Patent Information
- Application Number
- CN202420592179.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Utility models(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-25
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2034-03-25
AI Technical Summary
The existing microcontroller battery power detection methods have problems such as large power consumption, large IO resources occupancy or high detection costs.
Design a detection circuit including a first MOS tube, a second MOS tube, a resistor and a timer, realize battery voltage and power detection through a single GPIO, use the combination of MOS tube and a resistor for voltage-dividing sampling, occupying only one GPIO resource, and Optimize detection time with timer.
It realizes low-power, low-cost and high-precision battery power detection, uses only one GPIO resource, and due to the short detection time, the circuit is in a shutdown state most of the time, achieving ultra-low-power detection effect.
Smart Images

Figure CN221946370U_ABST
Abstract
Description
Technical Field
[0001] The utility model relates to the field of battery detection circuits, and more specifically, to a battery detection circuit for a single-chip microcomputer and the single-chip microcomputer. Background Art
[0002] In the prior art, the microcontroller usually detects the battery power by directly dividing the voltage with a resistor and then detecting the battery voltage via an ADC, thereby realizing the battery power detection. The disadvantage of this solution is that the power consumption is large;
[0003] Another solution is to directly use two IOs to implement battery voltage detection, thereby realizing battery power detection. One common IO output is used to control the switch of the detection circuit, and the other IO is set to ADC input for voltage detection. The disadvantage of this solution is that it occupies the IO resources of the microcontroller.
[0004] In addition to the two commonly used detection methods mentioned above, there is also a method of directly using a power detection IC to detect the battery power. Since a dedicated chip is required, the disadvantage of this solution is that the detection cost is relatively high and it occupies more IO resources of the microcontroller. Utility Model Content
[0005] The technical problem to be solved by the utility model is to provide a detection circuit and a single chip microcomputer which have low power consumption and occupy a single GPIO to realize the voltage and power quantity detection of a battery for a single chip microcomputer.
[0006] The purpose of this utility model is achieved through the following technical solutions:
[0007] A battery detection circuit for a single-chip microcomputer, the single-chip microcomputer comprising a battery and a GPIO, the detection circuit comprising the first MOS tube, the second MOS tube, a first resistor, a second resistor, a third resistor and a fourth resistor;
[0008] The source of the first MOS tube is connected to the positive electrode of the battery, the drain of the first MOS tube is connected in series with the second resistor and the fourth resistor in sequence and then grounded, a first node is provided between the second resistor and the fourth resistor, a single GPIO is connected to the first node and connected to the gate of the second MOS tube through the third resistor, one end of the first resistor is connected to the positive electrode of the battery, and the other end of the first resistor is connected to the gate of the first MOS tube and the drain of the second MOS tube; the source of the second MOS tube is grounded, and the negative electrode of the battery is grounded.
[0009] Further, the resistance range of the first resistor is 0.8 to 1.2M ohms, the resistance range of the second resistor is 10 to 14K ohms, the resistance range of the third resistor is 80 to 120K ohms, and the resistance range of the fourth resistor is 18 to 22K ohms.
[0010] Furthermore, the first MOS tube is a PMOS tube, the model of which is CJ2305, and the second MOS tube is an NMOS tube, the model of which is CJ2306.
[0011] Another solution of the utility model is a single-chip microcomputer, which includes a battery, a connection bus, and a CPU, a memory and an I / O connected through the connection bus. The I / O is provided with a plurality of GPIOs, and the detection circuit is electrically connected to a single GPIO.
[0012] Furthermore, the single chip microcomputer also includes a timer, the timer is connected to the CPU via the connection bus, and the timer is used to start the detection circuit at a fixed time.
[0013] The utility model can achieve relatively high detection accuracy due to the simple design of the detection circuit and the low material cost, and only uses one GPIO (General-purpose input / output) and occupies less multi-functional composite GPIO resources; and because the detection process time is extremely short and the detection circuit is in a closed state most of the time, the technical solution can achieve ultra-low power consumption and accurate detection of battery power. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] Figure 1 It is a schematic diagram of a detection circuit of an embodiment of the utility model;
[0015] Figure 2 It is a structural schematic diagram of a single chip microcomputer according to an embodiment of the utility model;
[0016] Among them, Q1 is a first MOS tube; Q2 is a second MOS tube; R1 is a first resistor; R2 is a second resistor; R3 is a third resistor; R4 is a fourth resistor; and J1 is a first node. DETAILED DESCRIPTION
[0017] In the description of the present utility model, it should be understood that the terms "center", "lateral", "up", "down", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present utility model and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present utility model. In addition, the terms "first" and "second" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.
[0018] In the description of the present utility model, unless otherwise specified, "plurality" means two or more. In addition, the term "including" and any variation thereof are intended to cover non-exclusive inclusions. In the description of the present utility model, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be internal communication between two components. For those of ordinary skill in the art, the specific meanings of the above terms in the present utility model can be understood according to the specific circumstances.
[0019] The utility model is further described below in conjunction with the accompanying drawings and preferred embodiments.
[0020] like Figure 1 As shown, this embodiment discloses a battery detection circuit for a single-chip microcomputer, the single-chip microcomputer includes a battery and a GPIO, and the detection circuit includes a first MOS tube Q1, a second MOS tube Q2, a first resistor R1, a second resistor R2, a third resistor R3 and a fourth resistor R4; wherein the first MOS tube Q1 and the second MOS tube Q2 are combined to be used as a switch of the detection circuit; the first resistor R1 provides a bias voltage for the first MOS tube Q1; the second resistor R2 and the fourth resistor R4 are used as voltage dividing resistors and provide a bias voltage for the MOS tube Q2, and the voltage of the battery is sent to the ADC for sampling after being divided by the second resistor R2 and the fourth resistor R4; the third resistor R3 provides a bias voltage for the second MOS tube Q2, and reduces the influence of the leakage current of the gate of the second MOS tube Q2 on the sampling accuracy.
[0021] The VBAT terminal and the VDET terminal of the detection circuit are connected to the battery to be detected, the source of the first MOS tube Q1 is connected to the positive electrode of the battery, the drain of the first MOS tube Q1 is connected in series with the second resistor R2 and the fourth resistor R4 in sequence and then grounded, a first node J1 is provided between the second resistor R2 and the fourth resistor R4, a single GPIO is connected to the first node J1 and connected to the gate of the second MOS tube Q2 through the third resistor R3, one end of the first resistor R1 is connected to the positive electrode of the battery, and the other end of the first resistor R1 is connected to the gate of the first MOS tube Q1 and the drain of the second MOS tube Q2; the source of the second MOS tube Q2 is grounded, and the negative electrode of the battery is grounded.
[0022] The detection circuit design of the technical solution is simple and the material cost is low, and it can achieve relatively high detection accuracy. It only uses one GPIO (General-purpose input / output), occupying less multi-functional composite GPIO resources. Moreover, because the detection process time is extremely short and the detection circuit is in a closed state most of the time, the technical solution can achieve ultra-low power consumption for accurate detection of battery power.
[0023] The detection process includes: setting GPIO to high-level output, turning on the first MOS tube Q1 and the second MOS tube Q2, and turning on the detection circuit; setting GPIO to ADC input, at which time the first MOS tube Q1 and the second MOS tube Q2 remain in the on state; turning on ADC sampling to detect the voltage of the battery after the voltage is divided by the first resistor R1 and the second resistor R2; calculating the actual battery voltage; calculating the battery power according to the corresponding relationship between voltage and power given by the battery manufacturer; turning off ADC sampling, setting GPIO to low-level output, and turning off the detection circuit; turning on the timer to regularly detect the battery voltage and calculate the battery power.
[0024] Among them, the resistance range of the first resistor R1 is 0.8~1.2M ohms, the resistance range of the second resistor R2 is 10~14K ohms, the resistance range of the third resistor R3 is 80~120K ohms, and the resistance range of the fourth resistor R4 is 18~22K ohms. The resistance values of the first resistor R1, the second resistor R2, the third resistor R3 and the fourth resistor R4 can be set according to actual needs; for example, the resistance value of the first resistor R1 is 1M ohm, the resistance value of the second resistor R2 is 12K ohms, the resistance value of the third resistor R3 is 100K ohms and the resistance value of the fourth resistor R4 is 20K ohms.
[0025] The first MOS tube Q1 is a PMOS tube, and the model of the first MOS tube Q1 is CJ2305. The second MOS tube Q2 is an NMOS tube, and the model of the second MOS tube Q2 is CJ2306.
[0026] like Figure 2 As shown, this embodiment discloses a single-chip microcomputer, which includes a battery, a connection bus, and a CPU, a memory, and an I / O connected through the connection bus. The I / O is provided with a plurality of GPIOs, and the detection circuit is electrically connected to a single GPIO.
[0027] The single chip microcomputer further includes a timer, which is connected to the CPU via a connection bus, and the timer is used to start the detection circuit at a fixed time.
[0028] The specific testing process includes the following steps:
[0029] 1. Set GPIO to high level output, the first MOS tube Q1 and the second MOS tube Q2 are turned on, and the detection circuit is turned on;
[0030] 2. Set GPIO to ADC input. At this time, the first MOS tube Q1 and the second MOS tube Q2 remain in the on state;
[0031] 3. Turn on ADC sampling to detect the voltage of the battery after being divided by the first resistor R1 and the second resistor R2;
[0032] 4. Calculate the actual battery voltage;
[0033] 5. Calculate the battery capacity according to the voltage and capacity correspondence given by the battery manufacturer;
[0034] 6. Turn off ADC sampling, set GPIO to low level output, and turn off the detection circuit;
[0035] 7. Turn on the timer to regularly detect the battery voltage and calculate the battery power.
[0036] The detection circuit design of the technical solution is simple and the material cost is low, and it can achieve relatively high detection accuracy. It only uses one GPIO (General-purpose input / output), occupying less multi-functional composite GPIO resources of the microcontroller. Moreover, because the detection process time is extremely short and the detection circuit is in a closed state most of the time, the technical solution can achieve ultra-low power consumption for accurate detection of battery power.
[0037] The above contents are further detailed descriptions of the present invention in combination with specific preferred implementations, and the specific implementation of the present invention cannot be considered to be limited to these descriptions. For ordinary technicians in the technical field to which the present invention belongs, several simple deductions or substitutions can be made without departing from the concept of the present invention, which should be regarded as falling within the protection scope of the present invention.
Claims
1. A battery detection circuit for a single-chip microcomputer, the single-chip microcomputer comprising a battery and a GPIO, characterized in that: The detection circuit includes a first MOS tube, a second MOS tube, a first resistor, a second resistor, a third resistor and a fourth resistor; The source of the first MOS tube is connected to the positive electrode of the battery, the drain of the first MOS tube is connected in series with the second resistor and the fourth resistor in sequence and then grounded, a first node is provided between the second resistor and the fourth resistor, a single GPIO is connected to the first node and connected to the gate of the second MOS tube through the third resistor, one end of the first resistor is connected to the positive electrode of the battery, and the other end of the first resistor is connected to the gate of the first MOS tube and the drain of the second MOS tube; The source of the second MOS tube is grounded, and the negative electrode of the battery is grounded.
2. A battery detection circuit for a single chip microcomputer as claimed in claim 1, characterized in that: The resistance value of the first resistor is in the range of 0.8 to 1.2M ohms, the resistance value of the second resistor is in the range of 10 to 14K ohms, the resistance value of the third resistor is in the range of 80 to 120K ohms, and the resistance value of the fourth resistor is in the range of 18 to 22K ohms.
3. A battery detection circuit for a single chip microcomputer as claimed in claim 1, characterized in that: The first MOS tube is a PMOS tube, the model of which is CJ2305; the second MOS tube is an NMOS tube, the model of which is CJ2306.
4. A single chip microcomputer, characterized in that: The single chip microcomputer comprises the detection circuit according to any one of claims 1 to 3, a battery, a connection bus, and a CPU, a memory and an I / O connected via the connection bus, wherein the I / O is provided with a plurality of GPIOs, and the detection circuit is electrically connected to a single one of the GPIOs.
5. A single chip microcomputer as claimed in claim 4, characterized in that: The single chip microcomputer further comprises a timer, the timer is connected to the CPU via the connection bus, and the timer is used for timing to start the detection circuit.
