赞
踩
实验要求:
(一)实验目的
(1)掌握组合逻辑电路和时序电路的 FPGA实现方法;
(2)熟悉EDA开发板和开发软件的使用方法;
(3)学习静态数码管的使用和7段数码显示译码器设计;
(4)掌握时钟在时序电路中的作用;
(5)掌握分频电路的实现方法。
(二)实验要求
设计BCD计数器,可任选模的大小(最大模值至少3位),实验要求:
(1)计数结果用3位数码管显示,显示BCD码;
(2)给出此项设计的仿真波形;
(3)选择实验电路验证此计数器的功能。
(4)设计模值可变的输入端口,通过输入模值和设置信号改变计数器模值
(5)设置涉及1个开关和一个按键,开关作为使能控制,按键作为异步清0。(6)带有进位输出,并进位输出用LED灯显示
波形仿真应能观察到复位、使能、模值进位输出、设置模值。
在实验室用开发板下载测试,下载测试现象与仿真相吻合。
按键能复位,使能无效时计数暂停,能切换模值。
为缩短仿真时间,仿真和下载测试时对50MHz系统时钟的分频系数可不同。
使用vivado软件
可实现0-1024任意模
代码如下
- //源文件
- module CNT(
- input CLK, // 时钟输入
- input SW1, // 开关输入,用于计数器使能控制
- input KEY1, // 按键输入,用于计数器异步清零
- input [9:0] M_SET, // 模数设置输入
-
- output reg [9:0] cnt_count,
- output reg [10:0] display_segout,
- output reg LED_OUT //输出,用于显示进位状态
- );
- reg [6:0] BCD_OUT0; // BCD计数结果输出
- reg [6:0] BCD_OUT1; // BCD计数结果输出
- reg [6:0] BCD_OUT2; // BCD计数结果输出
-
- wire [9:0] M; // 计数器模数
- wire [3:0] bw;
- wire [3:0] sw;
- wire [3:0] gw;
-
- assign M[0]=M_SET[0];
- assign M[1]=M_SET[1];
- assign M[2]=M_SET[2];
- assign M[3]=M_SET[3];
- assign M[4]=M_SET[4];
- assign M[5]=M_SET[5];
- assign M[6]=M_SET[6];
- assign M[7]=M_SET[7];
- assign M[8]=M_SET[8];
- assign M[9]=M_SET[9];
-
- reg [19:0]count=0;
- reg [30:0]count2=0;
- reg [2:0] sel=0;
- parameter T1MS=50000;
- //多位数码管显示
- always@(posedge CLK)
- begin
- count<=count+1;
- if(count==T1MS)
- begin
- count<=0;
- sel<=sel+1;
- if(sel==3)
- sel<=0;
- end
- end
- 仿真
- //wire clk1;
- //assign clk1=CLK;
- //板子计数频率
- reg clk1;
- always @(posedge CLK)
- begin count2=count2+1;
- if(count2/10000000%2==1) begin clk1=1'b1; count2=0;end
- else clk1=1'b0;
- end
- 板子数码管显示
- always@(posedge CLK)
- begin
- case(sel)
- 0:display_segout<={4'b0111,BCD_OUT0};
- 1:display_segout<={4'b1011,BCD_OUT1};
- 2:display_segout<={4'b1101,BCD_OUT2};
- default:display_segout<=11'b1111_1111111;
- endcase
- end
- //计数器逻辑
- always @(negedge clk1 or posedge KEY1)
- begin
- if(KEY1 == 1'b0) // 异步清零
- cnt_count <= 10'd0;
- else if(SW1 == 1'b1) // 使能控制
- begin
- if(cnt_count<M)
- begin
- cnt_count<=cnt_count+10'd1;
- LED_OUT<=1'b0;
- end
- else
- begin
- cnt_count<=10'd0;
- LED_OUT<=1'b1;
- end
- end
- end
-
- assign bw =cnt_count/100;
- assign sw =cnt_count%100/10;
- assign gw =cnt_count%10;
-
- always @(posedge clk1 or negedge KEY1)
- begin
- if(!KEY1)
- begin
- BCD_OUT0<=7'b0000001;
- BCD_OUT1<=7'b0000001;
- BCD_OUT2<=7'b0000001;
- end
- else
- begin
- case (gw)
- 0:BCD_OUT0<=7'b0000001; 1:BCD_OUT0<=7'b1001111;
- 2:BCD_OUT0<=7'b0010010; 3:BCD_OUT0<=7'b0000110;
- 4:BCD_OUT0<=7'b1001100; 5:BCD_OUT0<=7'b0100100;
- 6:BCD_OUT0<=7'b0100000; 7:BCD_OUT0<=7'b0001111;
- 8:BCD_OUT0<=7'b0000000; 9:BCD_OUT0<=7'b0000100;
- default: BCD_OUT0<=7'b0000001;
- endcase
- case (sw)
- 0:BCD_OUT1<=7'b0000001; 1:BCD_OUT1<=7'b1001111;
- 2:BCD_OUT1<=7'b0010010; 3:BCD_OUT1<=7'b0000110;
- 4:BCD_OUT1<=7'b1001100; 5:BCD_OUT1<=7'b0100100;
- 6:BCD_OUT1<=7'b0100000; 7:BCD_OUT1<=7'b0001111;
- 8:BCD_OUT1<=7'b0000000; 9:BCD_OUT1<=7'b0000100;
- default: BCD_OUT1<=7'b0000001;
- endcase
- case (bw)
- 0:BCD_OUT2<=7'b0000001; 1:BCD_OUT2<=7'b1001111;
- 2:BCD_OUT2<=7'b0010010; 3:BCD_OUT2<=7'b0000110;
- 4:BCD_OUT2<=7'b1001100; 5:BCD_OUT2<=7'b0100100;
- 6:BCD_OUT2<=7'b0100000; 7:BCD_OUT2<=7'b0001111;
- 8:BCD_OUT2<=7'b0000000; 9:BCD_OUT2<=7'b0000100;
- default : BCD_OUT2<=7'b0000001;
- endcase
- end
- end
-
- endmodule
- //仿真文件
- `timescale 1ns / 1ps
- //
- // Company:
- // Engineer:
- //
- // Create Date: 2023/03/16 21:54:56
- // Design Name:
- // Module Name: sim_CNT
- // Project Name:
- // Target Devices:
- // Tool Versions:
- // Description:
- //
- // Dependencies:
- //
- // Revision:
- // Revision 0.01 - File Created
- // Additional Comments:
- //
- //
- `timescale 1ns/1ps
-
- module sim_CNT();
- reg SW1,KEY1;
- reg [9:0]M_SET;
- wire [9:0] cnt_count;
- wire [10:0] display_segout;
- wire LED_OUT;
-
- reg clk1;
-
- initial
- begin
- clk1= 1'b0;
- SW1 = 1'b0;
- #2 KEY1 = 1'b1;
- M_SET =10'b0000001111;
- #2 KEY1 = 1'b0;
- #2 KEY1 = 1'b1; SW1 = 1'b1; //计数使能信号有效,且不复位
- end
- always
- begin
- #10 clk1 = ~clk1;
- end
- CNT uu1(clk1,SW1,KEY1,M_SET,cnt_count,display_segout,LED_OUT);
-
- endmodule
前任栽树,后人乘凉,希望你们不要简单的cv喔大家有什么问题可以私聊我哦。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。