Electrical – Design 5 bit counter with two control inputs (direction and stop)

counterdigital-logicflipflop

I am designing a 5-bit counter with two control inputs including direction (up/down) D and stop S.

Here is how counter works:

DS = 00: down (or decrease)

DS = 01: don't care

DS = 10: stop

DS = 11: up (increase)

I tried this as the reference here by using 5 D flip flops and logic gates.

However, the result requires a lot of logic gates.

There are some questions I am not clear now.

  1. For this problem, is there a way to know what kind of flip flops (SR, JK, D,…) will use the smallest number of logic gates?
  2. I referred the method to solve this problem by drawing state diagram and then implementing it as the reference above.

However, because the large number of bits (5 bits), the implementation is complex and mistake-prone.

Is there a better way to design instead the way above?

Also, are there any simpler counter that can do the task above?

Best Answer

The simplest way would be to use an integrated chip that does the whole up/down counting. There are some specialized for this, for example the 74HC191.

If you use this specific chip, the input are a bit different than what you need: you have the \$\overline{CTEN}\$ pin which can serve as a STOP input (if it is 1, the count is inhibited), and the \$D/\overline{U}\$ input, which of course works the other way around from what you require. So if you can't change the specs of your D and S inputs, you need a bit of logic to adapt it to this chip. An inverter gate from your D input could provide \$D/\overline{U}\$, and if you do a XOR between your D and S inputs, you obtain \$\overline{CTEN}\$. Note: you can implement the inverter with a XOR gate, as well, if you hardwire a 1 to one of its input. So you can have a single chip that does the two operations.

Now, the chip I mentioned is only a 4-bit counter. But you can chain them. Just use two such chips and connect the \$\overline{CTEN}\$ input of the second counter to the \$\overline{RCO}\$ output of the first, and tie the clocks of both chips together, and the D/U pin of both chips together (see figure 2 of the datasheet). Now, you even have an 8-bit counter !

In short, you can implement this with three chips.

... Of course, using a small microcontroller for all that would actually be cheaper and more effective. And this would also certainly allow you to simplify other parts of the whole circuit...