|

楼主 |
发表于 2010-4-23 13:56:24
|
显示全部楼层
占空比1:1,输入8'b00000000,输出持续低电平,输入8 'b00000001为1分频,依次8'b00000010为2分频,依次。。。
module clk_fenp(
clk_in,
clk_out,
switch_8bit_in
//test
//,clk_q1,clk_q2,count,count_clk
);
input clk_in;
input[7:0] switch_8bit_in;
output clk_out;
//,clk_q1,clk_q2;
reg[7:0] count_clk;
reg clk_q1,clk_q2;
//output[7:0] count,count_clk;
wire[7:0] count;
wire estop,switch_0,switch_1;
assign switch_0=switch_8bit_in==8'b00000000 ? 1'b1 : 1'b0;
assign switch_1=switch_8bit_in==8'b00000001 ? 1'b1 : 1'b0;
assign estop=switch_0 || switch_1;
assign count=switch_8bit_in[0] ? (switch_8bit_in-1)/2+1 : switch_8bit_in/2+1;
assign clk_out=switch_1 ? clk_in :
switch_8bit_in[0] ? (clk_q1 || clk_q2) : clk_q1;
always @(posedge estop or posedge clk_in)
if(estop)
begin
count_clk<=0;
clk_q1<=0;
end
else
if(count_clk<count-1)
begin
count_clk<=count_clk+1;
clk_q1<=1;
end
else
if(count_clk<switch_8bit_in-1)
begin
count_clk<=count_clk+1;
clk_q1<=0;
end
else
begin
count_clk<=0;
clk_q1<=0;
end
always @(posedge estop or negedge clk_in)
if(estop)
clk_q2<=0;
else
clk_q2<=clk_q1;
endmodule
VETLOG程序如上,,哪个朋友用VHDL改下下,,我才入门,,下星期就必须交差 |
|