Hello, guys, and welcome back and this lecture, I wanna talk about finite state machines now in all
of our other courses, we have talked about this concept and this concept is very, very important in
the electrical electronics and in the programming fields.
So this is why I'm going to go through it and we're going to see how we can implement it, using circuits
like how if you have switches and logic gates, how can you create a sequence controller?
But let us first see what is FSM?
It is a controller that is used to implement a sequence of actions.
And I'm going to show you right now what kind of sequence of actions are we talking about?
Let us take this example.
Assume that I have an alien right here.
This example is actually the project that you are going to implement at the end of the section, and
what we're seeing right here is an ACLU, which we've talked about intensively.
Then we have three resistors or C or A and or B and we have one multiplexed and here we have our FSA.
So regardless of the FSM, you have some combination of logic, but there is nothing to control it.
I mean, right here, the purpose of the circuit is to sum or subtract or do any arithmetic operation
or whatever data is in a and whatever data is in.
So we have a register.
It has two inputs.
One of them is data.
The other is right so that you put the data and you trigger the right in order to store the data.
Same thing for B, and then these two registers will go to the ACLU.
However, all the way of the array there is the multiplex.
Her and this multiplex, sir, can take the data either from A or it can take it back from RC.
But we will see that in a minute.
What does it mean that we are taking back from our C..
So when this selectivity is is one, it means that we are taking data from A and B, it's going to allow
you some operation is being done, depending on what operation you assigning here.
And then this result has gone to our see, and if you write this it with the right see trigger right
here, the result will be here.
And now you have the option to enable the select right here and let's say choose select equals zero.
And by that, this value is going to take data from the RC back directly to the value.
See that so this multiplexed can either take the data that is stored in or see from a previous operation,
or it can take new data from logging.
Now, how can we control this?
I mean, it's not really practical that I need to press.
Right.
A right to be.
And the result here I press.
Right.
See, but it's not logical if I want that say to multiply three by three, which is a three plus three
plus three.
So if I repeat this operation of summation three times, this Alio, let's say, can do multiplication
for me.
But this is really not practical.
If I want to control that manually, this is why I have an officer in FSM, I just say, OK, my data
is three and my second data is three.
And I choose the operation I want and I just start and then this FSM, if I, let's say, choose multiplication,
it's going to sum this three times or let's say I could have a mode that, OK, I want to add two numbers
and then automatically I want to add the result to the second number one more time.
So it's not really practical that I control this manually.
So all I need to do is select the mode of the FSM, let's say the mode that we have just talked about.
And I start and it will do everything automatically.
It will just sequence all the steps for you.
Another example for the sequence detector, which is used in any digital lock, let's say that you have
this door knob right here.
If you enter the right sequence, well, this handheld can be opened by someone, otherwise it will
stay locked.
So the principle is that you put a sequence of numbers in the correct order.
And in this case it is one zero one zero one zero one, the one that automatically it will unlock the
door.
Now, in order to do that, you need a finite state machine, which is going to sequence that you have
put one that zeros and one and so on and so forth.
Let us take this example one step further and go to a little bit to the details, so let us assume that
the sequence is only one zero one one zero.
You put the numbers here sequentially and then you get an output.
So let us see how we can represent a finite state machine.
Our first state is called in it, which is the initial state.
Now, remember, we want no one right here to be in the input in order for us to move to the next step.
So this is my state.
The circles are called states and they are just names of the states.
You can call them whatever you want.
What matters here is the input and the output.
So right now, if you put zero, well, there is this back arrow that is coming back from the state
to the state.
Again, it means that if you input zero, you're going to stay in the state in it because, well, we
shouldn't be moving in the sequence in order to move in the sequence.
We need to input what because if we input one, we are at the first number of the sequence so that I
say that we have input one.
And now we are in a state that is called one.
And you will see here is zero, which means the output is zero.
Great, because in order to get an output of one, meaning that we unlock the door, we need to go through
all the sequence, then this output is going to be what?
So right now the output is still zero because the sequences are still incomplete and you have giving
the sequence only, number one.
Now, if you give the sequence number one again, well, nothing is going to happen.
And as you can see, there is an error that is coming back to the same state, meaning that if you put
one well, you are just coming back to the same state.
Now, if you give it a zero, as we can see here, we will jump to the third state, which is one zero,
meaning that we have inputted one zero.
Same thing.
If you give it a zero right now, we are at one zero.
Right.
If you give it to zero, it will not let us progress in the sequence.
And we will stay waiting for the right number.
The output is still zero and we will be waiting for one.
In order to move to the next sequence.
Which is one zero one now, same thing if you put zero here.
Well, we will stay in the same state.
If you give it the one meaning that we are producing, the less the state, it means that we are at
the final state.
If you check the final state, its output is one meaning that this lock will be unlocked.
Now, if you give it a whirl, it doesn't really matter.
It will go back to the beginning of the sequence and this makes sense, right?
So you need to put one zero one one and then you will have an output of one.
Otherwise, the output is always zero.
Now, this is a little bit of a stupid, finite state machine and a really stupid luck.
Why?
Because what you're doing right here is that let's say that you are in this state and you put zero.
What's supposed to happen is that you should go back to the first stage.
Right.
Otherwise, it's very easy to hack this digital lock.
I mean, you are putting one right here.
You are in this state now.
You you have only two options.
Either you go to zero or you go to one.
Right.
Let's say you put one and nothing happens.
Well, that's a little bit stupid because it means that you can only try the other option and you will
progress or progressing is very easy.
In order to make this a little bit harder to hack, what we need to do is we need to have an arrow that
goes back to the initial state.
Every time we put a rock sequence, let's say you put one right.
You are in it and you give it the one you at the first state.
Let's say that you are giving it another one.
Well, it should go back to the beginning and you should guess the sequence one more time.
This is more practical.
Let's say that you have inputted the first three digits correctly and the third digit, you just put
a zero instead of four one.
You should go back all the way to the first state so that you can start the sequence one more time.
So this is the basic functionality of a finite state machine, and we are going to implement that also
in Soviet style examples.