FPGA线上课程平台|最全栈的FPGA学习平台|FPGA工程师认证培训
登录
首页-技术文章/快讯-工程案例,技术分享-正文

FPGA实验

二牛学FPGA二牛学FPGA
工程案例, 技术分享
10个月前
0
0
325

半加器

module  half_qwer(a,b,cout,sum);//半加器设计input a,b;output cout,sum;assign sum = a^b;assign cout = aendmodule

全加器

  • 利用for循环进行级联设计 数据流
`timescale 1ns / 1psmodule qwe(a,b,cin,cout,sum);//一位input a,b,cin;output sum,cout;assign sum = a^b^cin;assign cout = (a&b)|(a&cin)|(bendmodule//四位全加器module asdfg(sum,cout,a,b,cin);input[3:0] a,b;input cin;output[3:0] sum;output cout;assign {cout,sum} = a+b+cin;endmodule================四位全加器仿真===================	initial begin		// Initialize Inputs		a = 0;b = 0;cin = 0;#100;        		// Add stimulus here		repeat(10000) #100 {a,b,cin} = {a,b,cin}+1;	end//八位全加器module qwer(a,b,cin,sum,cout);parameter SIZE	= 8;input[SIZE-1:0]a,b;input cin;output[SIZE-1:0] sum;output cout;wire[SIZE:0] c;assign c[0] = cin;generate //for循环级联8位	genvar i;	for(i=0;i<SIZE;i=i+1)		begin : add            qwe fi(a[i],b[i],c[i],sum[i],c[i+1]);//模块调用		endendgenerateassign cout = c[SIZE];endmodule

2-4译码器

module fgvh(A,Q);input[1:0] A;//两位输入output reg[3:0] Q;//四位输出always @(A)begin	case(A)	2'b00  : Q[3:0] =4'b1110;	2'b01  : Q[3:0] =4'b1101;	2'b10  : Q[3:0] =4'b1011;	2'b11  : Q[3:0] =4'b0111;	endcaseendendmodule=========================建议使用下面的方法=============================module qwe(A,Q);//2-4译码器  for循环input[1:0] A;output reg[3:0] Q;integer i;always @(A)begin	Q = 4'b1111;	for(i=0;i<=3;i=i+1)		if(A==i)			Q[i] = 0;		else			Q[i] = 1;	endendmodule============================================================//仿真激励代码initial begin		// Initialize Inputs		A = 0;		#100;		forever begin A=A+1;#100;end	end

3-8译码器

module sanba(A,Q);//3-8译码器  法一(不推荐)input[2:0] A;output reg[7:0] Q;always @(A)begin 	case(A)	3'b000:Q=8'b1111_1110;	3'b001:Q=8'b1111_1101;	3'b010:Q=8'b1111_1011;	3'b011:Q=8'b1111_0111;	3'b100:Q=8'b1110_1111;	3'b101:Q=8'b1101_1111;	3'b110:Q=8'b1011_1111;	3'b111:Q=8'b0111_1111;	endcaseendendmodule======================推荐使用下面方法==========================module qwerttgy(A,Q);//3-8译码器  for循环  方法二(推荐)input[2:0] A;output reg[7:0] Q;integer i;always @(A)begin	Q=8'b1111_1111;	for(i=0;i<=7;i=i+1)		if(A==i)			Q[i] = 0;		else			Q[i] = 1;	endendmodule

编码器

module bvhk(A,Q);input[3:0] A;output reg[1:0] Q;always@(A)	begin	case(A)	4'b0001:begin Q=2'b00;end	4'b0010:begin Q=2'b01;end	4'b0100:begin Q=2'b10;end	4'b1000:begin Q=2'b11;end	default:begin Q = 2'bx;end	endcase	endendmodule=============仿真==============		A = 1;		#100;		forever begin A=A*2;#100;end

分频器

module aerwyghz(fout,clk,res);//分频器input clk,res;output reg fout;reg[29:0] counter;always@(posedge clk)begin	if(res)begin counter<=0;fout<=0; end	else begin         if(counter==24)//50分频,10分频counter==9			begin 			counter<=0;fout<=~fout;			end			else begin			counter <=counter+1;			end	endendendmodule==================分频器仿真=======================		clk = 0;res = 1;		clk=1;#100;		res=0;		forever #10 clk = !clk;

PWM

module ryuj(clk,res,pwm,fout);input clk,res;input[3:0]pwm;output reg fout;reg[30:0] j;always@(posedge clk or negedge res)begin	if(res==0) begin j<=0;fout<=0;end	else begin 		if(j==9) begin j<=0;end			else j<=j+1;			if(j<pwm)fout<=1;			else fout<=0;			endendendmodule========================仿真========================	initial begin		// Initialize Inputs		clk = 0;pwm = 0;res = 1;res = 0;#100;		res = 1;		pwm = 8;		repeat(100) begin #100; clk = ~clk;end	end

七段数码管译码器*

`timescale 1ns / 1psmodule rtyu(bcd_out,bit_S,indec,res);input [3:0]indec;input res;output reg[3:0] bit_s;output reg[6:0]bcd_out;always@(res,indec)begin    if(!res)begin bcd_out=7'bx;bit_s=4'b1111;end	else begin		bit_s=4'b1110;		case(indec)//共阳数码管  dp、g、f、e、d、c、b、a		0:bcd_out=7'hc0;//1100_0000		1:bcd_out=7'hf9;//1111_1001		2:bcd_out=7'ha4;//1010_0100		3:bcd_out=7'hb0;//1011_0000		4:bcd_out=7'h99;//1001_1001		5:bcd_out=7'h92;//1001_0010		6:bcd_out=7'h82;//1000_0010		7:bcd_out=7'hf8;//1111_1000		8:bcd_out=7'h80;//1000_0000		9:bcd_out=7'h90;//1001_0000		endcase	endendendmodule============仿真代码================		indec = 0;		res = 1;#50;		repeat(10)begin#100 indec=indec+1;end		res=0;indec=0;		repeat(10)begin#100 indec=indec+1;end

流水灯

module jhfgx(clk,led,res);output reg[7:0]led;input clk,res;reg[29:0] counter;always@(posedge clk)begin if(res)begin counter<=0;led<=8'b0000_0001;endelse beginif(led==0) led<=8'b0000_0001;	if(counter>=25_000_00)		begin counter<=0;		led<=led<<1;		end		else counter<=counter+1;endendendmodule=====================仿真代码=====================	initial begin		// Initialize Inputs		clk = 0;res = 1;clk=1;#100;		res = 0;		forever begin #25 clk=~clk;end	end
标签:
本文原创,作者:二牛学FPGA,其版权均为FPGA线上课程平台|最全栈的FPGA学习平台|FPGA工程师认证培训所有。
如需转载,请注明出处:https://z.shaonianxue.cn/9554.html
分享:
【FPGA算法加速】FPGA编程开发环境:Vivado安装教程详细说明
【FPGA算法加速】FPGA编程开发环境:Vivado安装教程详细说明上一篇
【FPGA实验】数码管静态显示下一篇
【FPGA实验】数码管静态显示
相关文章
总数:1.27K

FPGA 仿真指南:高效调试状态机逻辑的设计与验证实践

QuickStart:快速搭建状态机仿真环境本指南旨在帮助FPGA工程师快速掌握状态机仿真调试的核心方法。以下步骤可在15分钟内完成一…
二牛学FPGA二牛学FPGA
技术分享
1个月前
0
0
61
0

FPGA入门不迷茫:从点亮第一颗LED到玩转状态机的完整实践路线

如果你是一名电子、通信或计算机专业的大学生,面对FPGA(现场可编程门阵列)时感到无从下手,这太正常了。Verilog、开发板、时序约束……一堆…
FPGA小白FPGA小白
技术分享
1个月前
0
0
137
0

Vivado 2026.1时序收敛:基于机器学习的自动路径分组方法

QuickStart打开Vivado2026.1,新建或打开一个已完成综合的设计工程。在TclConsole中运行report_t…
FPGA小白FPGA小白
技术分享
26天前
0
0
48
0

FPGA低功耗设计技巧:时钟门控与电源门控的工程实践

在FPGA设计中,功耗已成为与性能、面积同等重要的关键指标。本文聚焦于两种最核心的动态功耗管理技术——时钟门控与电源门控,提供从原理到上板验证的…
二牛学FPGA二牛学FPGA
技术分享
1个月前
0
0
72
0

FPGA 零基础入门指南:2026 年高效学习路线图

QuickStart:30分钟跑通第一个FPGA工程本指南假设你已具备数字电路基础(与门、触发器、状态机等基本概念)。以下步骤将引导你在…
二牛学FPGA二牛学FPGA
技术分享
1个月前
0
0
62
0

Verilog仿真调试进阶:利用VCS/Xcelium进行高效波形分析与断言调试

在FPGA/ASIC开发流程中,仿真调试是验证设计功能正确性、定位逻辑与时序问题的核心环节。当设计复杂度提升时,传统的“打印日志+肉眼比对波形”…
FPGA小白FPGA小白
技术分享
1个月前
0
0
89
0
评论表单游客 您好,欢迎参与讨论。
加载中…
评论列表
总数:0
FPGA线上课程平台|最全栈的FPGA学习平台|FPGA工程师认证培训
没有相关内容