yfeng
Newbie level 4
hi,everyone,
I want to design a frequence divider, the dividing ratio is 2000; It has a clk input and three same clock outputes, when i use modelsim-Altera simulation,problems come, there are only one clock output,others are zeros;however,when i use three always structure ,the output is all ok;I don't know why?
Following is my verilog codes:
This is my previous codes:
module ft(
inclk1,
clkout3,
clkout4,
clkout5
);
input wire inclk1;
output clkout3;
output clkout4;
output clkout5;
parameter N=2000;
parameter bitlongth=15;
reg clkout3=0;
reg clkout4=0;
reg clkout5=0;
reg[bitlongth:0] counter=16'b0;
always @(inclk1)
begin
if(counter==(2*N-1))
begin
counter<=0;
end
else
counter<=counter+1;
end
always @(counter)
begin
if(counter<=1)
begin
clkout3<=0;
clkout4<=0;
clkout5<=0;
end
else if(counter==2) begin
clkout3<=1;
clkout4<=1;
clkout5<=1;
end else
clkout3<=0;
clkout4<=0;
clkout5<=0;
end
endmodule
This is later codes,which has three "always" structures:
module ft(
inclk1,
clkout3,
clkout4,
clkout5
);
input wire inclk1;
output clkout3;
output clkout4;
output clkout5;
parameter N=2000;
parameter bitlongth=15;
reg clkout3=0;
reg clkout4=0;
reg clkout5=0;
reg[bitlongth:0] counter=16'b0;
always @(inclk1)
begin
if(counter==(2*N-1))
begin
counter<=0;
end
else
counter<=counter+1;
end
always @(counter)
begin
if(counter<=1)
begin
clkout3<=0;
// clkout4<=0;
// clkout5<=0;
end
else if(counter==2) begin
clkout3<=1;
// clkout4<=1;
// clkout5<=1;
end else
clkout3<=0;
// clkout4<=0;
// clkout5<=0;
end
always @(counter)
begin
if(counter<=1)
begin
// clkout3<=0;
clkout4<=0;
// clkout5<=0;
end
else if(counter==2) begin
// clkout3<=1;
clkout4<=1;
// clkout5<=1;
end else
// clkout3<=0;
clkout4<=0;
// clkout5<=0;
end
always @(counter)
begin
if(counter<=1)
begin
//clkout3<=0;
//clkout4<=0;
clkout5<=0;
end
else if(counter==2) begin
// clkout3<=1;
// clkout4<=1;
clkout5<=1;
end else
// clkout3<=0;
// clkout4<=0;
clkout5<=0;
end
endmodule
TestBench:
`timescale 1 ns/ 1 ns
module ft_vlg_tst();
reg inclk1;
// wires
wire clkout3;
wire clkout4;
wire clkout5;
// assign statements (if any)
ft i1 (
// port map - connection between master ports and signals/registers
.clkout3(clkout3),
.clkout4(clkout4),
.clkout5(clkout5),
.inclk1(inclk1)
);
initial
begin
inclk1=0;
end
always #250 inclk1=~inclk1;
always
begin
#3500000 $stop;
end
endmodule
I want to design a frequence divider, the dividing ratio is 2000; It has a clk input and three same clock outputes, when i use modelsim-Altera simulation,problems come, there are only one clock output,others are zeros;however,when i use three always structure ,the output is all ok;I don't know why?
Following is my verilog codes:
This is my previous codes:
module ft(
inclk1,
clkout3,
clkout4,
clkout5
);
input wire inclk1;
output clkout3;
output clkout4;
output clkout5;
parameter N=2000;
parameter bitlongth=15;
reg clkout3=0;
reg clkout4=0;
reg clkout5=0;
reg[bitlongth:0] counter=16'b0;
always @(inclk1)
begin
if(counter==(2*N-1))
begin
counter<=0;
end
else
counter<=counter+1;
end
always @(counter)
begin
if(counter<=1)
begin
clkout3<=0;
clkout4<=0;
clkout5<=0;
end
else if(counter==2) begin
clkout3<=1;
clkout4<=1;
clkout5<=1;
end else
clkout3<=0;
clkout4<=0;
clkout5<=0;
end
endmodule
This is later codes,which has three "always" structures:
module ft(
inclk1,
clkout3,
clkout4,
clkout5
);
input wire inclk1;
output clkout3;
output clkout4;
output clkout5;
parameter N=2000;
parameter bitlongth=15;
reg clkout3=0;
reg clkout4=0;
reg clkout5=0;
reg[bitlongth:0] counter=16'b0;
always @(inclk1)
begin
if(counter==(2*N-1))
begin
counter<=0;
end
else
counter<=counter+1;
end
always @(counter)
begin
if(counter<=1)
begin
clkout3<=0;
// clkout4<=0;
// clkout5<=0;
end
else if(counter==2) begin
clkout3<=1;
// clkout4<=1;
// clkout5<=1;
end else
clkout3<=0;
// clkout4<=0;
// clkout5<=0;
end
always @(counter)
begin
if(counter<=1)
begin
// clkout3<=0;
clkout4<=0;
// clkout5<=0;
end
else if(counter==2) begin
// clkout3<=1;
clkout4<=1;
// clkout5<=1;
end else
// clkout3<=0;
clkout4<=0;
// clkout5<=0;
end
always @(counter)
begin
if(counter<=1)
begin
//clkout3<=0;
//clkout4<=0;
clkout5<=0;
end
else if(counter==2) begin
// clkout3<=1;
// clkout4<=1;
clkout5<=1;
end else
// clkout3<=0;
// clkout4<=0;
clkout5<=0;
end
endmodule
TestBench:
`timescale 1 ns/ 1 ns
module ft_vlg_tst();
reg inclk1;
// wires
wire clkout3;
wire clkout4;
wire clkout5;
// assign statements (if any)
ft i1 (
// port map - connection between master ports and signals/registers
.clkout3(clkout3),
.clkout4(clkout4),
.clkout5(clkout5),
.inclk1(inclk1)
);
initial
begin
inclk1=0;
end
always #250 inclk1=~inclk1;
always
begin
#3500000 $stop;
end
endmodule