Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

counter

$
0
0
I am currently using de1 board and Altera quartus II software. as a beginner to digital design, I am learning by going through the Altera lab exercise. I am stacked on trying to design a 4bit t ff based counter. my code counts up to7 without problem but it won't go further I was intending to count from 0 to 15 by instantiating my t ff 4 times as shown in the code below. Will you pleas help identifying my error?

module counter_4bit(q, En, Clk, Clr, );
input En, Clk, Clr;
output [0:4] q;

wire [0:2] temp;

tflipflop T0(q[0], En, Clk, Clr);
tflipflop T1 (q[1], q[0], Clk, Clr);
and(temp[0], q[1], q[0]);
tflipflop T2 (q[2], temp[0], Clk, Clr);
and(temp[1], q2, q1, q0);
tflipflop T3 (q[3], temp[1], Clk, Clr);



endmodule

module tflipflop(Q, t, Clk, Clr);
input t, Clk, Clr;
output reg Q;
initial Q = 0;
always @(posedge Clk)
if(Clr)
Q = 0;
else
Q = Q ^ t;
endmodule

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>