Design Tasks
Design and make a digital capacitance meter. The functions and requirements of the system are as follows:
(1) The designed capacitance meter can measure capacitance less than 2μF.
(2) The designed capacitance meter uses a 3.5-digit display with a maximum display value of 1 999.
(3) The designed capacitance meter adopts nF as the reading unit, and the range is divided into 4 levels. The actual capacitance value is the reading multiplied by the corresponding factor.
2. Proposal demonstration
2.1 Circuit scheme
(1) Solution 1: Basic circuit construction
The capacitance meter that uses basic circuit to realize digital display has complex circuit structure, large failure coefficient, difficult debugging and large error.
(2) Option 2: MCU Programming
When designing a circuit with a single-chip microcomputer, the circuit structure is simple and debugging is relatively convenient because it uses a combination of software and hardware. Compared with the first solution, the advantages are very obvious.
2.2 Display scheme
(1) Solution 1: Static display
For static display, the display driver circuit has an output latch function. After the microcontroller sends out the data to be displayed, it does not need to be taken care of until the next time the display data needs to be updated and the data is transmitted again.
This solution is easy to program, simple to manage, has high display brightness, stable display data, and takes up very little CPU time. However, it has many leads, complex circuits, and high hardware costs.
(2) Solution 2: Dynamic display
Dynamic display requires the CPU to constantly refresh the data of the display device. The displayed data will flicker and take up more CPU time, but uses less hardware and 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
According to the above analysis, the system is based on AT89C2051 single-chip microcomputer as the core, and the system block diagram is shown in Figure 1.
3 AT89C205l 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
The digital capacitance meter uses the charging law of capacitors as the measurement basis, and 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, assuming that 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 in-phase input terminal, and P1.1 is the inverting input terminal. 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 P3.6 port is 0. Once the voltage at both ends of the battery voltage CX exceeds 0.632E+, the output of P3.6 port becomes 1. Based on the output level of 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Ω.
Digital tubes DS1~DS4, resistors R8~R14, etc. form a digital display circuit. This machine adopts a dynamic scanning display method and decodes the font code with 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 triodes. R8~R14 are pull-up resistors for 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.
5 Software Design
The program is written in C language. The software consists of the main program, timer interrupt service subroutine and other modules. 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 commissioning
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 the 2 nF position and 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 when measuring the reading. Therefore, do not select this gear during debugging to avoid affecting the accuracy of debugging due to distributed capacitance.
The C file source program is as follows:
Previous article:Small RTOS51 realizes the design of temperature controller based on 8-bit microcontroller
Next article:Solar Energy Environmental Parameters Tester Based on AT89S52 Single Chip Microcomputer
Recommended ReadingLatest update time:2024-11-17 00:18
- 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
- BQ34Z100-G1 Topic Selected Questions and Answers
- [Raspberry Pi Pico Review] 3. Pico outputs PWM signals to control four-wire fans
- Please help me see how to clear the data of TS1102A
- I want to know if this method is correct to predict the change in capacitance of chip capacitors due to temperature drift?
- [NXP Rapid IoT Review] Analysis of Rapid-Iot boot process (K64 part)
- Date in spring + go out and get a sea bass
- 【Multi-function open source custom macro keyboard】Bluetooth keypad project construction and experiment
- Can I teach myself Java to find a job?
- Last day, 74% winning rate: Watch the video "Avoiding Common AC-DC Design Pitfalls" and win a prize
- Serial port baud rate selection