# Mealy subtractor using JK flip-flops

I have to prepare a subtractor FSM for my laboratories (using Mealy graph, and build it with JK flip-flops). I'm in the point where I can do it using D flip-flops. So here's how it looks:

a,b - inputs

Now, using Karnaugh minimalization, I would get

$$Y=\overline{a}b+\overline{a}y+by$$

and

$$S=a \oplus b \oplus Q1$$

where Q1 is the output from first D flip-flop.

So I would plug Y to the first D flip-flop, and S to the second D flip-flop, and Q0 would be the output from the second flip-flop, and I would plug it to the bulb. And it works. Now my question is, how to convert it to JK flip-flops?

• try Googling: convert d ff to j-k ff – tcrosley Nov 7 '16 at 20:41
• I mean, I got to the point, where converting from D to JK, was like: take D input, plug it to J, and negate it and plug it to K. Thats it? – bg34ob312 Nov 7 '16 at 20:44
• I want to make sure I understand. You are subtracting b from a and if y is one you have a borrow. Is that correct? – owg60 Nov 7 '16 at 21:46

You need a third table called the excitation table to use JK flip-flops. In this case it looks like this.

In the y=0 ab=00 case, we want to remain in the 0 state. That means j has to be 0 but k can be 0 or 1. We don't care if we stay in the 0 state by doing nothing or resetting it to zero. In the y=0 ab=01 case, we want to go to the 1 state. That means j must be 1 but k can be 0 or 1. We don't care if we go to the 1 state by setting it or toggling it.

Once this table is complete, you split it into two Karnaugh maps. One provides the J minimized logic and the other the k minimized logic.

No excitation table was needed to use D flops becasue the next state table is the same as the excitation.

There is no way to know which type of flip flops will use the minimum amount of logic. Different type just have to be tried. There are methods to minimize more complated state machines however.

I did this table very fast. Don't trust this table without double checking.

• So in this case there will be only 1 FF? – bg34ob312 Nov 11 '16 at 16:19
• Yes, There is only 1 FF. You current state column tells your you need one FF because you only have 2 states. With 2 FFs you could do up to 4 states. Three 8 states and so on. To complete this for J1, you would cover up the K1 columns. You should see this is a Karnaugh map with inputs a,b, and y. This will give what you need for the J input logic. Similarly if you cover up the J1 columns, you have the K logic Karnaugh map. – owg60 Nov 11 '16 at 17:40
• Okay, so it gives me: J1=not(a)*b, and K1=a*not(b). What's the equation for the output then? – bg34ob312 Nov 11 '16 at 18:18
• When you did this for a D flop, you created a variable called Y. I would have just called it D. It gives the input to the D FF. For your D input you a'b+a'Y+bY. I would have called this a'b+a'Q+bQ. Your output S depends on a,b,and Q. When we changed to the JK we only change how we set and reset the FF. The output stayed the same. – owg60 Nov 11 '16 at 18:33
• But didn't we changed like a'b+a'Y+bY to J1=a'b, K1=ab'? Cuz now it looks like: i.gyazo.com/0026be66cd2afddaddb58ea6b19b6ae1.png – bg34ob312 Nov 11 '16 at 18:38