当前位置:首页 > 基于DE2-115开发板的FPGA入门设计实验
基于DE2-115开发板的FPGA入门设计实验
1、Lab1: 4位加法器、减法器的设计 1.1 摘要
在文件add_sub里面的工程文件operation_4.v为顶层文件,该顶层文件包含了三个子模块,分别为数码管显示模块,4位带进位的二进制加法器模块和4位带借位的二进制减法器模块,最后通过DE2-115开发板显示实验结果。 1.2 程序
1)add_4bits.v 加法器 module adder_4bits ( );
always@(posedge clk or negedge rst_n) begin
if(!rst_n) input clk, input rst_n, input [3:0] x, input [3:0] y, output reg [3:0] sum, output reg
carry_out //溢出位
{carry_out, sum} <= 0;
else
{carry_out, sum} = x + y;
end endmodule
2)substractor_4bits.v减法器 module subtractor_4bits ( );
always@(posedge clk or negedge rst_n) begin
if(!rst_n)
{borrow_out, sub} <= 0; input clk, input rst_n,
input [3:0] x, input [3:0] y, output reg [3:0] sub, output reg
borrow_out
else begin
if(x >= y)
{borrow_out, sub} = {1'b0, x - y};
else
{borrow_out, sub} = {1'b1, x - y};
end
end endmodule
3)seg7_lut.v 数码管显示译码模块 module Seg7_lut ( );
always @(iDIG) begin
case(iDIG)
4'h1: oSEG = 7'b1111001;
// ---t----
input
[3:0] iDIG,
output reg [6:0] oSEG
4'h2: oSEG = 7'b0100100; // | | 4'h3: oSEG = 7'b0110000; // lt
rt
4'h4: oSEG = 7'b0011001; // | | 4'h5: oSEG = 7'b0010010; // ---m---- 4'h6: oSEG = 7'b0000010; // | |
4'h7: oSEG = 7'b1111000; // lb rb 4'h8: oSEG = 7'b0000000; // | | 4'h9: oSEG = 7'b0011000; // ---b---- 4'ha: oSEG = 7'b0001000; 4'hb: oSEG = 7'b0000011; 4'hc: oSEG = 7'b1000110; 4'hd: oSEG = 7'b0100001; 4'he: oSEG = 7'b0000110; 4'hf: oSEG = 7'b0001110; 4'h0: oSEG = 7'b1000000; endcase
end endmodule 1.3 结果
本设计通过Verilog HDL硬件描述语言。描述加法、减法算法,包括了进位以及借位,最终可以在实验板上观察结果,验证了算法的正确性。拨码开关SW[7:0]输入两位计算值,SW[17]为复位按键,如下图所示:
该实验结果显示的是7+b=02,进位位在LEDG[0]显示,
共分享92篇相关文档