电力电子转战数字IC20220521day5——半整数分频

3.5分频的解题思路:用上升沿和下降沿做两个7分频然后逻辑或

自己写出来的跑出来总是没有结果,暂时是没有结果,。

module threed5fd(clk,rst,clk3);
//3.5分频,用两个沿做两个7分频(奇数)后,逻辑或得到3.5分频。
input clk;
input rst;
output clk3;
reg [2:0] count1;
reg [2:0] count2;
reg clk1,clk2,clk3r;
assign clk3=clk3r;

always @(posedge clk or negedge rst)
	if(!rst)
		 count1<=3'd0;  
		else if(count1==3'd0 || count1==3'd1)
			begin clk1<=!clk1; count1<=count1+3'd1; end
				else if(count1==3'd6)
				count1<=3'd0; 
					else count1<=count1+3'd1;
			
always @(negedge clk or negedge rst)
	if(!rst)
		 count2<=3'd0; 
		else if(count2==3'd3 || count2==3'd4)
			begin clk2<=!clk2; count2<=count2+3'd1; end
				else if(count2==3'd6)
				count2<=3'd0;	
				else count2<=count2+3'd1;
				
always clk3r=clk1 ||clk2;

endmodule

最后还是用文章中的代码尝试出来了,三个clk都是wire型,新的条件语句assign wire= 语句1?是则执行:否则执行;

//module threed5fd(clk,rst,clk3);
//input clk;
//input rst;
//output clk3;
//reg [2:0] count1;
//reg [2:0] count2;
//reg clk1,clk2,clk3r;
//assign clk3=clk3r;
//
//always @(posedge clk or negedge rst)
//	if(!rst)
//		 count1<=3'd0;  
//		else if(count1==3'd0 || count1==3'd1)
//			begin clk1<=!clk1; count1<=count1+3'd1; end
//				else if(count1==3'd6)
//				count1<=3'd0; 
//					else count1<=count1+3'd1;
//			
//always @(negedge clk or negedge rst)
//	if(!rst)
//		 count2<=3'd0; 
//		else if(count2==3'd3 || count2==3'd4)
//			begin clk2<=!clk2; count2<=count2+3'd1; end
//				else if(count2==3'd6)
//				count2<=3'd0;	
//				else count2<=count2+3'd1;
//				
//always clk3r=clk1 ||clk2;

endmodule

tb

`timescale 1ps/1ps

module threed5fdtest;
reg clk,rst;
wire clk3;

threed5fd t1(.clk(clk), .rst(rst), .clk3(clk3));

always #5 clk=~clk;

always
	begin
	clk=0;rst=1;
	#10 rst=0;
	#15 rst=1;
	#90 rst=0;
	#110 rst=1;
	#200 $stop;
	end

endmodule

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值