Share this

Hardware and software design for displacement measurement based on grating sensor

2026-04-06 06:15:32 · · #1
As a tool for precision measurement, gratings have been widely used in precision instruments, coordinate measurement, precise positioning, and high-precision machining due to their inherent advantages [1, 2]. Grating measurement technology is based on the moiré fringe signal formed by the relative movement of the grating. By processing this signal in a series of ways, the displacement of the relative movement of the grating can be obtained [3]. By combining the grating displacement sensor with microelectronics technology, linear displacement can be measured to achieve higher measurement accuracy. This paper uses a grating as the sensing element, which is converted into a periodically changing electrical signal (approximately a sinusoidal signal) after passing through the receiving element. A logic direction discrimination circuit is used to distinguish the positive and negative directions of the displacement. A microcontroller is used for data processing and to display the results. The software is implemented in assembly language. 1 Hardware Circuit The hardware circuit of this design mainly consists of a microcontroller 89C51, a counter 8253, a subdivision and direction discrimination circuit, a signal conversion circuit, and a grating displacement sensor. As shown in Figure 1. 1.1 Grating Displacement Sensor The grating displacement sensor includes the following parts: grating; grating optical components. The function of the grating optical system is to form moiré fringes; photoelectric receiving system. The photoelectric receiving system is composed of photosensitive elements, which convert the optical signals of moiré fringes into electrical signals. This system uses four silicon photodiodes as photosensitive elements. 1.2 Signal Conversion Circuit Signal conversion involves converting the sinusoidal electrical signal output by the photosensitive element into a square wave signal. The comparator LM339 used in this paper receives the electrical signals from the moiré fringes of the grating onto the silicon photodiodes. These signals are applied to the positive inputs of the two comparators in the LM339. A certain reference voltage is preset at the negative inputs of these two comparators, ensuring that the high and low level widths of the square wave output by the grating are the same. 1.3 Subdivision and Direction Discrimination Circuit 1.3.1 Subdivision Circuit To record the number of fringes that have moved across the grating and to determine the grating's shift rate, a four-electrode silicon photodiode is used in the sensor to receive the moiré fringe signal. The width B of the moiré fringe is adjusted to be exactly the same as the width of the four silicon photodiodes. This directly obtains four signals that are sequentially 90° out of phase, i.e., a 4x subdivision. See Figure 2. 1.3.2 Direction Discrimination Circuit In addition to magnitude, displacement also has directional properties. To distinguish the direction of displacement of the scale grating, relying solely on a single photosensitive element outputting a single signal is insufficient. At least two signals must be present, their phase differences determining the displacement direction. Therefore, this design uses four silicon photodiodes to receive the moiré fringe signal. The four output signals are sequentially 90° out of phase. The direction discrimination circuit designed using this characteristic is shown in Figure 3. In the figure, u1, u2, u3, and u4 are distinguished by the same circuit. When the moiré fringe moves upward (assuming it passes the first two silicon photodiodes, at which point u1 and u2 have signals, while u3 and u4 have no signals), a counting pulse is generated at point A, and a constant level is observed at point B. When the moiré fringe moves downward (assuming it passes the first two silicon photodiodes, at which point u1 and u2 have signals, while u3 and u4 have no signals), a counting pulse is generated at point B, and a constant level is observed at point A. The direction can be determined by recording the number of pulses formed by the upward and downward movement of two different counters. 1.4 LED display This paper adopts a dynamic 4-bit display. The first bit is the sign bit, and the upward movement of the moiré fringe is positive and the downward movement is negative; the second and third bits are integer bits; the fourth bit is the decimal bit. All segment selection lines are connected in parallel and controlled by the P1 port of the microcontroller, while the common cathode common terminal is controlled by P3.0, P3.1, P3.2, and P3.3 respectively to realize time-division selection of each bit. 2 Software part The software part mainly consists of acquisition subroutine, data processing and display subroutine [4]. The acquisition subroutine completes the reading and conversion of the count value; the data processing subroutine completes the linearization of the acquired data; the display subroutine displays the results in a loop. The program flow is shown in Figure 4. 3. Conclusion The hardware designed in this paper uses an LM339 comparator to convert the output signal of the photosensitive device into a square wave signal, and employs a logic direction-sensing circuit to accurately determine the forward and reverse movement of the grating. Two counters from an 8253 microcontroller are used to count the forward and reverse signals respectively. Then, an 89C51 microcontroller is used for data processing, and the data is sent to the display. The hardware structure is simple, low-cost, reliable, and has relatively high accuracy. The software is implemented using assembly language, making the program simple, readable, and efficient.
Read next

CATDOLL 126CM Sasha (Customer Photos)

Height: 126cm Weight: 23kg Shoulder Width: 32cm Bust/Waist/Hip: 61/58/66cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22