文档详情

基于DE2-115开发板的FPGA入门设计实验.doc

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