Design of a Vehicle Virtual Instrument Data Acquisition System Based on CAN Bus Technology
2026-04-06 06:21:27··#1
Abstract: This paper introduces the design method of a multi-channel data acquisition system for a vehicle Virtual Instrument based on CAN bus, and provides a detailed system block diagram and key circuit diagram. The CAN communication subroutine is analyzed in detail, and flowcharts for CAN communication initialization, data transmission, and interrupt service routines are presented. Keywords: Virtual Instrument, CAN bus, Data Acquisition System, F/V conversion 1 IntroductionVehicles present a unique application environment. The increasing automation of vehicles places higher demands on vehicle instruments. Traditional moving magnet instruments are increasingly unsuitable for the needs of modern intelligent transportation, while virtual instruments have gained widespread attention due to their interactive, intelligent, and easily expandable features. This project requires the design of a virtual instrument cluster for a vehicle, with the host computer using a PC104 embedded microcomputer based on an RTOS development environment. The vehicle environment data acquisition system, as a crucial subsystem of the virtual instrument cluster, is required to complete data acquisition and communication functions, and possess high real-time performance and reliability. This paper, based on the author's experience, introduces the method of designing a vehicle data acquisition system using Philips' high-performance microcontroller P80C592, focusing on system design and CAN communication programming. 2 System Introduction According to the design requirements, this system mainly processes sensor signals and acquires vehicle operating condition data, sending the data to the host computer via the CAN bus. It is required to process 16 analog signals, 4 frequency signals, and 32 extended I/O signals. The acquired parameters mainly include: engine oil pressure, water temperature, oil temperature, engine speed, vehicle speed, transmission oil pressure, fuel tank level, mains voltage, door status, turn signal indication, vehicle overwidth indication, and in-vehicle environment warnings. The signal forms include voltage, frequency, and switching signals, with a frequency range of 0–6 kHz. 2.1 System Hardware Structure Design Figure 1 shows the system hardware structure. The core device used in the system is the Philips P80C592 8-bit high-performance microcontroller, which is fully compatible with the standard 80C51. Its main features include: a built-in CAN controller capable of DMA data transfer with internal RAM; four capture ports and two standard 16-bit timers/counters; a 10-bit ADC converter with eight analog inputs; 2 × 256 bytes of on-chip RAM; and a watchdog timer. The P80C592's on-chip CAN controller can fully implement the CAN protocol, thus reducing system wiring and enhancing diagnostic and monitoring capabilities. The digital-to-analog converter is a 12-bit AD1674A with a resolution of 0.02% and a conversion time of 25µs. To improve the system's anti-interference capability, opto-isolation is used between the analog-to-digital circuits and between the system and the CAN bus. The analog and digital circuits are designed as two independent PCBs, which are stacked to form a complete system. Hardware Operation: Temperature, pressure, and voltage signals are processed by relevant circuits and sent to a 16-channel analog switch MAX306EP. These signals are then input to an AD1674A via a voltage follower circuit for A/D conversion. To improve reliability and stability, the system does not use an on-chip ADC converter for the microcontroller. Under program control, the 16 signals are sequentially selected. The acquired data is encapsulated into CAN protocol packets within the CAN controller and transmitted to the CAN bus via opto-isolation and a transmitter. The fuel level signal is opto-isolated, shaped, and frequency-divided before being sent to the P80C592's capture port for frequency measurement. The engine speed and vehicle speed signals are shaped and split into two paths: one path is divided by a frequency divider and sent to the microcontroller's capture port, while the other path is converted from F/V and sent to the ADC for sampling. Access to the ADC and I/O expansion ports is controlled by the programming logic output of the GAL decoder. [align=center]Figure 1[/align] 2.2 Frequency Signal Measurement Frequency signal measurement is a design challenge of this system. In this project, different sensors are selected for different vehicle models. Therefore, there are two methods for processing the frequency signals of rotational speed and vehicle speed: First, when using a contact sensor with an output frequency range of 0-100Hz, the CS289 frequency-to-voltage converter chip is used to convert the frequency signal into a voltage signal of 2.2-7.2V and then send it to the ADC for acquisition; Second, when using a non-contact sensor with an output signal frequency range of 0-3000Hz, the frequency is measured by pulse counting through the microcontroller's capture port. To improve the system's versatility, both methods can be used simultaneously. The specific method used to obtain the data is set by the microcomputer software. Figure 2 shows the F/V conversion circuit diagram; [align=center]Figure 2[/align] The CS289 is a single-chip high-precision dedicated rotational speed measurement chip manufactured by Cherry AG, which has good linear output in a temperature range of -400 to +850°C. It can be used not only for F/V and V/F conversion, but also as a function generator and a driver for moving magnet instruments. The F/V conversion circuit constructed from it has few external components, is easy to debug, and operates stably and reliably. As shown in Figure 2, the shaped speed pulse signal is input to pin 10 of the CS289 via a filter network and a limiting input. The voltage signal is output from pin 8 and, after filtering to eliminate possible power frequency interference, is sent to the sampling circuit. In this circuit, the relationship between the output voltage and the input frequency is determined by the following formula: the host computer calculates the frequency value based on this linear relationship. To ensure that the F/V conversion has sufficiently high linearity, a reasonable value should be selected. 3 System Software Design The system software mainly completes three tasks: 1. Sampling and calculating sensor signals; 2. Transmitting the collected data to the host computer when it requests data; 3. Uploading data to complete the switching from sensor signals to standard signals when receiving a self-test command from the host computer. The program flow is shown in Figure 3: [align=center] Figure 3[/align]. The main program adopts modular programming. Self-diagnostic capability is a key feature of virtual instruments. Therefore, the data acquisition system incorporates three sets of standard signals: frequency, voltage, and resistance. The self-test module's main function is to disconnect the sensor input upon receiving a self-test command from the host computer, allowing the standard signals to be connected to the data acquisition system. The obtained data is then uploaded to the host computer and compared with the standard values to determine whether the fault lies in the sensor system or the data acquisition system. A successful self-test indicates that the data acquisition system is functioning correctly. The data transmission module primarily handles data communication with the host computer. This system is designed to send data packets to the host computer every 20 milliseconds. The data transfer module handles the writing of various data into the main RAM. To distinguish data types, corresponding type identifiers are added to the data blocks; these identifiers are defined by the user-level protocol. The A/D sampling module controls the system's sampling process and reads each 12-bit sampled data into designated RAM units in two steps. The frequency signal processing module completes the measurement of the capture port frequency. Its basic idea is: within one cycle of the measured signal, the timer T2 is started and stopped by two pulse falling edges respectively. The reciprocal of the difference between the two count values is the frequency value. This module only needs to calculate the difference, and the frequency value is calculated by the host computer. 3.1 CAN controller programming One of the difficulties in the software design of this system is the programming of CAN. The CAN program modules processed by this system are: CAN initialization subroutine, CAN interrupt program and CAN data transceiver subroutine. The CAN controller appears as a CPU memory image of the peripheral device. The data transmission between the CPU of P80C592 and the CAN controller is realized through four special function registers, namely: CANADR, CANCON, CANSTA and CANDAT. Through these four special function registers, the CPU can access any register (address 0~29) and DMA logic inside the CAN controller. Table 2 gives a brief description of the functions of these four SFRs. The read and write operations of CANCON and CANSTA have different meanings. For a detailed introduction of all registers inside the CAN controller, please refer to reference [1]. [align=center]Table 1[/align] The CAN controller initialization (Figure 4) is a very important subroutine in CAN communication, and its proper execution directly affects the entire communication process. CAN controller initialization must first be achieved by setting the "Reset Request" bit in the CAN control register. Setting the "Reset Request" bit does not affect an ongoing transmit/receive operation. It is particularly important to note that registers at internal CAN addresses 4-8 can only be accessed when the reset request is set. After the reset operation, this bit must be set to 0 to retain the settings and return the CAN to its working state. [align=center]Figure 4[/align] Both the P80C592 and its on-chip CAN controller have interrupt registers; the difference between the two must be noted. The CAN interrupt subroutine (Figure 5) first reads the CAN interrupt register (IR) to determine the interrupt type and then proceeds to the corresponding operation. If the receive buffer is full and the first byte of another message needs to be stored, the data overrun bit is set. In this case, the overrun bit should be cleared, the receive buffer released, and the data request retransmitted. In the data receiving subroutine, after the data is transferred to the RAM area, the receive buffer should be released in a timely manner to prepare for receiving the next frame of data. [align=center] Figure 5[/align] [align=center] Figure 6[/align] The data sending subroutine is shown in Figure 6. When the CAN controller sends data to the bus, it first writes the starting address of the data storage in the main RAM to CANSTA, and then reads the value of CANSTA.6 (reading CANSTA is actually a read operation of the CAN controller's internal status register; CANSTA.6 is the error display bit, which will be set by the CAN controller when at least one bus error counter reaches the CPU alarm limit). If an error is detected, the CAN initialization subroutine is executed. If normal, the receive status and transmit buffer status are checked. If the transmission conditions are met, the transmit buffer address is written to CAANADR and the DMA control bit is set (MOV CANADR, 8AH). DMA transfer is then started, the data field is copied from RAM to the transmit buffer, and the transmit request bit (CANCON.0) is set before data transmission begins. 4 Conclusion The vehicle environment data acquisition system composed of high-performance P80C592 and AD1674A data acquisition modules has a high cost performance. The system has been put into trial use and is running well. CAN bus is very suitable for serial communication networks for distributed control or real-time control. This project only involves data acquisition. If vehicle auxiliary control and important data backup functions are extended on this basis, the system will have a broader application prospect. References: [1] Wu Kuanming. CAN bus principle and application system design. Beijing University of Aeronautics and Astronautics Press. 1996