Grating sensors play an important role, especially in closed-loop feedback control of measuring tools, CNC machine tools, coordinate measurement of machine tools, etc.
At present, USB port has become the standard port of microcomputer motherboard. By using USB bus technology, various instruments and equipment suitable for scientific research and industrial production are developed to replace the serial RS232, parallel interface and ISA or PCI bus instruments and equipment used in traditional computer measurement and control systems. This can not only make computer measurement and control systems more efficient, real-time, convenient and flexible, but also meet the requirements of high-quality, high-reliability and low-cost computer measurement and control systems. This paper takes the design background of grating displacement sensor detection system and introduces the hardware and software design methods of the system in detail.
The basic principles and characteristics of grating displacement sensors
The basic structure of the grating displacement sensor is a pair of gratings, one of which is fixed and the other is moving. When they move relative to each other and light passes through them, a fringe signal equivalent to that obtained in an interferometer, the so-called moiré fringe signal, can be obtained. Compared with ordinary displacement sensors, it has the following characteristics.
● High precision. Grating displacement sensors are only inferior to laser interferometers in terms of long-range measurement of length or linear displacement. Grating sensors are also the most accurate in terms of circular indexing and angular displacement measurement.
● Large-range measurement with high resolution. Inductive synchronizers and magnetic grating sensors also have the characteristics of large-range measurement, but their resolution and accuracy are not as good as grating displacement sensors.
● Dynamic measurement can be realized, and the automation of measurement and data processing can be easily realized.
● It has strong anti-interference ability. The requirements for environmental conditions are not as strict as those of laser interference sensors, but it is not as adaptable as inductive synchronizers and magnetic grating sensors. Oil and dust will affect its reliability. It is mainly suitable for use in laboratories and workshops with good environments.
System hardware design
1 Introduction to system principles
The grating displacement sensor is a photoelectric converter for high-precision displacement measurement. It converts displacement micro-variables into multi-channel sinusoidal grating signals. The hardware circuit requires that the sinusoidal grating signals be synthesized first to eliminate the common-mode interference signal in the measurement, and then one channel enters the single-chip microcomputer for A/D conversion; the other channel is converted into a digital signal by a comparator, and the D flip-flop and the AND gate circuit complete the direction identification of the grating displacement, and then enters the single-chip microcomputer for forward and reverse counting; the single-chip microcomputer then sends these data to the computer through the USB port, and finally the computer performs data segmentation and processing to obtain the grating displacement length.
2. Selection of the plan
There are two data acquisition schemes using the USB bus. One scheme is to use an ordinary single-chip microcomputer plus a dedicated USB communication chip. The more popular dedicated chips now include National Semiconductor's USBN9602, USBN9603, USBN9604, Philips' PDIUSBD12, and SanLogic's SL11. This scheme can make full use of the original hardware resources and software knowledge of developers, and the development cost is low, but the design and debugging are more troublesome, and the electromagnetic compatibility is poor, which easily causes the host to fail to recognize the USB device. The other is to use a single-chip microcomputer with a USB interface function. At present, many major foreign chip manufacturers have successively launched single-chip microcomputers with USB communication interfaces. The data acquisition system circuit composed of these dedicated chips is simple in design, easy to debug, and has good electromagnetic compatibility. The USB grating displacement detection system interface circuit designed in this design uses Microchip's USB PIC single-chip microcomputer.
3 PIC18F4550 chip features
Microchip's PIC18F4550 microcontroller with USB communication interface is a 40/44-pin package equipped with a powerful 12MIPS RISC core, self-programmable flash memory and nanowatt energy-saving technology, operating frequency of 48MHz, and data transmission rate of up to 12Mb/s. The new device also features Microchip's advanced PMOS electrically erasable unit (PEEC) flash memory technology, which can withstand up to 1 million erase and write times, and the data retention period can exceed 40 years. In addition, its full-speed USB 2.0 interface includes an on-chip transceiver and a parallel stream port, which can directly transmit data to external devices, reduce CPU overhead, and greatly increase the system's anti-interference ability and work reliability.
A key feature of the PIC18F4550 microcontroller is that it is equipped with 32Kb of self-programmable enhanced Flash memory, allowing designers to upgrade their end applications in the field through the USB port. Combined with the new device's range of on-chip peripherals and nanoWatt power management features, this full-speed USB PIC microcontroller is ideal for a variety of embedded applications, including industrial, medical, automotive, battery-powered applications and consumer products.
There are 5 signals input from the grating sensor: ±SIN, ±COS and zero window signal ZERO. They are synthesized by the differential amplifier circuit and divided into 3 channels to enter the analog input port of the PIC microcontroller for A/D conversion; at the same time, the SIN and COS signals synthesized by the differential amplifier circuit are converted into digital pulse signals after the zero comparator, and then the direction of the grating displacement is completed through the D flip-flop and the AND gate circuit. The T0 and T1 ports of the PIC microcontroller receive the digital pulses from the AND gate circuit to complete the calculation of the grating displacement (calculate the number of complete gratings moved by the grating ruler); the RC1 port of the PIC microcontroller outputs a 4MHz PWM pulse signal as the CP signal of the D flip-flop. The two data lines of the USB interface of the computer are connected to the D+ and D- ports of the PIC18F4550 respectively to complete the data communication between the computer and the microcontroller. The USB power supply of the computer provides energy for the PIC microprocessor on the one hand, and is converted into ±12V power supply through the power module on the other hand to provide positive and negative power supply for the operational amplifier circuit.
System software design
1 Design of MCU software
The software part of the microcontroller mainly completes the data acquisition of the grating displacement sensor, A/D conversion, calculates the number of positive and reverse Moiré fringes of the grating displacement sensor, provides CP pulses for the digital circuit, and completes USB communication. [page]
① Program design of A/D conversion part
The ADC module of the PIC18F4550 device has 13 input channels. This module can convert any analog input signal into a corresponding 10-bit digital signal. This detection system needs to convert the COS and SIN two-way sinusoidal analog signals into digital signals, and at the same time send a zero-position pulse signal to the microcontroller register. Therefore, when designing the A/D conversion part of the program, RA0 and RA3 are set as the input of the SIN and COS two-way analog signals, RA5 is set as the digital input of the zero-position signal, and other analog signal ports are set as digital output ports, so as to minimize the impact of the microcontroller's peripheral circuit on the system's signal acquisition, and improve the anti-interference ability and accuracy of the entire system.
② Programming of the timer/counter part
The single-chip microcomputer of this detection system needs to calculate the number of grating lines that the grating displacement sensor moves in the forward direction and the number of grating lines that move in the reverse direction, and then send it to the host computer through the USB interface as the large part of the grating displacement length. After the sinusoidal signal output by the grating displacement sensor passes through the signal conditioning circuit, the number of grating lines it moves can be converted into digital pulses, so that the purpose of calculating the number of grating lines can be achieved by calculating the number of pulses. Therefore, we can choose Timer0 and Timer1 as counters to calculate the number of grating lines that the grating displacement sensor moves in the forward and reverse directions.
③ Design of Compare/Capture/PWM (CCP) module
PIC18F4550 has a 16-bit data and resolution capture (Capture) / Compare (Compare) / PWM (Pulse Width Modulation) module CCP2 and an enhanced capture / compare / PWM module CCP1. Among them, the enhanced CCP1 has dead zone control and fault protection input functions. Each CCP module has a 16-bit register, which can be used as a 16-bit capture register, a 16-bit compare register or a PWM master/slave duty cycle register. Because this design only needs one PWM output, we only need to use one CCP2 to meet the design requirements. According to the system design requirements, we use the Timer2 of the microcontroller in conjunction with the CCP of the microcontroller to make the CCP module output a 4M square wave.
④ Design of USB module
As for the microcontroller control program, no manufacturer currently provides tools to automatically generate firmware, so all programs must be compiled manually. The design of this system is completed based on the DEMO program provided by Microchip, with necessary modifications.
2 Design of PC software
The software part of the PC is mainly used to complete the USB communication between the upper computer and the lower computer, the subdivision and display of the displacement signal of the grating displacement sensor, etc. In order to further develop the software and interface with other software of the manufacturer, the software part of the upper computer of this system is implemented with VC++6.0 at the request of the manufacturer.
The device driver uses Microchip's universal USB device driver, and the interface communication program uses Microchip's BAPI.DLL dynamic link library.
The computer subdivides the last sine signal, and the subdivision points are obtained by calculating the phase program combined with the quadrant discrimination of the sine and cosine signals. In order to improve the accuracy, we divide the sine and cosine signals into 8 quadrants, and then find the ratio of the subdivision points, and then find the phase of the grating scale by finding the arc tangent function of the subdivision point, and then calculate the displacement value of the grating scale subdivision point according to the radian value of the grating scale phase, and finally add the displacement value of the grating scale subdivision point to the number of complete grating lines moved by the grating scale to obtain the displacement value of the grating scale.
Because the grating scale has different grating pitches, for the versatility of the design, we have processed the three commonly used grating pitches (100 lines/mm, 50 lines/mm, and 25 lines/mm) separately during programming. If the grating scale has 100 lines/mm, that is, the grating pitch is 0.01mm, and the sinusoidal signal is subdivided by 100, the distance measurement resolution can be 0.1μm.
When designing this project, I chose MFC-based dialog box design, and the display of data was all completed using Windows common controls.
Previous article:MCU crash problem
Next article:How to exit the sleep state of PIC16C5X microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The virtual machine Ubuntu system runs C language code and Python code
- ADC_DAC Basics
- [Help] How should I set the pull-up or pull-down resistor for ZYNQ's MIO?
- Show off the development board of ON Semiconductor's Internet of Things Innovation Design Competition!
- How to use Labview to perform secondary development on Ginkgo 2
- Looking forward to the review of the Yatli series~
- Common problems and solutions in CCS compilation
- Share the software phase-locking tutorial of C2000's 2812
- Dual-core intelligent electro-hydraulic servo controller using DSP and STM32
- Please help me find out what models these devices are.