Now, let us design our finite state machine so we need a new deal.
Let's take a few HGL file and let us start.
By typing our finite state machine.
So let us start by tapping our entity, FSM is.
And we have bought.
No, our finite state machine will have a clock.
It's going to have a reset.
And it's going to have other two inputs which are accumulate and start in order to choose which state
we are going to start in.
Now it's going to have a couple of outputs which are right a.
Right to be.
Right, see and select.
That's a great now, let's say, and for some.
And let's start our architecture.
Let's start our architecture.
Several.
Of FSM is.
Now we're going to use the type keyword in order to define the states.
This is how we define states.
So it's like defining a new type.
So you you know, you have steady logic.
You have a steady logic vector, you have integer, you have signed, you have signed, but you can
also define your own types.
So what I'm going to define is a new type, which is called state, and this type is going to have multiple
valuables in it for the initial state.
Fetch for the fetch numbers, the state process, in order to calculate the numbers than we have right
result.
Or let's just we have the right result.
And finally, we had accumulate, so ask, OK, so here this is how we define our states, you define
a new type and you say, what kind of names are you going to give?
And you define your type and then you define your states like that.
OK, next, I want to define two internal signals.
One of them is called Current State.
And the other one is called Next State.
And which type they are from, they are from this type state.
OK, so first I created a new type, then I created current state and next state from the state, which
I just created right here.
Now, these are like pointers.
They are going to point the program and tell it, OK, your current state is this one.
And what you should jump to the next time is this one.
You are going to see how we can do it together.
I just want you to know that current and next state are just pointers and like flags that tells you
where you are now initialize and you should jump to fetch or you are now in process and you should jump
the right result.
OK, we're going to see how we can use them.
Let's begin and let's start my process.
I my process is going to be sensitive to clock and tourist, remember, finite state machine works on
clocks.
So every clock it's going to evaluate the state.
It's going to say, OK, I should stay at this state or I should jump to the next state if the jumping
conditions or the transition conditions are satisfied.
OK, so begin.
No, we're going to create two processes.
And this is how we could find it.
State machines actually recreate two processes.
One process is responsible for driving the clock and the reset and the second process that is responsible
only for transition between the states.
OK, so as I said, a process is in sequential matter.
OK, so let's say here are created a process and.
OK, and I started another process here, which is dependent on start signal and accumulate signal,
because by changing these signals here, we're going to be triggering this process.
OK, so this is my process, as if I say begin and I say and process.
OK, now here is how will this work?
This whatever instruction I have in between here are going to be executed line by line.
Same thing here.
Whatever I have in process, they will be executed line by line.
However, these two processes will be executing independently of each other.
OK, so two processes, if they are defined in detail, they will be executing in parallel.
So this is why this one is responsible for Gloc and for resetting the whole state machine and this one
is responsible for jumping in between states.
OK, so by that the clock won't be blocked by this process.
The clock is always being evaluated at every moment.
And here the states are being evaluated at every moment that they are not blocking each other.
So.
We are going to say if.
Reset equals one.
What should we do if I hit reset?
Remember our state machine, when you hit reset, we jump back to the first state.
So I'm going to say my current state pointer.
Is going to equal to in it.
OK, so if I were to reset and the state machine is looking OK, why should I go if I said this is a
pointer that says, OK, jump to in it, so my current state should be immediately in it.
No, let's say Elsbeth.
I have a falling at.
Of Klok.
So if my clock is at its falling edge, I want my current state.
To equal to the next state pointer.
How do we know what is my next state pointer, this is the job of this process, so this process is
always going to tell me, OK, the next state is like that.
OK, so the clock comes here.
When the clock falling it comes.
This go interstate will be whatever next the state is being sent by the subprocess, let me recap.
You have a clock and the clock has a falling gege.
And once this falling is detected, the point that says, OK, where am I right now?
Am I in it?
Am I in fetch?
Because we're evaluating at every falling edge, it's going to equal to the next state and this next
state is going to be sent or is going to be evaluated by this process.
Now, when we continue coding, this will be a little bit clearer.
But for now, just know that this next state is going to be determined by this process.
OK, so remember, when you create state machines, what we need is the case process.
So we have a case and we have current state.
OK, so this is my current state, what does this mean?
It means that depending on the current state I have, I'm going to start jumping to other states.
So let's see how we can do that when.
Remember this when Syntex.
When in it.
And what is in it?
Well, we have already defined it.
It is a state.
So I'm saying when in it, what do you want to do when you are in the state?
So let's say you started your a year ago, then you're on your FPGA and you just hit reset, which is
the default.
You should always start your electronic book with a reset.
Once you hit reset, you will be in it.
OK, well what should the signals state looked like when we are in it?
Well, we have a right a which should be zero.
Everything should be zero actually at the recent state as the initial state we have.
Right.
See right to be.
All of them also are zero.
This is our see, this is sorry, this is Oraibi and this is obviously then I have select.
And select is also zero, right?
Now, this is this of the output signals I have.
Do I have other output signals?
No.
So in every state I should specify what are my output signals?
No.
Next, I need to specify how to jump to the next state.
Now, if you take a look at the state machine, we can see that if doctors want an accumulator is zero,
I should be jumping to fetch numbers.
Right?
I should be jumping to the state that is called fetch.
OK, so I'm going to say, if start equals one and accumulation equals zero, then what should I do
in this case?
I need to jump in order to specify the jump.
You need to say next the state is equal to.
Fetch.
OK, is that correct?
This fetch will be linked right here as well.
So I said this to fetch it means that when I have a falling killock, my current state will be fetch
after I have specified that.
OK, so then it's going to be and the state is not over.
But I'm just showing you, then you will be at this stage, which is called When Fetch.
OK, so when this current state is set to fetch, which is sent by here, the next evaluation of process
will be will check the current state.
What is my current state?
Now it is fetch, right?
Because we have said this to fetch.
So we will jump to fetch, but we are not done here.
So we will take a look at this later.
Now we're not done.
Now elss if my start.
Equals one.
And my accumulation also equals one, remember, we need to jump to accumulate state, so we're going
to say my next state is equal to accumulate.
Now, otherwise, if they are anything other than that, I want to stay at my SO else, my next.
State, what do you think it's going to be?
It is, and it's and I got to end my.
Is that clear, OK?
For the sake of understanding, I'm going to write all the states so I have one fetch.
What's going to happen?
I have one accumulate.
What's going to happen?
I have on the process.
What's going to happen?
And finally, I have one I am writing to back.
When I am writing back my rizzle.
What's going to happen, is that correct?
OK, so again, we start with both reset, my current state is in it.
So this process is working.
It's checking what is my current state?
It is in it.
It says, OK, well, I need to execute this because well stated in it, it's not it's not fair.
It's not accumulate.
So it will execute everything inside here until here.
OK, so we set everything to zero and I checked my other inputs.
If my start is one next state, meaning I'm going to jump next to fetch.
So this one is evaluating immediately.
It notices that when it's falling edge that it needs to evaluate it evaluates is risk at the press.
No, there is no reset.
It says here is my following edge.
Am I the falling edge?
Yes, I am.
What should be my current state?
It should be whatever next the state is and who sat next to state.