Design of general industrial controller based on STM32+FPGA (1) System scheme design

This chapter first introduces the general situation of the existing PLC system, and then presents the general industrial controller designed in this paper.
The overall solution architecture, analyzes the functions that need to be realized on the hardware and software, and finally analyzes the functions of each part and proposes
specific implementation plans.
2.1 Introduction to PLC system
Programmable Logic Controller ( Programmable Logic Controller , PLC ) is based on the microprocessor,
A new type of universal automatic control developed by combining computer technology, automatic control technology and communication technology
device [14] . It uses a type of programmable memory for its internal storage program, execution of logic operations, sequence control,
User-oriented instructions such as timing, counting, and arithmetic operations, and control various types of
The mechanical or production process is the core part of industrial control [15] .
The Siemens S7-200 series PLC is an integral PLC , and Figure 2-4 shows the interior of one of the PLC basic units.
Structural diagram, its structure is composed of three parts: the upper part is the core board or CPU , which includes the dial switch, expansion unit
interface; the middle part is the interface board, including I/O interface, RS485 communication interface, 220V AC power input interface,
24V DC power output interface, etc.; the lower part is the switching power supply board, 220V AC input, 24V DC output.

2.1.3 PLC software system
PLC software includes system programs and user programs. The system program is solidified inside the CPU chip
The user cannot directly modify the program, and the system program includes abnormal state detection and I/O unit operation.
Operation, user program execution, communication with the outside world and other functions. The user program is used by the user to match with the PLC controller
The program developed by the development software, the most commonly used development language is the ladder diagram language ( LD ), in addition to the instruction language
language ( IL ), function block diagram language ( FBD ), sequential function flow chart language ( SFC ), structured text language ( ST ).
For the user, it is not necessary to understand the system program in detail, and only needs to write the user program according to the actual production requirements to realize the logic
Edit control can be [28] .
Many ready-made function blocks are often used when editing ladder diagrams, such as timer modules, counter modules, high-speed
Counter module, analog input module, analog output module, PID module, communication module and other functional blocks, these
The realization process of the function blocks is included in the system program, and the user program only calls these function blocks when using these function blocks.
Implementation process [29] .
2.2 Overall program structure
This article adopts the integral PLC structure, as shown in Figure 2-7 , the overall structure is divided into the main controller and the remote module, the main
The controller is composed of core board, interface board, switching power supply, integrated central processing unit ( CPU ), I/O unit, power supply
In one. As an expansion module, the remote module is used in industrial sites with large area and wide range, so that the main controller needs
To control field devices with a long distance, at the same time, the number of I/O points can be increased for the main controller , so that the controller can be extended to a large
and move closer in the direction of globalization and multi-function. The remote module mainly includes digital input module ( DI ), digital output module ( DO ),
Analog input module ( AI ), analog output module ( AO ) and Ethernet communication module ( EN ), among which Ethernet
The communication module is mainly responsible for communicating with the main controller, sending the status and data of each remote module to the main controller and
Receive control commands from the master controller.

The controller designed in this paper mainly realizes the following structures and functions:
In terms of hardware: the hardware PCB board needs to include the core board, interface board, switching power supply, Ethernet communication module, digital
Word quantity input module, digital quantity output module, analog quantity input module, analog quantity output module. Interface board needs package
Including digital input and output interface, analog input and output interface, digital high-speed input and output interface, high-speed USB
Communication interface, RS485 communication interface, Ethernet communication interface, etc.
Software: Modbus communication protocol, as the data protocol when the main controller communicates with the remote module;
The internal communication protocol of the module is used as the data protocol for communication between remote modules. Design modular control functions,
Including motion control and process control that are often used in industrial sites, and PID control algorithm will be used at the same time, if necessary
To drive a frequency converter or an inverter, the SPWM algorithm and the SVPWM algorithm will also be used. Designing a High-Speed ​​Counter
Module for acquiring sensor signals such as rotary encoders. Design the human-computer interaction interface, which is convenient for on-site workers to operate
controller. Design the programming language of the user program, as a bridge between human natural language and the underlying chip programming language,
It is convenient for ordinary workers without any programming language foundation to carry out on-site programming and testing.
2.3 Main controller scheme design
The overall scheme design of the main controller is shown in Figure 2-8 , which is divided into core board, interface board, and switching power supply.
Symmet provides STM32+FPGA motion control solutions.
Almost all the external interfaces of the main controller are designed on the interface board, only the interface connected to the local expansion module is designed
Count on the core board. Due to the limited volume of the main controller, the number of interfaces and I/O points included are limited, such as
If more I/O points are needed, the Ethernet interface needs to be connected to the remote module for use. The external interface on the main controller includes 16
16 -way digital input interface, 16- way digital output interface (relay output), 8- way digital high-speed output interface (crystal
Body tube output), 220V AC power input interface, 24V DC power output interface, high-speed USB communication interface,
RS485 communication interface, Ethernet communication interface. Inside the main controller, the switching power supply is connected to the interface board, and the interface board
Input the 220V AC power input from the outside to the switching power supply board, and then it will be stabilized after passing through the switching power supply.
A fixed 24V DC power supply. The interface board is connected to the core board, one is 5V obtained by stepping down 24V through DC/DC
The power is transmitted to the core board, and the second is to transmit I/O signals and serial port communication with the control chip on the core board.
2.3.1 Core board scheme design
The hardware structure of the core board includes control chip circuit, download circuit, crystal oscillator circuit, reset circuit, chip power supply
circuit, RS485 communication circuit, state selection circuit, state indication circuit, I/O indication circuit, level conversion circuit
wait.
The control chip is controlled by the currently popular " MCU+FPGA " method [32] . MCU is a microcontroller
Unit ( Micro Controller Unit ), also known as single-chip microcomputer or single-chip microcomputer, is the central processing unit, memory,
Counter, USB , A/D conversion, UART , PWM , DMA and other peripheral interfaces are integrated into one chip to form
Chip-level computers are used in control fields such as mobile phones, remote controls, cars, and robotic arms. FPGAs are field programmable
Gate Array ( Field Programmable Gate Array ), which is a semi-custom circuit in ASIC, usually
The low-level logic gate array is combined through programming, so as to realize the connection between internal modules and I/O .
FPGA has the following advantages: high parallelism, can support multiple modules to perform independent calculations at the same time; can be customized, that is,
Realize your own logic circuit through programming, and can be programmed infinitely; the operation speed is fast, and the task is usually in
Running on hardware is faster than running on software. For example, comparing the size of a 64- bit high 32 -bit and low 32- bit, the CPU
The following requires 2 area number instructions, two bit-and instructions, a shift instruction, a comparison instruction and a write-back instruction, and
Under the FPGA, only one comparator is required. FPGA also has disadvantages at the same time, all functions rely on hardware implementation
Now, operations such as branch conditions and jumps cannot be realized, and at the same time , there are few peripherals such as A/D conversion, flash , etc., which just can
Enough to rely on MCU to make up for. Therefore, this article uses the combination of MCU and FPGA to maximize the advantages of both.
Self-advantage [33] .
The MCU chooses the 32- bit STM32 microcontroller developed by STMicroelectronics , which is based on ARM
The embedded microcontroller with Cortex-M processor core has the characteristics of high integration and low power consumption. FPGA selection
ALTERA 's Cyclone IV series chips, which are based on Cyclone , CycloneII and CycloneIII
Based on improved performance and reduced costs. STM32 uses its own rich peripherals as the main control chip, using UART
Communicate with the outside world; FPGA processes I/O signals by using the characteristics of fast computing speed and good concurrency . STM32
The communication methods with FPGA include serial communication, parallel communication and shared memory communication. Boots required for serial communication
There are fewer pins, but the speed is not as fast as the other two communication methods; the shared memory communication method is more complicated on the hardware circuit,
It is generally used in occasions with a large amount of data exchange, and it is a bit overkill to use it here; although parallel communication occupies more pins,
But the communication efficiency is high [34] . On the whole, choose the parallel communication method.
The power circuit needs to be determined according to the voltage required by the control chip. The control chip STM32 selected on the core board
The specific model is STM32F103ZET6 , the working voltage is 3.3V , the specific model of FPGA is EP4CE6E22C8 ,
Operating voltages are 3.3V , 2.5V and 1.2V .
The download methods of STM32 include SWD and JTAG methods. SWD mode is more efficient than JTAG under high-speed mode.
More reliable, the JTAG download program will fail in the case of a large amount of data , but the probability of SWD will be very small
Many, and the number of pins required by SWD is small, which can save PCB space. Although STM32 has 8MHz internal crystal
Oscillation, but the precision is not as high as the high-speed crystal oscillator with external configuration. There are two types of external crystal oscillators: high-speed crystal oscillator and low-speed crystal oscillator.
The typical low-speed crystal oscillator is 32.768KHz , and the high-speed crystal oscillator can be selected from 4~32MHz , and then it can be set by the phase-locked loop
The main frequency rises to 72MHz . The expansion module interface that needs to be reserved on the core board is used to connect multiple expansion modules.
The communication method between the expansion modules here chooses RS485 communication, because RS485 supports one master and multiple slave modes. at the same time
It is necessary to design a state selection circuit and a state indication circuit around STM32 . The state selection circuit uses a dial switch as a
The pin input of STM32 , the status indication circuit uses LED as the pin output of STM32 .
FPGA does not have on-chip flash , so FPGA programs need to be stored in off-chip flash , here select
EPCS4SI8N is used as the off-chip flash of FPGA . FPGA download methods include JTAG mode, AS mode and PS
model. In AS mode, the program is burned into the configuration chip EPCS , and each time the FPGA is powered on, it acts as a controller from the configuration chip.
Set the chip EPCS to read data; PS mode is to use EPCS as a control device, use FPGA as a memory, and FPGA
When powered on, EPCS will actively write data into FPGA , this mode can realize online programming of FPGA ;
The JTAG mode is the most commonly used mode, which directly burns the program into the SRAM of the FPGA , so after power failure
sequence will disappear. When the FPGA is working normally, its configuration data is stored in the SRAM , and it must be downloaded again when it is powered on.
In the experimental system, a computer or controller is usually used for debugging, so PS can be used . But in practical system
In most cases, the configuration operation process must be actively guided by the FPGA . At this time, the FPGA will actively
The configuration data is obtained from the storage chip, and the FPGA configuration information in this chip is obtained by using a common programmer to design the .pof
The format file is burnt in through AS . Burning the .sof file through JTAG mode will burn the program into the SRAM ,
However, through file conversion, the .sof file is converted into a .jic file, and the program will pass through the FPGA through JTAG mode burning.
It is solidified into the configuration chip EPCS , so that the FPGA will read the program from the EPCS when it is powered on again. The final examination of this article
Considering the convenience of debugging, we chose the JTAG mode.
The main frequency of the FPGA needs an external crystal oscillator, and the STM32 has a crystal oscillator start-up circuit inside, so a passive crystal oscillator can be used.
But FPGA does not have it, so FPGA can only be connected with active crystal oscillator, here choose 50MHz as FPGA clock source,
A clock of up to 300MHz can be obtained by multiplying the frequency of the phase-locked loop .
FPGA pins can be configured as either input mode or output mode, all of which are 3.3VTTL signals.
The FPGA input and output pins directly control LEDs as I/O indicator lights, a total of 40 , 16 input points, 16 output
Out point, 8 high-speed output points. The core board and the interface board are connected together through connectors to transmit I/O point data signals.
No., between the FPGA and the connector, a level conversion chip is also connected, between the 3.3VTTL signal and the 5VTTL signal
Inter-conversion, and the level conversion chip can play a protective role to prevent FPGA pins from being directly connected to the outside [35] .
2.3.2 Interface board scheme design
The hardware structure of the interface board includes optocoupler input circuit, relay output circuit, transistor output circuit, RS485
Communication circuit, USB communication circuit, Ethernet communication module, DC/DC step-down circuit, core board and power board
interface circuit, etc.
The optocoupler input circuit is used to input the external switch signal. Generally, the input module of PLC consists of several input points
and a common terminal. As shown in Figure 2-9 , a) and b) are two different forms of PLC DC input circuits, the difference is that
When the external switch is closed, the current in a) flows out of the PLC (source input) from the common terminal M , and the current in b) flows from the common
Terminal M flows into the PLC (sinking input). When the switch is closed, the light-emitting diode of the optocoupler inside the PLC lights up, and the photosensitive three
The pole tube is saturated and turned on, and then the signal is sent to the central processing unit, and it is considered that there is an input signal. c) and d) are a) and b) respectively
multi-channel signal structure. In order to adapt to more field devices, this paper uses the hybrid input circuit shown in e) , optocoupler
Choose a bidirectional input optocoupler, and the external wiring form can be both energy input and sink input.

2.5 Software scheme design
2.5.1 Embedded Operating System
Although embedded applications can run directly on the chip, in order to call multitasking more reasonably,
To make full use of system resources, this paper adopts the scheme of transplanting embedded operating system on STM32 . currently used embedding
The embedded operating systems include μClinux , μC/OS-II , eCos and FreeRTOS .
μClinux ( micro-control Linux ) is a micro-control Linux . Compared with standard Linux , the μClinux kernel
Small, but still inherits the good stability and portability of Linux , and has powerful network functions, excellent text
software system, standard-rich API and TCP/IP network protocol, etc. In terms of transplantation, since μClinux is Linux
An improvement aimed at embedded systems, so its structure is more complicated, and the target processor needs an external
ROM and RAM , for STM32F103 , transplanting this system requires at least 512KB of RAM space, 1MB
ROM /FLASH space, and STM32F103 only has 256KB of FLASH , so an external memory is required,
This increases hardware costs. Moreover, μClinux has a complex structure, is difficult to transplant, and has poor real-time performance, so it is not suitable as a
The transplantation scheme of this system.
μC/OS-II is a compact, preemptive multitasking real-time kernel written in C language. µC/OS-II
Up to 64 tasks are supported , corresponding to priorities 0~63 , where 0 represents the highest priority, 63 is the lowest, and the system
The 4 highest priorities and 4 lowest priorities are reserved , so there are 56 tasks available to the user .
µC/OS-II
It can provide functions such as task scheduling and management, memory management, synchronization and communication between tasks, time management and interrupt service, etc.
It has the characteristics of high execution efficiency, small footprint, excellent real-time performance and strong scalability. In porting, μC/OS-II
Supports most of the currently popular CPUs . Due to its small core, the minimum code is only 2KB , and data space is required
There is only 4KB of RAM , so the porting is relatively simple, only need to modify the code related to the processor, which is more suitable
It can be transplanted on this system together.
eCos ( embedded Configurable operating system ) is an embedded configurable operating system, a
Kaiyuan's configurable, portable, real-time operating system for deeply embedded applications. its biggest feature
That is, the kernel is configurable, and the flexible configuration brought about by the modular design method. The core part is composed of similar components.
Components such as the kernel, C language library, and underlying runtime packages can be easily configured through the eCos configuration tool, and can be easily
Good to meet the needs of different embedded applications. In terms of porting, the eCos kernel is small, the minimum code is only 10KB , and the required
The data space is only 10KB of RAM , and the portability is good, which is easier than μClinux and μC/OS-II , but
Its application is not extensive, and there are not as many documents as μC/OS-II , and it is more suitable for applications such as consumer electronics.
FreeRTOS is a real-time operating system that is completely free and can run on small RAM microcontrollers.
Features such as code development, strong portability, tailorability, and flexible scheduling strategies. FreeRTOS operating system can complete
Task management, time management, semaphore, message queue, memory management, recording and other functions can meet a minimum
Basic requirements of the operating system. In terms of porting, FreeRTOS can be easily ported to different processors, such as
ARM , MSP430 , PIC , AVR , C8051F , etc., the core of STM32 is ARM , so FreeRTOS
It is suitable for transplantation of this system, and it is also the embedded operating system adopted in this article.
2.5.2 Software system
A software system consists of system programs and user programs. The system program is the program solidified in the control chip.
The controller is composed of a main controller and a remote module. There are two control chips, STM32 and FPGA , on the main controller. There are 5 types
The remote modules each have a STM32 as the control chip to realize their respective functions , so it is necessary to design 7 sets of different
System program, programming language includes C language required by STM32 and Verilog HDL language required by FPGA . use
Editing of user programs This paper designs two sets of solutions, one is to design a PC -side programming software, which can be downloaded through the USB port
to the flash on the main controller STM32 , and the other is the on-site programming function, that is, through the human-computer interaction interface, using
Keywords allow ordinary users without programming foundation to write simple test programs, which is convenient for on-site debugging [36][37] .
2.5.3 Modular function
This paper designs modular functions, motion control and process control. Motion control is often used in machinery, machine tools, machine
Robots, elevator control and other occasions, used to drive stepper motors, servo motors or AC motors, at this time a controller is required
To generate corresponding driving signals, such as driving asynchronous AC motors, SPWM and SVPWM algorithms are required to simultaneously move
The control will often use the encoder to measure the speed and position. This paper designs the function of the high number counter on the software. process
Control is often used in metallurgy, chemical industry, boiler control, etc., for closed-loop control of analog quantities such as temperature, pressure, and flow
Control, at this time, the controller needs to implement the PID algorithm.
2.5.4 Communication protocol
Each PLC manufacturer generally has its own communication protocol. For example, Rockwell’s PLC supports the DF1 protocol.
GE 's 90-70 and 90-30 series PLCs support SNP protocol, and Siemens S-200 series PLCs support MPI and PPI
Schneider PLC supports Modbus and Modbus Plus protocols, Omron PLC supports Host Link protocol
According to the agreement, Mitsubishi PLC supports CC-Link protocol, and Panasonic PLC supports MEWTOCOL-COM protocol. Among them Modbus
It is not only the communication protocol of PLC , it is also used in many smart instruments and frequency converters, and it has been used in the field of industrial control
It has been widely used in the field [38] . In this paper, Modbus is selected as the data protocol for communication between the main controller and the remote module.
In the above-mentioned protocol, the MEWTOCOL-COM protocol is open and simple. This paper makes some changes on the basis of it.
As a data protocol for communication between RMEN and I/O modules, it will be called RM-COM protocol later.

Symmet provides STM32+FPGA motion control solutions.

Guess you like

Origin blog.csdn.net/YEYUANGEN/article/details/131952318