VHDL code for 4 bit ALU and Realization on FPGA development Board

Ekeeda
16 Aug 202317:08

Summary

TLDRIn this instructional video, the presenter guides viewers through the process of designing a 4-bit ALU (Arithmetic Logic Unit) using VHDL code. The tutorial covers understanding ALU's logical functions and boolean expressions, creating an Xilinx ISE project, coding, simulating, synthesizing, and generating a bit file for FPGA implementation. The presenter also demonstrates how to create a UCF file for pin constraints and uses an FPGA programmer to load the ALU functionality onto the board, testing it with switches and LEDs to verify the operations.

Takeaways

  • πŸ˜€ The video is a tutorial on designing a 4-bit ALU (Arithmetic Logic Unit) using VHDL and implementing it on an FPGA development board.
  • πŸ” The presenter starts by explaining the logical functions and boolean expressions of the ALU before writing the VHDL code.
  • πŸ’» The tutorial involves creating a project in Xilinx ISE, writing VHDL code for the 4-bit ALU, simulating the code, and synthesizing it.
  • πŸ“ˆ The ALU performs various operations based on the select line inputs, including addition, subtraction, AND, NAND, XOR, XNOR, OR, and passing through the input A.
  • πŸ”’ The inputs to the ALU consist of two 4-bit inputs (A and B) and a 3-bit select line, with the output being a 4-bit ALU result.
  • πŸ“ The VHDL code uses a 'with select' statement to handle different operations based on the select line values.
  • πŸ”© The synthesis process involves implementing the ALU using components like adders, subtractors, and multiplexers.
  • πŸ–₯️ The video demonstrates a simulation of the ALU to verify its functionality for different select line inputs and operations.
  • πŸ”Œ A UCF (User Constraint File) is created to define pin connections for the FPGA implementation, specifying the physical connections for inputs, outputs, and select lines.
  • πŸ’Ύ The final step involves generating a bit file, programming the FPGA board, and testing the ALU functionality using switches and LEDs on the board.

Q & A

  • What is the main topic of the video session?

    -The main topic of the video session is to write VHDL code for a 4-bit ALU (Arithmetic Logic Unit) and its implementation on an FPGA development board.

  • What are the logical functions and boolean expressions needed to understand before writing the VHDL code for the ALU?

    -Before writing the VHDL code, one must understand the logical functions such as addition, subtraction, AND, OR, XOR, and NAND operations, as well as the boolean expressions that represent these functions in the ALU design.

  • What is the purpose of the select line in the 4-bit ALU design?

    -The select line in the 4-bit ALU design is used to choose between different operations such as addition, subtraction, AND, OR, XOR, and other functions based on the combination of bits set on the select line.

  • How many bits are in the select line for the 4-bit ALU design?

    -The select line for the 4-bit ALU design is 3 bits, allowing for eight different combinations of operations.

  • What is the process of implementing the VHDL code on the FPGA development board?

    -The process involves writing the VHDL code, creating a project in Xilinx ISE, simulating the code, synthesizing it, creating a UCF file, generating a bit file, and then implementing the bit file on the FPGA development board.

  • What is a UCF file used for in the context of FPGA implementation?

    -A UCF (User Constraint File) is used to define pin connections between the FPGA and external components, specifying the physical pins to which the signals in the VHDL code are assigned.

  • How many different operations can be performed with the 4-bit ALU design as described in the script?

    -With the 3-bit select line, the 4-bit ALU design can perform eight different operations, each corresponding to a unique combination of the select line bits.

  • What is the significance of the 'others' clause in the VHDL code for the ALU?

    -The 'others' clause in the VHDL code for the ALU is used to handle any remaining cases that are not explicitly covered by the select statements, ensuring that all possible input combinations are accounted for.

  • What are the steps involved in testing the ALU functionality on the FPGA board?

    -The steps include loading the bit file onto the FPGA, connecting the select lines and input switches to the appropriate pins on the FPGA, and observing the LED outputs to verify that the ALU performs the expected operations based on the selected operation.

  • How does the video script guide the user to verify the simulation of the ALU operations?

    -The script guides the user to verify the simulation by providing examples of input values for A and B, and the expected results for each operation based on the select line settings. It also demonstrates how to force values in the simulation and observe the outputs to confirm the correctness of the ALU operations.

Outlines

00:00

πŸ“ Introduction to 4-bit ALU VHDL Coding

This paragraph introduces the session on writing VHDL code for a 4-bit Arithmetic and Logic Unit (ALU) and its implementation on an FPGA development board. The speaker outlines the process, which includes understanding logical functions and boolean expressions, creating an Xilinx ISE project, writing VHDL code for the ALU, simulating, synthesizing, creating a UCF file, generating a bit file, and implementing it on the development board. The ALU design involves two 4-bit inputs, a select line, and a 4-bit output with various operations based on the select line combinations.

05:01

πŸ” Detailed Explanation of ALU Operations and VHDL Code Writing

The speaker provides a detailed explanation of the ALU operations and the process of writing VHDL code. The ALU performs different operations based on the select line inputs, such as addition, subtraction, AND, NAND, XOR, XNOR, and OR. The VHDL code includes declarations of inputs and outputs, use of the 'with-select' statement for conditional operations, and the implementation of arithmetic and logical operations using standard VHDL constructs. The paragraph also covers the syntax checking and synthesis process to ensure the code is correctly translated into hardware components.

10:02

πŸ”¬ Simulation and UCF File Creation for FPGA Implementation

This paragraph discusses the simulation of the ALU to verify its functionality with different input values and select line combinations. The speaker demonstrates the simulation process, showing how the ALU performs addition, subtraction, and logical operations. Following the simulation, the speaker explains the creation of a UCF (User Constraint File) necessary for mapping the VHDL code to the physical pins of the FPGA. The UCF file specifies the pin connections for the select lines, input A and B, and the ALU output.

15:03

πŸš€ Finalizing FPGA Programming and Testing ALU Functionality

The final paragraph covers the steps to program the FPGA using the generated bit file and testing the ALU functionality. The speaker guides through opening the programmer, selecting the appropriate FPGA family and COM port, and programming the FPGA board. After programming, the speaker describes how to test the ALU by connecting switches to the select lines and input A and B, and observing the output on LEDs. The goal is to verify that the ALU performs the correct operations as per the select line settings.

Mindmap

Keywords

πŸ’‘VHDL

VHDL stands for Very High Speed Integrated Circuit Hardware Description Language. It is a hardware description language used in the design and modeling of digital systems, especially in the field of FPGA (Field Programmable Gate Array). In the context of the video, VHDL is used to write code for a 4-bit ALU (Arithmetic Logic Unit), which is a key component in digital systems for performing arithmetic and logical operations.

πŸ’‘ALU

ALU, or Arithmetic Logic Unit, is a digital circuit that performs arithmetic and logical operations. In the video, the focus is on designing a 4-bit ALU, which means it can handle operations on 4-bit binary numbers. The ALU is essential in processing units of computers and other digital systems for executing basic operations like addition, subtraction, and logical AND, OR, etc.

πŸ’‘FPGA Development Board

An FPGA Development Board is a hardware platform used for designing, testing, and implementing digital circuits using Field Programmable Gate Arrays. In the video, the ALU design is realized on an FPGA development board, demonstrating how the VHDL code is synthesized and implemented in hardware, allowing for practical testing and verification of the ALU's functionality.

πŸ’‘Boolean Expressions

Boolean Expressions are mathematical expressions that can be either true or false. They are fundamental in digital logic design and are used to describe the logical relationships between inputs and outputs in a system. In the video, Boolean expressions are likely used to define the logic of the ALU operations, such as how the inputs A and B are combined to produce the output based on the select line.

πŸ’‘Select Line

In the context of the video, the select line is a control input that determines which operation the ALU will perform. It is a three-bit input, allowing for multiple operation modes. For example, when the select line is '000', the ALU performs addition; when it is '001', it performs subtraction. This concept is crucial for the flexibility of the ALU in performing different arithmetic and logical operations.

πŸ’‘Simulation

Simulation in digital design refers to the process of testing and verifying the behavior of a digital system using software tools before implementing it in hardware. In the video, simulation is used to check the correctness of the VHDL code for the 4-bit ALU, ensuring that it performs the expected operations under various input conditions.

πŸ’‘Synthesis

Synthesis is the process of converting a high-level digital design, such as VHDL code, into a form that can be implemented in hardware. In the video, synthesis is used to translate the VHDL code for the ALU into a format that can be used on an FPGA development board, involving the creation of a bit file that represents the hardware configuration.

πŸ’‘UCF File

A UCF (User Constraint File) is a file used in FPGA design to specify the physical constraints for the implementation of a digital circuit. It maps the logical elements of the design to the physical pins of the FPGA. In the video, a UCF file is created to define the pin connections for the ALU, ensuring that the inputs and outputs are correctly connected to the FPGA board.

πŸ’‘Bit File

A Bit File is a binary file that contains the configuration data for an FPGA. It is the result of the synthesis process and is used to program the FPGA, effectively loading the digital design into the hardware. In the video, a bit file is generated for the 4-bit ALU design, which is then used to program the FPGA development board.

πŸ’‘Implementation

Implementation in the context of FPGA design refers to the process of loading the synthesized bit file onto the FPGA board, making the digital design operational in hardware. In the video, the final step is to implement the bit file on the FPGA development board, allowing the 4-bit ALU to perform its intended functions in a physical device.

Highlights

Introduction to a VHDL code design course for a 4-bit ALU and its FPGA implementation.

Understanding the logical functions and Boolean expressions of a 4-bit ALU before coding.

Creating a Xilinx ISE project for 4-bit ALU coding using VHDL.

Process of simulation, synthesis, and bit file generation for FPGA implementation.

Description of a 4-bit ALU design with two 4-bit inputs and a 4-bit output.

Eight different combinations of operations for the ALU using a 3-bit select line.

Explanation of the ALU operation when the select line is set to zero for addition.

Demonstration of subtraction operation with the select line set to 001.

Illustration of the AND operation when the select line is 010.

NAND operation explanation with the select line set to 011.

XOR and XNOR operations explained for select line values of 100 and 101.

OR operation demonstration for a select line value of 110.

Pass-through functionality of the ALU for a select line value of 111.

Writing of VHDL code for the 4-bit ALU with input declarations and entity definition.

Use of a with-select statement to write the ALU program in VHDL.

Synthesis of the VHDL code to verify the implementation of ALU operations.

Simulation of the ALU to test various operations and validate the design.

Generation of a UCF file for pin constraints and FPGA board implementation.

Programming the FPGA board with the bit file and testing the ALU functionality.

Transcripts

play00:00

[Music]

play00:01

hello friends welcome to the village

play00:04

design course

play00:05

so in today's session we are going to

play00:08

write a vhdl

play00:09

code for 4-bit aou and its relation

play00:13

realization on the fpga development

play00:15

board

play00:16

[Music]

play00:23

so before starting writing a vhdl code

play00:26

first of all we have to understand its

play00:28

logical functions then its boolean

play00:31

expressions

play00:32

then we are going to create a vhdl

play00:35

um xilinx isc project where we are going

play00:38

to write a

play00:40

4 bit alu coding using a vhdm

play00:43

then we are going to do the simulation

play00:45

then synthesis

play00:46

creating a ucf file generate a bit file

play00:49

and that bit file you are going to

play00:50

implement on the

play00:52

development board so let's start so

play00:55

this this is a four bit aou uh design i

play00:58

have taken

play00:59

so in this in this we have four bit

play01:02

input four bit out uh so so we have two

play01:06

four bit input a is a four bit

play01:08

b also four bit and

play01:12

alu out is also four bit so

play01:15

and these are the various combinations

play01:17

or operations we are going to do

play01:19

using alu so we have taken

play01:23

eight different combinations so for that

play01:25

we need a select line so again select

play01:27

line is again a three bit

play01:28

input so totally we have

play01:32

three inputs and one output so out of

play01:34

these three input

play01:35

input a b are four bit and select line

play01:37

as a three bit

play01:38

so how it how it works when select line

play01:41

is zero zero

play01:42

we are going to do the operation of a

play01:44

plus b

play01:45

we are going to do the operation of a

play01:47

plus b

play01:48

and that is going to the output alu out

play01:51

when select line is zero

play01:52

zero 1 what we are doing we are doing a

play01:55

minus

play01:56

b a minus b then

play01:59

when select line is equal to 0 1 0 we

play02:02

are doing a

play02:03

and b then if it is a 0 1 1 a

play02:06

nand b one zero zero then a xor b

play02:10

one zero one a x nor b where it is one

play02:13

one zero

play02:14

a or b and finally if it is a one one

play02:17

one we are passing whatever input of

play02:19

a bit uh a four bit you are passing to

play02:21

the output

play02:22

a load so for this function for this

play02:25

function

play02:26

now we are going to write a vhdl vhdl

play02:29

code okay so let's let's begin to write

play02:32

a vhdl code

play02:34

so open the isc create a new project

play02:36

file new project

play02:38

so we are going to write a l u 4

play02:41

b ok so i am creating a project alu 4

play02:45

bit

play02:46

next so these these parameters are

play02:49

exactly same because it is already one

play02:50

time we have saved

play02:52

so for our family is spartan 3 xc3s 58

play02:56

tq144

play02:57

next finish

play03:01

now we have to add a new source so vhdl

play03:04

module

play03:05

vsdn module a l you

play03:08

underscore for underscore bit okay

play03:11

so we are going to write vhdl code for

play03:15

four bit alu so as i said as i said

play03:18

how many inputs we have we have input a

play03:20

b which are four bit

play03:22

so let us declare it a comma b

play03:26

r of type in bus and total four bits

play03:29

means three down to

play03:31

zero then we have another input select

play03:33

line

play03:34

that is also an in with a bus of three

play03:37

bits so it is

play03:37

two down to zero and we have output alu

play03:41

underscore

play03:42

out this is the output

play03:46

and the bus width is three down to zero

play03:50

so that is a four bit

play03:51

okay so this much declarations we have

play03:53

to do

play03:54

so let's reconfirm a four bit b four bit

play03:57

select line three bit

play03:58

alu out 4-bit ali out

play04:01

ali out for it so let's generate a

play04:06

entity so here we are going to use some

play04:09

some additional features like additional

play04:11

subtraction so we need to add a

play04:13

library called unsign so let's add it

play04:18

okay done now your entity is also

play04:22

already declared so library declaration

play04:23

then entity

play04:24

port a comma b in 4 bit select line

play04:28

input 3 bit ali out 4 bit

play04:31

now here we have to write a program so

play04:34

we are going to use

play04:36

we are going to use

play04:42

we are going to use a with select with

play04:44

select

play04:45

uh statement to write to write a

play04:49

alu program okay

play04:54

so let's begin let's begin so i am going

play04:56

to write

play04:57

with s e l

play05:00

select this is a concurrent statement

play05:02

right everyone knows that we have

play05:04

already seen this

play05:06

statement syntax and usage so with

play05:09

scl select now output is a l you

play05:11

underscore

play05:12

out is equal to

play05:17

the first condition is a plus b

play05:20

so a plus b

play05:24

when when this straight line is equal to

play05:28

when it is

play05:29

0 0 0 right

play05:34

then we have to know other conditions

play05:37

also we need to write

play05:43

when it is 0 0 1 what is the condition

play05:47

a minus b and

play05:53

then when 0 1 0 it is a and b 0

play05:56

1 0 it is

play06:00

a and b

play06:04

then it is 0 1

play06:07

1 when it is 0 it is an and xor xnor

play06:11

then i am writing here a nand b

play06:19

then it is when it is one zero zero it

play06:22

is

play06:24

for four it is xor

play06:28

xor yes then

play06:32

for one zero one it is

play06:35

x nor

play06:38

x no right

play06:42

when it is a six it is a or b

play06:48

a or b right and it is a final event is

play06:55

when others clause

play06:58

so here we are terminating when others

play07:01

so that means when it is a 1 1

play07:03

1 we are going to write a right

play07:07

so this this this completes our program

play07:09

this completes our program

play07:11

so we have to check for the syntax let

play07:13

us check the syntax if any by mystically

play07:15

we have done any mistake then it will

play07:17

indicate through an error

play07:24

okay then do the synthesis

play07:28

so let's see the synthesis

play07:34

really four bit so

play07:37

it is implemented if you see here adder

play07:39

subtractor

play07:41

then multiplexer for selection and here

play07:44

it is implemented using xor

play07:46

and other functionality and gate

play07:48

everything it is implemented right

play07:50

so let us let us let us see the

play07:51

simulation fastly

play07:53

and then we will go for generating a bit

play07:55

file so simulate it

play07:58

so let's start

play08:01

so i am giving a value some random value

play08:03

let us say uh

play08:06

1 0 1 0 sorry

play08:09

1 0 1 0 binary apply

play08:13

ok b

play08:18

let us take example b is 0

play08:22

1 0 1 ok for you

play08:26

then select line let us start with the

play08:29

initial

play08:30

so it is 0 0 0 apply ok

play08:33

and run it ok now if you can see here

play08:38

so a plus b okay

play08:41

so 10 plus 5 becomes 15 10 plus 5

play08:45

becomes 15 if you can see here so

play08:48

the first operation au operation is when

play08:50

straight line is 0 0

play08:52

0 it performs a plus b now if select

play08:55

line is 0

play08:56

0 1 it should perform

play08:59

it should perform 0 0 1 it should

play09:02

perform a minus b

play09:03

so 10 minus for you again it should come

play09:06

five so result should be five got it

play09:09

got it now if select line is

play09:13

zero one zero okay zero

play09:16

one zero okay so it should perform and

play09:19

operation

play09:21

so it should perform and operation but

play09:22

if you see the end operation

play09:24

so zero it is a bit wise bitwise

play09:27

operation so zero

play09:28

and and one it is zero zero

play09:32

one zero one zero again zero and zero

play09:35

one again

play09:36

zero so this is and operation now let us

play09:39

see the for nand operation

play09:41

so zero one one if straight line is zero

play09:44

one one

play09:45

what is operation as per the select line

play09:48

is zero 1 1 we have written a code for

play09:50

nand

play09:51

so let's simulate it so 9 is invert off

play09:54

and so whatever here we are getting 0 0

play09:57

0 it will imply

play09:58

invert so all are ones now when it is

play10:01

1 0 0 when it is a fourth condition if

play10:04

select line is 1

play10:05

0 0 what is the operation we have

play10:08

written we have written

play10:10

for 1 0 0 it is a a x or b so let's

play10:14

let's do it

play10:16

so a x or b

play10:19

ax or b also exactly same because 0 1 1

play10:22

1 0 1 and 0 1 1 1 0 1 so let us change

play10:26

some a value and again run it so force

play10:29

constant

play10:31

so one one zero zero okay

play10:34

okay run it now check it now x so zero

play10:40

zero one zero x or one it is one

play10:44

zero x xor 0 is 0 1 x or 1 is 0 and 1

play10:48

x or 0 is 1 so like that like that we

play10:51

can verify the

play10:52

simulation like that we can verify the

play10:54

simulation

play10:56

so let us let us go ahead with

play10:59

writing or generating a ucf file so for

play11:02

that for that what you have to do

play11:04

why we need to use a file now to

play11:06

implement this program onto a pc we need

play11:09

a pin connection

play11:10

yes so for that pin connections we need

play11:13

a

play11:14

ucf generation so let's generate it

play11:17

right click

play11:18

new source then you have to select

play11:21

implement constraint file and this is

play11:23

a l u dot u c f

play11:26

okay so i'm going to write a ucl file

play11:30

next

play11:30

finish okay so here you say file is

play11:33

generated

play11:34

so uh i will use some

play11:38

already written to shorten our time

play11:42

okay so for that go back now

play11:45

now what we are going to use we are

play11:47

going to use this

play11:49

these three switches as a select line so

play11:51

for that select two is a

play11:53

pin pin location is p8 select one is p3

play11:56

and select

play11:57

0 is p5 so just modify it so select

play12:01

2 is p8

play12:06

yes select 2 is p8 select off one is p3

play12:10

and select of zero is p5 it is already

play12:12

there okay

play12:13

now for the for the inputs

play12:16

uh four bit b input and four bit a input

play12:20

we are going to use this j14 header so a

play12:23

of a of 0 is connected to p 15

play12:27

or or we can say the first four switches

play12:31

are used for

play12:31

four bit b input and next four bit

play12:35

four switches are used as a 4-bit a

play12:38

input so

play12:38

here 4-bit a so sorry b input

play12:41

and here is a input so for that b of 3

play12:44

is equal to p-31

play12:45

that is the first switch so first switch

play12:48

represent the msb of b and the fourth

play12:52

switch represent the

play12:53

lsb of the b input similarly this fifth

play12:56

switch will represent as a

play12:58

msb of a and last switch as a lsb of

play13:03

b so let's let's do it so b of 3 is

play13:05

equal to

play13:06

p 31 so b of 3 already it is p 31 b of 2

play13:10

is p 32

play13:12

b of 1 is p 28 v of 0 is p

play13:15

30 b of 0 is p 30 correct

play13:18

then a of 3 we have to assign p21 a of 3

play13:22

p27 sorry p27

play13:25

then p29 p24 p25 all right

play13:28

all right now then the ali output we are

play13:32

going to connect

play13:33

to the this led output and that is

play13:35

connected to this p4 port

play13:37

so for ali out of 3 so that is msb out

play13:40

is 141

play13:41

so ale of 3 msb is 141 so i am modifying

play13:45

here

play13:46

141 then

play13:48

second is 140 3

play13:52

i guess yes 143 138 139

play13:56

then 138

play14:00

then 130 right

play14:03

so this creates our ucf file now we are

play14:05

ready with the ucf file save it

play14:08

and let's generate a programming file

play14:11

okay

play14:11

so once the programming file is ready

play14:14

then we

play14:15

are going to open a pga programmer

play14:18

and using fpga programmer we are going

play14:20

to write a

play14:22

implementer write a bit file onto a pg

play14:25

and we will check the alu functionality

play14:28

okay so let's wait for some time

play14:31

it is generating yes almost regenerated

play14:33

a bit file

play14:35

then meanwhile time i will just open the

play14:37

programmer

play14:38

so this is the programmer we are using

play14:40

usually to write a

play14:42

fpga so for that usually it will show us

play14:45

the

play14:45

uh the fpga board family it is xc3s

play14:49

says and you have to select a com port

play14:51

so i am using com4

play14:53

because the usb port i connected to the

play14:56

fpga is a

play14:57

com 4 now once this bit file is

play15:00

generated

play15:01

through this open file we are going to

play15:02

open the bit file

play15:04

so open file so wherever you have

play15:07

written a code so we have

play15:08

created a new project that is yearly 4

play15:10

bit

play15:11

and you can see here alu 4 bit bit file

play15:13

is generated

play15:14

we have to say open and let's say

play15:17

program

play15:19

so my fpga started programming

play15:22

so now we'll move to the fpga board

play15:29

so yes now if you if you can observe

play15:32

here if you can observe here

play15:34

the fpga is program and the led

play15:37

is blinking over here led is blinking

play15:40

over here blue led

play15:41

now we have to see the connections for

play15:44

the connections

play15:46

we have used this p6 uh sorry uh p2

play15:49

header

play15:50

p2 header for this select line so that i

play15:52

have to connect to the

play15:55

j3 header j3 header

play15:59

once again i will confirm okay so

play16:03

now our program is ready we are loaded

play16:07

alu functionality into this fpga

play16:11

so how we are going to test it so these

play16:13

are the select lines

play16:14

select line of three two one sorry

play16:17

sorry two one zero so three bit select

play16:20

line

play16:20

so this first switch will act as a msb

play16:23

of b input so

play16:24

b first four switches for the b input

play16:27

and

play16:28

second remaining four switches for the a

play16:32

input

play16:32

and this first four leds indicates the

play16:34

alu output okay

play16:36

so let us make it so if i make it a

play16:39

is one b is one

play16:44

so for zero zero it should add so what

play16:46

is not adding

play16:47

maybe weight so this is

play16:51

j3 j3

play16:54

so let me verify it once again

play17:07

you

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
VHDL ProgrammingFPGA BoardALU DesignDigital LogicHardware ImplementationProject TutorialCoding TutorialElectronic EngineeringBitwise OperationsLogic Synthesis