《VerilogHDL47分频代码.doc》由会员分享,可在线阅读,更多相关《VerilogHDL47分频代码.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、VerilogHDL47分频代码四分频module quarter_clk(reset,clk_in,clk_out); input clk_in,reset;output clk_out;reg clk_out;reg 4:0count;always(posedge clk_in)beginif(!reset) clk_out=0;else if (count1)begincount=count+1;endelsebegincount=0;clk_out=clk_out;endendendmodule仿真define clk_cycle 50module test_quarter_clk;r
2、eg clk,reset;wire clk_out;alwaysclk_cycle clk=clk;initialbegin clk=0;reset=1;100 reset=0;100 reset=1;#10000 $stop;endquarter_clk quarter_clk1(reset,clk,clk_out);endmodule7分频module div7(rst,clk,cout1,cout2,cout); input clk,rst; output cout1,cout2,cout; reg 2:0 m,n;wire cout; reg cout1,cout2; assign c
3、out=cout1|cout2;always (posedge clk)begin if(rst) begin cout1=0;m=0;endelse if(!rst) begin if(m=6) begin m=0;endelse m=m+1; if(m=2) cout1=cout1; else if(m=5) cout1=cout1; end end always (negedge clk)begin if(rst) begin cout2=0;n=0;end else if(!rst) begin if(n=6) begin n=0;end else n=n+1; if(n=2) cout2=cout2; else if(n=5)cout2=cout2; end end Endmodule仿真timescale 1ns / 1psdefine clk_cycle 50module qii;reg clk,rst;wire cout1,cout2,cout;alwaysclk_cycle clk=clk;initialbegin clk=0;rst=1;200 rst=0;#10000 $stop;enddiv7 div71(rst,clk,cout1,cout2,cout); endmodule