Quartus Prime Hardware Experiment Development (DE2-115 Board) Experiment 1 Design of CPU Instruction Calculator

Experiment 1 Design of CPU Instruction Calculator

  • Purpose
  1. Master the use of input, synthesis, simulation and download of experimental tools such as QuartusII
  2. Master the device features and usage methods of the DE2 development version
  3. Master the main methods and techniques of Verilog HDL combinational logic system design
  4. Master and apply design methods and processes
  • Preview requirements
  1. Understand the method and process of QuartusII and other discipline distribution and download
  2. Understand the working characteristics of the input and output display resources of the development board
  3. Understand the methodology and process of board design, development and testing
  • Experimental requirements

Design a simple CPU instruction calculator, the instruction format is as follows.

Operation Type 1

Operand 1

Operation Type 2

Operand 3

Operand 4

The specific functions completed are defined as follows:

  1. Operation type 1: Treat operand 1 as an unsigned binary number, and display the equivalent value of the binary sequence in decimal in the seven-segment tube.
  2. Operation type 2: Realize the operations of addition, subtraction, and multiplication between operand 3 and operand 4, and display the operand and result in decimal/hexadecimal on the seven-segment tube. Operands 3 and 4 are 2-digit decimal numbers represented by BCD code (represented values ​​are 00-99).

Notice:

  1. In operation type 2, if a negative number appears in the subtraction logic, "-" is displayed, and a positive number may not display a sign
  2. In operation type 2, the operands and results of addition, subtraction and multiplication are displayed in decimal, which can be realized by cyclic display on the seven-segment tube.
  3. Note that operands 3 and 4 are input in BCD code, and the output processing problem of BCD code exceeding 9.
  4. Attempt to add operations implemented in a pipelined fashion. Note the number of significant digits.
  5. If you feel that the display ability of the seven-segment tube is weak, you can query the control module code of LCD1602 and use LCD display.

1. Plug the board into the computer first (black line power supply, white line computer)

2. In the start setting board, select Cyclone IV E, and then select 1.2V (ce115f29 series board) for the voltage below

3. After completing the configuration of the board, enter the main file code:

module zhiling(key,x2,x3,Hex0,Hex1,Hex2,Hex3,Hex4,Hex5,Hex6,Hex7,x);
input [7:0] x2,x3;
input key;
reg[7:0] x1;
input [1:0] x;//表示七段管的显示模式
output reg[6:0] Hex0,Hex1,Hex2,Hex3,Hex4,Hex5,Hex6,Hex7;
reg[11:0] add;
reg[7:0] sub;
reg[13:0] mul;
wire[7:0] n3,n2;
integer flag;//符号标志位
//加法变量
reg cout1,cout2;
reg [6:0] fh;
reg [3:0] low,low0,mid,mid0;
reg [3:0] a1,a2,a3,a4;//乘法各位表达
reg [3:0] t1,t2,t3;//x1的值
reg [3:0] s1,s2;
assign n2=x2[7:4]*10+x2[3:0];
assign n3=x3[7:4]*10+x3[3:0];
always@(*)
begin
   if(key==1)
	begin
   x1=x2;	
   t1=x1%4'b1010;
	t2=x1/4'b1010%4'b1010;
	t3=x1/4'b1010/4'b1010;
	end
end
//加法,二级流水线方式
always@(*)
begin
{cout1,low0}=x2[3:0]+x3[3:0];
if(cout1==1) begin low=low0+4'b0110; end
else if(low0>9&&cout1==0) begin {cout1,low}=low0+4'b0110;end
else begin low=low0;cout1=0;end
end

always@(*)
begin
{cout2,mid0}=x2[7:4]+x3[7:4]+cout1;
if(cout2==1) begin mid=mid0+4'b0110; end
else if(mid0>9&&cout2==0) begin {cout2,mid}=mid0+4'b0110;end
else begin mid=mid0;cout2=0;end
add={cout2,mid,low};
end
//减法
always@(*)
begin
flag=0;
if(n2>=n3) sub=n2-n3;
else begin flag=1;sub=n3-n2;end
fh=(flag==1)?7'b0111111:7'b1111111;
   s1=sub%4'b1010;  
	s2=sub/4'b1010;
end
//乘法
always@(*)
begin
   mul=n2*n3;
   a1=mul%4'b1010;  
	a2=mul/4'b1010%4'b1010;
	a3=mul/4'b1010/4'b1010%4'b1010;
	a4=mul/4'b1010/4'b1010/4'b1010;
end

always@(x)
begin
case(x)
2'b00:begin {Hex2,Hex1,Hex0}={show(t3),show(t2),show(t1)};Hex3=7'b1111111;Hex4=7'b1111111;Hex5=7'b1111111;Hex6=7'b1111111;Hex7=7'b1111111;end
2'b01:begin {Hex7,Hex6}={show(x2[7:4]),show(x2[3:0])};{Hex5,Hex4}={show(x3[7:4]),show(x3[3:0])};
				{Hex2,Hex1,Hex0}={show(add[11:8]),show(add[7:4]),show(add[3:0])};Hex3=7'b1111111;  end
2'b10:begin {Hex7,Hex6}={show(x2[7:4]),show(x2[3:0])};{Hex5,Hex4}={show(x3[7:4]),show(x3[3:0])};
				{Hex2,Hex1,Hex0}={fh,show(s2),show(s1)};Hex3=7'b1111111;  end
2'b11:begin {Hex7,Hex6}={show(x2[7:4]),show(x2[3:0])};{Hex5,Hex4}={show(x3[7:4]),show(x3[3:0])};
				{Hex3,Hex2,Hex1,Hex0}={show(a4),show(a3),show(a2),show(a1)};  end
endcase
end

function [6:0]show;
   input[3:0] a0;
	reg[6:0] b;
	begin
	case(a0)
  4'd0:b=7'b1000000;
  4'd1:b=7'b1111001;
  4'd2:b=7'b0100100;
  4'd3:b=7'b0110000;
  4'd4:b=7'b0011001;
  4'd5:b=7'b0010010;
  4'd6:b=7'b0000010;
  4'd7:b=7'b1111000;  
  4'd8:b=7'b0000000;
  4'd9:b=7'b0011000; 
default:b=7'b1111111;
	endcase 
	show=b;
	end
	endfunction
endmodule

4. Click import assignment

5. Import the pin assignment, the data set download link of experiment 1:

fpga hardware experiment one CPU instruction calculator design pin configuration - data set document resource - CSDN download

6. Then open the Pin Planner to see if the pins are connected properly 

7. The interface defined by the first module corresponds to the pin assignment file. After importing the pin assignment file, check the pin connections in the pin planner. If there is a blank line, it means that the pin file is wrong and needs to be modified and imported again. ( It has been tested, if you use the above link to import the pins, it can run normally, this step can be omitted )

8. If you modify the pin assignment file, you need to remove the original imported pin file, remove assignments. Re-opening the pin planer will see that the connections are clear and all lines have become colorless. ( It has been tested, if you use the above link to import the pins, it can run normally, this step can be omitted )

 9. After importing the pin assignment table correctly, there is no error. Re-synthesize the entire project

10. After the synthesis is completed, there is no error. Connect the development board, turn on the power, and prepare to download.

In the programmer window, there may be no hardware displayed in the box, there is no hardware. Click the hardware setup function. The hardware setup window pops up to add hardware.

11. If there is no USB driver, you need to manually update the driver

Right-click the "My Computer" icon and select "Manage"

12. Select "manual search", enter the Quartus prime installation directory file, and find "USB"

13. You can choose one of the two "USB" (when the time comes, choose one of the sockets on the hardware 115 board and plug it in)

14. After the installation is complete, you can

15. After completing the driver update, click the Programmer window again and click the hardware setup function. Pop up the hardware setup window, add hardware

16. After the configuration is complete, click Start directly

Then start the hardware test, the first experiment is the CPU instruction calculator, the operation of addition, subtraction and multiplication

multiplication:

addition:

Subtraction:

Guess you like

Origin blog.csdn.net/yyfloveqcw/article/details/124362063