# 4-bit synchronous counter which is counting upwards from 3 to 12?

#### dl324

Joined Mar 30, 2015
13,534
so U7 got all 3 input to high when counter switching 7 to 8.
Synchronous counter designs don't use preset or clear.

Go back and check your notes. You either start with a state diagram or a truth table.

#### Papabravo

Joined Feb 24, 2006
17,297
I'll give you two hints which may help you, at the risk of getting banned
First: The counter must operate in two modes which are:
1. Count, that is "increment the count by 1" on the next clock edge
2. Load, that is "do a parallel load" operation of the data on the D input. The thing you are primarily interested in "loading" is the value 3 or 0b0011 which is a constant.
Second: When the counter reaches 12 (0b1100) you need to switch from Count to Load before the next clock edge and once the Load has taken place you must switch back to Count before the subsequent clock edge

That says nothing about how you accomplish the ultimate goal but is does give you a 10,000 foot overview.
If you want extra credit on this assignment, do somethin sensible if the counter gets into an illegal state. What is an illegal state? Glad you asked. Any of the following states are illegal:
0, 1, 2, 13, 14,15 and there are ten legal states which are all the rest.

#### Sedus

Joined Mar 25, 2021
31
I assume I need this table to build gates. Is this correct?

#### Papabravo

Joined Feb 24, 2006
17,297
Yes that is a pretty good start, but I see a mistake on line 12. The next state after 12 should be 3 or 0b0011
You could also replace the X's in the next state columns with 3' or 0b0011 and that would map all illegal states to the desired starting state on the next clock pulse.
Since you are using JK flip-flops, there are particular values of J & K that will load a constant value into the output. That is what you want to use to load the starting value of 3 or 0b0011.
Also it does not seem reasonable that there are x's in any of the JK columns. They each need to be set to do one of the following:
1. Clear to "0"
2. Set to "1"
3. Toggle
4. Hold

#### Sedus

Joined Mar 25, 2021
31
According to my notes
1. Clear to "0" is 01
2. Set to "1" is 10
3. Toggle is 11
4. Hold is 00
So if I have 0 and I want 0 I can hold and I can clear to 0 too, this is why 0X, or is it nonsense?

#### dl324

Joined Mar 30, 2015
13,534
I assume I need this table to build gates. Is this correct?
It would be helpful if you posted the complete text for the problem. In your original post, you were using T flip flops; now you're using JK.

Is that the way you were taught to build a truth table? I was taught to use gray code to facilitate transferring the data to Kmaps. That requires you to be able to read binary numbers, but that isn't difficult.

Kudos to you for minimizing cell width and centering data. It makes it much easier to read.

I'm glad to see that you're using A as the LSB. Too many are teaching students to use A as the MSB as you showed in your first schematic.

#### Papabravo

Joined Feb 24, 2006
17,297
According to my notes
1. Clear to "0" is 01
2. Set to "1" is 10
3. Toggle is 11
4. Hold is 00
So if I have 0 and I want 0 I can hold and I can clear to 0 too, this is why 0X, or is it nonsense?
I see what you are saying and I've always been more comfortable with knowing that on each clock edge there was only one possible thing that was going to happen. Implemented in discrete parts there may be some advantage to the use of don't cares, but they make me nervous. I don't know why. It's probably a personality defect. When it comes to problem solving there are three steps:
1. First, make it work
2. Second, make it smaller, faster, whatever
3. Last, make it elegant.
I don't know if this approach is universal but it has always worked well for me. Your mileage may vary. I'm here to help, not throw stones.

#### Sedus

Joined Mar 25, 2021
31
I see what you are saying and I've always been more comfortable with knowing that on each clock edge there was only one possible thing that was going to happen. Implemented in discrete parts there may be some advantage to the use of don't cares, but they make me nervous. I don't know why. It's probably a personality defect. When it comes to problem solving there are three steps:
1. First, make it work
2. Second, make it smaller, faster, whatever
3. Last, make it elegant.
I don't know if this approach is universal but it has always worked well for me. Your mileage may vary. I'm here to help, not throw stones.
Summed up, 0X is good but you more comfortable with the other method?

#### Papabravo

Joined Feb 24, 2006
17,297
Summed up, 0X is good but you more comfortable with the other method?
Yes, until I get it working. Then all possible optimizations are on the table. The more straightforward and unambiguous a design is the easier it is to debug if (when) things go wrong. After you get it working it is easy to make small changes and look for potential side effects. If the implementation is in an FPGA with logic gate resources to burn then I wouldn't even bother with optimization. It would be a waste of time if 90% of the gates in the FPGA are unused.

#### dl324

Joined Mar 30, 2015
13,534
So if I have 0 and I want 0 I can hold and I can clear to 0 too, this is why 0X, or is it nonsense?
Your table is correct except for when the count is 12.

#### Sedus

Joined Mar 25, 2021
31

Im not sure 0,1,2 would be 3 or XXXX?

#### dl324

Joined Mar 30, 2015
13,534
Im not sure 0,1,2 would be 3 or XXXX?
Did your instructions give any requirements for the number of clocks required to count out of an illegal state?

#### Sedus

Joined Mar 25, 2021
31
No.

#### Sedus

Joined Mar 25, 2021
31
but I guess 1 will be the best

#### dl324

Joined Mar 30, 2015
13,534
Then treating the invalid counts as don't cares could simplify the logic.

#### Sedus

Joined Mar 25, 2021
31
XXXX is a dont cares?

#### dl324

Joined Mar 30, 2015
13,534

#### Sedus

Joined Mar 25, 2021
31
but if I can use dont cares for 0,1,2, why I must use 3 at 12,13,14,15?

#### dl324

Joined Mar 30, 2015
13,534
why I must use 3 at 12,13,14,15?
You don't need to for 13-15, but the reason for 12 should be obvious.