Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

4-bit up/down counter fault

Not open for further replies.


Newbie level 2
Dec 6, 2010
Reaction score
Trophy points
Activity points
Hi everyone,
I am writing a block code via the gate level model for a 4-bit up/down synchronous counter.

The counter should be able to count up to a certain number (which is not larger than 15) predefined by a 4-bit input, and to count down from a certain number as well.

I used TFF in my design, in which I define D[3:0] as the counting bound, as mentioned above, eg D = 1010. A flag Up denotes up or down counting.

Using the Karnaugh map, I obtained these:

Clear[] = ~up + (Q[0]^D[0]) + (Q[1]^D[1]) + (Q[2]^D[2]) + (Q[3]^D[3]);
Preset = up + ~D + Q[0] + Q[1] + Q[2] + Q[3];

To illustrate, when I put up = 1 to count up to D = 4'b1010, if Q = 1010 we have clear[] = 0 while preset still gets 1; so the next Q = 0000.
Similarly, when I want to count down from D = 0111, whenever Q reach 0000, it will be set to 0111 because Clear = 1111 and Preset = 1000.

When I implement the code to Quartus, using functional simulation, it give good result for many cases.

But in several cases, eg, counting up to D = 0111, it just counts from 0 to 3 instead.

I remain stuck with this problem and I dunno where is the mistake.
Hope to receive your replies. Thank you.

Not open for further replies.

Part and Inventory Search

Welcome to