State Machine problem Help.

Thread Starter

alejandrodj

Joined Sep 10, 2012
13
hey guys. i was given a homework and i was wondering if you can help me get started. im not good at this and i need help.

the problem is. there are 4 LED, and i have to come up with a table that describe them lighting in sequence. transition table, exitation table. and ultimately an equation that performs this using JK flip flops.

state 0 = 0 0 0 0
state 1 = 1 0 0 0
state 2 = 1 1 0 0
state 3 = 1 1 1 0
state 4 = 1 1 1 1
state 5 = 0 1 1 1
state 6 = 0 0 1 1
state 7 = 0 0 0 1
state 8 = 0 0 0 0

the rules are. two inputs. the first input controls the direction.(0 backward, 1 forward)
the second input controls the freeze. (0 not hold, 1 hold)

3 state bits
4 output bits.

I cant even start because dont i need 3 inputs? instead of just two?
how can i start?
 

Attachments

Thread Starter

alejandrodj

Joined Sep 10, 2012
13
If i have to use JK flip flops i start by building a truth table:

J K Q
0 0 (nc)
0 1 0 (reset)
1 0 1 (set)
1 1 (toggle)

=

J K Q Q(next)
0 0 0 0
0 0 1 1
0 1 0 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 0

if im correct so far. what would be the next step?
 

WBahn

Joined Mar 31, 2012
29,979
the rules are. two inputs. the first input controls the direction.(0 backward, 1 forward)
the second input controls the freeze. (0 not hold, 1 hold)

3 state bits
4 output bits.

I cant even start because dont i need 3 inputs? instead of just two?
how can i start?
Why do you think you need 3 inputs? What do you think the three inputs need to be?
 

WBahn

Joined Mar 31, 2012
29,979
If i have to use JK flip flops i start by building a truth table:

J K Q
0 0 (nc)
0 1 0 (reset)
1 0 1 (set)
1 1 (toggle)

=

J K Q Q(next)
0 0 0 0
0 0 1 1
0 1 0 0
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 0

if im correct so far. what would be the next step?
You are correct in that this is the truth table for a JK flip flop, but that is not the best place to start for designing your circuit -- this comes much later.

The problem statement actually tells you what order to do things in:

1) a table that describe them lighting in sequence
2) a transition table
3) an exitation table
4) an equation that performs this using JK flip flops

You've got part of the first steo already done. You have a table that describes them lighting in sequence under a particular set of input conditions. What are the input conditions that must exist for the table you provided in your first post to hold? Also, in that table, what is true about 'state 8' in relation to 'state 0'?

What does the sequence look like for the other possible input conditions? How many possible input conditions are there? Can you describe, in words, what each one means?
 

Thread Starter

alejandrodj

Joined Sep 10, 2012
13
You are correct in that this is the truth table for a JK flip flop, but that is not the best place to start for designing your circuit -- this comes much later.

The problem statement actually tells you what order to do things in:

1) a table that describe them lighting in sequence
2) a transition table
3) an exitation table
4) an equation that performs this using JK flip flops

You've got part of the first steo already done. You have a table that describes them lighting in sequence under a particular set of input conditions. What are the input conditions that must exist for the table you provided in your first post to hold? Also, in that table, what is true about 'state 8' in relation to 'state 0'?

What does the sequence look like for the other possible input conditions? How many possible input conditions are there? Can you describe, in words, what each one means?
well. that's where it gets confusing. I can see a relation between state 0 and state 8; all LED are turned off. and the other states also have a relation only they are reversed. when you say the input conditions you mean JK? or inputs Q , Q+1, Q+2? building the table is what i cant seem to grasp. starting with the fact that i have to do it with only two inputs.
 

WBahn

Joined Mar 31, 2012
29,979
Okay, 'state 8' IS 'state' 0'. What they are trying to get across is that you have a system that runs forward through the sequence of states labeled 'state 0' through 'state 7' and then repeats.

So let's take things in small pieces. Design a machine that just does the above. No inputs at all. At every clock it advances to the next state in the sequence.

Once you have that working, add an input that, when LO, has no affect on the prior behavior but, when HI, halts the machine wherever it is. If it is in 'state 3', then it stays in 'state 3'.

Once you have that working, add a second input that, when LO, has no affect on the prior behavior but, when HI, makes the machine run the other direction. If it is in 'state 3', then it goes to 'state 2' instead of 'state 4'. But, if the first switch is HI, it still stays in 'state 3'.

At that point, you are done.

So, to begin with, work the problem as if you have no inputs and just want to make a machine that cycles forward through the eight states.
 

Thread Starter

alejandrodj

Joined Sep 10, 2012
13
ok so putting together a table that makes the LEDs in a sequence.

Q0Q1Q2Q3|Q0 Q1 Q2 Q3(next)
0 0 0 0 | 1 0 0 0
1 0 0 0 | 1 1 0 0
1 1 0 0 | 1 1 1 0
1 1 1 0 | 1 1 1 1
1 1 1 1 | 0 1 1 1
0 1 1 1 | 0 0 1 1
0 0 1 1 | 0 0 0 1
0 0 0 1 | 0 0 0 0

this would be 4 outputs displaying the sequence needed.
 

WBahn

Joined Mar 31, 2012
29,979
You have most of the right idea, but you don't want to work with the outputs, you want to work with the states. This is because the outputs are a function of the state and state only, while what your machine is controlling is which state to transition to next.

If you have eight states, how many bits do you need to encode those eight states? Now make a table just like the last one, only using the state encodings instead of the output values.
 

Thread Starter

alejandrodj

Joined Sep 10, 2012
13
this is where it gets tricky for me. if i understood you well then my table would look like this

to encode 8 states i would need 3 bits then:

current state | next state
A B I | A B O
0 0 0 | 0 0 1
0 0 1 | 0 1 0
0 1 0 | 0 1 1
0 1 1 | 1 0 0
1 0 0 | 1 0 1
1 0 1 | 1 1 0
1 1 0 | 1 1 1
1 1 1 | 0 0 0
 

WBahn

Joined Mar 31, 2012
29,979
Exactly (although I don't know why you have ABI as the column headings on the left and ABO as the column headings on the right).

Now, you have three bits of state information, so you need three flip flops (one for each bit). You can choose whichever type of flip flop you want for each bit -- they don't even have to be the same. For simplicity, the D flip flop has a lot of attractiveness for many situations. But it appears you are expected to use JK flip flops, which is just fine.

What you need to realize at this point is that your table is actually three separate tables, one for each bit. So work with them as separate tables, one for each bit. If you are going to use a JK flip flop, then each bit actually represents two tables, one for that bit's J input and one for that bits K input. So you really end up with six tables, each with three inputs and one output.

I recommend making a table that looks something like the following:

A|B|C||A'|J|K||B'|J|K||C'|J|K
0|0|0||0|?|?||0|?|?||1|?|?
0|0|1||0|?|?||1|?|?||0|?|?
.|.|.||
0|0|0||0|?|?||0|?|?||1|?|?
1|1|1||0|?|?||0|?|?||0|?|?

As a look to the near future, once you get this table done, you will simply add two more inputs (so five total, three from the present state and two from the fwd/rev and run/hold inputs) and end up with a table that is four times as long, but not any wider (beyond a column for each additional input). But, by then, we'll see that there is going to be a real simple trick for implenting the run/hold logic, especially since we are using JK flip flops.

For now, just get the above table fleshed out.
 
Top