You are on page 1of 6

Multiple Closed Loop System Control with Digital

PID Controller Using FPGA

Şirin AKKAYA Onur Akbatı and Haluk Görgün


Control and Automation Engineering Department Control and Automation Engineering Department
Istanbul Technical University Yildiz Technical University
Istanbul, Turkey Istanbul, Turkey
sakkaya@itu.edu.tr oakbati@yildiz.edu.tr, gorgun@yildiz.edu.tr

Abstract— PID (Proportional – Integral - Derivative) performance a sine micro stepping driver system model of
controllers are the most widely used closed loop controllers due stepper motor is introduced. Different types of digital PID
to their simplicity, robustness, effectiveness and applicability for algorithm based on parallel, serial and mixed architecture is
much kind of systems. With the rapid development of technology, implemented and simulated in [5]. The structure proposed in
implementation of PID controller has gone several steps from [6] is based on a distributed arithmetic algorithm where, a
using analog components in hardware to using some software- Look-Up-Table mechanism inside the FPGA is utilized and in
based program to execute PID instructions digitally in some [7] System on a Programmable Chip (SOPC)-based PID
processor-based systems. And also, these developments have controller Intellectual Property (IP) core is implemented on
brought an alternative solution to implement PID instructions in
FPGA using hardware description language.
Programmable Logic Devices (PLD). Field Programmable Logic
Array (FPGA) is the most advanced members of PLDs. This For a low voltage synchronous buck converter, FPGA
paper presents the digital PID algorithm on FPGA. The based PID controller is designed and implemented in [8]. And
controller algorithm is developed using VHDL and implemented also, FPGA has been used in motion control systems which are
using Altera DE0 Nano Board. As the controlled system, five axis employed all sort of robotic applications, such as in [9] and
robot arm is selected, which have five dc motor and four [10], a technique has been adopted for the generation of the
potentiometer to determine the positions of motors. The results control input for controlling the DC motor driver circuit and
show that digital PID controller and also multi-feedback control decoding the optical encoder data for using it for speed
systems can be implemented successively using FPGA devices.
feedback in the PID control loop. In [11], an FPGA controller
Keywords—fpga, digital pid, pwm, vhdl, robot arm
is designed and programmed to control the speed of the
permanent magnet DC motor of a portable dough mixing
machine, using digital PID algorithm with PWM signals. In
I. INTRODUCTION
[12], a simple approach for designing a fractional order FPGA
The new and effective theories and design methodologies based PI controller for controlling the speed of a DC motor is
are being continually developed in the automatic control field, presented and in [13], for multi-axis systems a high
however, Proportional – Integral – Derivative (PID) controllers performance PID IP core controller is described. In [14] the
are still the most widely adopted controllers in industry. Owing design and implementation of a fuzzy-control based speed
to the advantage of simple structure, good stability, reliable control IC for permanent magnet synchronous motor is
operation, robustness and effectiveness, the PID controllers are presented, with Simulink/Modelsim co-simulation and FPGA
properly used in different areas such as aerospace, process realization. And also robotic control applications are one of the
control, manufacturing, robotic, automation, transportation most recent targeted fields covered by FPGA. For a three
systems and real time multi tasking applications. degree-of-freedom (DOF) wafer-handling robot, three current
The implementation of PID control has same evolutionary vector controllers, three position/speed controllers and one
stages from the early mechanical and pneumatic designs to trajectory planning are implemented in a single FPGA chip
software based microcontroller systems. But these systems [15]. For a modular reconfigurable robot controller is proposed
encounter some difficulties such as overloading or computing which based on the Advanced RISC Machine (ARM)
speed limits to implement the requirements of modern control processor and FPGA [16].
systems. Recently, Field Programmable Gate Arrays (FPGA) In this paper, the design and implementation of a FPGA-
has become alternative solution for the realization of digital based digital PID controller for a five axis robot arm is
control systems, particularly PID [1]. And some works about presented. The organization of this paper is as follows: In
how to implement PID controller using FPGA has begun to be section II, digital PID controller algorithm, five axis robot arm
published. In [2], the basic discrete PID equation and algorithm and FPGA development board are described, in section III, the
is given, and in addition to PID algorithm in [3], some implementation of analog input interface, digital PWM block
peripheral interfaces (analog to digital converter and digital to and digital PID block implemented in FPGA and the results are
Analog converter) are introduced, in [4], to verify the design discussed. In section IV, the conclusion of the work is given.
This project is supported by Yildiz Technical University Scientific
Research Projects Coordination Unit under rule 2012-04-04-YL02.

978-1-4799-6773-5/14/$31.00 ©2014 IEEE

764
II.STRUCTURE OF CLOSED LOOP CONTROL SYSTEM u[k ] = K p e[k ] + ui [k − 1] + K i e[ k ] + K d (e[k ] − e[ k − 1]) (5)
The overall block diagram of the system is shown in Fig. 1. where K i is the integral gain, K d is the derivative gain, e[k]
is the current error signal, e[k-1] is the previous error signal
r[ k ] e[k ] u[k ] y (t ) and u[k] is the control signal, u[k-1]is the previous integral
control signal. The discrete PID algorithm given (5) is known
b[k ] as the absolute form or position form of PID algorithm [17].

B. The Controlled System


To show the applicability of the algorithm in multi-
feedback control systems, a basic five axis robot arm selected
Fig. 1. The block diagram of the system as a controlled system is shown in Fig. 2.

Where r[k] is the discrete reference signal, e[k] is the


discrete error signal, b[k] is the discrete feedback signal, u[k]
is the controller output and y(t) is the output of the controlled
system. In FPGA, there are three block; digital PID controller
block, analog input interface and digital PWM block.
A. Digital PID Controller
The PID algorithm consists of three basic modes as
Proportional mode, Integral mode and Derivative mode. The
general form of PID controller given in (1);
Fig. 2. Five axes robot arm
1 t de(t )
u (t ) = K p (e(t ) +
Ti ∫0 e(t )dt + Td dt ) (1)
The robot arm has a five axes pick-and-place manipulator
which consists of mechanical parts forming a rotating base,
three links and a gripper with dc motors and rotary
where K p is a proportional gain, Ti is integral time constant potentiometers and motor driver units. Each of these axes is
and Td is derivative time constant. For a small sample time Ts , driven by a small DC electric motor. These five axes consist of
(1) can be turned into a difference equation with approximating a shoulder, elbow and wrist having 180, 270 and 90 degree
the derivative mode by backward difference approximation and rotational limits respectively for vertical movement, and the
the integral mode by backward integration rule. axes at base has 270 degree rotational limit for horizontal
movement. The potentiometer is an electro mechanic device
k
used for measuring the angular position of the motor in terms
Ts Td
u[ k ] = K p ( e[ k ] +
Ti ∑ e[n] + T
n =0 s
(e[ k ] − e[ k − 1])) (2) of voltage levels. The motor driver unit is an electronic circuit
which links the controller and the robotic arm; adjust the
voltage level to control motor direction and speed according to
Parallel PID algorithm is also shown in (3) as sum of three controller’s output. The basic driver unit generally consists of
basic blocks, where u p [k ] is proportional part, u i [k ] is H-bridge as an integrated circuit in a chip or can be built from
discrete components. L298 chip is well known H-bridge which
integral part and u d [k ] is derivative part of algorithm. allows driving DC motor in both directions and adjusts the
speed with PWM inputs. A driver unit can drive two motors
u[k ] = u p [k ] + u i [k ] + u d [k ] (3) simultaneously, so three units are used to control five DC
motors.
The robotic arm is designed for training purpose, but there
u p [k ] = K p e[k ]
is not enough information about the parameters of the dc motor
K p Ts k
K p Ts k −1
K p Ts and the material. So to obtain the mathematical model of the
u i [k ] =
Ti ∑ e[k ] = Ti ∑ e[k ] + Ti
e[k ] robotic arm, each of the joint is considered as a separated
n=0 n =0 system and the linear model of each axis (motor and
K p Ts (4) mechanical load) are created by using model based system
u i [k ] = u i [k − 1] + e[k ] identification technique. The basic idea of this technique
Ti
depends on applying a sinusoidal signal to a linear system as an
K p TD input; and measuring the sinusoidal output with the same
u d [k ] = (e[k ] − e[k − 1])
Ts frequency but different amplitude and phase. The model of the
each joint is thought as motor and mechanical load and the
By using (4), (3) can be written as below; schematic diagram is shown in Fig. 3 and the estimated transfer
function is shown in (6) for each joint of the robotic arm [18].

765
To compare these signal values the mathematical model of
each joint is obtained for base, shoulder, elbow, and wrist
respectively and the results are shown in Fig. 7.
θ m (t)
θ 4 (s) 0.492
=
E4 (s) s(s + 30.9)

Fig. 3. The diagram of the motor and the mechanical load [20] θ3 (s) 0.8232
=
E3 (s) s (s+ 28.10)

θ m ( s) 1 /( Ra J m ) A (6)
= = θ 2 (s) 0.7374
E a (s) s[s + (1 J m )( Dm + ( K t K b Ra ))] s(s + B ) E2 (s)
=
s(s+ 24.55)

where θ m is the position of motor, Ea is the armature voltage,


Ra is the armature resistance, K t and K b the motor constants, θ1 (s) 0.58
=
J m is the equivalent inertia of the motor and the load and Dm E1 (s) s (s+ 19.44)

is the equivalent constant of friction of the motor and the load.


To obtain the linear model of each joint of robotic arm the
testing system is created as in Fig. 4.
Fig. 7. The mathematical model for each joint of robotic arm

C. FPGA Development Board


FPGA, a PLD is a semicustom component, which includes
configurable logic blocks, input-output blocks and
interconnects. It has some important characteristics; highly
integrated, fast computer speed, could be parallel programmed
and online programmed. The proposed PID controller
Fig. 4. The testing system for system identification algorithm is implemented with VHDL using the Altera Corp.
DE0Nano (Cyclone® IV EP4CE22F17C6N FPGA) device.
As seen in Fig. 4, the input signal (AC 30Vpp) which is given The components of this board are shown in Fig. 8. This board
the motor is shown in Channel 1 and the output signal which is introduces a compact-sized FPGA development platform suited
taken from potentiometer is shown in Channel 2 of for to a wide range of portable design projects, such as robots
oscilloscope. The graphics for axes of robots is given in Fig 5 and mobile projects. It features Cyclone FPGA with 22,230
and Fig 6. logic elements, 32MB of SDRAM, 2 kB EEPROM and 64 MB
serial configuration memory device. For connecting to real-
world sensors, it includes a National Semiconductor 8-channel,
12 bit ADC device, 13-bit, 3 axis accelerometer device, two
pushbuttons, 8 use LEDs, a set of four dipswitch, three
expansion headers [19].

Fig. 5. The graphics for axis 1 and axis 2 (Channel 1: 5.00 V/Div, 50.0
ms/Div - Channel 2: 100.0 mV/Div Time/Div - 50.0 ms/Div)

Fig. 8. DE0 Nano FPGA Education and development board

The components which is used in the study; Cyclone IV


EP4CE22F17C6N FPGA, USB type-mini AB port to connect
the board to computer to power the board and download the
Fig. 6. The graphics for axis 3 and axis 4 (Channel 1: 5.00 V/Div, 50.0 VHDL program to FPGA, 50 MHz clock oscillator which can
ms/Div - Channel 2: 50.0 mV/Div Time/Div - 50.0 ms/Div)
use as a source clock, ADC and 26-pin header to take the

766
motors position values as a voltage level and transmit these to B. Digital PWM Block
FPGA as s digital value, push button for reset the system and Pulse width modulation is a simple method of using
LEDs to see the same values about the program values. rectangular digital waveform to control an analog variable by
changing ON and OFF ratio or the output pulse in discrete time
III.IMPLEMENTATION domain. It is used in a variety of applications ranging from
In FPGA, three basic blocks are executed, which are communications to automatic control. In this application, pulse
Analog Input Interface Block, Digital PWM Block and, Digital width modulation (PWM) block implemented within FPGA
PID Block. In this section, these blocks is introduced. The and adjusts on and off period of each terminal of the full H-
FPGA design is generally synchronous, that means that the bridges to control five DC motors at the robot axes.
design is clock based and each rising edge allows all the D-flip The total PWM period T can be stated as in (7) and where
flops to simultaneously take a new state. But, most of the Ton= ON time and Toff = OFF time.
designs need one more clock which works in a different
frequency. To solve this problem, there are some techniques
about clock domain crossing (CDC). In this design, a binary T = Ton + Toff (7)
counter is created (33 bits) triggered by 50 MHz main
oscillator clock and suitable divided bits are chosen for ADC, The output voltage is calculated as in (8), where Vout is the
digital PID and digital PWM blocks. average output voltage, Vin is the input voltage and D is the
duty cycle.
A. Analog Input Interface
The ADC performs the function of converting a
⎛ Ton ⎞
continuous-valued analog signal into a discrete-valued digital Vout = ⎜ ⎟Vin , Vout = DVin , (8)
signal. FPGAs are well suited for serial analog to digital ⎜T +T ⎟
⎝ on off ⎠
converters owing to serial interface consuming less
communication lines while the FPGA is fast enough to
The simplest digital PWM architecture, counter-based
accommodate to high speed serial data. The DE0Nano board
PWM, and can be easily implemented only by an n-bit counter
contains ADC120S02 analog to digital converter provides up to
and n-bit comparator shown in Fig. 11. The counter counts
8 channels of analog input and converts them into a 12-bit
each positive transit of reference clock and when the value of
digital signal [20]. ADC receives analog signals via the eight
counter is less than the digital settling code K, the output
analog inputs from IN0 to IN7. When performing a
(A<B) of the comparator remains high level state until the
conversation, the ADC reads the signal on one of these eight
content of the counter is large then K [21]. Therefore, this
input channels and converts it to a digital output. These eight
output will generate a pulse width corresponding to duty cycle
pins are part of 2x13 GPIO header. The ADC also has four
and a frequency.
wires connected to the FPGA and these wires are used to
control the ADC and allow communication between ADC and
the FPGA. ADC120S02 is a high speed, low power 12 bit
converter. In this study the first four channels of ADC is used
actively. The ADC is connected both the FPGA and the 2x13
GPIO header as shown in Fig 9.

Fig. 11. Basic structure of counter based digital PWM[23]

The modulating signal is 12 bit digital value. The source


(reference) clock signal of FPGA is 50 MHz and the period is
20ns. To represent 212 = 4096 level of modulation signal,
Fig. 9. Signals to and from the ADC 20 × 4096 = 81920 ns period is necessary. This allows a
maximum PWM frequency of about 12.2 KHz. This frequency
The timing diagram of ADC is shown in Fig. 10; is experimented on motors and found to be sufficient. All axes
are driven with 12V DC motors, the PWM signal of all motors
change between 100% - 0% and to apply this PWM value H-
bridges supplied with 12V are used.

C. Digital PID Block


In FPGA, the digital PID control algorithm is implemented
and synthesized using Altera Quartus II, the RTL
implementation of controller is described using VHDL
language. Finally, the generated implementation file is
Fig. 10. The Timing diagram of ADC[20]
downloaded to the FPGA development board for testing. The

767
four closed loop digital PID algorithm is executed so K d is set to zero. The parameters for each axes is given in
simultaneously in FPGA for control base, shoulder, elbow and Table I.
wrist motors.
In the loop, the first step is that the previous error signal TABLE I. PID PARAMETERS
e[k-1] and the total previous integral signal ui[k-1] is updated.
Axis 1 Axis 2 Axis 3 Axis 4
Then the present error e[k] is obtained to subtract reference
point from the output of the system. The reference and the Kp 40 50 60 130
output of the system are both 12 bits wide and the sign of the Ki 4 5 6 13
result is checked to see if the error is positive or negative. If
the error sign is positive or zero the sign bit is set to ‘0’, Below, the application results for a pick and place
otherwise is set to ‘1’. Then e[k], e[k-1] are multiplied by the experiment are given for each axis of robot. The reference
PID parameters. The sign bits of the multiplicands are found position is calculated by using Matlab and the real time motor
with XOR to get the sign bit of the products. With the multiple position is obtained by using Quanser Q2 data accusation
12 bit two signals, the result is found as 24 bits. After two board.
additions, the output of PID controller is found 26 bits. As a
result, 26 bits value is reduced to 12 bits duty cycle value. All 2.2
reference pos i ti on
of the values in PID control algorithm are binary. In the 2
real ti me motor pos i ti on for axi s 1

algorithm there are no decimal points. The sampling time of

position (volt)
the algorithm is 20ms. The block diagram of the digital PID 1.8

controller in FPGA is shown as below;


1.6

1.4

0 10 20 30 40 50 60 70
time (seconds)

Kp Kd Ki
Fig. 13. Reference and real time motor position for axis1

Kd

1.9 reference position


real time motor position for axis 2
1.8

1.7
position(Volt)

1.6

1.5

1.4

1.3

0 10 20 30 40 50 60 70
time (second)

Fig. 12. Digital PID implementation in FPGA


Fig. 14. Reference and real time motor position for axis 2
There are various methods to determine PID parameters
and in this paper, the proportional ( K p ), integral ( K i ) and
1.7 reference position
derivative ( K d ) gains are obtained from Matlab Sisotool with real time motor position for axis 3

the help of linear system model which obtained in Section II, 1.6

based on step response[22]. The basic criteria to find these


position(Volt)

1.5
parameters, the overshoot for all robot axes are assumed to be
zero. However, theoretical studies show proportional control 1.4
satisfy, but in the real system owing to unmodelled nonlinear
1.3
disturbance and dead-zones requires integral control. In this
method at first K i and K d parameters are set to zero and the 1.2

proportional gain is increased until the step response reaches 1.1


the overshoot boundary. After that, K p and K i have been set 0 10 20 30 40
time(seconds)
50 60 70

to get desired fast control system with minimal steady state


error and the result show that there is no need derivative term Fig. 15. Reference and real time motor position for axis 3

768
International Conference on Instrumentation, Measurement, Computer,
2.05 reference position Communication and Control, 2011.
real time motor position for axis 4
[5] V. Subasri, K. Lavanya, and B. Umamaheswari, "Implementation of
2 digital PID controller in Field Programmable Gate Array
(FPGA)," Proceeding of the International Conference on Power
position (Volt)

1.95
Electronics (IICPE), 2006..
[6] Y. F. Chan, M. Moallem, and W. Wang, "Efficient implementation of
PID control algorithm using FPGA technolog,." Proceeding of the 43rd
1.9
IEEE Conference on Decision and Control (CDC), 2004.
[7] S. Yang, M. Gao, J. Lin and Z. Li, "The IP core design of PID controller
1.85 based on SOPC," Proceeding of the International Conference on
Intelligent Control and Information Processing (ICICIP), 2010.
1.8 [8] S. Chander, P. Agarwal, and I. Gupta, "FPGA-based PID controller for
0 10 20 30 40 50 60 70
time (second) DC-DC converter." Proceeding of the International Conference
on Power Electronics, Drives and Energy Systems (PEDES), 2010.
[9] S. Ghosh, R. K. Barai, S. Bhattarcharya, P. Bhattarcharya, S. Rudra, A.
Fig. 16. Reference and real time motor position for axis 4 Dutta, R. Peyne, "An FPGA based implementation of a flexible digital
PID controller for a motion control system." Proceeding of the
International Conference on Computer Communication and Informatics
Fig 13, 14, 15 and 16 show the trajectory of each robot axes (ICCCI), 2013.
against the reference trajectory, respectively. Four axis [10] B. Behnam and M. Mansouryar, "Modeling and simulation of a DC
controllers are executed simultaneously, with help of the motor control system with digital PID controller and encoder in FPGA
parallel nature of FPGA as they are seen in the results. The using Xilinx system generator." Proceeding of the International
Conference on Instrumentation Control and Automation (ICA), 2011.
axes keep tracking the reference trajectories without overshoot
[11] J. O. Inwelegbu and T. A. Nwodoh. "FPGA controller design and
except axis 4; small overshoots and steady-state errors are simulation of a portable dough mixing machine." Nigerian Journal of
caused by undesired noise and mechanical problems. Technology , vol: 30.1, 2011.
[12] C. I. Muresan, S. Folea, G. Mois, E. H. Dulf, "Development and
IV.CONCLUSIONS implementation of an FPGA based fractional order controller for a dc
motor," Mechatronics, vol: 23.7, pp. 798-804, 2013.
In this paper, FPGA-based digital parallel PID controller is
[13] A. Astarloa, J. LAzaro, U. Bidarte, J. Jimenez, A. Juloaga, "FPGA
designed and implemented for multi axes control systems. technology for multi-axis control systems," Mechatronics, vol.19.2 pp.
Altera DE0 Nano board is used to control five axes robotic arm 258-268, 2008
as a multi axes system. The digital PID block, digital PWM [14] Y. S. Kung, N. V. Quynh, N. T. Hieu, C. C. Huang, L. C. Huang,
block and Analog Input Interface block are successfully "Simulink/Modelsim Co-Simulation and FPGA Realization of Speed
designed on an FPGA to control the position of four motor Control IC for PMSM Drive." Procedia Engineering, vol. 23, pp. 718-
which is places in joint of robot. VHDL language is used for 727, 2011.
coding. The results demonstrate that FPGA can be shown as a [15] Y. S. Kung, C. T. Hsu, H. H. Chou, T. W. Tsui, "FPGA-realization of a
motion control IC for wafer-handling robot," Proceeding of the
flexible solution for multi axes systems. The digital PID International Conference on Industrial Informatics (INDIN), 2010.
controller is implemented on FPGA in some study seen in
[16] M. Xu, W. Zhu and Y. Zou. "Design of a reconfigurable robot controller
literature, but this paper shows that how to control a real based on fpga," Proceeding of the International Conference
model-unknown system with digital PID using FPGA. on Embedded Computing, 2008.
[17] M.Gopal, Digital Control & Stat War method 3E, Tata McGraw-Hill
REFERENCES Education, 2008
[18] Norman S. Nise, Control System Engineering, John Wiley & Sons,
California State Polytechnic University, Pomonai.
[1] B. V. Sreenivasappa and R. Y. Udaykumar, "Design and implementation [19] DE0 Nano User Manuel v:1.9. Available: http://www.terasic.com
of FPGA based low power digital PID controllers," Proceeding of the
International Conference on Industrial and Information Systems (ICIIS), [20] Using DE0 Nano ADC, Altera University Program. Available:
2009. http://www.altera.com
[2] L. Bing and C. Hua, "The research of the PID controller based on [21] H. C. Chen, "A high-resolution digital PWM controller using capacitor
FPGA," Proceeding of the International Conference on Electronic and integration," Proceeding of the International Conference on Next-
Mechanical Engineering and Information Technology (EMEIT), 2011 Generation Electronics (ISNE), 2010.
[3] A. Trimeche, A. Sakly, A. Mtıba and M. Benrejeb, "PID control [22] MATLAB, Siso Design Tool
implementation using FPGA technology,” 3rd International Design and http://www.mathworks.com/help/control/getstart/siso-design-tool.html
Test Workshop, 2008.
[4] D. Feng, L. Yan, L. Xu, W. Li, "Implement of digital PID controller
based on FPGA and the system co-simulation," Proceeding of the First

769

You might also like