G
G
Guest
If you simulate independently "cnt_15.v", it begins counting AT the
same rising clock edge as when you assert "ce"(counter enable).
If you simulate independently "div_16M.v", it generates a "0" one clock
cycle after the last count value(1111) or at the beginning of a new
count(0000) and then resumes its high state until 1111.
Why is it when I use the "div_16M.v" module to supply the "ce" signal
for the counter module("cnt_15.v") and simulate these two modules at
the top level, does the counter begin counting one cycle after "ce" is
asserted high again? This screws up my timing at the
transition(Eventually, this will be a simple two digit LCD hex
counter...). Thanks for any help...
BTW, This is pre-fit, behavioral simulation using ModelSim...For
reference:
// Module: cnt_10.v
// This module counts from 0 to 15 and then rolls over.
module cnt_10(ce,clk,clr,tc,qout);
input ce;
input clk;
input clr;
output tc;
output [3:0] qout;
reg [3:0] count = 0; //Current count value
always @(posedge clk or posedge clr)
begin
if (clr) //asynchronous RESET active High
count <= 4'b0;
else
if (ce)
if (count==4'hF)
count <= 4'h0;
else
count <= count + 1;
else
count <= count;
end
assign qout = count;
assign tc = (count==4'hF); //Terminal count flag
endmodule
// module: div_16M.v
// This module divides the incoming 30 MHz clock by 2^24 and generates
a
// terminal count pulse of one clock width during the counter rollover.
module div_16M(clk,tc_1s);
input clk;
output tc_1s;
//output count;
reg [3:0] count = 0; //Current count value
reg tc_1s;
always @ (posedge clk)
begin
count <= count + 1;
tc_1s <= ~&count;
end
endmodule
// module: test.v
// This is the top level module that ties all sub-modules together
module test(clk,reset,tc_ones,ones_en,cnt_1s);
input clk;
input reset;
output tc_ones;
output ones_en;
output [3:0] cnt_1s;
wire nreset;
wire ones_en;
wire tens_en;
wire tc_ones;
div_16M DIV_16M(
..clk(clk),
..tc_1s(ones_en)
);
cnt_10 ONES(
..ce(ones_en),
..clk(clk),
..clr(nreset),
..tc(tc_ones),
..qout(cnt_1s)
);
assign nreset = ~reset;
endmodule
same rising clock edge as when you assert "ce"(counter enable).
If you simulate independently "div_16M.v", it generates a "0" one clock
cycle after the last count value(1111) or at the beginning of a new
count(0000) and then resumes its high state until 1111.
Why is it when I use the "div_16M.v" module to supply the "ce" signal
for the counter module("cnt_15.v") and simulate these two modules at
the top level, does the counter begin counting one cycle after "ce" is
asserted high again? This screws up my timing at the
transition(Eventually, this will be a simple two digit LCD hex
counter...). Thanks for any help...
BTW, This is pre-fit, behavioral simulation using ModelSim...For
reference:
// Module: cnt_10.v
// This module counts from 0 to 15 and then rolls over.
module cnt_10(ce,clk,clr,tc,qout);
input ce;
input clk;
input clr;
output tc;
output [3:0] qout;
reg [3:0] count = 0; //Current count value
always @(posedge clk or posedge clr)
begin
if (clr) //asynchronous RESET active High
count <= 4'b0;
else
if (ce)
if (count==4'hF)
count <= 4'h0;
else
count <= count + 1;
else
count <= count;
end
assign qout = count;
assign tc = (count==4'hF); //Terminal count flag
endmodule
// module: div_16M.v
// This module divides the incoming 30 MHz clock by 2^24 and generates
a
// terminal count pulse of one clock width during the counter rollover.
module div_16M(clk,tc_1s);
input clk;
output tc_1s;
//output count;
reg [3:0] count = 0; //Current count value
reg tc_1s;
always @ (posedge clk)
begin
count <= count + 1;
tc_1s <= ~&count;
end
endmodule
// module: test.v
// This is the top level module that ties all sub-modules together
module test(clk,reset,tc_ones,ones_en,cnt_1s);
input clk;
input reset;
output tc_ones;
output ones_en;
output [3:0] cnt_1s;
wire nreset;
wire ones_en;
wire tens_en;
wire tc_ones;
div_16M DIV_16M(
..clk(clk),
..tc_1s(ones_en)
);
cnt_10 ONES(
..ce(ones_en),
..clk(clk),
..clr(nreset),
..tc(tc_ones),
..qout(cnt_1s)
);
assign nreset = ~reset;
endmodule