Design of digital capacitance meter based on AT89C2051 single chip microcomputer

Publisher:HarmonyInLifeLatest update time:2009-11-17 Source: 现代电子技术Keywords:AT89C2051 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:

Keywords:AT89C2051 Reference address:Design of digital capacitance meter based on AT89C2051 single chip microcomputer

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

A brief discussion on the design of the four-character LED display of AT89C2051
Abstract: In view of the widespread use of LED advertising screens today, the programmable function and serial communication function of AT89C2051 are used to design a controllable LED display system that communicates with the computer. The upper computer is a computer, and the lower computer is a single-chip microcom
[Microcontroller]
A brief discussion on the design of the four-character LED display of AT89C2051
Design of VCN-MIO Intelligent Node Template Circuit Based on AT89C2051 Single Chip Microcomputer
  0 Preface   Based on the intelligent node template of Neuron chip with three CPUs and solidified LonTalk communication protocol, since Neuron chip is an eight-bit processor, and only provides 11 general I/O ports, and adopts a software scheduling mechanism based on event inspection, its control function is relativel
[Microcontroller]
Design of VCN-MIO Intelligent Node Template Circuit Based on AT89C2051 Single Chip Microcomputer
LED running light circuit produced by microcontroller AT89C2051
1. Circuit diagram Purchase the components and breadboard according to the picture below, and build the circuit on the bread experiment board by referring to the picture on the right. Insert the AT89C2051 microcontroller chip that has been cured with the simplest program into the left and right seams of the experiment
[Microcontroller]
LED running light circuit produced by microcontroller AT89C2051
The production of kitchen timer based on AT89C2051 single chip microcomputer
The device uses 5 minutes as a timing unit and can last up to 1 hour. It uses a 3V battery as the power source and has a buzzer alarm. The power consumption is about 6mA when working (using AT89C2051). It can use a 3V button battery and has an automatic shutdown function. The power consumption is negligible when n
[Microcontroller]
AT89C2051 burner circuit DIY
這是一個簡易的AT89C2051燒錄器的電路,+5V和+12V可由電腦接出來,或使用7805,7812做電源供應,Q1,Q2可使用9013或相似的電晶體皆可,看到這張圖之後,有沒有覺的燒路器其實很容易做的,閒暇之餘不彷做一個,以備日後不時之需.
[Microcontroller]
AT89C2051 burner circuit DIY
AT89C2051+AD7545 sine signal generator
;********************************************************************; ;Description: ;1. This program uses AT89C2051 microcontroller to drive DA converter AD7545 to output single-phase 50Hz sine wave signal. ;2. Output a square wave signal in phase with the sine wave at port P3.5. The square wave signal can be used
[Microcontroller]
LG Display successfully develops world's first stretchable display that can be expanded by 50%
LG Display has unveiled the world’s first stretchable display that can stretch up to 50 percent, the highest stretch ratio in the industry. The company demonstrated the panel at a meeting of more than 100 Korean industry, academic and research stakeholders involved in the national project on stretchable displays at
[Semiconductor design/manufacturing]
LG Display successfully develops world's first stretchable display that can be expanded by 50%
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号