Design of CAN bus ultrasonic ranging intelligent node based on PIC18F2580

Publisher:数字冲浪Latest update time:2011-05-18 Keywords:PIC18F2580 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction
Mobile robots must have automatic navigation and obstacle avoidance functions to operate in uncertain environments. Sensors play a vital role in the navigation system of mobile robots. Vision, laser, infrared, ultrasonic sensors, etc. have been widely used in practical systems. Among them, ultrasonic sensors are widely used as ranging sensors for mobile robots due to their simple information processing, fast speed and low price, so as to achieve functions such as obstacle avoidance, positioning, environmental modeling and navigation. The design of the CAN bus intelligent node introduced in this article is based on the PIC18F2580 control core of Microchip. Since the PIC18F2580 has a built-in CAN controller and provides many dedicated hardware functions for CAN applications, it is used as the CAN bus controller of the system, which greatly saves the resources of the main control system. The transceiver of the CAN bus uses TJAl040. The overall structure diagram of the system is shown in Figure 1.

Figure 1 System overall structure block diagram
The robot system control core is implemented by ARM or DSP. Its main function is to process information that requires complex calculations, send the processed information back to the CAN bus, and manage the entire network. The main function of the ultrasonic intelligent node control system is to determine the location of obstacles, and transmit the obstacle information that hinders the forward direction of the mobile robot back to the main control system through the CAN bus. The main control system will make corresponding processing and perform obstacle avoidance actions. This article will focus on the ultrasonic intelligent node control system.
2 Ultrasonic ranging principle
The principle of ultrasonic ranging is relatively simple. Generally, the transit time method is used, that is:
D=ct/2 (1)
Where D is the distance between the mobile robot and the obstacle to be measured, and c is the transmission rate of sound waves in the medium. The transmission rate of sound waves in air is:
c=co (2)
Where T is the absolute temperature, co =331.4m/s. In the case where the ranging accuracy is not required to be very high, c can generally be considered as a constant. The transit time method mainly measures the time interval t from the ultrasonic emission to the ultrasonic return, that is, the "transit time", and then calculates the distance according to formula (1).
3 Hardware Design of Ultrasonic Intelligent Node Control System
The hardware circuit of the ultrasonic intelligent node control system is shown in Figure 2.
3.1 Control Circuit
The control part of the ultrasonic sensor uses the PIC18F2580 produced by Microchip. It is a single-chip 8-bit high-performance microcontroller that adopts the Harvard bus structure, has high operating speed, low power consumption, strong anti-interference ability, and an on-chip CAN controller.
As the system control core, PIC18F2580 has two main tasks. The first is to serve as the control core of the ultrasonic sensor, expanding the receiving and transmitting circuits of the ultrasonic sensor on its ordinary I/O port, using the microcontroller software function to generate a 40 kHz signal and transmit it through the drive amplification, and then using the receiving circuit for reception. In addition, the remaining port lines can continue to expand the ultrasonic sensor to realize the design of multiple ultrasonic sensor systems. The second is to use the on-chip CAN controller of the PIC18F2580 to connect to the CAN bus. This design changes the previous design of ultrasonic ranging system on the robot control core. It not only transfers the ultrasonic detection and processing work to the single-chip microcomputer, greatly saving the system resources of the robot control core, but also transfers most of the control work of the CAN bus intelligent node to the single-chip microcomputer, saving hardware resources. At the same time, the use of CAN bus greatly improves the system's anti-interference ability and makes the robot control system work more stably.

Figure 2 Ranging node control circuit diagram [page]

3.2 Ultrasonic sensor transmitting circuit design

Figure 3 Ultrasonic emission circuit diagram
In Figure 3, LM386 is an audio integrated amplifier with the advantages of low power consumption, adjustable voltage gain, large power supply voltage range, few external components and low total harmonic distortion. It is widely used in recorders and radios. It is a three-stage amplifier circuit. The hardware circuit of this part is relatively simple. It mainly uses the drive amplification function of LM386 to amplify and output the 40 kHz square wave generated by the single-chip microcomputer. Because the work of the single-chip microcomputer in the intelligent ultrasonic node control system is relatively small, in order to save hardware, it is better to hand over the generation of the 40 kHz square wave to the CCP module of the single-chip microcomputer. TX1 is the ultrasonic transmitter.
3.3 Ultrasonic sensor receiving circuit design
The circuit uses the integrated circuit CX20106A. This is an infrared detection receiving integrated circuit, which is commonly used in infrared remote control receivers for televisions. Considering that the commonly used carrier frequency of 38 kHz for infrared remote control is close to the ranging ultrasonic frequency of 40 kHz, it can be used as an ultrasonic detection circuit. Experiments have shown that it has high sensitivity and strong anti-interference ability. By changing the value of C11 appropriately, the sensitivity and anti-interference ability of the receiving circuit can be changed. R12 and C11 control the internal amplification gain of CX20106A, and R14 controls the center frequency of the bandpass filter. Generally, R12=4.7Ω, C11=1μF. The values ​​of the other components are as shown in Figure 4. RX1 is the ultrasonic receiving head. When receiving ultrasonic waves, a falling edge is generated and connected to the external interrupt INTO of the microcontroller.

Figure 4 Ultrasonic receiving circuit diagram
When the ultrasonic receiving head receives a 40 kHz square wave signal, it will drive and amplify the signal through the CX20106A and send it to the external interrupt 0 port of the microcontroller. After receiving the interrupt request of external interrupt 0, the microcontroller will transfer to the interrupt service program of external interrupt 0 for processing. In the obstacle avoidance work of the mobile robot, the shortest distance that needs to be processed by the microcontroller can be set in the interrupt service program, such as 0.4m. For obstacles with a distance greater than 0.4m, the interrupt service program can be directly jumped out without processing; for obstacle information with a distance less than or equal to 0.4m, it will be processed in the interrupt service program and reported to the robot system control core through the CAN bus, and the robot system control core will issue commands to guide the robot's obstacle avoidance action. For a multi-ultrasonic sensor system, each ultrasonic sensor can perform simple processing on the obstacle information in its interrupt service program when it determines that there is an obstacle to the robot's movement. The information reported to the robot system control core can be relatively simple. The robot system control core only needs to control the actual action of the robot, such as turning right 20°, without the need for the robot system control core to calculate again, which will save a lot of system resources to do other more complex work.
3.4 CAN bus design part
TJAl040 is a high-speed CAN bus transceiver produced by Philips Semiconductor. The device provides an interface between the CAN protocol controller and the physical bus, as well as differential transmission and reception functions for the CAN bus. TJAl040 has excellent EMC performance and ideal passive performance when not powered on; it also provides low power management and supports remote wake-up. It is worth mentioning that TJAl040 has an automatic fail-safe function. The STB pin is grounded in normal mode, and the pin TXD provides a pull-up to VCC to keep the pin TXD at a recessive level when not in use. If VCC loses power, the pins TXD, STB and RXD will become suspended to prevent reverse current from flowing through these pins.
6N137 is a photocoupler. The purpose of using the photocoupler 6N137 is to enhance the anti-interference ability of the CAN bus nodes. This design can well achieve electrical isolation between the CAN nodes on the bus. However, it should be noted that the two power supplies VCC and VDD used in the optocoupler circuit must be completely isolated, otherwise the optocoupler loses its meaning.
As a CAN bus transceiver, TJAl040 also takes anti-interference measures in the interface part with the CAN bus. The CANH1 and CANL1 pins of TJAl040 are each connected to the CAN bus through a 5Ω resistor. The resistor can play a certain current limiting role and protect TJAl040 from overcurrent shock. [page]

Two 30 pF capacitors are connected in parallel between CANH and CANL and the ground to filter out high-frequency interference and certain electromagnetic radiation on the bus. A protection diode is connected between the two CAN bus terminals and the ground. When the CAN bus has a high negative voltage, the diode can provide a certain overvoltage protection. The 120Ω resistors connected at both ends of the bus play a role in matching the bus impedance. Ignoring it will greatly reduce the anti-interference performance and reliability of data communication or even make it impossible to communicate.
4 Software Writing of Ultrasonic Intelligent Node Control System
The software writing work mainly consists of two parts: the ultrasonic ranging part and the CAN bus communication part.
4.1 Software Design of Ultrasonic Ranging Part
When the ultrasonic receiver receives the echo, the hardware circuit generates a pulse level to trigger the external interrupt 0 port of PIC18F2580. The main idea of ​​software writing is to pre-set a value by the register in the interrupt service program. This value is the shortest distance for the robot to avoid obstacles. From the time the ultrasonic transmitter emits a square wave to the time the ultrasonic receiver receives the echo, this time is converted into a distance and compared with the above shortest distance. If it is greater than the shortest distance, no processing is done and the interrupt service routine is exited; if it is equal to or less than the shortest distance, the corresponding action is executed. Figure 5 is the flow of this part of the program.

Figure 5 Ultrasonic ranging software flow chart
4.2 Software writing of CAN bus communication part
This part of software writing mainly consists of the following parts: initialization, receiving processing, sending processing, interrupt processing and error handling functions. Since any node in the system can actively communicate with other nodes at any time, the communication programs of each node are roughly the same. For the specific program writing, please refer to the user manual of PIC18F2580.
5 Conclusion
This paper discusses the basic idea of ​​expanding multi-channel ultrasonic sensors with CAN bus, and introduces a CAN bus intelligent ultrasonic ranging system with Microchip's PIC18F2580 as the ultrasonic sensor control core and CAN bus controller. TJAl040 is used as the CAN bus transceiver. The expansion of multi-channel ultrasonic sensors is transferred to the intelligent node part, which simplifies the work of the mobile robot system control core; a relatively simple hardware design is adopted, mainly to concentrate the control core of the ultrasonic sensor and the CAN bus controller together, and use PIC18F2580 as a device to complete the work of two chips, saving hardware. In addition, the expansion of the CAN bus will also make the subsequent development of the mobile robot system more flexible.

Keywords:PIC18F2580 Reference address:Design of CAN bus ultrasonic ranging intelligent node based on PIC18F2580

Previous article:LED display circuit based on PIC12C508
Next article:Design of intelligent charger based on UCC3895 and PIC 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号