Application of USB bus in grating displacement sensor detection system

Publisher:ularof不加糖Latest update time:2013-03-21 Source: dzsc Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  Grating sensors are widely used in the machinery industry because of their high measurement accuracy, wide dynamic measurement range, non-contact measurement, and easy system automation and digitization.

  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.

Reference address:Application of USB bus in grating displacement sensor detection system

Previous article:MCU crash problem
Next article:How to exit the sleep state of PIC16C5X microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号