9 » IC Electronic information » Category: A

IC Electronic information

A Picoblaze Modbus communication protocol to achieve the design of nuclear

In Electronic Infomation Category: A | on April 18,2011

Currently, the major FPGA vendors from sales data, published, Xilinxs FPGA market share to nearly 50%. Spartan-3E family of devices densities ranging from 100,000 to 1,600,000 system gates, the unit cost of FPGA logic cells of the lowest in the industry, able to achieve the standard price microprocessors, microcontrollers and SI9104DW datasheet and digital signal processor functions , and SI9104DW price and support for 18 common I / O standards, but also to operate through the ISE PicoBlaze soft-core. Spartan-3E platform combined with a powerful FPGA features and SI9104DW suppliers and low price. Thus enable more designers to enjoy the benefits of programmability.

1 Picoblaze nuclear structure

This paper, Xilinxs Spartan-3E * The evaluation board and PicoBlaze IP Core for Modbus communication protocol based on system design. The system is based on the overall structure of PC as a host computer and embedded Picoblaze * soft core assessment panel as the next crew, in order to achieve Modbus communication protocol. Xilinx PicoBlaze is an 8bit microcontroller, the companys soft-core, it is very small. Can be embedded into the Cool Runner , Virtex-E, Virtex-II (Pro) and the CPLD and the Spartan-3E FPGA. For the entire instruction set, PicoBlaze to execute an instruction requires two clock cycles.

Be developed in the PicoBlaze, first need to understand and implement the program PicoBlaze Assembler been converted into the corresponding FPGA HDL files stored in the internal Block Memory (so, PicoBlaze required to execute an instruction clock cycle is fixed a). Then, the micro-controller core KCPSM3 then reads the program from the Block Memory according to the order of execution. PicoBlaze of storage space for 1024x18bit, that is, it can store 1,024 bits long for 18 of the instructions. The PicoBlaze instruction set support is also very thin (only 57), which contains the program control class (jump, call, return), arithmetic classes (addition, subtraction, comparison), logic type (AND, OR, XOR), interrupt class (interrupt on / off), shift / rotation class (left / right, L / D-) and input / output type (input, output). PicoBlaze core of the structural framework shown in Figure 1.

Figure 1 PicoBlaze core of the structural frame diagram

Figure 2 is a micro-controller core KCPSM3 structural framework map. KCPSM3 length for a total of 16 8-bit general purpose registers, each register can be named in the assembly code. One, Scratch Pad Memory size is 64 Bytes, acts as a temporary storage area. KCPSM3 only supports an interrupt signal, but in fact can be a logical combination of multiple interrupt signal into a way to use (will reduce the performance of a single interrupt channel).

Figure 2 the structure of the microcontroller core KCPSM3 frame map

2 Modbus protocol

2.1 Modbus Protocol Overview

Modbus protocol is used in electronics on a common language for the controller. Through this agreement, between the controller, the controller via the network (such as Ethernet) and other devices can communicate. Modbus interface uses standard RS-232C compatible serial interface, use the master-slave controller communication technology, it is only one device (the master) can initiate the transfer (query). Other equipment (from equipment) is provided under the master data query to the appropriate response.

2.2 Serial Transfer Mode

Standard Modbus, the controller can use the ASCII or RTU communication mode for communication. In this design, the RTU mode. When the controller Modbus RTU mode to communicate on the bus, the information in each 8-bit bytes can be divided into two 4-bit 16 hexadecimal characters, the models main advantage is in the same baud rate, its transmission density higher than the ASCII character mode, but each message must be continuous transmission. The RTU mode of data transmission formats such as listed in Table 1.

Table 1 RTU mode data transfer format

In RTU mode, each byte format 8-bit coding system for binary, hexadecimal 0 to 9 and A ~ F. The data bits include a start bit, 8 data bits (LSB first delivery), odd / even parity 1 / 0 when no parity, with parity 1 stop bit / no parity 2 stop bit. Error checking of the system by using cyclic redundancy check (CRC).

2.3 Modbus message frame

Either ASCII or RTU mode mode, Modbus messages are transmitted in frames, each frame has a definite starting point and end point. Table 2 is the RTU mode, message frame format.

Table 2 RTU mode, the message frame format

Use, the receiving device starting point in the read address information and determine the equipment to be addressed (broadcast on all the equipment) and information transmission end time. Can also detect some of the information, errors can also be set as a result. This article uses the RTU message frames.

In RTU mode, messages start at least 3.5 times the character of the rest. According to the baud rate, it is easy to calculate the rest of the time (Table 2, the T1-T2-T3-T4). After the first data area is the device address. The character of each area are allowed to send 16 hexadecimal 0-9, A-F.

Devices on the network can continuously monitor the network information, including the rest time. When receiving the first address data, each device decodes it immediately to determine whether it is their address. Symbol transmitted after the last word, it will have a rest time of 3.5 characters, and then to send a new message.

The information must be continuously sent. If the frame information is sent greater than during the rest time of 1.5 characters, the receiving device flushes the incomplete information and under the assumption of an address data.

Similarly, if a message immediately after sending a new message (if not the character of the stationary time of 3.5), will generate an error. This is because the information generated is invalid CRC checksum error.

RTU mode, the error can be calculated CRC checksum, CRC checksum is sent with all the data. It will ignore the message data in a single character parity method.

2.4 Error Detection Method

Standard Modbus serial networks use two kinds of parity error detection and frame detection method, in which the parity of each character are available, and frame detection (LRC or CRC) is applied to the entire message. As this paper RTU mode data transfer, so use the CRC check method, it can check all the data transmitted. The specific method is as follows:

CRC code is 2 bytes / 16-bit binary value. Usually calculated by the CRC value of the sending device and attached it to go to the information; receiving equipment to receive information in the process of re-calculated CRC with the CRC value and the actual value for comparison. If the two are inconsistent, it produces an error. Check the beginning, you first 16-bit registers are set to "1", then the information in the adjacent two 8-bit bytes of data processing into the current register. To only 8-bit data of each character for the CRC processing, and the start bit, stop bit and parity bit does not participate in CRC calculations.

CRC checksum, each 8-bit data first with the contents of the register XOR, then the least significant bit (LSB) the direction of the shift, when filled with the most significant bit of zero (MSB), then Check on the LSB, if LSB = 1, then register with the preset fixed value or vary, if the LSB = 0, not for XOR.

, Repeat the above process until the shift 8 times. The last (8th) shift, the next 8-bit bytes of data and then with the register XOR the current value, and then repeat the process. All processed information in the data byte, the final register value obtained is the CRC value.

CRC value attached to information, low earlier, high in the post. CRC generating polynomial is:.

2.5 Feature Selection Select this article

03 Read Holding Registers and 06 preset single register to be highlighted.

(1) 03 Read Holding Registers

Query information, addressing the start address register 0000, register an address corresponding to 16 0 to 15, respectively.

Response information in the register data is binary data, each register corresponding to 2 bytes, the first byte of the high value data, the second low-byte data. Table 3 is a list of 03 Read Holding Registers function example.

Table 3 03 Read Holding Registers function example

(2) 06 preset single register

Query information in the register, the register addressing the start address is 0, corresponding to the address register 1 is 0. Preset value requested in the query data area. Register is preset, return to the normal response. Table 4 is a list of 06 preset function of a single register for example.

Table 406 preset single register function example

3 Program Design

First of all, the program designed to clear the Modbus protocol to achieve the function, and to determine the transmission mode and error checking methods. This paper is to achieve 03 Modbus protocol to maintain registers and 06 read a single pre-register functions, and mode of selection of RTU communication, using CRC error checking method.

Second, be familiar with Picoblaze nuclear structure, programming and instruction set, and register to be used to determine number and I \ O interface, text editor, write a program using the assembly instructions, and. psm format.

Then be compiled to use Kcpsm3 comprehensive and has written a good program (. Psm) into. vhd format. Specific operation, the first to program (. Psm file) to the following Assembler Kcpsm3 folder folder, and then set up a. Txt file to be used to store the compiled results (eg result.txt). This file can be opened result.txt program is found in the bottom of the error, if error, the system should prompt the relevant error; If the program is correct, it will show success. This can be used in the Dos environment Kcpsm3 compiler. Figure 3 shows the flow chart of the system software. Figure 4 shows the graph of its related commands.

Figure 3 system software flowchart

Figure 4 by the psm vhd files into ROM format file

Next, you can download using the ISE General to the newly generated. VHD file to the project. And then build the project file, so that the end of operation, etc., you can download the program.

Finally, through a host computer installed Modbus Modbus Poll program to test the accuracy of data transmission, and then select the function to be achieved, address and register, and write data, and then can choose to send, send it later The results shown in Figure 5. After everything is ready, you can write data to the appropriate address.

sent the results of the Figure 5

4 Conclusion

This paper, the industrial Modbus communication protocol commonly used in the basic means of communication, and based on Xilinx Spartan-3E FPGAs Picoblaze soft core implements the Modbus RTU mode communication protocol. Experiments show that the mode of sending and receiving communications both good, to achieve expected results. Thus proving that the method has a certain practicality.

SI9104DW datasheetSI9104DW suppliersSI9104DW Price

All right © 2010-2016 Certificate