Precision measurement and control system of photoelectric mouse sensor with speed based on single chip microcomputer

Publisher:东土大唐88Latest update time:2016-08-01 Source: ck365Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
 introduction

Belt drive is a common transmission device used in industrial production. Its commonly used speed detection device is a photoelectric encoder installed at the rotating end of the motor. However, in the long-term use of the equipment, due to unpredictable conditions such as wear, the motor speed and the belt drive speed are seriously inconsistent. This semi-closed loop control method has a large error in the belt drive speed control that requires higher precision. Grating rulers are expensive and have high requirements for the on-site environment, so they are often not very suitable for the modification of belt drive devices in ordinary working conditions. In view of this, this paper proposes to use a general commercial photoelectric mouse to replace the traditional detection device, and realize the on-site PID control through the AT89S51 microcontroller, so that the belt drive speed can meet our satisfactory requirements.

1. Hardware composition of the detection system

1.1OM02 optical sensor chip and mouse controller

This optical COMS sensor is a non-contact photoelectric mouse chip for personal computers. It integrates a digital signal processor (DSP), a dual-channel orthogonal output port, etc. There is a photosensitive eye at the bottom of the chip, which can continuously take pictures of objects and send the two previous and subsequent images to the DSP for processing to obtain the direction and distance of movement. The displacement value generated by the DSP is converted into a dual-channel orthogonal signal, and the dual-channel orthogonal signal is converted into a PS/2 data format that can be processed by the microcontroller in conjunction with the mouse controller. The device is installed on a set of plastic optical lens devices and is equipped with a high-intensity LED. In addition, it can provide a resolution of up to 400 dots/inch and a speed detection of less than 16 inches/second.

 

Mouse chip installation diagram

Figure 1 is the installation diagram of the mouse chip. Because the OM02 chip is a COMS sensor, it must be equipped with a high-intensity light-emitting diode that is compatible with it, and the emission angle and the bottom plate angle are within the range of 30°~45°. After standard installation, the effective distance between the bottom plate and the working surface is within 0mm~2mm, and the OM02 chip can perform normal data reception and detection.

1.2 Detection and control principle

This system adopts a full closed-loop control method, as shown in Figure 2 below. The displacement increment detected by the mouse is fed back to the microcontroller, and digital PID control is performed. The calculation result is transmitted to the inverter through the D/A conversion chip , thereby controlling the speed of the motor.

 

Photoelectric mouse detection control schematic diagram

This experimental system is mainly composed of a prime mover, a transmission part, an execution part and a control part. As an important part of the machine, the mechanical transmission system should not only be able to achieve the expected function, but also have good performance. To this end, this experiment uses a three-phase AC asynchronous motor (Y2-63M1-4, 0.12KW), a frequency converter (Fuji FRN0.4C1S-4C), a 30:1 worm gear reducer, a v-type B-phase belt transmission device, a P204 ball bearing and a bearing seat as the main transmission and execution parts of the simulated industrial equipment. By adjusting the output voltage U of the digital-to-analog converter through the single-chip microcomputer, the output frequency of the frequency converter can be changed, thereby changing the motor speed.

2. MCU Programming

2.1 Principle of Mouse Communication Protocol

The data communication method between the mouse and the microcontroller adopts the PS/2 communication protocol.

The physical interface of the PS/2 mouse is a 6-pin circular interface, and only 4 pins are needed for use: 1-pin Data, 3-pin GND, 4-pin +5VPower and 5-pin Clock.

The mouse implements a bidirectional synchronous serial communication protocol, sending or receiving data serially under the action of the clock signal. Usually, the microcontroller has bus control priority on the bus and can suppress the communication from the mouse at any time. The data from the mouse to the microcontroller is read on the falling edge of the clock, and conversely, the data from the microcontroller to the mouse is read on the rising edge of the clock. The clock signal is always provided by the internal chip of the mouse, and the clock frequency is generally 10~20KHz.

2.1.1 MCU to mouse communication

According to the protocol requirements, the MCU only needs to pull down the clock line for at least 100us to disable its communication, and the MCU pulls down the data line to put it in the request to send state. As shown in Figure 3, when the clock line rises to a high level and is pulled down again by the PS/2 device, the MCU can start communicating with the mouse.

 

Timing of MCU communication with PS/2 device

2.1.2 Mouse to MCU Communication

Because the MCU has control over the bus, when the mouse wants to send information to the MCU, it must first check whether the clock line is at a high level. As shown in Figure 4, when the clock line is at a high level and the data line is at a low level, it indicates that the mouse requests to send and the MCU can accept data from the mouse.

 

Mouse to microcontroller communication timing

2.1.3 Control data sent by the microcontroller

According to the PS/2 protocol specification of the mouse, when programming, first send 0xff to the mouse to reset it. The default sampling frequency is 100 times/second, the scaling ratio is 1:1, and data reporting is prohibited. Use the 0xea command to enter the stream mode, and use 0xe8 and 0x03 commands to set the resolution to 8 points/mm. Use the 0xf4 command to enable data reporting. In conjunction with the timer function of the AT89S51 microcontroller, set its time constant to 0.1s, and send the 0xeb command to read the displacement data information each time an interrupt occurs. Each time it is issued, the displacement data packet received by the microcontroller contains the displacement information and key action information. The specific format is shown in Table 1. When compiling, you only need to extract the valid data packet of X3, that is, the displacement increment in the Y direction.

 

3D mouse receiving data format

2.2PID control software algorithm

The system was simulated and tested in Matlab using neural network PID adaptive control, and the results were quite satisfactory. However, the multi-order matrix operations of its input layer, hidden layer, and output layer greatly increase the operation time of the single-chip microcomputer, resulting in an increase in the uncertainty of time. Compared with the incremental PID control, although the latter requires adjustment of three control parameters, it can also achieve the expected accuracy and the operation time is greatly reduced. Therefore, the incremental PID algorithm can still be used as the control. The control algorithm of the incremental digital PID is:

U(k)=U(k-1)+*(e(k)-e(k-1))+*e(k)+*(e(k)-2e(k-1)+e(k -2))

Where e(k) is the change between the current displacement increment and the previous displacement increment. Similarly, e(k-1) and e(k-2) are the displacement changes in the previous time interval.

By using the serial interrupt receiving function of the microcontroller, the kp, ki, and kd parameters of the PID can be adjusted in real time on the PC.

3. Host computer monitoring design

Send through the serial port of the microcontroller, write a program in LabVIEW to complete the PC control data communication equipment to exchange data, directly receive external data through the serial port and display it graphically, and store the data in a txt file. In Labview, direct serial port data communication is mainly achieved through VISA controls, and data communication is achieved through RS-232 serial interface and Labview.

 

Time displacement graph with motion

The readstring control can be used for display. Data reception is not continuous, but with a certain delay. In order to achieve uninterrupted reception of serial data packets sent by the microcontroller, the previous write and delay must be removed. Because the data received by the serial port is character type, the data is converted to single-precision integer through forced conversion. Create an array to combine data and array initialization to obtain a complete array. The real-time display and recording of the host computer can be achieved through the Waveformgraph control and shift register.

4. Detection and control performance evaluation

The maximum constant frequency of the PS/2 interface is 33kHz. This experimental microcontroller uses a 12MHz crystal oscillator, which can easily complete the interface function. However, due to the characteristics of its chip, although the highest resolution that can be used by the OM02 mouse chip is 400DPI, when using a higher resolution, the error rate of the mouse transmission will increase, and its displacement accuracy will also be questioned. In order to ensure the accuracy of the displacement, a resolution of 200DPI is used, and with the watchdog, the accuracy error and program stability will be greatly improved.

5 Conclusion

Using an optical mouse as a speed sensor to detect belt movement is cheap, accurate and easy to use. Combined with the digital PID control of a single-chip microcomputer and the graphic detection of labview software, it can be well modified for equipment with low speed requirements and not very high precision, so that it can achieve stable output speed. In addition, because the optical mouse technology has become mature, the requirements for the detection surface are not high under general resolution conditions, and it can still ensure smooth operation under relatively harsh working conditions. The laser mouse launched in recent years has a resolution of up to 0.01 mm, which is very effective. The experiment was tested on-site in a semiconductor company in Beijing, and the effect was ideal.

Keywords:MCU Reference address:Precision measurement and control system of photoelectric mouse sensor with speed based on single chip microcomputer

Previous article:LED--8051 driver test program
Next article:Implementing multiple serial ports with STC89C51RC/RD+

Recommended ReadingLatest update time:2024-11-15 14:39

[MCU] x_strtok, safe segmentation function
/*  * Copyright (c) 1988 Regents of the University of California.  * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  * 1. Redistributions of source code must retain the above copyright  *   
[Microcontroller]
Sharing of PIC microcontroller programming experience
PIC microcontroller (Peripheral Interface Controller) is an integrated circuit (IC) used to develop and control peripheral devices. It is a CPU with decentralized (multi-tasking) functions. This content describes the learning of programming in PIC microcontrollers. 1. The basic format of PIC microcontroller program
[Microcontroller]
Sharing of PIC microcontroller programming experience
51 MCU with nrf905 header file
Introduction: This article provides a code for a 51 microcontroller using the nrf905 header file. #define nRFMainDev //Main device //#define SysWaitTime 20//0.5*20=10S, stop flashing if no key is pressed #define SysWaitTime 6 //0.5*20=3S, no key press, stop flashing #define SysPushKeyTime 150 //Long press key 150 * 20
[Microcontroller]
51 microcontroller digital tube display study notes
This experiment is mainly to understand the hardware circuit diagram and software programming operation of the 51 microcontroller and digital tube connection. Table of contents: Hardware circuit: 1. Digital tube latch module: The eight latches of the 74HC573 are all transparent D-type latches. When the enable (
[Microcontroller]
51 microcontroller digital tube display study notes
st7735 color LCD simulation (Proteus 8 +bascom avr microcontroller)
Proteus simulation test of st7735 The microcontroller source program is as follows: '----------------------------------------------------------------------------' '                      ST7735R display library                             ' '                         resolution 128x160                                 
[Microcontroller]
st7735 color LCD simulation (Proteus 8 +bascom avr microcontroller)
51 MCU timer setting method_51 MCU timer/counter
There are two timers/counters T0 and T1 inside the 8051 microcontroller, which have both timing and counting functions. T0 and T1 do not require CPU participation during the counting process, and do not affect other CPU operations. When the count overflows, the timer/counter gives an interrupt signal, requesting the C
[Microcontroller]
51 MCU timer setting method_51 MCU timer/counter
Single chip microcomputer controls 12864 to display multiple lines of Chinese characters
PROTEUS simulation circuit diagram: Simulation experiment results show: Chinese character modeling process (software download link is at the end of the article): Step 1: Open the LCD simulation layout software Set relevant parameters: Input Chinese characters: Save the image somewhere: Step 2: Open the
[Microcontroller]
Single chip microcomputer controls 12864 to display multiple lines of Chinese characters
Principle and application of mobile phone distance sensor
Distance sensors are also called displacement sensors. Distance sensors are usually located on both sides of the handset or in the groove of the handset to facilitate their operation. When a user brings the phone close to his head to answer or make a call, the distance sensor can measure the distance and notify the sc
[Analog Electronics]
Principle and application of mobile phone distance sensor
Latest Microcontroller Articles
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号