Aiming at the application of rotary encoders in industrial sites, this paper designs a rotary encoder acquisition module based on the LPCI768 hardware platform. The module has high-precision analysis, shaping, and decoding circuits inside, which can analyze and decode 2 encoder input signals at the same time. The processed rotation signal is collected and digitally filtered by a high-performance processor. The rotary encoder also calculates the angular velocity of the 2 encoder signals. Finally, the module sends the collected rotation position value and angular velocity value to the DPU (distributed processing unit) through the CAN bus for use in industrial sites.
1 Rotary encoder
A rotary encoder is a sensor that measures the movement of a rotating part. It converts the mechanical displacement of the rotation into an electrical signal, and then processes the signal to detect position, speed, etc. The so-called encoding is actually the process of converting the information of the rotation angle into an electrical signal that can be read by a single-chip microcomputer. Rotary encoders can be divided into three types according to their working principles: contact, photoelectric, and electromagnetic. According to the form of the output signal, they can be divided into incremental and absolute values. Among them, the incremental encoder is the most commonly used encoder in industry.
The incremental encoder includes a code disk, a light-emitting element, a receiving element, and a signal processing part. When the shaft rotates, the code disk is driven to rotate, so that the engraved lines are transparent and the intervals are not transparent. The transmitted light is received by the receiving element and input into the signal processing part, generating a pulse signal output. The output signal generally includes two phases A and B (with a phase difference of 90°). Some encoders will also output a zero pulse Z for each revolution as a mechanical reference zero position. When the spindle rotates clockwise, the A channel signal is located before the B channel; when the spindle rotates counterclockwise, the A channel signal is located after the B channel, so it can be determined whether the spindle is rotating forward or reverse.
2 CAN bus
CAN bus (Controller Area Network) is one of the most widely used field buses in the world. CAN bus was originally developed by Bosch in Germany for automotive applications in 1983. It is a serial communication network that can effectively support distributed control and real-time control and belongs to the category of field bus. With the continuous improvement and development of CAN bus, it has been adopted as an international standard by international standard organizations.
CAN bus is a multi-master serial communication bus. The basic design specifications require a high bit rate and high anti-interference performance, and the ability to detect any errors. When the signal transmission distance reaches 10 km, it can still provide a data transmission rate of up to 5kb/s. After being standardized by ISO, the CAN protocol has two standards: ISO11898 and ISO11519. The difference between the two lies in the different definitions of the physical layer. ISO11898 is a CAN high-speed communication standard with a communication speed of 125 kb/s---1 Mb/s, while ISO11519 is a CAN low-speed communication standard with a communication speed of less than 125 kb/s.
3 Hardware Design
According to the system function requirements, this paper selects the LPCI768 processor produced by NXP. This processor is a 32-bit processor based on the ARMCortex--M3 core. It has 3 pipelines and Harvard structure, with independent local instruction and data buses and a slightly lower performance third bus for peripherals. It also includes an internal prefetch unit that supports random rotation and can operate at a frequency of up to 100MHz. The peripheral components of the LPCI768 processor include up to 512 kB of Flash memory, 64 kB of data memory, 4 general timers, 8-channel 12-bit ADC, 10-bit DAC, motor control PWM, 4 UARTs, 2 CAN channels, ultra-low power RTC with independent battery power supply, and up to 70 general I/0 pins. Figure 1 is the overall block diagram of the rotary encoder acquisition module.
Figure 1 Overall block diagram of the rotary encoder acquisition module
3.1 CPU part
According to the chip manual, LPCI768 can select the internal RC oscillator or the main oscillator as the system clock source. However, since the accuracy of the internal RC oscillator cannot meet the requirements of CAN bus communication, and the main oscillator can work in the frequency range of 1 MHz to 25 MHz, a 12 MHz crystal oscillator plus a 22 pF capacitor is selected to form a Pierce oscillator as the clock source of the main oscillator. Since the A/D module of the chip is not used in this system, VDDA can be connected to 3.3V together with VDD, and a 0.1uF decoupling capacitor needs to be connected between each pair of VDD and GND pins. At the same time, JTAG and communication pins are connected to VDD through a 10k pull-up resistor to improve the stability of signal transmission.
3.2 Rotary encoder acquisition part
When the rotary encoder is used for angle positioning or measurement, the shaking of the rotating shaft may cause the encoder output waveform to shake, thus causing miscounting. In this case, the waveform cannot be counted correctly. This system uses a monostable trigger to eliminate the jitter of the rotary encoder output pulse signal. Figure 2 shows one of the rotary encoder acquisition circuits.
Figure 2 One of the rotary encoder acquisition circuits.
By analyzing the circuit, we can know that when the rotary encoder rotates forward, F1 outputs a pulse sequence, and when the rotary encoder rotates reversely, R1 outputs a closed pulse sequence. The circuit simulation waveform is shown in Figure 3. [page]
Figure 3 Rotary encoder acquisition circuit simulation waveform
3.3 CAN bus communication part
The LPC1768 processor supports the CAN 2.0B specification and is compatible with the IS011898-1 standard. Based on this, this paper selects the PCA82C250 chip produced by Philips Semiconductors as the CAN bus transceiver, and the communication matching resistor is selected as 120 , i1. The CAN transceiver circuit is shown in Figure 4.
Figure 4 CAN transceiver circuit
3.4 Power supply
The operating voltage of LPC1768 is 3.3 V, while the voltage of CAN transceiver and rotary encoder acquisition circuit is 5 V, so MC33063 is used to reduce the input voltage to 5 V for related circuits, and then LM1117-3.3V is used to reduce the 5 V voltage to 3.3 V as the processor operating voltage. The power supply circuit is shown in Figure 5.
Figure 5 Power supply circuit
4 Software Design
The system uses RealView MDK-ARM V4.10 as the development platform and C language as the main development language. The program is mainly divided into three parts: the rotary encoder acquisition part uses the interrupt method to complete the counting of the input pulse signal through the timing capture unit of LPC1768; the CAN communication part also uses the interrupt method to monitor the commands from the DPU or other control host, and then execute the corresponding data transmission task; and the main program uses a certain time scheduling algorithm to complete the judgment of the rotary encoder's rotation direction, the calculation of the angular velocity, and the setting of the corresponding indicator light status, handle abnormal conditions in the CAN communication process, and feed the dog. The main program flow chart is shown in Figure 6.
Figure 6 Main program flow chart
5 Conclusion
The rotary encoder acquisition module designed in this paper is suitable for various industrial control sites and has a broad application prospect. After preliminary laboratory verification and application in an industrial field test, the module's processing results for the rotary encoder input signal meet user requirements, and can reliably communicate with the field control system, with stable working performance, strong anti-interference ability and high security.
Previous article:I2C bus PTZ motor control design in high-definition video surveillance
Next article:Feiling OK6410 timer accurately controls LED
- 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
- [Zero-knowledge ESP8266 tutorial] Quick start 21 world clock demo
- A question about the schematic
- Annual review: 2019 TI training course highlights, good reviews and gifts!
- Which development environment do I use for C8051F58x/F59x?
- C2000 CLA FAQ: Accessing Peripherals
- When adding LIB library in PROTEL99 under WIN10, it prompts FILE IS NOT RECOGNIZED. Is it only possible to modify AdvSch?
- TI MSP430F55xx ultra-low-power MCUs enable smarter connectivity
- 30. "Wanli" Raspberry Pi car - Phase 1 completed demonstration (introduction from scratch)
- Design of small signal precision rectifier circuit
- To help the development of China's IC design industry chain, OpenEDA open source platform is officially launched