FPGA Tabanlı Modbus Ağ Geçidi Tasarımı

thumbnail.default.alt
Tarih
2015-01-29
Yazarlar
Akkaya, Şirin
Süreli Yayın başlığı
Süreli Yayın ISSN
Cilt Başlığı
Yayınevi
Fen Bilimleri Enstitüsü
Institute of Science and Technology
Özet
Protokol lisanları aynı iki olgu arasında, belirli bir düzeyde iletişimi sağlamak amacı ile gerekli kuralları ortaya koyan bir sistemdir. Endüstriyel haberleşme protokolleri endüstriyel sistemler arasında veri alış verişini sağlayan standart dillerdir. İki cihaz arasında veri iletimi olabilmesi için cihazların aynı endüstriyel protokol ile haberleşmeleri ya da arada dönüştürücü bir cihaz kullanmaları kullanılmalıdır. Günümüzde en çok kullanılan endüstriyel haberleşme protokolleri Fieldbus, Profibus, Modbus, Canbus, Devicenet ve Controlnet olarak sıralanabilir. Modbus protokolü 1970'li yıllarda geliştirilmiş ve zamanla yeni sürümleri oluşturulmuştur.  Kolay, hızlı ve açık kaynaklı bir protokol olması günümüzde elektronik cihazlarda çok yaygın olarak kullanılmasının en büyük etkenlerindendir. Modbus protokolü ilk defa seri hat üzerinden gerçeklenmiştir. Modbus seri hat protokolü Modbus RTU ve Modbus ASCII olmak üzere iki alt protokolden oluşur. Ethernet teknolojinin gelişmesi ve yaygınlaşması ile beraber Modbus protokolünü Ethernet ağına uygun hale getirme ihtiyacı duyulmuş ve Modbus TCP protokolü geliştirilmiştir.  Bu tez çalışmasında Modbus RTU ve TCP protokolleri incelenmiş ve bu iki protokolü destekleyen bir ağ geçidi (gateway) cihaz tasarlanmış ve tasarlanan cihaz kurulan bir endüstriyel sistem üzerinde test edilmiştir. Modbus RTU protokolü OSI modelinin veri bağlantı katmanında (ikinci katman) çalışır. Bu protokol kullanıldığı zaman fiziksel katmanda veri iletimi EIA/TIA 485 (RS-485) ya da EIA/TIA 232 (RS-232) veri iletim modları kullanılabilir. Tez çalışmada fiziksel katmanda veri iletimi için EIA/TIA 485 (RS-485) standardı kullanılmıştır. OSI modelinin üçüncü, dördüncü, beşinci ve altıncı katmanları boştur ve uygulama katmanı olan yedinci katmanda Modbus uygulama protokolü çalışır. Modbus RTU protokolü bir çeşit master/slave protokolüdür ve seri ağ üzerinde bir ana cihaz (master cihaz) ve buna bağlı çalışan bir ya da birden fazla bağımlı cihaz (slave cihaz) bulunur. Ana cihaz istediği bağımlı cihaza belirlenmiş protokol formatında veri gönderir ve bağımlı cihaz veriyi alır, istenilen işlevi yerine getirdikten sonra ana cihaza cevap gönderir. Bağımlı cihazlar kendi aralarında haberleşemezler ve ağ üzerinde tek bir paket akışı olur. Verinin kontrolü protokol içersinde CRC hata kontrol yöntemi ile denetlenir.  Modbus TCP protokolü Ethernet TCP/IP ağı üzerindeki cihazlar ile client/server (istemci/sunucu) haberleşmesi sağlar. İstemci cihaz haberleşmek istediği sunucu cihaza talep gönderir ve sunucu cihaz talebi alır, istenilen fonksiyonu yerine getirdikten sonra istemciye cevap gönderir. Modbus TCP protokolünde ağ üzerinde birden fazla paket alışverişi olabilir. Modbus TCP protokolü OSI modeline göre incelendiği zaman fiziksel katmanın ve veri bağlantı katmanının iç içe çalıştığı görülür ve bu iki katmana ağ ulaşım katmanı adı verilir. Ağ ulaşım katmanında (birinci ve ikinci katman) Ethernet / MAC protokolü, ağ katmanında IP protokolü, taşıma katmanında TCP protokolü ve beşinci, altıncı ve yedinci katmanında Modbus uygulama protokolünü çalıştırılır. TCP'nin görevi bütün veri paketlerinin doğru bir şekilde alınmasını sağlamaktır. IP ise paketin doğru bir şekilde adreslenmesini ve yönlendirilmesini sağlar. TCP/IP protokolü sadece bir taşıma protokolüdür ve mesajın içeriği hakkında bir bilgi vermez. Modbus protokolü uygulama katmanında standart olan ve değişmeyen bir protokol veri birimi oluşturur. Protokol veri birimi yapılacak işlemi tanımlayan Modbus fonksiyon kodu bilgisini ve veri bilgisini taşır. Alt katmanlarda çalışan protokollere göre protokol veri biriminin başına ve sonuna ek birimler eklenerek Modbus uygulama veri birimi oluşturulur. Tez çalışmasında ağ geçidi tasarımı için Türkçeye “Alanda Programlanabilir Kapı Dizileri” şeklinde çevrilen FPGA kullanılmıştır. FPGA, üretimden sonra istenilen uygulamaya göre donanım yapısı kullanıcı tarafından değiştirilebilen bütünleşik devre şeklinde tanımlanabilir. FPGA içerinde VHDL veya Verilog dilleri kullanılarak donanım tasarımı yapılabileceği gibi içersinde yazılımsal bir işlemci oluşturularak gömülü bir sistem de kurulabilir. Tez çalışmasında Altera firmasının DE0 Nano FPGA Geliştirme ve Eğitim kartı kullanılmıştır ve firmanın üretmiş olduğu FPGA'ler için geliştirdiği Nios II/e işlemcisi kullanılarak gömülü bir sistem oluşturulmuştur. TCP/IP yönetimini sağlaması için sisteme Wiznet firmasının ürünü olan Wiznet W5500 modülü eklenmiştir. Bu modül OSI modeline TCP/IP işlemlerini ve fiziksel katmanda veriyi fiziksel ağa gönderme işlemlerini yerine getirmektedir. Wiznet modülü kendine özgü 32 bitlik SPI protokolünü kullanarak haberleşir ve sistemde FPGA ile haberleşmesi için FPGA içersinde VHDL dili kullanılarak bir SPI  modülü tasarlanmıştır. Ayrıca RTU ağı üzerinde bulunan cihazların FPGA ile haberleşmesi için MAX 485 entegresi kullanılarak tasarlanan RS485 dönüştürücü devresi tasarlanmıştır. Bu devre Modbus RTU protokolünün fiziksel katmanda veriyi RTU ağına iletmesi sağlamaktadır.  Altera firmasının FPGA programlamak için ücretsiz olarak kullanıcılara sunduğu Quartus II programlama platformu ile sistemin yazılımı hazırlanmıştır. Quartus platformu donanım tasarlamak, FPGA içersinde işlemci ve çevresel birimleri oluşturmak ve işlemcinin programlanmasını sağlamak için alt araçlar içeren kapsamlı bir yazılım paketidir. Programın sunduğu Qsys sistem tasarlama aracı kullanılarak NiosII/e işlemcisi ve çevresel birimleri oluşturulmuştur. Oluşturulan çevresel birimlerin birbirleri ile bağlantısı yapılmış ve adres ayarları program tarafından otomatik olarak ayarlanmıştır. İşlemcinin programlanması yine Quartus programı içersinde yer alan Nios II Software Build Tools for Eclipse aracı kullanılarak C dilinde yapılmıştır. Programlama sırasında Qsys aracının oluşturduğu adres bölgelerinden faydalanılır. Sistemin tasarımı ve programlanması tamamlandıktan sonra FPGA içersine kalıcı olarak gömülmüştür. Sistem bir tane Modbus TCP istemci cihaz, altı tane Modbus TCP sunucu cihazı ve altı tane Modbus RTU bağımlı cihazı destekleyecek şekilde oluşturulmuştur. Bu sayı uygulamaya göre artırılabilir. TCP cihazlar birden altıya kadar numaralandırılmış (adreslendirilmiş) ve RTU cihazlar da yediden on ikiye kadar numaralandırılmıştır. Sistemde istemci cihaz olarak Modbus TCP ağı üzerinde çalışan bir PLC bulunmaktadır. Sunucu ve bağımlı cihazlar Modbus giriş/çıkış modülleridir. İstemci cihaz TCP ağı üzerinden Wiznet modülü ve FPGA içersinde tasarlanmış olan SPI modülü aracılığı ile Nios işlemciye talebini bildirir. İşlemci gelen talep paketini inceler ve paketi yeniden düzenler. Paket TCP cihaza gönderilecekse SPI modülü ve Wiznet üzerinden paketi TCP cihaza gönderir ve cevap da aynı yol ile önce işlemciye sonra da istemci cihaza gönderilir. Eğer paket RTU cihaza gönderilecekse işlemci paketi TCP formatından RTU formatına çevirir ve RS485 dönüştürücü devresi ile RTU cihaza talebi iletir. RTU cihazın cevabı işlemci ile TCP formatına dönüştürülür ve istemci cihaza gönderilir. Böylece TCP ve RTU ağları arasında veri alışverişi tamamlanmış olur. Sistemde bulunan cihazların konfigürasyon bilgileri DE0 Nano kartı üzerinde bulunan EEPROM modülüne yüklenmiştir İşlemcinin EEPROM ile haberleşmesi için FPGA içerisinde tasarlanmış olan I2C modülü kullanılır. Bu tez çalışmasında ile seri hat üzerinde haberleşen Modbus RTU cihazları ile Ethernet teknolojisi kullanarak haberleşen Modbus TCP cihazların FPGA tabalı bir ağ geçidi tasarlanarak birbirleri ile veri alış verişi yapmaları sağlanmıştır. Tasarlanan ağ geçidi cihaz protokol dönüştürme işlemi yapmaktadır. Çalışma içersinde Modbus protokolleri detaylı olarak incelenmiş, FPGA ve gömülü sistem oluşturma, Wiznet modülü, RS 485 dönüştürücü devre tasarımı ve ek birimler tanıtılmıştır. Bunlara ek olarak FPGA içersinde donanım tasarımı (SPI modülü ve I2C modülü) ve işlemcinin programlanması anlatılmış ve son bölümde tasarlanan cihazın test sonuçlarına yer verilmiştir.
Protocol is a system that outlines the rules with the aim of achieving a certain level of communication between two same cases. Industrial communication protokols are standart languages that allow data exchange among industrial devices and systems. Data transmission between two devices can obtain either using the same indutrial communication protocol or using an industrial protocol converter. Nowadays, the most used industrial protocols can list as Fieldbus, Profibus, Modbus, Canbus, Devicenet and Controlnet. Modbus protocol was developed in 1970s and new versions were developed in years. Electronic devices are widely used Modbus protocols nowadays, because of easy, fast and open source. Modbus protocol was first implemented over serial line. There are two serial transmission mode which is commonly used are Modbus RTU and Modbus ASCII. The transmission mode and serial port parameters must be the same for all devices on a Modbus serial line. Although, the ASCII mode is required in some specific applications, but generally for interoperability between Modbus devices RTU mode is used. Modbus RTU transmit data using specific data frame, but Modbus ASCII transmit data with using ASCII characters. With the development and expansion of Ethernet technology, Modbus protocol need to adapt Ethernet network and Modbus TCP protocol has been developed. In this thesis, Modbus RTU and Modbus TCP protocols are examined and a gateway device, which supports both Modbus protocols, is designed and tested on an industrial system that have different Modbus devices. Modbus RTU protocol works on the data link layer of the OSI model. On the physical layer, data transmission obtained using EIA/TIA 485 (RS-485) or EIA/TIA 232 (RS-232) data transmission modes. For RTU protocol, the third, fourth, fifth and sixth layer of OSI model is empty. Modbus application protocol works on application layer (seventh layer) of OSI model. Modbus serial line protocol is a kind of master/slave protocol. A master/slave type system has one master node that issues explicit commands to one-slave nodes and processes responses. Slave nodes are not typically transmit data without a request from the master node and do not communicate with other slaves. The control of the data obtains on the protocol frame using CRC error checking method. Modbus TCP protocol provides a server/client communication between devices connected on Ethernet TCP/IP network. TCP refers to the Transmission Control Protocol and IP refers to the Internet Protocol, which provides the transmission medium for Modbus TCP/IP messaging. Modbus TCP/IP uses TCP/IP and Ethernet to carry the data of the Modbus message structure between compatible devices. That is, Modbus TCP/IP combines a physical network (Ethernet), with a networking standard (TCP/IP), and a standard method of representing data. Essentially, the Modbus TCP/IP message is simply a Modbus communication encapsulated in an Ethernet TCP/IP wrapper. TCP/IP Standard Model, Ethernet handles the bottom 2 layers (1 & 2) of the seven-layer OSI stack, while TCP/IP handles the next two layers (3 & 4). The application layer lies above TCP, IP, and Ethernet and is the layer of information that gives meaning to the transmitted data. In this thesis, FPGA (Field Programmable Gate Array) is used to design Modbus gateway device. FPGA as the integrated circuits of which their hardware configuration can be changed by the user according to the desired functions. Using VHDL and Verilog hardware description language, hardware design can create using FPGA and embedded processor system can be design on it. In this thesis, Altera DE0 Nano FPGA Development and Education board has used for operation system and Nios II/e embedded processor, which is also Altera’s software microprocessor, is embed on FPGA. Wiznet W5500 module has added on system for TCP/IP management. This module is used for fulfill TCP/IP operations of OSI models and sending data on physical layer. Wiznet module supports 32-bit SPI module to communicate FPGA, so a hardware developed on FPGA using VHDL language, named SPI module. To communicate RTU devices, a circuit is design using MAX485 integrated device that works on RTU physical layer. Quartus II programming platform, which is free and download from Altera website is used to program FPGA device. Ouartus is a multitasking development platform, which provide both hardware design and allow embedding microprocessor and peripheral devices on FPGA. Using Qsys system development tool, Nios II/e microprocessor and peripheral devices can design and connected each other. The program also creates the address map of processor. After generating the system, a software-embedded system is created on FPGA.  Nios II Software Build Tools for Eclipse software also reached on Quartus platform and used to program the microprocessor using C language. In the testing industrial system, there are six Modbus TCP server devices and six Modbus RTU devices. The number of the devices can increase depending on the application. TCP devices are numbered from one to six (addressed was) and RTU devices are numbered from seven to twelve. The system includes a PLC that works on the Modbus TCP network as the client device. Servers and Modbus slave devices are Modbus input / output modules. The client device over a TCP network reaches the FPGA gateway via Wiznet and SPI module and informs the processor about which devices can send request. Processor examines the incoming request packet and redesigns it according to application. If the package send to the TCP device, it sends over the SPI module and Wiznet to TCP devices and the response is sent to the client device in the same way after the processor ago. If the package sends to the RTU device, processor translates it to the RTU format and sends it to the RTU network over the RS 485 converter circuit.  RTU device receives the packet to the physical layer, performs the action and initiate the response. The response sent to RTU devices converts into the TCP format on processor and sent to the client device. Thus, exchange of data between TCP and RTU network is completed. Communication between Modbus TCP devices using Ethernet technology, Modbus RTU devices using serial line has been provided in this study by designed a FPGA based gateway. In addition, this thesis presents detail information about Modbus protocol over serial line and Ethernet in order to used by all system designer when they need to implement Modbus protocols. Moreover, the basic information is presented about gateway design which is used not only between Modbus protocols but also can be used another protocol using on industrial system.  Hardware design and embedded processor design using FPGA is examined and presented. SPI and I2C communication protocols details, data formats, pin connections, data reading and writing examples is presented. About system components, such as PLC, switch, additional modules some sufficient information is given, and finally the results of application that perform on the testing system is added.
Açıklama
Tez (Yüksek Lisans) -- İstanbul Teknik Üniversitesi, Fen Bilimleri Enstitüsü, 2015
Thesis (M.Sc.) -- İstanbul Technical University, Institute of Science and Technology, 2015
Anahtar kelimeler
Fpga, Vhdl, Modbus, Ağ Geçidi, Tcp, Rtu, Fpga, Vhdl, Modbus, Gateway, Tcp, Rtu
Alıntı