# Need help making a counter controlled by a button

I'm trying to simulate a binary counter that is supposed to be activated by a button B, then count until 40, reset and stop until B gets pushed again. If B is pushed while the counter is working it resets and starts over.

I'm supposed to build this with simple stuff like flip flops. I already have an 8 bit counter available with a clock and Reset input entries.

I know how to read 40 off the counter (2^5+2^3, or when outputs 5 and 3 are true).

I think I need a variable B, for the button, a variable T, which is $$\lnot (C_5.C_3)$$ (C is the counter's outputs, so T will be true while the counter's output isn't 40), and R which is the value of reset. I tried to draw the state diagram:

I'm not sure which are flip flops and which are variables here or even if this is entirely correct. I think I am supposed to use a flip flop for R but I don't really know how to go about it.

• A way of many: 1. Find how to cause JK flipflops to toggle. 2. Arrange 5 flip flops so 1st clocks 2nd, 2nd clocks 3rd etc. You now have a 5 stage counter. 3. Find out what AND (or NAND) gates do. 4. Arrange an AND gate to combine FF outputs as required to make a I_AM_AT_40 signal - use this to stop the clocking. 5. Work out how to reset all flipflops and unstop the clocking. 6. Ask if unclear. Dec 30, 2019 at 7:34

A way of many.

You need a clock source. This may be provided or you MAY have to provide / generate it.

1. Find how to cause JK flipflops to toggle.

2. Arrange 5 toggling flip flops so 1st clocks 2nd, 2nd clocks 3rd etc.

You now have a 5 stage counter.

1. Find out what AND (or NAND) gates do.

2. Arrange an AND gate to combine FF outputs as required to make an I_AM_AT_40 signal - use this to stop the clocking.

3. Work out how to reset all flipflops and unstop the clocking.