# When to use mealy machine and when to use moore machine.

#### sanskarsb

Joined Oct 30, 2022
7
.I am trying to design a round robin arbiter but stuck at the question whether to do it with mealy or moore model. Please tell when to use the models and in this arbiter which model to use and why

#### WBahn

Joined Mar 31, 2012
29,469
A Moore machine's outputs are only a function of state, while a Mealy machine's output is not only a function of state, but also a function of the current inputs.

If your logic is such that knowing the state is all that is needed to know what the outputs should be, then use a Moore machine. If, however, the output should also depend on what the current inputs are, then use a Mealy machine.

Don't make it harder than it is.

#### sanskarsb

Joined Oct 30, 2022
7
A Moore machine's outputs are only a function of state, while a Mealy machine's output is not only a function of state, but also a function of the current inputs.

If your logic is such that knowing the state is all that is needed to know what the outputs should be, then use a Moore machine. If, however, the output should also depend on what the current inputs are, then use a Mealy machine.

Don't make it harder than it is.
I am a bit confused in the round robin scheduling part. Which model should I use here for this kind of arbiter.

#### WBahn

Joined Mar 31, 2012
29,469
Since I have no idea what the logic specification is that you are trying to design to, there is no way for me to even think of offering an opinion. You talk as though "round robin scheduling part" is some universal thing that everyone is expected to know exactly what it is you are trying to do.

#### sanskarsb

Joined Oct 30, 2022
7
Since I have no idea what the logic specification is that you are trying to design to, there is no way for me to even think of offering an opinion. You talk as though "round robin scheduling part" is some universal thing that everyone is expected to know exactly what it is you are trying to do.
I am trying to design an arbiter which follows the round robin algorithm or scheduling. In the model it has three request inputs and 3 grant outputs.
If more than one requests occurs at the same time the priority is 1>2>3.
Round robin scheduling means equal time slices are assigned to each process in a circular fashion. Like if process 1 is finished the grant will be given to 2nd process and the first process will be at the last of the queue.

#### WBahn

Joined Mar 31, 2012
29,469
So what does each state of your machine represent?

What does each input represent?

What does each output represent?

When can your machine change state?

Does it make sense for your outputs to change in between state changes?

#### sanskarsb

Joined Oct 30, 2022
7
So what does each state of your machine represent?

What does each input represent?

What does each output represent?

When can your machine change state?

Does it make sense for your outputs to change in between state changes?
From your first question, i had one more doubt. So in the moore or mealy model, what does state mean exactly. Is it same as the output of the combinational block? So i am not sure about the answer to the first question.

Each input represents the requests. So if only process one is requesting the input will be 100 and if all three are requesting the input will be 111.

Each output represents the grant signal. If process one has to be given the grant, output should be 100. Only one process can be given grant at a time. So only three possible outputs 100, 101 and 001.
The machine changes state in every clock cycle. This is because the process are given a fixed interaval of time. Suppose all three process are requesting. So as per the priority first process will be given the grant. In the second clock cycle the second process will be given the grant irrespective of the fact that first one is completed or not.
If the first process is not completed it has to wait in the queue. That is after third.process it will be given the grant.

#### Papabravo

Joined Feb 24, 2006
20,578
The way to organize this problem is probably not unique. If we want to try to see if a machine with four states would work, we could try the following encoding.

1 - Task 1 is running
2 - Task 2 is running
3 - Task 4 is running

Does this help?

#### sanskarsb

Joined Oct 30, 2022
7
The way to organize this problem is probably not unique. If we want to try to see if a machine with four states would work, we could try the following encoding.

1 - Task 1 is running
2 - Task 2 is running
3 - Task 4 is running

Does this help?
Yeah i have understood this, i tried drawing the state diagram too. So should I proceed with mealy machine?

#### Papabravo

Joined Feb 24, 2006
20,578
Yeah i have understood this, i tried drawing the state diagram too. So should I proceed with mealy machine?
I was suggesting a Moore machine might be possible since the GRANT outputs correspond to transitions from one of the four states to another one of the four states. So, the GRANT signals can be synthesized from the two state bits. The reason you might need a Mealy machine is if any state has two or more transitions into it with different input conditions and different output values. That means, how you get to a state allows for two or more output values.

#### sanskarsb

Joined Oct 30, 2022
7
I was suggesting a Moore machine might be possible since the GRANT outputs correspond to transitions from one of the four states to another one of the four states. So, the GRANT signals can be synthesized from the two state bits. The reason you might need a Mealy machine is if any state has two or more transitions into it with different input conditions and different output values. That means, how you get to a state allows for two or more output values.
Thank you !!

#### sanskarsb

Joined Oct 30, 2022
7
Can
I was suggesting a Moore machine might be possible since the GRANT outputs correspond to transitions from one of the four states to another one of the four states. So, the GRANT signals can be synthesized from the two state bits. The reason you might need a Mealy machine is if any state has two or more transitions into it with different input conditions and different output values. That means, how you get to a state allows for two or more output values.
Can you please elaborate when to use which machine. And what is the difference between a state and output of the model. Are they different?

#### WBahn

Joined Mar 31, 2012
29,469
From your first question, i had one more doubt. So in the moore or mealy model, what does state mean exactly. Is it same as the output of the combinational block? So i am not sure about the answer to the first question.

Each input represents the requests. So if only process one is requesting the input will be 100 and if all three are requesting the input will be 111.

Each output represents the grant signal. If process one has to be given the grant, output should be 100. Only one process can be given grant at a time. So only three possible outputs 100, 101 and 001.
The machine changes state in every clock cycle. This is because the process are given a fixed interaval of time. Suppose all three process are requesting. So as per the priority first process will be given the grant. In the second clock cycle the second process will be given the grant irrespective of the fact that first one is completed or not.
If the first process is not completed it has to wait in the queue. That is after third.process it will be given the grant.
The "state" is the value of all of the registers in the system. It is NOT the combinatorial logic output.

The state of the machine generally captures all of the important information that has occurred in the history of the machine.

You skipped over the key question related to whether you want to use a Mealy or a Moore machine. If an input changes partway through a clock cycle, do you want/need any of the outputs to change?

Your description, "Suppose all three process are requesting. So as per the priority first process will be given the grant. In the second clock cycle the second process will be given the grant irrespective of the fact that first one is completed or not," has a hidden assumption about the history of the machine, namely that this is what is happening immediately after startup. Otherwise you have a contradiction. You first say that if all three processes are requesting that the first process will be given the grant. Well, if that's true, then in the second clock cycle if all three processes are requesting, the first process will be given the grant. Clearly, just knowing which processes are requesting and their priority is not sufficient to determine who gets the grant; the history of who has requested previously and who has been granted previous plays a role. THAT is the information that the state has to capture.

So what you need to ask is not what happens on the first or second clock cycle, but what happens on the 1,745th clock cycle when all three are requesting. What information do you need to know about what has happened before in order to make the decision about who gets control and what information do you now need to remember for the 1,746th clock cycle to be able to make the next decision?

xox