N bit Multiplier in Verilog (with code)| Verilog Project | Xilinx Vivado | Electronics Project

Arjun Narula
28 Jan 202207:59

Summary

TLDRIn this wavelog project, Arjun Narula introduces an n-bit multiplier with a binary to BCD converter. The video demonstrates creating an n-bit multiplier using the shift and add algorithm, converting the binary result to BCD with the double-dabble method. The process is illustrated with a flowchart and Verilog code, showcasing the multiplication of two eight-bit numbers and the conversion of the result to a 16-bit BCD. Test benches are included to verify the functionality with examples, and resources for further learning are provided in the description.

Takeaways

  • 😀 The video is a tutorial by Arjun Narula on creating an n-bit multiplier with a binary to BCD converter.
  • 📈 The project involves building an n-bit multiplier using the shift and add algorithm, with the result being in binary form.
  • 🔄 The binary result is then converted to BCD (Binary-Coded Decimal) using the double-dabble algorithm.
  • 📑 The video script provides a step-by-step explanation of converting a binary number to BCD, using the number 151 as an example.
  • 💡 A key statement for the double-dabble algorithm is provided: if the number is greater than four, add three and shift; otherwise, just shift.
  • 🛠️ The flowchart of the problem is discussed, detailing the process from reset to multiplication and BCD conversion.
  • 🔢 The script mentions a parameterized n-bit multiplier, where 'n' can be any value, with an example using n as 8 bits.
  • 📝 The Verilog code for the project is available in the video description, and the video includes a test bench for verification.
  • 🔄 The multiplication process involves shifting and adding, with specific checks for when to add three during the double-dabble algorithm.
  • 📊 The video demonstrates the simulation results for multiplying 26 by 13 and 13 by 13, showing the output in both binary and BCD.
  • 👏 The video ends with a call to like, share, and subscribe to the channel, and acknowledges the contribution of Mayank Goel in the project.
  • 📚 The video description includes book recommendations for learning Verilog, with links provided for purchase.

Q & A

  • What is the main topic of the video by Arjun Narula?

    -The main topic of the video is an n-bit multiplier project with a binary to BCD converter.

  • What is the algorithm used for multiplication in the project?

    -The project uses the shift and add algorithm for multiplication.

  • How is the binary result of the multiplication converted to BCD form?

    -The binary result is converted to BCD using the double-dabble algorithm.

  • What is the significance of the 'double-dabble' algorithm in BCD conversion?

    -The 'double-dabble' algorithm is used to adjust the BCD digits when they are greater than 4, by adding 3 and shifting the digits.

  • What is the purpose of the 'reset' variable in the flowchart?

    -The 'reset' variable is used to reset the clock and the input when set to 1, allowing for a fresh start of the multiplication process.

  • How does the 'start' variable affect the flow of the multiplication process?

    -When the 'start' variable is 0, it stores the values of a and b, sets the bits, and initializes the output to zero. If 'start' is 1, it checks the zeroth bit of b and proceeds with the multiplication process.

  • What is the maximum output size in bits for the multiplication of two eight-bit numbers?

    -The maximum output size for the multiplication of two eight-bit numbers is 16 bits.

  • How is the output of the multiplication divided for BCD conversion?

    -The output is divided into parts of three bits each, which are then processed for BCD conversion.

  • What is the role of the 'bit' variable in the multiplication process?

    -The 'bit' variable is used to keep track of the number of bits left to process in the multiplication, and it is decreased by one with each iteration.

  • How are the test inputs applied in the test bench of the Verilog code?

    -The test inputs are applied by initializing the multiplier and using a forever loop to create a clock signal, followed by the test inputs for multiplication, such as multiplying 26 and 30 in decimal.

  • What is the final step in the BCD conversion process as described in the video?

    -The final step in the BCD conversion process is to display the output in both binary and BCD form, ensuring the correct representation of the multiplication result.

Outlines

00:00

📚 Introduction to N-Bit Multiplier with Binary to BCD Conversion

Arjun Narula introduces a new wavelog project focusing on an N-bit multiplier with a binary to BCD converter. He emphasizes the importance of subscribing to the channel for more content. The project involves creating an N-bit multiplier using a shift and add algorithm, with the binary result being converted to BCD using the double-dabble method. The script explains the theoretical and practical differences in converting binary numbers to BCD, highlighting the double-dabble algorithm's process of adding three and shifting when the number is greater than four. A flowchart is mentioned as a visual guide for the process, which includes initializing variables, performing the multiplication, and converting the output to BCD.

05:03

🔍 Detailed Explanation of Verilog Code for N-Bit Multiplier

The script delves into the Verilog code for the N-bit multiplier, parameterized for an 8-bit scenario but applicable to any N-bit value. It explains the output requirements for the multiplication, which can be up to 16 bits for two 8-bit numbers. The BCD conversion process is described as tricky, involving dividing the output into parts of three, adding, multiplying, and subtracting to align with the BCD format. The script outlines the steps in the Verilog code, including initializing registers, handling the reset condition, and performing the multiplication and BCD conversion. A test bench is also discussed, with test inputs to multiply 26 by 30 and 13 by 13, demonstrating the correctness of the implementation. The video concludes with observations on the finished signal and a call to action for viewers to like, share, and comment on the video, as well as a mention of resources for learning Verilog and a thank you note to a contributor.

Mindmap

Keywords

💡Wavelog Project

A wavelog project, as mentioned in the script, refers to a specific type of educational content that involves creating and explaining digital circuits or systems. In this video, the project is an 'n-bit multiplier with binary to BCD converter,' which is a digital circuit that multiplies two binary numbers and then converts the result into Binary-Coded Decimal (BCD) format. The video script serves as a tutorial for understanding how such a project is conceptualized and implemented.

💡n-bit Multiplier

An 'n-bit multiplier' is a digital circuit that can multiply two binary numbers, each with 'n' bits. In the context of the video, it is the core component of the wavelog project, where 'n' is parameterized as 8, but it could be any number to generalize the multiplier's functionality. The script explains how this multiplier uses a shift-and-algorithm to perform the multiplication operation.

💡Binary to BCD Converter

A 'Binary to BCD Converter' is a circuit or function that translates binary numbers into their BCD equivalent. BCD is a way of representing decimal numbers in binary form, where each decimal digit is represented by a fixed number of bits. In the video, after the multiplication, the binary result is converted to BCD using a specific algorithm, which is a crucial part of the project's demonstration.

💡Shift-and Algorithm

The 'shift-and algorithm' is a method used in digital electronics for multiplication of binary numbers. It involves shifting and adding bits to perform the multiplication. In the script, this algorithm is used within the n-bit multiplier to calculate the product of two numbers, emphasizing its importance in digital computation.

💡Double-Double Method

The 'Double-Double Method' is a specific technique for converting binary numbers to BCD format. As explained in the script, it involves checking if a binary segment is greater than four and then adding three, followed by shifting. This method is used in the video to demonstrate the conversion process after the multiplication is completed.

💡Verilog

Verilog is a hardware description language used to model and design digital systems, such as the n-bit multiplier with a BCD converter discussed in the video. The script mentions Verilog code, which is the means by which the project's digital circuit is described and simulated, allowing viewers to understand the implementation details.

💡Flowchart

A 'flowchart' is a graphical representation of an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. In the video script, the flowchart is used to outline the steps involved in the multiplication and conversion process, providing a visual guide to understanding the project's logic.

💡Test Bench

A 'test bench' in digital design is a verification component used to test and stimulate a digital circuit, such as the multiplier in the video. The script describes a test bench setup where different inputs are applied to the circuit to verify its functionality and observe the results, such as multiplying 26 by 13 in decimal.

💡BCD

BCD, or Binary-Coded Decimal, is a digital encoding method used to represent decimal numbers using binary digits. In the script, the BCD format is the final output format for the multiplication result, demonstrating how binary data can be converted into a more human-readable form for certain applications.

💡Reset

In the context of the video, 'reset' refers to a control signal or function that initializes or clears the system to its starting state. The script mentions that if 'reset' is 1, the system will reset the clock and inputs, which is a common feature in digital systems to ensure a clean start for operations.

💡Start Signal

The 'start signal' in digital systems is a control mechanism that initiates a process or operation. In the video script, the start signal is used to begin the multiplication process. If the start signal is 1, the system checks the bits and performs the necessary operations, such as shifting and adding, to complete the multiplication.

Highlights

Introduction of an n-bit multiplier project with binary to BCD conversion.

Encouragement for new subscribers to the channel.

Explanation of using shift and add algorithm for multiplication.

Conversion of binary result to BCD using the double-dabble method.

Theoretical simplicity versus practical complexity in BCD conversion.

Step-by-step guide through the double-dabble algorithm.

Flowchart overview of the n-bit multiplier process.

Reset functionality and its role in the multiplier's operation.

Initialization of output and variable settings for multiplication.

Multiplication process including bit shifting and adding.

Adaptation of the double-dabble algorithm for BCD conversion in Verilog.

Parameterization of n for an n-bit multiplier, with n set to 8 for demonstration.

Division of output into parts for BCD conversion.

Register creation and continuous assignments in Verilog code.

Case statement implementation for the start condition in Verilog.

Multiplication completion check and BCD conversion process.

Test bench setup for verifying the multiplier's functionality.

Simulation results for decimal multiplication examples.

Observations on the 'finished' signal indicating completion of multiplication.

Acknowledgment of contributions and resources provided for further learning.

Closing remarks and call to action for likes, shares, and comments.

Transcripts

play00:07

hello everyone welcome back to  the channel i'm arjun narula  

play00:10

and i'm back with another wavelog project which  is n-bit multiplier with binary to bcd converter  

play00:16

so before getting started first of all i like to  point out one thing which is that 99 of you have  

play00:22

still not subscribed to the channel so if you are  new to the channel please consider subscribing it  

play00:26

motivates us to bring out more such content so now  let's get started so what we'll do is that will  

play00:33

create an n-bit multiplier of two numbers it will  multiply using shift and algorithm and finally the  

play00:39

answer which would be in binary form would be  converted to a bcd using double double method  

play00:44

in the end the output will be displayed in  both binary and bcd form so let us see how  

play00:49

can we convert a binary number to a pct form we  have a number 151 which in binary is represented  

play00:56

as this now if this number we had to convert in  bcd in theory it was a pretty easy task right  

play01:02

we would have assigned just three nibbles and  the lower nibble would have gotten the number one  

play01:08

the middle number middle bill would have gotten  the number five and the highest number would  

play01:13

have gotten the number one so this was this easy  but in reality in computers this does not happen  

play01:20

so what happens let us see so for the double  double algorithm i'll just give you a one  

play01:25

statement which will solve the entire thing for  you which is if the number is greater than four  

play01:30

you add three and shift otherwise you shift right  so now the number is zero so you simply shift here  

play01:39

we have shifted again the number is one you simply  shift again we simply shift now the number has  

play01:46

become nine so what we do is we add three we add  what do we add three zero one one now once we have  

play01:55

added we again shift again we add three now we  again shift again we add three now we again shift  

play02:04

so this way when we reach to the answer the answer  is this only what we had written in theory right  

play02:13

so now let us look at the flowchart of the problem  so first of all how we'll go is that we'll start  

play02:21

we'll say that if reset is 1 then we'll reset  the clock and the input now if reset is 0  

play02:28

then we'll start and we'll see if start is  0 we have a variable start if it's 0 then we  

play02:34

store the values of a and b set the bits and  initialize the output with zero if start is  

play02:41

one then we'll check b zero which is the zeroth  bit if it is zero then we'll simply shift right  

play02:49

so in the simple multiplication which we  saw earlier if it was 0 we simply added  

play02:54

a placeholder right so we'll simply shift  if it is 1 then we'll add the multiplier  

play03:01

again so that will be the same thing right we'll  add the multiplier right and then shift right  

play03:08

next we'll reduce uh will uh left shift by one  will reduce the bits by one and finally we'll  

play03:15

convert the output to the bcd right so now let  us get started with the verilog co here we have  

play03:22

parameterized n as 8. now what i need you to  understand is that we have made a generalized  

play03:29

n-bit multiplier and here n could be anything 8  16 32 64 128 but for the sake of understanding i  

play03:36

have here taken n as it right so now the output  of the multiplication of two eight bit numbers  

play03:43

could maximum be 16 bits right so here the  output is of 16 bits if we put n here right  

play03:50

now for the bcd output this part is a bit  tricky what we have done is we have divided  

play03:55

that output into parts of three then added one  multiplied four and eventually subtracted one  

play04:00

right that this one subtraction is because it  is from zero to that number right so if it we  

play04:06

have 16 bits it is 0 to 15 right so now what we do  is we declare the inputs we create the reference  

play04:13

registers here we have we are doing nothing just  creating the registers right standard theory  

play04:20

next we have the continuous assignments next we  have now if you remember the flowchart now we have  

play04:26

the reset now if the reset is one we reset the  clock if the reset is zero then we start right

play04:36

so now we have the case statement with start now  if start is zero what we do what we'll do is we  

play04:42

store the values in a and b we'll set the bits and  we initialize all the outputs as 0 right so now  

play04:51

if start is 1 right what we do is shift on our  multiplication so what we what we are doing is  

play04:57

that a in register is getting shifted to right  so that the next bit could be multiplied and b  

play05:03

is getting shifted to the left for the place of  the placeholders right here bits is a variable  

play05:09

which is getting decreased by one now if bit  gets to zero then the multiplication is completed  

play05:15

right and now here what we are doing is  that we are checking the values by hard code  

play05:22

that if whether we need to add three or not  right so if the number particular number is  

play05:28

between this range then we'll have to add three  or not right so this is what we are doing is  

play05:33

when we use the double double algorithm right  

play05:37

next we have the test bench what we are doing  is here we have declared the inputs and outputs  

play05:42

simply initializing the multiplier here we have  created clock using forever loop next we have  

play05:48

the test inputs so now we have two test inputs  first first one is we'll multiply 26 and 30 in  

play05:56

decimal which is written in decimal then we'll  multiply 13 and 13. now let us see the results  

play06:02

so this is the simulation which we'll be looking  at so first of all we multiply 26 with 13 right  

play06:08

so as soon as the finished signal gets high  here finished signal gets high so we get  

play06:13

the answer as 780 right now to see the 780 in  bcd what we do is so first four numbers right

play06:23

so this is actually a 16 bit bcd right so  first four number here i just cross out them  

play06:31

next four will represent 7 next 4 represent  

play06:35

8 and the last 4 represent 0 hence the answer we  have got is 780 right in the similar way 13 to  

play06:42

13 multiplication is also correct right next we  have some of the observations the out represents  

play06:49

the value of the multiplication value one when  finished signal gets to the one right here we  

play06:55

discussed it as soon as the finished signal  gets the one our multiplication is completed  

play06:59

right then we have this simple things which we  have already uh you know discussed this marks  

play07:05

the end of the video if you have reached till  here please do consider to like share the video  

play07:12

here i would also like to thank may goel who  has put an immense effort in this project  

play07:17

and has written the code in very long you  can find the verilog code in the description  

play07:21

and do write your queries in the comment  section also if you are wondering which  

play07:27

book should you buy to study verilog i  have written two books in the description  

play07:32

if you want to buy please do consider buying from  the link it really helps the channel thank you  

play07:57

foreign

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
N-bit MultiplierBinary to BCDVerilog CodeDouble DoubleShift AlgorithmWavelog ProjectTechnical TutorialComputer ConversionArjun NarulaEducational Content
¿Necesitas un resumen en inglés?