FPGA and VHDL Assignment
FPGA and VHDL Assignment
SID: 2253483
ASSIGNMENT
1
2253483
Table of contents
1 Abstract……………………………………………………. 3
2 Introduction………………………………………………... 3
3 Design Steps (Methodology)……………………………… 4
4 Problems must be solved………………………………….. 4
5 Possible solutions………………………………………….. 5
6 PWM duty cycle…………………………………………... 5
7 Why PWM to control (benefits) and how…………………. 6
8 VHDL Modelling types (Dataflow, structural, and
Behavioural)……………………………………………….. 7
9 Design the control of DC motor by PWM………………… 8
10 Configuration FPGA board with VHDL code synthesis in
Vivado and explanation of the codes……………………… 11
11 The H-bridge’s role………………………………………... 13
12 Appendix for pictures of the results……………………….. 14
13 Conclusion…………………………………………………. 18
14 References………………………………………………….. 19
15 Appendix for VHDL codes………………………………… 20
2
2253483
Abstract
This report outlines the design and successful working implementation of a PWM controlled
DC motor, using VHDL for modelling, and verification through simulation. Dataflow,
Structural and Behavioural VHDL models have been used to leverage the strengths of each
approach to develop a robust, efficient, and flexible control environment to precisely regulate
the speed of the motor, using adjustable PWM duty cycles to maximise a motorís
responsiveness to varying operational demands. The performance is characterized with analysis
of the relationship between motor stall speed and PWM duty cycles with tables compiled from
captured data from the hardware to ensure that engineered control strategy would deliver an
adequate response after development testing and implementation. This study demonstrates that
VHDL is an effective method to develop control systems and through this comparison between
reference data and actual performance, an alternative to existing control applications is
proposed, which could lead to enhanced power efficiency and allow greater operational
stability. The fact is that precise control over DC motor speed can be changed very efficiently
through a control system that can be designed in VHDL.
Introduction
Motors, especially, DC motors are used in varied fields from industrial machinery and
consumer electronics to automotive systems, advanced robotics, and aerospace technology.
Accurate control of speed, position, and torque is crucial for achieving efficient performance
and output in various general and specific applications. Motor control is essential in various
disciplines. In this chapter the main applications and significances will be introduced below.
3
2253483
DC motors are responsible for operating many components in automobiles such as power
window regulators, windscreen wipers, electric power steering systems and cooling fans. Due
to their durability and capacity to offer accurate control, they are essential in contemporary
automotive design. Also, various domestic gadgets, such as blenders, mixers, hoover cleaners
and electric shavers, depend on direct current (DC) motors for effective and regulated
functioning. Additionally, DC motors are essential components of robotic systems, providing
precise control over movement and positioning in a wide range of applications, including
industry and healthcare. In aerospace engineering DC motors drive critical systems in aircraft,
spacecraft, and defence equipment. They are used in various control mechanisms, from landing
gear operation to missile guidance systems. Lastly, conveyor belts, machine tools, and
production lines often depend on DC motors for consistent and precise motion control, ensuring
efficient manufacturing processes (Medium, 2023).
DC motors possess superior initial torque compared to AC motors, facilitating the initiation of
motion. An inherent limitation of these motors is that they cannot be initiated unless they are
already operating with a load. DC motors can easily burn up if they operate without a load to
impede their speed. DC motors are well-suited for applications that require a consistent low-
speed or adjustable-speed torque. Also, AC motors are vulnerable to harmonic effects that have
the potential to destroy the equipment or result in severe heating of the iron or copper
components. Harmonic issues not only result in excessive noise but can lead to premature
motor failure or misfiring, which can cause damage to other equipment or disrupt the
manufacturing process. DC motors do not experience this problem, so completely resolving
the issue. DC motors provide superior speed regulation compared to AC motors. When dealing
with high-capacity systems, having exact control over the speed can determine the outcome of
a task, either resulting in success or damaging the motor. That is the reason why they are
frequently utilised in paper mills and rolling mills, where it is crucial to maintain a regular pace
in order to guarantee a continuous level of product quality. DC motors are well-suited for tasks
that require a consistent supply of low-speed torque or the ability to change torque levels.
(Nichols, 2019).
The technique to designing and implementing a DC motor control system utilising FPGA
involves a systematic process that emphasises careful planning and execution phases. This
method guarantees accurate manipulation of the motor's velocity and direction by employing a
pulse width modulation (PWM) technology. In this project, we're using FPGA technology to
make DC motor control even better. By using FPGA, we can make the motor do what we want
it to do faster and more accurately than ever before. This is going to be super useful in all those
places where DC motors are already being used, like robotics and automation systems, where
being able to control motors well is super important. Below are the detailed steps and
procedures that are followed:
The primary issue this project tackles is how to precisely control the speed and direction of DC
motors using FPGA tech. DC motors are super important in all sorts of industries, like cars and
4
2253483
factories, where they are used to power stuff and give fine-tuned control over speed. Also, DC
motors have to handle a variety of speeds to meet different needs, but standart analog or
mechanical controls often are not very precise or adaptable PWM can help by tweaking the
average power fed to the motor using digital signals, giving you more control over the speed
(Abbas, Chisab, and Mnati, 2021).
Many applications need the motor to spin in both directions. When you use an H-Bridge
together with an FPGA, you can easily reverse the motor's direction by simply changing the
polarity of the voltage supplied to it. The design must ensure a seamless change in direction
for both the electrical and mechanical systems. Furthermore, optimising the motor control
system to utilise the least amount of power while getting the most out of it is critical, especially
when working with highly sensitive energy sources. When adopting an FPGA-based control
system, ensure that it is built to be as efficient as possible to avoid wasted energy or heat
buildup (Abbas, Chisab, and Mnati, 2021).
Possible solutions.
It can be solved using Pulse-Width Modulation (PWM) technique. We can select between
fixed-frequency PWM, which changes the duty cycle but keeps the frequency constant, and
variable frequency PWM, which changes both the duty cycle and frequency. Fixed frequency
PWM is typically easy to set up and control using an FPGA, and it works well for most motor
control applications. Variable frequency PWM, on the other hand, can assist reduce
electromagnetic interference and improve motor efficiency when the load varies. Also, High-
resolution PWM can enable tighter control over motor speed and torque, particularly in
applications that need precise motions. FPGAs can provide high-resolution PWM signals due
to their fast clock speeds, enabling for more precise motor control (Taylor, 2023).
Designing simulations with VHDL code and advanced tools like the Xilinx ISE Design Suite
can help us evaluate our FPGA configuration before putting it into a physical device. This can
assist identify errors in your VHDL code or system architecture, saving you headaches later
when you apply it in the real world.
In PWM, the speed of your motor is measured in revolutions per minute, and you can precisely
control it by tweaking the duty cycle. The duty cycle is basically the percentage of time a
voltage is on during each cycle. So, if you got a 40% duty cycle, the voltage would be high for
40% of the time and off for the other 60%. By changing this duty cycle, you can make the
average voltage delivered to your motor go up or down, allowing for precise control over your
motor's speed (Figure 1 and 2). This capacity not only ensures accuracy, but also allows your
5
2253483
motor to adjust to changing conditions without wasting a lot of energy. It's like having a built-
in safety valve that allows you to dial in just the perfect amount of power when you need it,
without adding extraneous features. That's an interesting feature (Dietrich, 2022).
Pulse width modulation (PWM) can be utilised to effectively address the challenges of
precision and efficiency while controlling the speed of DC motors. By what means does it
accomplish that? Initially, PWM deceives the motor by creating the illusion that it is still
operating on a fluctuating voltage alternating current power source. This capacity not only
ensures accuracy, but also allows your motor to adjust to changing conditions without wasting
a lot of energy. It's having a built-in safety valve that allows you to dial in just the perfect
amount of power when you need it, without adding extraneous features. That's an interesting
feature (Colley, 2020).
PWM lets you adjust almost instantly to load shifts in the motor's load by changing the duty
cycle. PWM can improve latency and power waste in applications with variable loads, such
as welding robots. PWM adjusts input voltage quantity rather than absolute voltage level,
making it less sensitive to supply voltage swings. PWM controllers can vary duty cycles to
keep motor speed steady even if supplied voltage drops or spikes. PWM adjusts input voltage
rather than absolute voltage, making it less sensitive to supply voltage swings. The PWM
controller may vary the duty cycle to maintain motor speed even if the supplied voltage drops
or spikes (Figure 2)(Özer, Kıvrak, and Oğuz, 2017). Lastly, efficiency: The PWM quickly
turns the motor voltage on and off thousands of times in speed control, reducing heat loss. In
contrast, resistive systems dissipate power as heat.
6
2253483
Figure 2. Voltage changing through PWM. (Özer, Kıvrak, and Oğuz, 2017).
There are three fundamental coding techniques that can be used to write an architecture,
namely, Dataflow, Behavioural and Structural. The distinction between these styles is
predicated on the variety of concurrent statements employed: A dataflow design exclusively
use concurrent signal assignment statements. A behavioural architecture exclusively uses
process statements. A structural architecture exclusively uses component instantiation
statements. Instead of exclusively adhering to one architectural style, we have the option to
combine two or more types, resulting in a hybrid or mixed design. Below other differences are
specified.
Dataflow style refers to a system that is defined based on the manner in which data moves
through it. The data dependencies in the description correspond to those found in a standard
hardware implementation. A dataflow description inherently entails a corresponding gate-level
implementation. Dataflow descriptions are comprised of multiple concurrent signal assignment
statements.
7
2253483
statements in the same order as they are written, similar to how sequential statements are
performed in a traditional programming language.
Our design will be based on following block diagram. The block diagram is shown in the
Figure-2.
Figure 3. Block diagram of DC motor control by FPGA board. (Abbas, Chisab, and Mnati,
2021).
To simulate the design and get result from it Vivado® Design Suite software, which is created
by AMD, is used. Using Vivado® Design Suite we can synthesize VHDL code in real hardware
board like Nexys4 DDR™ FPGA Board (Figure 3).
8
2253483
The Nexys4 DDR board is a fully equipped digital circuit development platform that utilises
the latest Artix-7™ Field Programmable Gate Array (FPGA) technology from Xilinx®. The
Nexys4 DDR is equipped with a spacious FPGA (Xilinx component number XC7A100T-
1CSG324C), ample external memories, and a variety of USB, Ethernet, and other connections.
This makes it capable of accommodating a wide range of designs, from basic combinational
circuits to advanced embedded processors. The Nexys4 DDR is equipped with many integrated
peripherals including as an accelerometer, temperature sensor, MEMs digital microphone,
speaker amplifier, and other I/O devices. These built-in components enable the Nexys4 DDR
to be utilised for a diverse range of designs without the need for additional external
components.
The Nexys4 DDR also offers an improved collection of ports and peripherals, including:
9
2253483
Based on the block diagram following circuit is built (Figure 4) and following components are
used:
-through the output ports output voltage is sent to DC motor (in our project electric fan is used
as a DC motor).
Between output voltage and DC motor a transistor and a diode are applied to regulate the
current.
10
2253483
Configuration FPGA board with VHDL code synthesis in Vivado and explanation of the
codes.
1. Running Vivado® Design Suite and writing the code given in Appendix for VHDL
codes page (Figure 4).
2.
Figure 6. Main window of the Vivado® Design Suite and its code editor section.
4. Testing the simulation by loading the bit stream to the FPGA board by clicking Run
Synthesis button, transferring the output voltage to the electric fan.
11
2253483
5. If the fan is working, we check the implementation of PWM signal by increasing duty
cycle using push buttons on FPGA board. Changes are shown on the 4-bit 7 segment
display (Appendix for pictures of the results: Figures 1-10).
It can be seen from the graphs propellers of the fan are changing their rotating speeds as duty
cycle has been changed (See Appendix for pictures of the results: Figures 11-15).
We write the code in 4 .vhd files of the Vivado’s code editor section. Let’s analyse the
VHDL code file by file and section by section.
The first file creates PWM signal using following bunch of VHDL code (Appendix for
VHDL codes):
1-3rd lines are declaration of the libraries and packages used. From 5th to 15th lines include an
entity declaration. Inside the entity input and output ports are assigned to signals. These port
names are assigned to the FPGA boards ports in Vivado before simulating. In here 9 th and 10th
lines are buttons to increase or decrease the duty cycle. The second part (17th 119th lines) is
architecture of the program where main functionality goes on.
The second which is called DFF_bounce just simple flip flop code. It assigns the input D flip-
flop to the output Q only when it is enabled (en = '1') at a rising edge of the clock signal.
Similarly, it has library and package declaration, entity and architecture declaration parts.
Codes in Seven_segment file represents change in the value of the duty cycle of PWM signals.
It can be seen in the pictures that 7 segment display working accurately after implementing the
code (Appendix for the pictures: Figures 1-10).
The last file is constraint file. We can say it acts like a driver of the computers. It declares
which pins assigned to the signal names in the code.
In the next step, we add a H-bridge to control direction of the DC motor and test the simulation
again.
12
2253483
H-Bridge
The H-bridge is the most fundamental and commonly employed circuit for driving and
controlling a DC motor. The H-bridge, depicted in Figure 7, has four switches that are typically
constructed using metal–oxide–semiconductor field-effect transistors (MOSFETs) arranged in
a "H" configuration surrounding a DC motor. An H-bridge is a circuit commonly used for
controlling DC motors. It enables precise control over the motor's direction and speed by
selectively activating and deactivating a series of switches (Hertz 2022).
In order to alter the rotational direction of the DC motor, it is imperative to modify the polarity
of the voltage that is supplied to the winding coil. The most prevalent method is utilising a "H
bridge" configuration to conveniently alter the direction of a DC motor. The circuit's
configuration bears a resemblance to the letter "H", so it was designated as a H bridge. Figure
(3) depicts a H bridge configuration. To achieve forward rotation, Q1 and Q4 are activated
while Q2 and Q3 are deactivated. During reverse rotation, Q2 and Q3 are activated while Q1
and Q4 are deactivated (Özer, Kıvrak, and Oğuz, 2017).
Figure 9. Direction of the current when H-bridge is applied. (Özer, Kıvrak, and Oğuz, 2017).
13
2253483
14
2253483
15
2253483
16
2253483
17
2253483
In conclusion, the report reveals that VHDL was effectively employed in designing and
developing of a DC motor control system using PWM (Pulse width Modulated) control. With
the combined use of Dataflow, Structural, and Behavioural VHDL models, it has been created
a flexible and robust control environment with effective stages allowing the user to control the
motor speed with adjustable PWM duty cycles. The relationship between motor speed and
PWM duty cycles demonstrated shows that the required motor speed increased when the duty
cycles were adjusted. Implementation on FPGA (Nexys4 DDR board) helped to create precise,
high speed, bitstream signals. Also, the use of FPGA in providing a superior efficiency with
improved power supplies. Use of H-bridge facilitates current flow control and control in
direction of the motor. In shortly, we have got desired results using FPGA board.
It can conclusively be stated that application of VHDL and FPGA-based control systems or
controllers in developing control systems can successfully perform well in comparison with
some conventional control methods. Low power consumption and high efficiency of
operation of the system provide an alternative means of developing power-saving and stable
systems.
18
2253483
References:
Abbas M.A.H., Chisab F.R., and Mnati J.M. (2021) ‘Monitoring and controlling the speed
and direction of a DC motor through FPGA and comparison of FPGA for speed and
performance optimization’, International Journal of Electrical and Computer Engineering
(IJECE), 11(3903). Available at: http://doi.org/10.11591/ijece.v11i5.pp3903-3912 (Aceessed: 17
Apr 2024).
Dietrich Sh. (2022) Understanding the Basics of Pulse Width Modulation (PWM). Available
at: https://control.com/technical-articles/understanding-the-basicsof-pulse-width-modulation-
pwm/#:~:text=The%20duty%20cycle%20of%20a,off%20for%20the%20other%20half
(Accessed: 18 Apr 2024).
Garcia-Reyes et. al. (2022) ‘Level-Shift PWM Control of a Single-Phase Full H-Bridge
Inverter for Grid Interconnection, Applied to Ocean Current Power Generation’, Applied to
Ocean Current Power Generation, 15(5). Available at: https://doi.org/10.3390/en15051644
(Accessed: 18 Apr. 24).
Hertz J. (2022) H-bridge DC Motor Control Using Complementary PWM, Shoot-through,
and Dead-time. Available at: https://www.allaboutcircuits.com/technical-articles/h-bridge-dc-
motor-control-complementary-pulse-width-modulation-pwm-shoot-through-dead-time-pwm/
Özer T., Kivrak S., and Oğuz Y. (2017) ‘H Bridge DC Motor Driver Design and
Implementation with Using dsPIC30f4011’, International Journal of Innovative Research in
Science, Engineering and Technology, 6. pp. 75-83. Available at:
https://www.researchgate.net/publication/317225711_H_Bridge_DC_Motor_Driver_Design_
and_Implementation_with_Using_dsPIC30f4011 (Accessed: 18 Apr. 24).
Pedroni A. V. (2010) Circuit design and Simulation with VHDL. 2nd Edtn. London:The MIT
Press.
19
2253483
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.all;
4 ----------------------------------------------------------------------------------------------------
5 entity pulsewidthmodulation is
6 port(
7 clk : in std_logic;
8 rst : in std_logic;
9 inc : in std_logic;
10 dec : in std_logic;
11 pwm_out : out std_logic;
12 a_to_g : out std_logic_vector(6 downto 0);
13 an : out std_logic_vector(7 downto 0)
14 );
15 end pulsewidthmodulation;
16 ---------------------------------------------------------------------------------------------------
17 architecture behaviural of pulsewidthmodulation is
18 component dff_button
19 port(
20 clk : in std_logic;
21 en : in std_logic;
22 d : in std_logic;
23 q : out std_logic
24 );
25 end component;
26 ---------------------------------------------------------------------------------------------------
27 component seven_seg
28 port(
29 clk_in : in std_logic;
30 data_in : in std_logic_vector(15 downto 0);
31 segs_out : out std_logic_vector(6 downto 0);
32 anodes_out : out std_logic_vector(7 downto 0)
33 );
34 end component;
35 ------------------------------------------------------------------------------------------------
36 signal duty : std_logic_vector(15 downto 0):= x"1388";
37 signal cnt : std_logic_vector(15 downto 0):= (others => '0');
38 signal pwm : std_logic;
39 signal slow_clk_en : std_logic := '0';
40 signal count_slow : std_logic_vector(23 downto 0):= (others => '0');
41 signal tmp1,tmp2,duty_inc: std_logic;
42 signal tmp3,tmp4,duty_dec: std_logic;
43 signal data_in : std_logic_vector(15 downto 0);
44
45 begin
20
2253483
46 process(clk)
47 begin
48 if(rising_edge(clk)) then
49 count_slow <= count_slow + x"000001";
50 if(count_slow>=x"2faf08") then
51 count_slow <= x"000000";
52 end if;
53 end if;
54 end process;
55 slow_clk_en <= '1' when count_slow = x"2faf08" else '0';
56
57 stage0: dff_button port map(clk => clk, en => slow_clk_en, d => inc, q => tmp1);
58 stage1: dff_button port map(clk => clk, en => slow_clk_en, d => tmp1, q => tmp2);
59 duty_inc <= tmp1 and (not tmp2) and slow_clk_en;
60 stage2: dff_button port map(clk => clk, en => slow_clk_en, d => dec, q => tmp3);
61 stage3: dff_button port map(clk => clk, en => slow_clk_en, d => tmp3, q => tmp4);
62 duty_dec <= tmp3 and (not tmp4) and slow_clk_en;
63
64 -- seven segment output
65 a1: seven_seg port map(clk_in => clk, data_in => data_in, segs_out => a_to_g,
66 anodes_out => an);
67
68 process(clk) -- process controlling the counter
69 begin
70
71 if(rising_edge(clk))then
72 cnt <= cnt + x"1";
73 if(cnt >= x"270f")then
74 cnt <= x"0000";
75 end if;
76 if(rst = '1')then
77 duty <= x"1388";
78 data_in <= x"0032";
79 else
80 if(duty_inc='1' and duty <= x"2328") then
81 duty <= duty + x"3e8";
82 elsif(duty_dec='1' and duty>=x"3e8") then
83 duty <= duty - x"3e8";
84 end if;
85 end if;
86
87 if(duty >= x"2710")then
88 data_in <= x"0100";
89 elsif(duty >= x"2328")then
90 data_in <= x"0090";
91 elsif(duty >= x"1f40")then
92 data_in <= x"0080";
21
2253483
22
2253483
16 begin
17 if (rising_edge(clk)) then
18 if (en = '1') then
19 q <= d;
20 end if;
21 end if;
22 end process;
23 end arch;
24 ----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
seven_segment.vhd
----------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
1 use ieee.numeric_std.all;
2 ----------------------------------------------------------------------------------------------------
3 entity seven_seg is
4 port(
5 clk_in : in std_logic;
6 data_in : in std_logic_vector(15 downto 0);
7 segs_out : out std_logic_vector(6 downto 0);
8 anodes_out : out std_logic_vector(7 downto 0)
9 );
10 end entity;
11 ---------------------------------------------------------------------------------------------------
12 architecture rtl of seven_seg is
13 signal count : unsigned(18 downto 0) := (others => '0');
14 signal count_next : unsigned(18 downto 0);
15 signal anodeSelect : std_logic_vector(1 downto 0);
16 signal nibble : std_logic_vector(3 downto 0);
17 signal segs : std_logic_vector(6 downto 0);
18
19 begin
20 -- Infer counter register
21 process(clk_in)
22 begin
23 if ( rising_edge(clk_in) ) then
24 count <= count_next;
25 end if;
26 end process;
27
28 -- Increment counter and derive anode select from top two bits
29 count_next <= count + 1;
30 anodeSelect <= std_logic_vector(count(18 downto 17));
31
32 -- Drive anodes
33 with anodeSelect select anodes_out <=
23
2253483
24
2253483
25