 So, in today's class we will look at another building block of a microprocessor which is sequential logic circuits ok, we will build some kind of a fundamental concepts around sequential logic and slowly we will develop the need for you know the memory elements which are built from your flip flops ok. So, that is how we will kind of structure this lecture. So, let us start with the you can see the slides. So, the sequential logic basic concept we will develop through an example ok. Some of the problems in the domain can be solved without any use of microprocessor one can kind of solve those problems directly by using some sequential logic circuits ok. And these circuits can also have some kind of a interfacing with some other you know mechatronic interfaces ok. So, that is why it is important to like understand what is possible with sequential logic ok. So, that we we we can at times some solve some of the problems with a lesser cost by using sequential logic rather than employing a microcontrollers or microprocessors for such a such a task ok. So, we will develop this concept by using the example of a number lock. So, so this number lock has very simple primitive kind of a number lock has 3 keys and you are asked to enter the keys in some particular sequence and then only the lock will open ok. The lock does not may or may not have other keys ok. So, right now we consider lock does not have other keys. So, can this problem be solved by combination logic is a question. So, let us say we can try one one attempt ok. So, you have this kind of keys 1, 2, 3 as as as given here. Let me get my pointer right ok. So, if they are expressed in the sequence 1 first 2 second and 3 last then only this lock should open any other kind of a sequence lock cannot open ok. So, we are given this kind of a problem to solve ok. Now, if we put our combination logic with the switches, switches to kind of give 1 or 0 when the switch is on like no one input is given to the to output of that switch and thing like that. So, we have these 3 switches when the switch is pressed that means, a key is pressed then the logic 1 will be there and we use say say AND gate ok. All the 3 switches are pressed then I can open the lock. But now we do not get notion of a sequence here like see if I press this 2 first and then like 3 and then 1 ok. Still my logic AND logic will just kind of say that ok I see all the 3 are pressed and it will open the thing. So, what is missing is the notion of sequence ok that ok I have pressed this first and then I am pressing the other one ok that that like now what is previously pressed that notion of the sequence is missing ok. So, how do we handle such a kind of a scenario for designing circuits which will achieve this kind of a job ok that is what is whole sequential logic about that you know where combination logic fails ok. Combination logic is only like you know given set of inputs you have fixed set of outputs ok and there is no notion of whether this is one key is pressed first or the other key is pressed first. Now that notion of sequence is not there in combination logic ok. So, far we have seen in the last class the combination logic circuit class all the circuits are of that kind. So, now how do we do develop these concepts here ok. So, that is what we will look at. So, the question here is how to know if whatever key pressed is a is a first time you are pressing that key or some key has already been pressed and you are pressing this key after that ok. So, we need to know what was the previously pressed key and beyond that if this key is pressed then we have some some kind of a knowledge that is happening which will further transform into into opening or not opening the lock ok. So, we need first notion an idea that we need to remember something what is that if we need to remember something what is what is like you know pressed before or something like that ok. So, this notion of memory is is there here and then other notion that we will need is the time ok or sequence ok. So, just remembering is not sufficient we need to know now sequence kind of a notion or notion of time or sense of time it needs to be there for this kind of problems ok. These are the two notions that we need a sense of time and this notion of memory ok. So, suppose we have that and we want to solve this problem ok. How do we go about doing that ok? How do we develop this now logic for for say we are given memory we are given some some notion of sequence or time then how would we attack or attempt this problem ok. So, for this then there is we need to define something called states ok. So, we introduce something called states so, that we can introduce the notion of sequence for going from one state to other state to other state like that ok. So, that is how we we we need to define states ok. That is how so, we will see how how that can happen for this particular problem and then this this concept or these notions can be generalized to solve any other such problem by using sequential logic concepts. So, we use clock for establishing some kind of a notion of time and then we introduce this notion of states to to say ok I need I need to remember now a previous state of the system ok and then I can proceed for the for the problem. So, this notion of state is for giving you this kind of a utility to use this notion of memory for solving such a such a logic problem ok. So, how do you develop with this what kind of a logic one can develop? How do we can develop? So, think about this pause here for a for a moment and then like you know you can proceed to to see the solution. So, see these pauses are important to develop something in your mind to to attempt the problem. Even if you do not get the problem is fine, but it is important to pause the video and think about and develop do something on your own and then understand then something will open up ok that is a that is a way the understanding happens ok. So, as we say like we have seen in the first class also ok. So, you need to ponder all these questions can you define states and develop a state diagram for this problem ok. So, how do we go up or doing that we pause and then like you know proceed. So, we develop like you know these two states like ok for sure we know that ok the the lock is open or lock is closed ok. Now what we want actually is that ok when the lock should open when say some sequence is there ok. So, sequence is what key one is pressed then followed by key two is pressed and followed by key three is pressed then my lock should be open ok. So, when my key one is pressed and it is the first key that is right key then I can change the state of the system ok. So, like you know somebody presses a key ok from reset point ok it comes to the lock and it presses a key. Now if that key is right ok first key is right key one is pressed and it is right then I will go to the second state ok. If that key is wrong in the first place itself I will go back to this closed state again ok. Then if a person from that state two when state two is there system is in state two and person presses a key two which is again the right key then I move to the next state three otherwise if the key is not correct then again I will go back to the to the reset kind of a state ok. So, suppose key two is also right and now I mean state three ok at the state three if the key is three is pressed which is correct key that is pressed then I will open the lock you know that is a kind of a way we define the states and we we say that ok this is how like you know the system will progress from one state to other state to other state when the right keys are pressed and my lock will be open ok. So, now how do we so complete this diagram like ok. So, right now this key pressed is correct key if other key is pressed then we need to kind of introduce that also in the state diagram ok. So, any other key is pressed you get to the reset state which is closed lock ok. So, so this is how one can start developing the logic about this kind of a problems ok. So, you need to use judiciously this notion of state what you define as a state is up to you ok. There are many different ways one can define what what what the state for a given problem is ok and many different states how many how many number of states that you want to use you can use and develop this kind of a state diagram based on which one can solve solve the logic. Once you have this diagram so, so the way you have a table in the combinational logic in the sequential logic you develop this kind of a state diagram ok. Once you have a state diagram then one can start writing a table ok. So, so how do we develop now a table? So, so let us say this state S 1, S 2, S 3 are there as it is like now we call them as a state S 1 and then like now we see ok there are this key 1, key 2, key 3 there are pressed and we will introduce in the state diagram a notion of previous state ok. So, that is where that is how we will we will use a memory ok. So, so memory is available what do we use it for to remember the current state ok or the current state so, that it will become a previous state when you start doing the thing. So, so you remember this state of a system ok. So, so that you can take a decision for the future. Then so, so now there are this some kind of a more nitty-gritty facts that assume all keys like buttons one press they will be remain pressed ok. So, one can have this kind of a way or if there is something button which is push button then there is a different kind of a way things are coming up. So, we will assume right now that ok this is this is there and there can be more complications say you can press and pop the button ok like keyboard logic ok. So, so these are all more and more nitty gritties we do not worry about that right now ok. So, our focus is to develop these ideas of defining states and solving the problem by using states and then like now how do you go about solving that problem is what we are looking at here now. So, how do you develop a state diagram is what you need to focus on and pause here again you develop your own state diagram the the table of the we have already developed the state diagram you develop a table around it saying that key 1 key 2 key 3 are the three inputs and state previous state is under input ok and then what we want as a current state ok that is a kind of a table that we need to develop ok. So, you can see here the key 1 key 2 and key 3 are the are the three inputs and previous state is under input and next state is output of the system output of this logic table ok. So, you remember your combination logic has always this some inputs and some outputs. So, here inputs have this additional input which is based on the memory ok this is a previous state as a memory here ok. So, so now say for example, now key key 1 is pressed and you are in state s 1 and correct key is pressed like you know from the reset then you go to state s 2 ok. Then now key 1 is pressed and key 2 is also pressed there like the next key is pressed is key 2 key 2 then you you are in s 2 state then you move to s 3 state ok. So, like that you will have this logic developed ok. So, so all the keys keys are pressed and you are in state s 3 then you are you know one. So, now if the keys are pressed and in some other kind of a sequence then like now you will have this next state will always be s 1 ok. So, any other kind of a combination of previous states and the keys would lead to state s 1 as a next state ok that is how we define this complete you know truth table for this sequential logic. So, the first step is about developing the state diagram and after the state diagram is developed then you introduce this previous state as a memory you know based you know that is what we remember in the truth table and then you move on to developing the complete truth table ok. And then once you have you know once you have this table you can use unknown map or whatever ways to to get your you know outputs expressed in terms of inputs and then you draw the circuits. Now, how do you draw the circuits we will see that later ok. How do you kind of use this memory notion for that you need some kind of a logic gates or which are having this memory notion in to them ok. So, that is what we will we will worry about. So, for example, now the states can be these are like you know some right now these are defined as some kind of abstract thing that they need to be coded into some kind of a binary numbers. Say I will say I will say 0 0 is my s 1 0 1 is s 2 and 1 0 is s 3 like that I can define this this kind of a three states ok. And then so, so you can have then logic developed based on this and then you can do your output expressed as a function of inputs and and so on and so forth all the all things can can happen that way ok. Only thing right now we are kind of not so, clear about is is how do you introduce this notion in the circuit what is the element in the circuit that will require to introduce this you know previous state notion ok. So, so we will see that in a minute now ok. So, how do you create memory is a is a is a basic question here ok. So, what gives you memory in in these digital circuits and and the simple kind of a way to create memory is use feedback ok. Using the feedback in digital circuits will give you some ability to remember state ok. How does it happen? Very simple. So, you say for example, you have these two inverters and then this value you are giving as a feedback here ok. So, this this value say for example, this value is 0 this value is 1 here this 1 is getting as a feedback and then this 1 is again producing 0 here that means, this is like a stable state here for this circuit ok. Circuit is stable holding this value 0 here and 1 here ok. So, so as long as the power is applied this value will be held ok. Now, we can kind of introduce the way to like know remove the value and store new value ok. So, how do you get this new value? So, you break the path ok. So, so so this is I say remember kind of a switch here. So, you open the switch and put like a new value into this circuit and then moment you close this switch that new value will be remembered now ok. Whether it is 0 or 1 does not matter if it is 1 here also the same thing happens ok that is a stable circuit ok. But now we cannot do this switching on and off manually ok. So, that is where one uses electronic switching and so, so this is a way like know load and value and remember the value, but this manually we cannot do this. So, that is where like know you introduce this other gates to have you know electronic switching kind of action going on ok. And that is where the RS flip flop comes into picture ok. You might have I mean as a prerequisite you might have gone through some of the RS flip flop literature and D flip flop literature and you may know how they are working. We will we will just touch upon some of the aspects of them we will not get into a lot of details about about them ok. So, if you want to you can brush up that knowledge again, but the fundamentally from microprocessor perspective that is a first kind of a you know the basic memory element into the into the system ok. So, now, this way RS flip flop works is is very simple actually it has these two NOR gates connected with this feedback. This is a recall for the of the NOR gate with this truth table one can find out figure out like ok with different inputs of R and S what is what is the output going to be and what is going to be the stored values ok. Like that one can kind of get a sort of truth table done for this RS flip flop. And simple way to think is that you know this NOR gate with one input 0 it acts as a inverter with with respect to other input ok. One input is 0 then like you know with respect to other input it is acting as a inverter ok. So, one input say A is 0 0 here. So, B is acting as B to Z or B to this output for the NOR gate is acting as a inverter or as a NOR gate here ok. So, say both R and S are 0 then we have exactly if you redraw the circuit when R and S are both 0 and this is acting as a inverter this is acting as also as a inverter then this this simply becomes our 2 NOR gate connected in series and having a feedback kind of a circuit ok. So, this is again like you know same concept as what we had for the memory ok before we had seen before when R and S are 0. So, when R and S are 0 this circuit is going to remember the values which is stable value. And to introduce new values you will change the value of R or S ok that is a simple kind of a way one can understand this R S flip flop or R S latch ok. So, we will not get into too many details about it, but one can brush up and like you know see how this values are change can cause like changes in the value of outputs is Q and Q prime. And when R and S are 0 then whatever value is previously there it will be remembered ok that is how one can see this as a memory. So, these are like some additional controls one can introduce now to enable this flip flop or you know disable it and things like that. So, then the changes will happen only when this is enabled then one can add further the gated R S flip flop ok, where you now use this clock to introduce this clock in the circuit to say that ok or the changes will take place only when the clock pulse is positive ok. See why this is introduced is basically there are so many kind of transistors that will be there now. So, see so many even this R S flip flop itself if you go to the circuit level it will have so many CMOS kind of transistors that are working. And we want these timings to be happening like know or this changes in the state from one R S flip flop to the next state you know they need to happen in some kind of a controlled manner ok. They need should not be like a runaway kind of a manner they should switch ok. So, that is why this is introduced here to make sure that when this pulse goes high then only like your switching is going to happen here ok. So, so then like know you connect these latches together with additional kind of inverter here to make sure like know the states changes that are happened in this circuit will get reflected to the next circuit only when the next kind of a clock cycle comes ok. So, so like that you introduce this gated R S latches along with the clock and is now inverter also here. So, so when this is acting then this is disabled. So, it will prevent like know the changes to ration to this ok. So, once this all these changes have happened here then only this when clock goes whatever high or low this will get enabled and changes from here will be passed on to the on to this latch and that will happen. Like that you do on the clock cycle then the things are you know more robustly achieved when we have scaled kind of a versions of the circuits coming in place for microprocessors ok. Now, we now add more one more kind of a modification you might have already seen this called a D flip flop where you put an inverter into R S flip flop ok. So, that R and S here. So, this inverter is put if you see is on the gates here ok. So, there output these are AND gates. So, so this will make sure that the this R and S cannot be both 0 when clock is enabled ok and this storing value will happen only during this clock cycle ok. So, so see this with this will make sure this you can just kind of do a little bit an analysis and you will find out that ok that R and S cannot be both 0 and then this changes will happen only during clock cycle ok. So, so see when the the the clock is is disabled for this this part then R and S are going to be 0 because these are AND gates here ok. So, R and S are going to be 0 that that 0 both 0 will store some value ok, but then this input cannot be both 0 ok. So, either 0 or 1 value is going to get stored or like you know it is going to get stored in based on the input that is given at D ok. So, that is what is this inverter is doing here ok. So, and that is how this D flip flop is getting built. So, so with this we we get this this D flip flop to remember. So, this is like Q plus state will be coming out here though this Q plus is 1 after 1 clock cycle ok this plus means after 1 clock cycle. So, if this input is D after 1 clock cycle that input will be reflected on this Q here ok. So, that is how this D flip flop will will work and this is a particularly negative H trigger D flip flop ok. So, there are many many variants of this flip flop, but for for our case right now what is most important is this memory notion that we are talking about ok. The notion of memory comes now here that a state will be remembered for 1 clock cycle ok and then and then the next state will be like you know the changes of the state will happen after 1 clock cycle ok. So, so at any point if you say ok this is input I am giving here, but output here is going to be previous state at any point of time. This input will this output will become a new state only after 1 clock cycle gets passed ok and after this this is changed to say like you know new value and my value is changed here this does not immediately change. So, this will be changing only again after next clock cycle. So, previous value will be remembered here till that time ok. So, that is how this notion of memory is is introduced here ok. So, in this D flip flop. So, so these are like some variants here, but and some kind of a case for you to think about and consider how this input changes to the to the D flip flop. This D is input and how the outputs will change and how the states will change in the clocks changes you know. So, think about this and then we can now put together this D flip flops to get different different kinds of circuits. The way you we had some kind of a combination logic circuits we have now this 4 bits say for example, this ring counter. So, we want to count these numbers here. So, we are putting some kind of a you know this D flip flop in series and like looking at the output of this flip flop as a clock ticks ok. And this in the output of the last one is again given as a input to this first one ok. So, under under the scenario like how this ring counter will work as a clock ticks ok. So, if you start from say 0 is a 1 0 0 0 state ok. So, let us say somehow we have got this state inside here ok. So, after 1 clock cycle so, so they say this is 1, this is 0, this is 0, this is 0 ok. After 1 clock cycle this 1 is going to get passed on to this ok. So, this will become 1 ok. What will come here is what is here? What is here is the output of this 4. So, this 0 is output right now like you know the 4 like last part 1 0 here that will come as a as a next state. So, this is how like you know the next state will be 0 1 0 0 and next next state will be 0 0 1 0 and thing like that ok. So, so this is one of the ways one can build these kind of a counters ok. So, these counters are very important in in micro micro possessors micro controllers both. So, so there are many variants that can be possible you can look at some of these various like a variant like these then you can introduce not get in the feedback ok to enhance the number of states that are represented. So, say you think about for example, for this here if you run through this time like you know as a clock ticks what are the states that will be represented by this Johnson counters or to say when we start at you know the state 1 0 0 0 ok. So, now this out final output is going to get inverted and it is going to come in the in the in the front ok. So, that is how it will look like you know 1 1 0 0 ok as a second state like that you will be able to kind of see all these state. So, you can with this kind of a thing you can see that we are able to now represent more number of states as a as a sequence in this counter. Now the question is suppose we want to count ok 3 bit for example ok, but we want to count in in in the way that we want the output to be binary 0 1 2 3 4 like that up to you know 8 or 7 rather the 3 bit up counter ok 1 2 3 4 it will count 0 1 2 3 4 8 numbers it will count. So, so these are binary numbers ok. So, how do we develop such kind of a counter ok. So, again we use a principle of a state here ok. So, this is how like you know the this sequential logic design needs like the definition of states and once you define states then like the problem becomes very easy that is expressed now as a as a combinational logic problem and then we will see how we use now D flip flops to get a circuit out of that combinational logic table ok. So, first thing here to develop a state diagram ok. So, you do that pause here do the state diagram development that if I am state at state 0 0 0 then what will be my next step next state. So, my next state will be 0 0 1 if I am that at that state what is the next state like that I develop the state diagram ok and you can see the simple state diagram will come up. So, so there are no external conditions for transition here ok. You remember in our log problem there are the conditions on the keys that will take us from one state to other state ok, but here there are no such kind of a conditions ok. So, there are no external inputs. So, so again we can develop then the the truth table in the similar way we have we do not have any other inputs we are going from just one state to other state without any kind of a condition on any any other kind of a key or any other input. So, this say number like say I say this number is C first number is C second is B and third one is A now what should be the truth table entries ok you can develop that ok. So, C now we have this C B and A are the present state ok then the next state should be what ok if the present state C 0 0 0 then next state should be what ok think about that. So, if the present state is 0 0 0 next state I am going to is 0 0 1 ok. So, I will write 0 0 1 here. So, these are like the next state C plus B plus and A plus are next states ok. So, we do not have any other outputs here ok in the previous case we had output of lock open or close we do not have that kind of output here ok. So, we just have this these three outputs and then we can complete this truth table ok. So, so you complete it yourself first and then only like no look at what is done it will open up some things for you some mistakes small kind of a nitty gritties you know that will get corrected ok. Now, we have generated like you know these then we can use K map or like no other kind of a whatever techniques you want to use for for getting like expression for C plus as a combination of A B C ok. So, I want to express C plus as a combination of A B C these are because these are my next states ok these are my outputs and these are my previous states ok. So, so I would express them and these these previous this next state are only dependent on previous state no other inputs they are dependent upon ok. So, that is how I have so, so I will express C plus as a as a binary or Boolean expression of A B C by using Carnot maps or by using some of products rules or some some kind of a way that you have learned in the past ok. So, so this is more like a development of Carnot maps and I am not going to get into how they are like no written there, but we get finally, this expression by using this K maps ok. You can pause here and go through if you want to like you know revise your Carnot map and get these expressions ok. Like that you will develop it for B plus also ok. So, B plus is expressed as a as some kind of a you know function or Boolean expression of A B C. So, this is it happens that this is not dependent upon C here and the same way for A plus ok. So, now the question is that these are the expressions for C plus, B plus and A plus and we want to now develop you know the circuit for implementing such a kind of a expressions ok by using now flip flops ok or memory elements ok. So, see now the new state C plus is dependent upon like is expressed as previous state some kind of a combination ok. So, how will you develop such a thing? So, this is what we want ok. The next state we want to be coming as a function of like no current states ok. So, current states are available as so, we use D flip flop for this purpose ok. So, how do we use that is explained here ok. So, the way we implement the previous and current state using D flip flop. So, say some input A is current state is available here ok and I want the state after one clock cycle to be given as here. So, I use now dependent upon the variables I have are three states I need to define ok. So, I need to use three D flip flops one is for A, one is for B and other is for C ok. So, these are three D flip flops I will use and for these D flip flops at any point of time the current state is available at the output here ok. And I use that state and then produce my A plus as a as a as per these relationships that I have produced already ok. So, if I do that then these circuits comes up ok and then this becomes like my circuit for 3 bit up counter which will be counting exactly the way I want binary numbers to kind of you get counted ok 0 0 0 0 0 0 0 1 0 0 1 0 like that it will come up ok. So, so so this is how like you know these circuits are to be developed ok. And in the same way our problem of you know the the the key lock ok the lock problem that we discussed can be also kind of converted into circuit now ok. So, what we need to remember is like you know the the state. So, we need to define for the state some kind of a binary representation previous state and new state like that it will come say say if you if your state is A B are two numbers that are defined then like now you will have A plus B plus coming up I mean when the previous state and new state are expressed in your truth ok. So, you can do that exercise as a homework ok. So, this is how we go about developing these counters or you know sequential logic circuits. Now we want to build memory. So, so we will talk about little bit about memory. So, memory we will we will use now say 3 bit memory we need to remember 3 numbers. So, we need like like the 3 D flip flops to be combined together. Now, how do we kind of put value in the memory and how do we get the value out of memory you know. So, that is what is is more nitty gritty to talk about. So, so we use this clock which is going to the D flip flop judiciously to to see ok when I want to store my value in the memory when I want to get value out of the memory how this this is done that is what we will see in the next class and then we will see some of the you know putting together now all these elements how we can kind of build some small primitive microprocessor to get you just a feel of like you know how things work in general. So, maybe we will stop at this point here and continue in the next class ok.