Electronic – Why can’t I implement a frequency divider using a mux in this way

counterfpgamux

I found an interesting interview question for FPGA engineer online – Implement a counter with Mux, so I decided to try to do that. I tried to keep it simple and so implement a counter with two bits, so it can count only to 3 and then reset.

I came to a conclusion I need 3 multiplexers, two for each bit, and the other one to serve as a frequency divider for the clock (I'm sure there are other ideas, would love to hear them as well).
Note that I wanted this frequency divider to work at the falling edge of the clock.

Basically this is what I tried to do:

schematic

simulate this circuit – Schematic created using CircuitLab

I used a clock of 1Hz just so it won't be too fast (though maybe it doesn't matter?), With mux1 being the frequency divider.

The idea here is that the counter is like this:

Q1 Q0
0  0
0  1
1  0
1  1

So, since Q0 changes with every clock edge, I connected the clock to mux3. Since Q1 toggles every two clocks, I tried to design a frequency divider which will make sure that Q1 will toggle every two clock (clk1) falling edges.

I thought it would work well, but in a simulation (used Multisim for that, because I don't know how to simulate it work circuitlab, would love if you could show me how I can do that), I got a very strange result – the simulation just stopped. Here is how it looked (the output of mux1):

Output of mux1

When I zoomed in at the falling edge (at 500ms) it looked like this:

output of mux1 zoomed in

So my questions are:

  1. Why doesn't my frequency divider work?
  2. Is this implementation of a counter even good, if that frequency divider worked? Is this even possible?

Best Answer

Think about what each part of your circuit does.

MUX3

All this is doing is saying if CLK1 is high, then output 1. If CLK1 is low, output 0. What is the purpose of this mux? Simply MUX3 = CLK1

MUX2

Again, if MUX1 is high, output 0, if MUX1 is low, output 1. So basically MUX2 = !MUX1

MUX1

What for example happens when CLK1 is low? It selects In0 of MUX1. In0 is simply the inverse of the output of MUX1.

So in other words MUX1 = !MUX1 - you've made an oscillator that will toggle at whatever the propagation delay of the not gate is. Uncontrolled inverter loops like this are almost never a good idea.

What happens if CLK1 is high? Well, you get MUX1 = MUX1, so basically the output will hold whatever state it had previously.


I think the theory of the interview question lies in the fact that a 2-input MUX is functionally complete - you can use multiple muxes to make any logic gate.

One of those is that a mux can be configured as an AND gate with one input inverted by simply tying the IN1 pin to GND. You can then simply use two of these to create an S-R latch.

Once you have an S-R latch it is very easy to build registers, and then counters.

Related Topic