FPGA入门二 3—8译码器

3—8译码器

1.逻辑文件
module  third_eighth_class(a,b,c,out);
  input a;
  input b;
  input c;
  output reg [7:0]out;
   always @(a,b,c)begin  //当a,b,c信号变化时,always语句触发
	    case({a,b,c})    //位拼接 {}
        3'b000: out = 8'b0000_0001; 
		  3'b001: out = 8'b0000_0010;
		  3'b010: out = 8'b0000_0100;
		  3'b011: out = 8'b0000_1000;
		  3'b100: out = 8'b0001_0000;
		  3'b101: out = 8'b0010_0000;
		  3'b110: out = 8'b0100_0000;
		  3'b111: out = 8'b1000_0000;
		  endcase 
	end
endmodule
2.仿真文件
`timescale 1ns/1ns
module  third_eighth_class_tb;
    
	   reg  a,b,c;  //激励信号
	   wire [7:0] out;  //被观测信号
third_eighth_class  third_eighth_class0( //模块例化
           .a(a),
           .b(b),
           .c(c),
           .out(out)
);

     initial begin 
	  a=0;b=0;c=0;
	  #100;
	  a=0;b=0;c=1;
	  
	  #100;
	  a=0;b=1;c=0;
	  
	  #100;
	  a=0;b=1;c=1;
	  
	  #100;
	  a=1;b=0;c=0;
	  
	  #100;
	  a=1;b=0;c=1;
	  
	  #100;
	  a=1;b=1;c=0;
	  
	  #100;
	  a=1;b=1;c=1;
     #200;
	  $stop;
	  end 
endmodule
前仿真

在这里插入图片描述

后仿真

全编译后可运行门级仿真
在这里插入图片描述

计数器IP核调用

仿真文件
`timescale 1ns/1ns
`define period_clock   20
module counter_tb ; //模块名
	reg cin;//进位输入 脉冲一次计数一次
	reg clk;//基准时钟
    wire [3:0] q;//计数器计数值
	wire  cout ;//进位输出 溢满输出脉冲
counter counter0(
	.cin(cin),
	.clock(clk),
	.cout(cout),
	.q(q)
	    );
    initial clk = 1;
	 always #(`period_clock/2) clk = ~clk; 
	 initial begin   
	   repeat(20)  begin 
         cin = 0;
	   #(`period_clock*5) cin=1;
      #(`period_clock)  cin=0;
		  end 
		#(`period_clock*200);
       $stop;
	 end
endmodule

cout当4位q计数满溢出脉冲一次。
在这里插入图片描述

两个4位的计数器级联实现8位计数器

将低位计数器的cout端连接到高位计数器的cin端,cin端输入脉冲一次g计数一次。
低位计数器q[3:0] , 高位计数器q[7:4]。

module count_top(
	cin,
	clk,
	cout,
	q
       );
   input cin;//进位输入 脉冲一次计数一次
	input clk;
	output cout;//进位输出 溢满输出脉冲
	output [7:0]q;
	wire cout0;	
	//counter模块调用,复用 例化
 counter counter0(
     .cin(cin),
	  .clock(clk),
	  .cout(cout0),
	  .q(q[3:0])   //q位截取
 );
 counter counter1(
     .cin(cout0),
	  .clock(clk),
	  .cout(cout),
	  .q(q[7:4])  //q位截取
 ); 
endmodule 

综合后的原理图 RTL viewer
在这里插入图片描述

编写顶层仿真文件
module count_top(
	cin,
	clk,
	cout,
	q
       );
   input cin;//进位输入 脉冲一次计数一次
	input clk;
	output cout;//进位输出 溢满输出脉冲
	output [7:0]q;
	wire cout0;
	
	//counter模块调用,复用 例化
 counter counter0(
     .cin(cin),
	  .clock(clk),
	  .cout(cout0),
	  .q(q[3:0])   //q位截取
 );
 counter counter1(
     .cin(cout0),
	  .clock(clk),
	  .cout(cout),
	  .q(q[7:4])  //q位截取
 ); 
endmodule 

在这里插入图片描述

BCD计数器

低位计数器满9进1,高位计数器满9进1。99计满。
1001_1001

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值