Trying to build a Moore FSM that displays sequence of numbers depends on the input

Thread Starter

raziell122

Joined Mar 28, 2023
62
Hello everyone!
I need to plan and build in Logisim Evolution a Moore FSM that displays on a 7-segment display the sequence: '3','1','6','2','5','7','4','1','9','.' (one by one) + the decimal point at the end.
If the system input X=0, then the sequence will be displayed one by one from left to right (including the decimal point).
If the system input X=1, then the sequence will be displayed one by one from right to left (including the decimal point).
I am allowed to use D-FFs + logic gates, and can't use a binary counter or another logic components.

What did I try?
I defined 9 states for the digits, each state represents the binary combination of a digit.
3 = 0011, 1 = 0001, 6 = 0110, and so on.. where Q3=MSB and Q0=LSB.
1708534012310.png
The 10th state that I defined is 1010 for the decimal point, and I want to turn it on by using an AND gate between Q3 & Q1 once the system arrives to the state 1010.

I built a states diagram + states table:
1708534064120.png


1708534103596.png

Then I created a 5-vars Karnaugh map for each input of the FFs and found the logic functions.
For example:
1708534209361.png

Then I built the final circuit in Logisim-Evolution, but the system doesn't work, for now the 7-segment display shows me just "0" without doing anything.
**I used a 7-segment to BCD component to transfer the output combination Q3Q2Q1Q0 for the 7-segment in each clock cycle!

If anyone sees any problem or mistake in my calculations please help me to figure it out!
Thank you in advance for any help!!
 

dl324

Joined Mar 30, 2015
16,935
display the sequence: '3','1','6','2','5','7','4','1','9','.' (one by one) + the decimal point at the end.
Were you given this sequence, or did you make it up? I don't see how you're going to be able to have 1 sometimes transition to 6 and 9 at other times without a lot of glue logic.

Why did you make the truth table the way you did? It would be easier to read if you just made a 5 variable table.
 

Thread Starter

raziell122

Joined Mar 28, 2023
62
Were you given this sequence, or did you make it up? I don't see how you're going to be able to have 1 sometimes transition to 6 and 9 at other times without a lot of glue logic.

Why did you make the truth table the way you did? It would be easier to read if you just made a 5 variable table.
Hello Dennis, my lecturer gave me this sequence.
What do you mean by "
Were you given this sequence, or did you make it up? I don't see how you're going to be able to have 1 sometimes transition to 6 and 9 at other times without a lot of glue logic.

Why did you make the truth table the way you did? It would be easier to read if you just made a 5 variable table.
Hello Dennis,
my lecturer gave me this sequence. What do you mean by "glue logic"?

About the table, do you mean the present state & next state table? That's the form that I know from my former course in college, but you are right, I should make it with 5 vars where X is LSB.
 

WBahn

Joined Mar 31, 2012
30,072
Hello everyone!
I need to plan and build in Logisim Evolution a Moore FSM that displays on a 7-segment display the sequence: '3','1','6','2','5','7','4','1','9','.' (one by one) + the decimal point at the end.
If the system input X=0, then the sequence will be displayed one by one from left to right (including the decimal point).
If the system input X=1, then the sequence will be displayed one by one from right to left (including the decimal point).
I am allowed to use D-FFs + logic gates, and can't use a binary counter or another logic components.

What did I try?
I defined 9 states for the digits, each state represents the binary combination of a digit.
3 = 0011, 1 = 0001, 6 = 0110, and so on.. where Q3=MSB and Q0=LSB.
View attachment 315824
The 10th state that I defined is 1010 for the decimal point, and I want to turn it on by using an AND gate between Q3 & Q1 once the system arrives to the state 1010.

I built a states diagram + states table:
View attachment 315825


View attachment 315826

Then I created a 5-vars Karnaugh map for each input of the FFs and found the logic functions.
For example:
View attachment 315827

Then I built the final circuit in Logisim-Evolution, but the system doesn't work, for now the 7-segment display shows me just "0" without doing anything.
**I used a 7-segment to BCD component to transfer the output combination Q3Q2Q1Q0 for the 7-segment in each clock cycle!

If anyone sees any problem or mistake in my calculations please help me to figure it out!
Thank you in advance for any help!!
You seem to be racing through a bunch of regurgitated steps without stopping to consider whether what you did in a particular state makes sense.

You chose to represent each state using the binary encoding for the value you want displayed on the 7-segment display. Not a bad thought, but is it viable?

If your machine is in state 0001, is it in State B or State H?

If you can't tell, then the machine can't since that is the ONLY information it has regarding what state it is in.

An FSM requires that each possible state have a unique encoding.

Another red flag is that your list of all states has ten that are used and seven that aren't. That's a total of seventeen states! You can only represent sixteen unique states with four flip flops.

If you don't develop of habit of looking for, and catching, mistakes like this shortly after you make them, you are doomed to go down rabbit holes wasting a bunch of time producing solutions that are guaranteed to not work.
 

WBahn

Joined Mar 31, 2012
30,072
Were you given this sequence, or did you make it up? I don't see how you're going to be able to have 1 sometimes transition to 6 and 9 at other times without a lot of glue logic.

Why did you make the truth table the way you did? It would be easier to read if you just made a 5 variable table.
This is a pretty typical assignment at this level in a logic design course. Part of the purpose is to have the student deal with a spec that is somewhat more complicated than it appears at first, precisely because many students will just blindly go down a rabit hold instead of thinking about the problem they are trying to solve.

While adding a 5th DFF is an option -- and a pretty straightforward one unless part of the expectation is dealing with unused states in a reasonable manner -- there is really no need for it. With a bit of thought, the glue logic needed to use a 4-bit machine is very tame, especially compared to the next-state logic that is already needed. In fact, there's a tradeoff between choosing a set of states that strikes a balance in total random logic associated with the next-state and the output decoding, though that is almost certainly beyond the scope of where the student is in this course at this point.
 

Thread Starter

raziell122

Joined Mar 28, 2023
62
You seem to be racing through a bunch of regurgitated steps without stopping to consider whether what you did in a particular state makes sense.

You chose to represent each state using the binary encoding for the value you want displayed on the 7-segment display. Not a bad thought, but is it viable?

If your machine is in state 0001, is it in State B or State H?

If you can't tell, then the machine can't since that is the ONLY information it has regarding what state it is in.

An FSM requires that each possible state have a unique encoding.

Another red flag is that your list of all states has ten that are used and seven that aren't. That's a total of seventeen states! You can only represent sixteen unique states with four flip flops.

If you don't develop of habit of looking for, and catching, mistakes like this shortly after you make them, you are doomed to go down rabbit holes wasting a bunch of time producing solutions that are guaranteed to not work.
Thank you for your reply!
Yes, you are right. Unfortunately, I find the logic design field pretty difficult. I find it interesting and it's a field that I would like to improve, but its still not easy.
About the assignment, if I define one of the states B/H with another binary combination, will it solve the problem? (of course I will have 16 states! didn't even pay attention to that 17)
Can you give me please an idea how can I turn another binary combination into the number "0001" so that it will still display the right digit on the seven segment?
 

WBahn

Joined Mar 31, 2012
30,072
Can you give me please an idea how can I turn another binary combination into the number "0001" so that it will still display the right digit on the seven segment?
This is where that additional glue logic is needed (glue logic is just a generic term referring to random logic needed to connect one part of a logic circuit to another -- it 'glues' the two portions together).

Look at your unused states. Is there one of them that is close to the duplicated state? If so, and if you use that for one of those duplicates, can you create a circuit that takes the four actual state outputs and produces the needed outputs (i.e., maps both of the states that are duplicates onto the same output, without affecting the other used states)? In this case, there is a pretty obvious candidate that results in you only having to do a bit of glue logic for just one of the four state outputs. That may or may not turn out to be the "best" choice, but it's a start and puts an upper limit on the added complexity.
 

dl324

Joined Mar 30, 2015
16,935
Can you give me please an idea how can I turn another binary combination into the number "0001" so that it will still display the right digit on the seven segment?
Choose one of the unused counts. If you give it some thought, you can minimize the amount of glue logic needed to turn segments off.

It wasn't as difficult as I thought it would be.

What do you intend to do with segments a-g when you turn on the decimal point?

Using D flip flops made the steering logic a bit cumbersome. I made a couple mistakes. If that happens to you, post the count problem and I can teach you how to troubleshoot the problem(s).
 

dl324

Joined Mar 30, 2015
16,935
Then I created a 5-vars Karnaugh map for each input of the FFs and found the logic functions.
For example:
1708534209361.png
I don't know when the World started doing things backwards. When I was in school, the most significant bits would have been on the left and the lesser significant bits across the top. That let you read the binary value without having to mentally swap bits.

I checked the Wikipedia article on Karnaugh maps and it was "backwards" too; using A for the MSB instead of LSB.

At any rate, your groupings aren't optimal. Why did you draw the red grouping that way? Why do you use N/A instead of the more traditional X for don't care? I didn't have any don't cares because you always have to drive the D input with the output you desire.

You show 7 terms, but your equation only has 6.
kmapGroupings.jpg
When I solved your problem, I didn't have any groupings larger than 2.
1708627901999.png

In the method I was taught, A is always the LSB (2^0) regardless of how many variables there are in the truth table. What they teach now seems to be that A is always the MSB and it's value changes depending on how many variables there are. This seems backwards to me. Even the AAC tutorial uses this backwards method.

By ordering things the way I was taught, reading left to right you can easily read the binary value directly. For example, the pinkish box is 00110 = 6. Using your method, you'd read 110 and prepend that to 00 to get 11000. That just seems like more work to me.
 
Last edited:

Thread Starter

raziell122

Joined Mar 28, 2023
62
I don't know when the World started doing things backwards. When I was in school, the most significant bits would have been on the left and the lesser significant bits across the top. That let you read the binary value without having to mentally swap bits.

I checked the Wikipedia article on Karnaugh maps and it was "backwards" too; using A for the MSB instead of LSB.

At any rate, your groupings aren't optimal. Why did you draw the red grouping that way? Why do you use N/A instead of the more traditional X for don't care? I didn't have any don't cares because you always have to drive the D input with the output you desire.

You show 7 terms, but your equation only has 6.
View attachment 315892
When I solved your problem, I didn't have any groupings larger than 2.
View attachment 315898

In the method I was taught, A is always the LSB (2^0) regardless of how many variables there are in the truth table. What they teach now seems to be that A is always the MSB and it's value changes depending on how many variables there are. This seems backwards to me. Even the AAC tutorial uses this backwards method.

By ordering things the way I was taught, reading left to right you can easily read the binary value directly. For example, the pinkish box is 00110 = 6. Using your method, you'd read 110 and prepend that to 00 to get 11000. That just seems like more work to me.
Hello Dennis,
thanks for your reply!
About the N/A, my lecturer explained us about N/As and Don't cares X but I did not really understand the difference between them. I just know that someone in class asked him if we can use the N/A states in K-map to minimize the function and he said yes. If you know the main difference between N/A & Don't cares, I would love to understand it from you!
About the Red & Cyan groupings, you are right! I should have made them fours.
About the green grouping, I have added the two left N/As later and I forgot to fix it.
Also, I see that you did not use any N/As, can you explain why?
 

WBahn

Joined Mar 31, 2012
30,072
About the N/A, my lecturer explained us about N/As and Don't cares X but I did not really understand the difference between them. I just know that someone in class asked him if we can use the N/A states in K-map to minimize the function and he said yes. If you know the main difference between N/A & Don't cares, I would love to understand it from you!
I've never heard of an N/A condition that is somehow distinct from a Don't Care, so you might ask your lecturer to explain the difference and then come back and explain it here. Then between us we can figure out what the deal is and perhaps all learn something.

Since N/A usually stands for either Not Available or Not Applicable, it would seem like it doesn't apply to a cell in a K-map, since that represents an output, which is always either a 0 or 1 (i,e., it's always available and the notion of it not being applicable doesn't make much sense, either), but saying that we don't care whether it's a 0 or a 1 makes complete sense. Using N/A in a state transition table, on the other hand, makes more sense, although "Don't Care" makes perfect sense there, too.

One thing to be aware of, which some courses mention but many do not, is that after ignoring Don't Care conditions when optimizing your logic, you should always go back and consider the behavior of your logic circuit for the choices you've imposed for those cases. You have to allow for the possibility that your circuit could, somehow, end up in any one of those states, be it because of random power-up or a glitch or a cosmic ray upsetting a FF, or whatever. Does the circuit behave in an acceptable fashion in each case? Part of this involves establishing what "acceptable" means for that application.
 

dl324

Joined Mar 30, 2015
16,935
I see that you did not use any N/As, can you explain why?
I've never heard of N/A.

It seems that I made a mistake for D flip flop transitions in my spreadsheet. I was forcing don't cares to be 0. I changed the kmap for the LSB and see that I was giving up some simplifications.

I'll change the spreadsheet and redo the kmaps.
 

dl324

Joined Mar 30, 2015
16,935
This is what I got for the LSB after correcting my transitions:
1708709839354.png
I normally put the largest groupings first in my equations, but I noticed that the 4th term (light blue) could be further simplified while I was writing the equation. Otherwise, it would have been DBA'.

Here are the first 4 rows of my truth table:
1708710187916.png

EDIT: Note that I use A for LSB.
 
Last edited:

Thread Starter

raziell122

Joined Mar 28, 2023
62
@raziell122 How are you getting along with your problem?

If you're still having problems, ask questions. I can teach you how to do this type of problem.

When is the assignment due?
Hey friend!
Thanks for your interest and your willingness to help!
I have already done the assignment, it works with some "glue logic"!
 

dl324

Joined Mar 30, 2015
16,935
I have already done the assignment, it works with some "glue logic"!
Glad you got it done.

Those types of problems can be a bit tedious, but they're not really very hard. I do them for fun.

It was good to see that you can solve 5 variable Kmaps. Most break it into 2 4x4's which I find awkward to simplify. I draw the line at 6 variables. I might do 7 (using 2 6 variable maps) if I really needed to.

This is my solution:
1708968883066.png
Working on your problem uncovered an error in the spreadsheet I used. I went back and checked all of the other problems using D flip flops and that was the only one that had that error. It was a mistake I made years ago. I should have suspected something when it was labeled old-D4+1.
 
Last edited:
Top