Design of digital capacitance meter based on single chip microcomputer

Publisher:快乐舞动Latest update time:2013-02-18 Source: dzscKeywords:MCU 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) Option 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. [page]


  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Ω.

  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 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:




References:

[1]. AT89C2051 datasheet http://www.dzsc.com/datasheet/AT89C2051_html.
[2]. AT89C51 datasheet http://www.dzsc.com/datasheet/AT89C51_810155.html.
[3]. DS1 datasheet http: //www.dzsc.com/datasheet/DS1_1106249.html.
[4]. DS4 datasheet http://www.dzsc.com/datasheet/DS4_1106244.html.

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

Previous article:How to implement 89C51 single-chip microcomputer I/O port simulation serial communication
Next article:Design of stepper motor control system based on single chip microcomputer and VC++

Recommended ReadingLatest update time:2024-11-16 21:28

Single chip microcomputer + PCF8591 to realize digital voltmeter
Making a digital voltmeter (2 credit hours) 1. Experimental purpose: 1. Understand the working principle and communication protocol of I2C serial bus 2. Understand the interface design of ADC0804, DAC0832, PCF8591 and AT89S51 3. Master the programming methods of ADC0804, DAC0832, and PCF8591 4. Be able to skillfully u
[Microcontroller]
Single chip microcomputer + PCF8591 to realize digital voltmeter
Design of Ultrasonic Therapeutic Instrument Based on AT89C2051 Single Chip Microcomputer
Abstract: This paper presents a design scheme of an ultrasonic physiotherapy instrument based on AT89C2051 single-chip microcomputer control. This scheme adopts a dual-channel input circuit of high-frequency and low-frequency signals, which can generate specific ultrasonic energy with low waveform peak and strong pe
[Microcontroller]
Design of Ultrasonic Therapeutic Instrument Based on AT89C2051 Single Chip Microcomputer
AVR MCU nrf24l01 driver
The source program of the avr microcontroller is as follows: //ICC-AVR application builder : 2018/6/1 21:34:07 // Target : M16 // Crystal: 8.0000Mhz #include iom16v.h #include macros.h #include "SPI.h" #include"key.h" #define uint  unsigned int #define uchar unsigned char  #define IRQ 0 //Input #define MISO 1
[Microcontroller]
MCU timer (timer0 working mode 2)
; Let the LED light change every R1ms COUNT EQU 92; for a crystal oscillator of 11.0592, 92 is equivalent to 100us LED EQU P1.1   ORG 0000H   MOV R0,#00H   DJNZ R0,$     MOV SP,#60H   MOV R1,#00H ; Use R1 as the overall count and use   MOV R2,#00H   //MOV A,TMOD   //ANL A,#11110000B    //CLR ACC.3   //CL
[Microcontroller]
Keil C51 MCU Integrated Development Environment Programming and Debugging Tutorial
Like general C language integrated development environments (IDEs) such as VC, Keil also uses "engineering" The source code and related files are managed in a project-based way. This management method is convenient for the development of large programs consisting of multiple source code files. Whether it is the simp
[Microcontroller]
Keil C51 MCU Integrated Development Environment Programming and Debugging Tutorial
Bit addressing programming based on 80C51 single chip microcomputer
The 80C51 microcontroller has a bit processing function and can operate on data bits, so there is a corresponding bit addressing mode. The so-called bit addressing is to directly set a bit in the internal RAM or the bit-addressable special function register SFR to 1 or reset it to 0. The scope of bit addressing, tha
[Microcontroller]
Bit addressing programming based on 80C51 single chip microcomputer
Microcontroller Learning 3
Addressing mode and instruction system Through the previous study, we have understood the internal structure of the microcontroller, and we also know that to control the microcontroller and let it do things for us, we need to use instructions. We have learned a few instructions, but they are very scattered. From now
[Microcontroller]
Development of mechanical equipment timer based on single chip microcomputer technology
1 Timer composition and working principle (1) Hardware composition and timing principle The timing intelligent control system adopts the method of hardware trigger plus software detection and control. It uses the vibration signal generated by the operation of mechanical equipment, and uses the microprocessor
[Microcontroller]
Development of mechanical equipment timer based on single chip microcomputer technology
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号