Application Skills/Intelligent Data Acquisition System under Windows 95[Copy link]
Abstract : An intelligent data acquisition system is proposed. The timing under Windows 95, which is complicated in programming, low in timing resolution and unreliable in operation, is replaced by the timing under single-chip microcomputer, which is simple in programming, high in timing resolution and reliable in operation. The problem of inaccurate short-term timing under Windows 95 environment is solved, and the user's application program is simplified. The whole system has a simple structure, is efficient and reliable, and realizes high-performance acquisition of signals.
Keywords : timer clock parallel port data acquisition
introduction
Data acquisition systems are widely used in all walks of life. At present, a variety of high-speed, high-precision, multi-channel data acquisition cards have been launched. The computer acquires data through the analog-to-digital converter on the card, and then performs data storage, data processing, and graphic display. With the development of microelectronics and computer technology, applications under the Windows 95/98 platform have become the mainstream of data acquisition and processing software development.
Conventional Windows timers for data acquisition have serious shortcomings. First, the timing resolution of conventional Windows timers is low. The timer interrupts once every 55ms, which is equivalent to a maximum sampling frequency of only 18.2Hz. Because applications under Windows 95/98 cannot interact directly with hardware, the timing time length cannot be changed by reinstalling the timing interrupt. Such a low sampling frequency is not suitable for most signal acquisition and processing, and a method must be found to acquire at a higher frequency.
Secondly, Windows is a multi-tasking operating system that drives events based on messages. The priority of the timer message WMTIMER in the serial message queue is very low, and it often does not get a timely response. Even several unprocessed timer messages in the message queue will be merged into one; and the application cannot determine the number of messages lost due to this processing, making the actual sampling interval uneven.
In response to the above problems, people have come up with many ways to solve them. The commonly used method is programming on a PC. Generally speaking, there are three methods:
(1) In Windows applications, use the delay() function which is commonly used in ordinary C language [2,3].
Delay() is a commonly used delay and timing function in C language. Using delay(), the maximum sampling rate can reach 1kHz, but delay() is not compatible with the multi-tasking Windows operating system. Using delay() directly in Windows applications will cause compilation warnings and connection errors. This error can be removed by displaying the prototype of the delay() function in the program and including the DELAY module in the Windows library, so that delay() can be used in Windows applications like ordinary C programs. However, this method of waiting with software is a huge waste of host resources.
(2) Using the Windows multimedia timer callback function [4,5]
The Windows multimedia timer can set the timer resolution through the function timeBeginPeriod, with a minimum resolution of 1ms and a maximum resolution of 16ms. This resolution represents a sampling rate of 60 to 1000Hz, which can meet the sampling rate requirements of general signals. In addition, the multimedia timer uses interrupts to complete the timing service, calling a callback function at the interrupt time instead of sending WM_TIMER information to the message queue. In the application, it is not easy to use the Windows multimedia timer, and strict steps must be followed. When using the callback function, data must be shared between the interrupt service program and the user's main program, which brings inconvenience to programming and debugging. The robustness of the program will also be affected. When the timing time is short, the host is overloaded.
(3) Real-time clock timing[6]
The real-time clock chip drives the internal clock circuit to work under the action of the reference frequency, and can select the 22-division output signal frequency by programming the internal register A (D3~D0). The real-time clock periodically outputs square waves and periodic interrupt request signals (the interrupt request is connected to IRQ8), thus providing another way to implement time control in the program. At the same time, in the Windows mechanism, using VxD with a priority higher than the general task level and equal to the system level to compile the driver can ensure that the driver enjoys the highest priority during operation, and will not be interrupted by other tasks when managing and controlling hardware devices, fully ensuring that the data returned to the user by the driver is a completely true value. In addition, the hardware can be accessed directly, so the real-time clock interrupt can be directly managed by writing VxD, and the timing resolution is higher. However, VxD has high requirements on the programming level of the debugger. If you are not careful, it is easy to have abnormal errors or freezes.
It is not difficult to see that directly programming on a PC to solve timing problems requires the debugger to have a high level of programming skills, and the program is difficult to debug and has poor reliability.
To this end, we designed an intelligent data acquisition system. The single-chip microcomputer 89C51 is used as the central processing unit to control peripheral devices such as analog/data conversion and external data storage to perform timed data acquisition and preprocessing. The parallel port that most computers have is used as the interface between the data acquisition system and the computer to transmit data with the PC. The single-chip microcomputer manages the timed sampling and performs some signal preprocessing work, which solves the problem of timed sampling under Windows 95, reduces the workload of PC programming, and allows the application to focus on post-data acquisition processing.
Intelligent data acquisition system
The block diagram of the intelligent data acquisition system is shown in Figure 1. The source signal enters the A/D converter after amplification and filtering. The single-chip microcomputer reads the output of the A/D converter at a certain acquisition rate within the timer interrupt and temporarily stores it in the RAM. Outside the timer interrupt, the data stored in the RAM is continuously sent to the PC through the parallel port. The application in the PC receives the data sent by the single-chip microcomputer through the parallel port, and processes and displays the data.
1. Parallel port communication between MCU and host
With the development of computer technology, the parallel port of microcomputer has undergone great changes. It has evolved from being only able to print, that is, only able to transmit data to peripherals, to a bidirectional parallel interface that can exchange data bidirectionally and quickly between microcomputers and peripherals. The use of a bidirectional parallel port enables the PC to communicate with the single-chip microcomputer of the data acquisition system in an asynchronous, fully interlocked bidirectional parallel manner. It can reduce the number of times users interact with external devices and complete data transmission at a higher transmission rate.
The principle of the parallel port communication hardware part is shown in Figure 2, and the flow chart of the software part is shown in Figure 3.
The parallel port communication uses the preset and clear functions of the D flip-flop 74HC74 to provide the handshake signal required for data transmission. The eight D latches 74HC573 are used to complete the latching of the data transmitted by the single-chip microcomputer. When the single-chip microcomputer sends data to the PC, the single-chip microcomputer first latches the data in the 74HC573. The output end of the 74HC573 is connected to the input end of the data register of the microcomputer parallel port. After the data is latched, the single-chip microcomputer clears the clear end CD of the 74HC74 to make the output end Q output a low level, and the Q end is sent to the status register of the parallel port at the same time, notifying the PC that it can take data. After the PC detects this signal, it selects the data latch through the control port, takes out the latched data, and sets the trigger set end SD to 1, so that the Q end outputs a high level, notifying the single-chip microcomputer that the data has been taken out and the next data can be sent. After the single-chip microcomputer detects that the output of the trigger Q end has become a high level, it latches another new data into the 74HC573, and at the same time flips the output level of the trigger, notifying the PC to take data. This process is repeated until the PC no longer needs to read data. It is worth noting that in order to avoid the simultaneous validity of the clear and set terminals due to timing mismatch, the set (clear) terminal of the PC (microcontroller) should be tested before the microcontroller (PC) performs clearing (setting); and in order to avoid data transmission errors, the accumulator and XOR check are performed once every 16 data are sent. If the PC finds that the check result is wrong, it will notify the microcontroller to resend the previous 16 numbers.
The circuit design is simple when using this circuit for parallel port channel, and only one 74HC573 and one 74HC74 are needed. The use of 74HC573 and 74HC74 is very simple, making the programming easy and greatly improving the transmission speed.
2. Data exchange between MCU and RAM
The introduction of RAM in parallel port communication is to solve the problem that applications under Windows cannot respond to messages in time during data collection. RAM plays the role of a "reservoir" in the system: the single-chip microcomputer 89C51 on the data acquisition card reads the conversion results of each channel of the analog/digital converter MAX126 at a sampling rate of 200Hz in the timed interrupt and sends it to the external RAM for temporary storage; in the main program, the data stored in the RAM is taken out and transmitted to the laptop through parallel port communication. The data is stored in the RAM in a circular queue. In this way, when Windows responds to other messages and the laptop is slow, the collected data is temporarily stored in the RAM; when the laptop is fast, the single-chip microcomputer takes out the data stored in the RAM and transmits it. Because generally speaking, the speed of the laptop is sufficient to transmit the data stored in the RAM within the interrupt time. Therefore, as long as the storage capacity of the RAM is large enough (several times the maximum time that Windows may take to respond to other messages), the continuous transmission of data can be guaranteed. The data exchange process between the single-chip microcomputer and the RAM is shown in Figure 4.
3. Limitation of the maximum sampling rate
The discussion of the maximum sampling rate can be divided into two cases: real-time transmission and non-real-time transmission.
In real-time transmission, as mentioned above, the single-chip microcomputer collects data, temporarily stores it in RAM during the timer interrupt, and continuously sends it to the PC through the parallel port outside the timer interrupt. Therefore, the maximum sampling rate of the acquisition system is limited by the data exchange between the single-chip microcomputer and RAM and the execution time of the communication instructions with the PC parallel port. Assuming that the sampling data accuracy is single byte when using 89C51, 12MHz crystal oscillator, the single-channel sampling rate should not be higher than 32kHz.
If the real-time requirements for data processing are not high and the signal can be processed later, the non-real-time transmission mode can be selected. That is, after the microcontroller collects the data, it is stored in a large-capacity RAM without sending the data to the PC. After all the data are collected, the parallel port communication between the microcontroller and the PC is carried out, and the data stored in the RAM is sent to the PC at one time. The maximum sampling rate of the non-real-time transmission mode is not limited by the address comparison between the microcontroller and the RAM and the data passing rate of the parallel port, so that the timing resolution of the sampling can be less than (1/32) ms.
A set of physiological electrical data acquisition system implemented by the above principle, using a 12MHz crystal oscillator, can collect and process 16 channels of physiological electrical signals in real time at a sampling rate of 500Hz. If a higher crystal oscillator frequency is used, or a smaller number of channels is used, the sampling rate can be further improved.
summary
This paper proposes an intelligent data acquisition system. The timing system under Windows 95, which is complicated in programming, low in timing resolution and unreliable in operation, is replaced by the timing system under Windows 95, which is simple in programming, high in timing resolution and reliable in operation. The "reservoir" function of the RAM on the microcontroller solves the problem of Windows 95 responding to messages during timing sampling. It not only solves the problem of short messages under Windows 95 environment. It not only solves the problem of inaccurate short-term timing under Windows 95 environment, but also simplifies the user's application program. The microcontroller can also pre-process the collected data, saving the host time to process the data. This allows the PC application program to ignore the timing problem and focus on the processing work after the data is collected.
The parallel port communication between the data acquisition system and the host computer not only solves the time sampling problem under Windows 95, improves the data throughput rate of the system, but also makes the entire system structure simple, efficient and reliable. At the same time, it brings a series of benefits: it does not need to occupy an expansion slot in the PC like the currently commonly used plug-in data acquisition card, and can be connected to a laptop computer, which is easy to carry and safe to use, and has little interference with the collected signal, thereby achieving high-performance signal collection.