3276 views|0 replies

1148

Posts

0

Resources
The OP

Design of multi-visual sensor measurement and control system based on CAN bus [Copy link]

5 CAN bus communication
CAN bus is a multi-master field bus. Each node has the right to send information to other nodes. Its protocol is simple, real-time, reliable and anti-interference, high bus utilization and low hardware cost. The main features are as follows:
1) Any node of the CAN bus actively sends data to other nodes on the network at any time without distinguishing between master and slave. The bus is occupied by which node through priority, and the communication is flexible.
2) The nodes on the CAN bus can be divided into different priorities through settings to meet different real-time requirements.
3) The CAN bus adopts non-destructive bus arbitration. When multiple nodes send data to the bus at the same time, the node with low priority will actively stop sending data and exit the competition, while the node with high priority will have the right to use the bus and continue to send data.
4) The CAN bus has multiple data communication transmission modes such as point-to-point, point-to-multipoint and global broadcast.
5) The communication bit rate between nodes is related to the distance between nodes. The farthest communication distance of the bus is 10km, at which time the communication rate is 5kbps, and the maximum communication rate can reach 1Mbps (within a communication distance of 40m).
6) The message ID can be used to determine whether to receive or block the message. The sent message can be automatically resent after being damaged.
7) Reliable error handling and error detection mechanism. The node has the function of automatically exiting the bus in the event of a serious error.
8) The message does not contain the source address and the destination address. Only the message identifier is used to indicate the function information and priority information.
5.1 CAN node hardware interface
The hardware part of the CAN bus interface is mainly composed of a microcontroller, a CAN controller and a CAN transceiver. The CAN controller implements the functions of the physical layer and the data link layer in CAN communication, and provides a physical line interface with the microcontroller and the bus. In this way, the user only needs to write an application layer protocol that meets his or her own communication and control requirements. In this system, the microcontroller uses Philips' 8-bit enhanced single-chip microcomputer P89C668, and the CAN controller and bus driver use Philips' SJA1000 and PCA82C250 to form a typical CAN communication node. Its hardware circuit diagram is shown in Figure 3:
The core part of the circuit is the P89C668 single-chip microcomputer, which uses 80C51 as the core, has an on-chip Flash memory with ISP (in-system programming) and IAP (in-application programming) functions, and the on-chip Boot ROM contains the underlying FLASH programming subroutine to download and upgrade programs through the serial port. It has 8K bytes of RAM (expandable to 64K) and 64K bytes of FLASH, as well as 4 interrupt priorities, 8 interrupt sources and 4 8-bit I/O ports, which can easily perform various on-chip operations and off-chip expansions. The CAN controller is equivalent to a memory I/O image device relative to the microcontroller. The SJA1000 chip has mode registers, status registers, command registers, interrupt registers, and receive and send registers. The microcontroller controls the SJA1000 by reading and writing these registers. The TX0, TX1, RX0, and RX1 pins of the chip are used for the interface of the CAN bus. The 12M crystal oscillator of the SJA1000 is provided by the external crystal oscillator generation circuit of the P89C668 at the same time; PCA82C250 is the interface between the controller and the physical bus, which can provide differential transmission and reception functions for the bus. Its TXD and RXD pins receive and send the driven signals respectively, and then connect to the bus transmission medium (twisted pair is used here) through CANH and CANL. At the same time, it should be noted that a 120 ohm terminal matching resistor should be added between CANH and CANL to ensure the normal communication of the bus.
5.2 Software Design of CAN Nodes
The software design of the CAN bus intelligent node mainly includes three parts: CAN node initialization, message sending, and message receiving. The communication of the CAN node is essentially to read and write the registers inside the CAN controller. Since these registers or send and receive buffers have certain addresses, the CPU can read and write them through peripheral access instructions. After the system is powered on and reset, the CPU writes the corresponding control word information to each control register of SJA1000 to complete the initialization of the CAN controller. In this example, the system software adopts a structured programming method. The program has good modularity and portability. For different detection systems and application environments, the program can be easily reorganized. The programming language adopts the single-chip microcomputer C language Keil C51, which has high efficiency and good readability, and can effectively reduce the workload of system software programming.
The key to the success of CAN bus communication is the initialization setting of SJA1000. The initialization program determines the working mode of CAN by writing the control word into the register of the CAN controller. P2.7 of P89C668 is used as the chip select signal to connect to the CS pin of SJA1000. The on-chip registers of SJA1000 and the registers of P89C668 microcontroller are overlapped. Therefore, when addressing the SJA1000 register, it should be defined as off-chip RAM addressing. The initialization procedure of the CAN node is given below:
Init_Can (void)
{ MODE = 0x09; file://Enter reset mode and initialize SJA1000;
CDR = 0x88; file://Select PeliCan;
CMR = 0x0C; file://Clear data overflow and release the receive buffer;
IER = 0x03; file://Open receive interrupt and send interrupt;
ACR0 = 0x66;
ACR1 = 0x66;
ACR2 = 0x66;
ACR3 = 0x66; file://Set the acceptance code register according to the specific protocol definition;
AMR0 = 0xFF;
AMR1 = 0xFF;
AMR2 = 0xFF;
AMR3 = 0xFF; file://Set the acceptance mask register according to the specific protocol definition;
BTR0 = 0x41;
BTR1 = 0x1B; file://Under 12MHz crystal oscillator, set the baud rate to 200kbps;
OCR = 0XAA;
EWLR =0x60;
RBSA = 0x00; file://RX buffer start address register is set to 0;
TXERR= 0x00; file://Transmit error receiver is set to 0;
ECC =0x00; ?
MODE= 0x08; file://Unidirectional filtering mode, enter normal mode, initialization completed;
Since the visual sensor measurement and control system needs to perform visual detection mostly online, the real-time requirement is strong. Here, each sensor node uses the interrupt reception method to receive the control command of the host computer. After the node is initialized, when a frame of information is confirmed as correct information after error detection and loaded into the receiving buffer, the INT pin of SJA1000 will generate an interrupt signal. This signal is connected to the external interrupt 0 pin of the microcontroller P89C668. In the external interrupt 0 interrupt handler, the identifier of the information is judged. If it is the address of this node, the data in the receiving buffer is read out and saved in RAM. The flowchart of the interrupt reception program is as follows:
The system uses the query method to send messages. The sensor node sends data after receiving the data request command from the main control computer. The sending module first performs a status query to determine whether the bus is idle. If it is idle, the destination node address is written into the sending identifier register, and the data is written into the sending buffer to complete a frame of CAN information sending.
The CAN information format is divided into two parts: information and data. The first two bytes are the information part, and the first 11 bits are the identifier. The first eight bits of the identifier are used for receiving judgment, which should contain the destination node address of this information packet, followed by an RTR bit (0 for data frame, 1 for remote frame, this example uses data frame), and finally four bits of DLC. The remaining eight bytes are the data part, which contains the actual data to be sent. In this example, only the first two data are used. The first one represents the sensor address, and the second byte indicates which of the two cameras in the sensor is selected to collect the image.
Another key to successful communication between CAN nodes is the baud rate setting. Not only should the lower-level nodes on the CAN bus be set to the same baud rate, but the USBCAN interface card connected to the upper PC should also have the same baud rate to ensure smooth communication. Since the CAN controller SJA1000 in the USBCAN interface card uses a 16M crystal oscillator, and the SJA1000 and P89C668 in each sensor node use a 12M crystal oscillator, it is necessary to calculate the BTR0 and BTR1 that are consistent with the two crystal oscillators for different communication rates to set the bus baud rate.
6 Conclusion
This paper mainly focuses on the design and research of the multi-visual sensor control system. At present, the system hardware and software have been preliminarily debugged, and can achieve the rapid switching and transmission of video images of each visual sensor, and the image jitter is small when switching, and the effect is good. Before the system is applied to visual inspection, it is also necessary to calibrate each visual sensor and the overall calibration of the system. After the system calibration is completed, it can be put into use. The accuracy of this system is mainly determined by the hardware. High-precision, high-resolution CCD cameras and lasers are selected. The finer the line structure light projected by the laser, the more uniform the light intensity distribution, and the higher the measurement accuracy. High measurement accuracy will inevitably lead to a small measurement field of view, and the effective field of view of the sensor is related to the placement angle between the camera and the laser and the internal parameters of the camera. Due to space limitations, it will not be repeated here.
In view of the excellent performance of the CAN network, it can exchange information quickly and reliably, and is particularly suitable for the interconnection of multiple communication nodes to form a multi-host controller local network. This paper explores its control application in the multi-visual sensor measurement and control system. This visual system must not only have good network expansion capabilities, but also increase or decrease some sensor nodes during the system operation will not affect the system operation, only a small modification of the software is required. For different measurement targets, the laser in the visual sensor can also be replaced with a halogen lamp (a power interface is reserved in the sensor circuit in advance), so that the system can easily face different measurement tasks. The CAN bus has strong driving ability and just the right network performance, which can meet the requirements of different measurement systems. The number of system nodes can be flexibly adjusted without affecting the reliability of the system. The CAN bus network has a high cost-effectiveness and strong portability. The multi-visual sensor measurement and control system designed in this paper has been successfully applied to online visual inspection of automobile bodies, and can be applied to other measurement control systems in the field of industrial automation with slight modifications.
This post is from Automotive Electronics

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list