|
楼主 |
发表于 2008-5-21 17:12:03
|
显示全部楼层
//*****产生系统所需的时钟信号,用状态机的方式产生了2、4分频时钟;*****//
module clk_gen(
clk,
reset,
clkn,
clk2,
clk4
);
input clk,reset;
output clkn,clk2,clk4;
wire clk,reset;
reg clk2,clk4;
reg[3:0] state;
parameter S1=4'b0001,
S2=4'b0010,
S3=4'b0100,
S4=4'b1000,
idle=4'b0000;
assign clkn=clk;
[email=always@(posedge]always@(posedge[/email] clk or negedge reset)
begin
if(!reset)
begin
clk2<=0;
clk4<=0;
state<=idle;
end
else
begin
case(state)
S1:
begin
clk2<=~clk2;
state<=S2;
end
S2:
begin
clk2<=~clk2;
clk4<=~clk4;
state<=S3;
end
S3:
begin
clk2<=~clk2;
state<=S4;
end
S4:
begin
clk2<=~clk2;
clk4<=~clk4;
state<=S1;
end
idle:
begin
state<=S1;
end
default:state<=idle;
endcase
end
end
endmodule |
|