Design and make a digital capacitance meter. The functions and requirements of the system are as follows:
(1) The capacitance meter can measure capacitance less than 2μF.
(2) The capacitance meter uses a 3.5-digit display, and the maximum display value is 1999.
(3) The reading unit of the capacitance meter is uniformly nF, and the range is divided into 4 levels. The actual capacitance value is the reading multiplied by the corresponding factor.
2 Solution demonstration
2.1 Circuit solution
(1) Solution 1: Basic circuit construction
Using basic circuit to realize digital display capacitance meter, the circuit structure is complex, the failure coefficient is large, it is not easy to debug, and the error is also large.
(2) Solution 2: Single chip microcomputer programming
Using single chip microcomputer to design circuit, because of the combination of software and hardware, the circuit structure is simple and debugging is relatively convenient. Compared with the first solution, the advantages are very obvious.
2.2 Display solution
(1) Solution 1:
Static display In static display, the display drive circuit has an output latch function. After the single chip microcomputer sends the data to be displayed, it does not need to be managed again until the next time the display data needs to be updated.
This solution is easy to program, simple to manage, high display brightness, stable display data, and takes up very little CPU time. However, there are more leads, complex circuits, and high hardware costs.
(2) Solution 2: Dynamic display
Dynamic display requires the CPU to refresh the display device data at all times. The display data will have a flickering feeling and occupy more CPU time, but less hardware is used, which can save circuit board space.
These two display modes have their own advantages and disadvantages. Although static display has stable data and takes up very little CPU time, each display unit requires a separate display driver circuit and uses more hardware. Although dynamic display has a flickering feeling and takes up more CPU time, it uses less hardware and can save circuit board space.
2.3 System Block Diagram
Based on the above analysis, the system is based on the AT89C2051 microcontroller as the core, and the system block diagram is shown in Figure 1.
3 AT89C2051 Introduction
AT89C2051 is a low-voltage, high-performance CMOS 8-bit microcontroller produced by Atmel. It contains 2 KB of repeatedly erasable read-only program memory (EPROM) and 128 B of random data memory. The device is produced using Atmel's high-density, non-volatile storage technology, compatible with the standard MCS51 instruction system, and has a built-in general 8-bit central processor and FLASH storage unit. As a simplified version of AT89C51, AT89C2051 has removed ports such as P0 and P2, reducing the number of I/O ports, but has added a voltage comparator, so its functions are enhanced in some aspects. The pin diagram is shown in Figure 2.
4 Circuit working principle
This digital capacitance meter uses the charging law of capacitors as the measurement basis. The test principle is shown in Figure 3. The power supply voltage E+ charges the measured capacitor CX through the resistor R, and the original voltage across CX increases with the increase of charging time. When the charging time t is equal to the RC time constant τ, the voltage across CX is about 63.2% of the power supply voltage, that is, 0.632E+. The digital capacitance meter uses this voltage as the test reference voltage, and measures the time it takes for the capacitor to charge to reach this voltage, so that the capacity of the capacitor can be known. For example, if the resistance value of the resistor R is 1 kΩ, and the time required for the voltage across CX to rise to 0.632E+ is 1 ms, then the formula τ=RC shows that the capacity of CX is 1 microfarad. The specific measurement circuit is shown in Figure 4.
In Figure 4, A is the voltage comparator of the internal structure of AT89C2051. In addition to being an I/O port, the P1.0 and P1.1 ports of AT89C2051 also have a function as the input of the voltage comparator. P1.0 is the non-inverting input port, and P1.1 is the inverting input port. The comparison result of the voltage comparator is stored in the register corresponding to the P3.6 port. The reference voltage of the voltage comparator is set to 0.632E+. When the voltage at both ends of CX rises from 0 to 0.632E+, the output of the P3.6 port is 0. Once the voltage at both ends of the battery voltage CX exceeds 0.632E+, the output of the P3.6 port becomes 1. Based on the output level of the P3.6 port, the charging time is counted by the timer T0 inside the AT89C2051, and the counting result is displayed to obtain the measurement result.
The whole circuit is shown in Figure 5. The circuit consists of a single-chip microcomputer circuit, a capacitor charging measurement circuit, and a digital display circuit.
The voltage comparator and resistors R2~R7 inside AT89C2051 form the measurement circuit. R2~R5 are range resistors, which are selected by the band switch S1. The reference voltage of the voltage comparator is obtained by dividing the 5 V power supply voltage by R6, RP1, and R7. The reference voltage can be adjusted by adjusting RP1. When the P1.2 port outputs a high level under the control of the program, the capacitor Cx begins to charge. The range resistors R2~R5 decrease by 10 times in each gear, so the displayed reading increases by 10 times in each gear. Since the pull-up resistor of the P1.2 port inside the single-chip microcomputer is about 200 kΩ after actual measurement, its output level cannot be used as a charging voltage, so R5 is used as its pull-up resistor. Since the other three charging resistors and R5 are in series, R2, R3, and R4 should be subtracted from the standard value by 1 kΩ, which are 999 kΩ, 99 kΩ, and 9 kΩ respectively. Since the relative error between 999 kΩ and 1 MΩ is small, R2 is still 1 MΩ.
The digital display circuit is composed of digital tubes DS1~DS4 and resistors R8~R14. This machine adopts dynamic scanning display mode and decodes the font code by software. P3.0~P3.5, P3.7 ports are used to output the seven-segment stroke font code for digital display, and P1.3~P1.6 ports are used to output the dynamic scanning bit drive code of four digital tubes. Common cathode digital tubes are used here. Since the P1.3~P1.6 ports of AT89C2051 have a pull-down current capacity of 25 mA, the digital tubes can be driven without transistors. R8~R14 are pull-up resistors of P3.0~P3.5, P3.7 ports, which are used to drive each field of the digital tube. When a certain port of P3 outputs a low level, the corresponding field stroke will not light up, and when it outputs a high level, the corresponding pull-up resistor can light up the corresponding field stroke.
[page]
5 Software Design
The program is written in C language. The software part consists of modules such as the main program and the timer interrupt service subroutine. Timer T0 is used to count the charging time of the capacitor under test. Timer T1 is used for timer interrupt service, and the timing time is 5 ins, that is, an interrupt is generated every 5 ms. Array BitTab[4] is used to store bit drive codes, DispTab[11] is used to store font codes, and the 4 elements of array DispBtlf[4] are used to store the 4-digit numbers of the ones, tens, hundreds, and thousands of the data read from timer T0. The program displays each digit for 5 ms, so the cycle for displaying a complete 4-digit number is 20 ms (4 interrupts). The data is refreshed every 240 ms (48 interrupts), that is, the capacitance is measured every 240 ms, and the measurement time is less than 2 ms. Since this time is less than the interrupt time of 5 ms, there will be no interruption during the measurement process. When measuring capacitance, the P1.2 port outputs a high level, the capacitor starts to charge, and at the same time, the timer T0 starts counting. When the capacitor is charged to the reference voltage, the P3.6 port outputs a high level. Based on this, the program makes a judgment to stop the counting of T0, and reads the data to the digital tube for display. If the capacity of the measured capacitor exceeds the range of the test file, the count value is greater than or equal to 2,000, and the display result is 1 in the thousands digit, and the other three digits are not displayed. After simulation and circuit testing, it is found that the microcontroller takes 3 machine cycles to determine whether the P3.6 port outputs a high level, which will increase the display value by 3. Therefore, this error is corrected in the program, and the count value is subtracted by 3. The output of the font code uses P3.0~P3.5 of the P3 port, P3.7, and P3.6 are empty, and the data output by the P3 port is obtained through the array DispTab. The corresponding relationship between data bits and fonts is shown in Table 1.
6 Installation and Debugging
This design uses AT89C2051 single-chip integrated circuit, X1 uses 12 MHz quartz crystal, S1 uses 1×4 band switch, and DS1~DS4 uses common cathode LED digital tube. Before installation, compile the C language source program into the target file, that is, HEX file, using KEIL 51, and then use the programmer to write the HEX file into the AT89C2051 chip. The debugging work is mainly to adjust the reference voltage by adjusting RP1. It is best to adjust it by measuring a capacitor with relatively high accuracy, rather than directly measuring the reference voltage. The specific method is to select a capacitor with a confirmed relatively accurate capacity, such as a 15 nF capacitor, set S1 to the 20 nF position, and adjust RP1 so that the measured display value is 1 500. The selected capacitor capacity must be at least 50% greater than the corresponding range, preferably close to the full range, so that it can be adjusted more accurately. After the gear is debugged, the other gears are also debugged. If a certain gear is found to have a problem with accuracy, the resistance value of its corresponding charging resistor can be changed to adjust it. During use, when S1 is set to 2 nF, when no test capacitor is connected, a display value of about 10 pF is normal, because this is the input capacitance of the voltage comparator and the distributed capacitance of the circuit.
Just remove this value during the measurement reading. Therefore, do not select this position during debugging to avoid affecting the accuracy of debugging due to distributed capacitance.
The C file source program is as follows:
Previous article:Application of 51 single chip microcomputer in boiler water treatment control
Next article:Self-debugging and online programming of 51 single-chip microcomputer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Elective course to get a gift] Keysight's new "Test and Measurement" series of courses, reservations open in the hot summer! Master-level lecturers live online~
- AD chip output digital signal problem
- Step-by-step tutorial | ESP32-Audio-Kit (8388 version) development environment setup video tutorial
- MSP430F5438A instruction cycle and clock cycle
- AVR assembler, paid help
- Allegro software design has been updated with the latest patch, but why can't I do 3D simulation?
- EEWORLD University ---- Embedded Linux Development Introduction Video
- What is a smart WiFi module? What are the types and functions of wireless router gateway control modules?
- Case! EMI rectification of power supply
- Reasons for choosing 4-20mA for flow meter