Design of a digital voltmeter based on a single-chip microcomputer

Source: Internet
Author: User

0 Introduction

There are many types and styles for the design and development of digital voltage meters. Traditional Digital Voltage meters have their own characteristics and are suitable for manual measurement at the site, however, to complete remote measurement and further process the measurement data, the traditional digital voltmeter cannot be used. Therefore, a digital voltmeter Based on PC communication is designed in this paper. This table can transfer measurement data and process measurement data through PC. Therefore, this type of digital voltmeter has incomparable advantages in both functions and practical applications, which makes it promising for development and application.

1 System Structure

The system consists of two parts: hardware and software. The hardware mainly includes the data collection circuit, the minimum data collection system of single chip microcomputer, and the interface circuit between single chip microcomputer and PC. The software mainly includes single-chip microcomputer data collection program, single-chip microcomputer and PC communication program, as well as PC Data Processing Program.

2. Data collection Circuit Principle

The voltage type measured by the new digital voltmeter is DC, and the measurement range is 0 ~ 5 V, the lower computer uses a single-chip microcomputer of, AD conversion uses the most common ADC0809, can communicate with the PC through RS232 serial port, in order to transmit the measured DC voltage data. Figure 1 shows the data acquisition circuit of the digital voltmeter. The circuit design has been minimized, that is, the operation of the ADC0809 conversion chip can be realized by using a single-chip microcomputer without any additional logic device as an interface circuit. In Figure 1, ADC0809 is an 8-bit Analog-to-analog conversion chip with eight analog switching and corresponding channel lock decoding circuit. The conversion time is about 100 μs. In circuit application, the data channel of ADC0809 must be specified first. When the external voltage enters the chip, the statr signal starts to convert from high to low and the pulse drops along ADC0809, at the same time, the EOC level of the pin is reduced, indicating that the conversion is in progress. After the conversion is completed, the EOC level of the pin is increased, indicating that the conversion ends once.

 

3. Software Programming

The software program of the system mainly includes the data collection program of the lower computer, visual interface program of the upper computer, serial communication between the single chip microcomputer and the PC, etc. The single-chip microcomputer can adopt C51 programming, and the upper-computer operation can adopt VC ++ 6.0 for visual programming. In this way, the "Serial-port debugging assistant" tool can be used for serial-port debugging, and effectively use this tool to improve the overall system efficiency.

3.1 MCU Programming

In this system, the single-chip microcomputer controls ADC0809 for data conversion and sends the converted data to the host computer through the serial port. Because the single-chip microcomputer does not have a strong ability to process data, it sends the collected data to the PC, and uses the powerful data processing capability of the PC to process the data and finally obtain the desired result. Because the ADC0809 clock requires an external clock signal (generally connected to 500 kHz), the clock signal frequency can be generated using a standard oscillator circuit, or the to or t1 port that comes with a single-chip microcomputer. To minimize the design, this design uses its own to port to provide clock signals. The program is as follows:

3.2 PC programming

The upper computer uses VC ++ 6.0 to implement visual interfaces and communicate with the lower computer. VC ++ is a programming language tool based on the Windows operating system. It can use API functions to directly communicate with the lower computer. However, this method involves many lower-layer settings, this article uses Microsoft ActiveX technology to achieve serial communication, that is, applications directly use the interfaces provided by ActiveX controls to Access ActiveX controls. Microsoft Communications Control (MSComm) is an ActiveX control provided by Microsoft to simplify serial communication programming in windows. It provides an easy way for applications to send and receive data through a serial interface. Specifically, it provides two methods to deal with communication problems: one is the event2driven method and the other is the query method. This design uses the query method, which is suitable for small applications. In this case, every time the application executes a serial port operation, it will constantly check the commevent attribute of the MSComm control to check the execution result or whether an event has occurred. This method may be more desirable if the application is small and self-contained. Therefore, this design is more desirable. The MSComm control has many important attributes, the first of which are listed in Table 1.

 

When programming on the upper computer, you should first create an application based on the dialog box, and then insert the MSComm control. You can put an edit box (idc_edit_receive) on the dialog box resources to display the voltage value, put the two button controls [start measurement idc_test) and stop measurement (id_stop ). In the dialog box, right-click the template, select classwizard, add the member variable, and set the idc_mscomml associated member variable m_mscomm to the cmscomm control type, but the idc_edit_receive associated member variable m_receive is not the control type, is a numerical value (float ). Then, add the message response function to the two buttons and the MSComm control, which can be automatically added under classwizard.

When adding code, you must first set the attributes of the MSComm control, which can be added to the oninitdialog function. This article uses the coml port with a baud rate of 9600, no parity bit, 8-Bit Data bit, l-bit stop bit, and binary data transmission and receiving. Add settimer (1,500, null) to the ontest () function of the Start measurement button; enable the timer to trigger a timer event every 500 ms, and stop the measurement button onstop () add killtimer (1) to the function to stop the timer event. Add the wm_timer message. You can add cbytearray bytoutarr and bytoutarr on ontimer (uint nidevent. add (0xfd); m_mscomm.setoutput (colevariant (bytoutarr); (send data 0xfd in binary mode, send data once in MS, the lower computer transmits the converted data back only after receiving 0xfd, which is equivalent to a simple communication protocol.

Data receiving and processing (which is also the focus of this article) can be done by checking whether the receiving event has occurred in the message response function of the MSComm control. The Code is as follows:

Void cctestvotdlg: ononcommmscomml ()
{Variant variant_indium;
Colesafearray safearray_indium;
Longlen, K;
Byte rxdata [1024]; // sets the byte array
Cstring strtemp;
If (m_mscomm.getcommevent 0 = 2) // if the event value is 2, the data is received.
{Variant_indium = m_mscomm.getinput 0; // read the buffer
Safearray_indium = variant_indium;
Len = safearray_inp.getonedimsize (); // obtain the valid data length.
For (k = 0; k <Len; k ++)
Safearray_inp.getelement (& K, rxdata + k); // convert it to a byte array
M_receive = rxdata [0]; // assign the received value
Float variable m_receive = m_receive/255; // the received data is an integer between (0,255 ).
M_receive = m_receive * 5; // The voltage value ranges from 0 to 5 V.
M_receive = setprecision (m_receive, 3) // This function retains the last three digits of the decimal point.
}
Updatedata (false); // update the edit box to display the value in the edit box.
}

 

4 Conclusion

The above implementation scheme can effectively implement the entire prototype function in practice. The actual use proves that all the indicators of the instrument can achieve the expected results. This article focuses on the use of MSComm serial communication methods, and analyzes the powerful functions, full flexibility and ease of use of ActiveX technology, has a certain practical significance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.