 Last class, we looked at interfacing using Tiva launchpad for PWM interface ok. So, how do you run the motor by using PWM interface? We took an example of Tiva, but that can be extended the syntax is different, but the philosophy remains the same. So, the same thing can be extended to any other microcontroller as well. Now, today's class we are going to look at interfacing of encoder by using this dedicated quadrature encoder interface QEI interface in Tiva launchpad. So, again here we will introduce first this philosophy of like how this encoder interfaces, they were typically what kind of registers or control registers are there for like getting these interfaces done and then we will look at little bit more details about programming using Tiva launchpad. And further than that we are going to look at also the sampling time, how do you set up the sampling time in the in the mechatonic system working ok. So, microcontroller needs to have some specific sampling time for the system to work ok, why all those kind of things we will discuss in the in the class. So, let us get started here. As you know this working of incremental encoders we we are just recalling we have seen it before. So, what happens is we have just slits in the wheel and then you have this light source and light detector photo diode and these light source and detector they work in pair and when the light passes you know you get pulse light passes through that and then the this slit passes the slit cuts the light you get a pulse ok. And then we know that there are two sensors needed A and B to sense the direction in this case ok. So, these two outputs A and B are 90 degree out of phase with each other, how they are made 90 degree out of phase by their proper placement with respect to each other electrical domain like you do not need to have them so closely spaced. One can be sensing here and other can be sensing somewhere else since this all the slits are uniform you will get 90 degree out of phase all the time. And we may use another sensor to to get a position absolute position of the of the encoder field ok that is called index pulse ok it is typically termed as I or Z. So, we we know that these are the pulses that we have we get and in one direction you will get this kind of pattern of the signals in other direction you get some other pattern of the of the of the signals. And A and B signals they they are to be processed in some way to to read these patterns and get you know encoder output ok. So, this is what encoder like you know the any circuit for decoding this you know they do they they recognize this pattern and then they produce some pulses corresponding to each of these phase or each of these kind of a combination of A and B. And so, the then the the the the pulses are to be counted to get the encoder count ok. So, that is how the the internal circuitry would would be designed or positioned to to count these pulses and then change the direction based on change the direction the count up or count down would be changed ok. And then the direction change will be sensed by saying ok look after 0 0 if there is 0 1 then there is a clockwise direction and after 0 0 there is a 1 0 then there will be anticlockwise direction. Something of that sort some logic will be used to get the direction sense ok. So, this is there are many advantages of using this incremental encoders as we have seen there digital output sensors. So, there are there are noise free. So, there is no noise error in the signals. And small amount of noise if it all that is in there that can be also taken care of by some filtering as we will see in this QEI interface of Tiva. Then it has a quadrature output the 4x kind of output. So, 4 pulses will get per one hardware slit ok. So, this is what will happen like you know these are the 4 kind of a signals you will get in one cycle of A for example ok or of one cycle of B would so to say. So, one slit will correspond to 4 pulses that is why it is called the term quadrature ok. This is a quadrature output. And then you get a very accurate speed estimation by looking at like you know time between two pulses or like you know number of pulses in a specific amount of time ok. That is a way like you know you get very accurate estimate of the speed in the in these encoders ok. There are two ways one is like you know look at time between the two pulses or you look number of pulses in a given amount of time. Now how this is up and down count is done in Tiva, how the speed can be estimated we will see in detail for the Tiva interface ok. So, as we have seen for this interface is for up and down counting of the incremental encoders as the position changes for the encoder. And then also for the speed and estimate. Now see in the absence of this interface like you would need some kind of a circuitry to do this job ok. So, if you are interfacing encoder with not with Tiva, but any other kind of a microcontroller and does not have this QEI interface ok. Then what to do? Then you will use this chip called HCTL 2021. That HCTL chip is going to do this job of what this interface is doing. So, basically idea is there is some kind of a clock based on the clock you will take this inputs A and B and process them internally to as I said like you know to generate like four pulses per one kind of a cycle of A. And then those four pulses are like you know those number of pulses will be counted by using some kind of a counter ok. And that up and down count will be changed based on the direction what direction logic ok. So, this is how this interface will typically work and we will not get into the details of logic circuit to do that and all, but we just need to kind of understand that it will have to take inputs of this A and B and process them in some way to kind of get you the count. So, this will happen in QEI interface which is already there in the microcontroller circuit itself like know it is part of the microcontroller. So, you do not need any extra chips as for a for Tiva kind of a microcontroller if you are using this interface. So, there are two modules in Tiva for QEI. So, you can like know interface two encoders in in Tiva ok. And each of the module has input signals A and B and index pulse also is input. So, three inputs are provided in each. And typical features are like there is a position integrator to track the encoder position of course, it will it should give us a position that is what we are interested in. Then programmable noise filter is there ok on inputs A and B and Z. You can have some kind of a noise filter to be applied. Then velocity capture that is done using some bit in timer we will see how this velocity capture is done. And the input frequency can go as high as up to 1 by 4 of the processor frequency ok. So, this is really fast kind of a interface. So, see so, then you can capture very like large amount of speed or very high speed data can be captured. Because higher the speed the number of pulses coming you can see would be much more quicker ok. So, for example, if you see these pulses that are coming like higher the speed this time duration between the two pulses of this A or B is going to like start reducing. And it may reduce at some very high speed to some extent that you may not be able to count at fast ok. So, this that is a limit that is given here ok 1 by 4 of the processor frequency is what. So, if you have 50 megahertz for process frequency typically 12.5 megahertz will be the frequency of input ok. So, that is pretty high I mean the depend upon encoder of course, your resolution you are using. If you are using encoder with a nanometer kind of a scale resolution then your speed will get limited by this number ok. But if you are using micrometer kind of a resolution for the encoder then I mean I am talking of linear right now, but it is applicable in the rotary case also as well ok. So, higher speed if you want like you know you need a faster kind of a microprocessor to get that higher speed encoder readings recorded. Otherwise you will have a trouble ok. Otherwise you will you will miss out the or you will lose the pulses. And when the pulses are lost and then your count will be will not be faithful. So, if you are using only the speed kind of a application there are some different kind of a ways we can one can do this operation you you do not need then depend upon how fast your speed application is. You can just make use of index pulse only to do the speed monitoring ok. If your speed fluctuations between the two kind of a index pulses or within the rotation are not too many to not bothering to your application then that can be done. But for all the robotic applications you will need a accurate positioning where you are interested in not just the index pulse, but you are interested in entire speed of the robot from starting to end kind of a trajectory point trajectory. Then like you know you will have to have you know plan your hardware I would say to do this high speed kind of a measurements faithfully ok. Then there are additional features where there is a interrupt generation also possible. So, you can generate interrupt on index pulse this will be useful for resetting your encoder value for example, in any in case. So, so say for example, if you have a robot kind of application it is a homing or zero position of that robot on the power up can be done based on these kind of a idea. Then you have a after velocity timer expiration there is some kind of interrupt generation. So, these are these kind of different possibilities for interrupt direction change happens you generate interrupt. The then phase signal error head then in that in that case you can generate some interrupt to kind of halt your application or something like that ok. So, this interrupt how do we how we can use this up to you to use this, but this is a facility that is provided by the by the interface ok. Now, let us see little bit more detail of this interface in Tiva. So, there are two phase signals phase A and phase B that is what they call it N is like no channel 1 channel 2 something and they can be swapped before repeated by the module ok. So, these are additional facility that is provided in Tiva. See many times it happens like when you say rotate the encoder you see look to set up things properly for our mechatomic system to work as what we do in our normal you know calculations or mathematical model. The positive voltage given to the motor should result in positive displacement ok. Many times this is this may not be true based on your hardware connections ok. So, if that is the case then we need to just swap this phase signals ok two phase signals. Then what will happen is for positive suppose for positive rotation like you know the count is actually going down or count is counting down then by swapping like you know you can correct for that ok. That is the facility that is provided in the. So, you see to correct some miss wiring of the system is what they say ok. So, you miss in the wiring. So, you can correct it by checking the wiring and like you know doing it correct wiring also, but this is a software facility that is provided by the interface to avoid the injury. Then input signals will have this digital noise filter that filter can be enabled by using this bit in this control register. So, see these are the kind of registers that you need to look for you know doing this using this facility ok. So, if you want to filter like you know use noise filter then you use this kind of a bit in the in this control register and you will get that facility. So, we will see there are two again as we said. So, in the case of PWM here are there are two kind of a ways of philosophy of programming ok and two ways of programming that both ways can be ok to kind of go ahead with. One is like based on these registers understanding how these registers work in the case of Tiwak in particular here and other is by using API libraries that are provided by the manufacturer ok. So, we saw that philosophy and how that can be used in case of PWM. We are going to look at similar kind of a thing in the case of this quadrature interface today. Then the mode of operation that can be changed there are. So, this you can see what are the modes of operations that are available, but that can be changed by using some other kind of a bit in the. So, there are these kind of a description will be given and then this model you know block diagram is given ok. So, this how do you read now this block diagram ok how to make sense of this ok. So, you need to read a little bit of a data sheet see these are the these names that you see here they are basically registers ok QI status register QI CTL is a control register then some like kind of a timer load register is there then you will have these signals are coming and getting into this some kind of a some circuitry which will give us output of the direction and number of pulses. So, phase FHB like know for one cycle it will generate 4 pulses here and those pulses are going to get kind of counted somehow up and down and the output will be available in this QI post kind of a register and these are the kind of a ways one can think about reading this ok. Then there are these interrupt control that is there here. So, some bits to kind of do this interrupt control some control registers to do that interrupt control ok. So, this is so, you need to see what are the inputs out of these what are the outputs and see whether like say for example, you can set this QI time or QI load kind of a register ok. And this QI count and QI speed are the results or outputs that are to be seen actually ok. So, these are the output registers QI post is again output register QI max post is where you can write this maximum position beyond which like know the this counting will get reset. Like that there are some things some of these things like I am telling from reading the data sheet, but you can also find out like you know these register details and you can start making sense of such a such diagrams ok. Then we will have little more description now about these ok. So, so, this after swapping like you know the signals are coming up here ok. So, these are already swapped signals ok. So, swapping algorithm is somewhere like you know something will be there in the control ok. So, then let me get this. So, then we have this more description of a. So, position integrator block is what is using these signals as we saw here. So, position integrator is here it uses this signals which are processed by this quadrature encoder and then like you know directly gives us this position in the QI post register ok. So, see this is so, easy I mean so, I do not know if you have an experience of like no reading encoder, but we had done it as a part of some other kind of activity and where to interface that HCTL chip to get to this point where you are actually start reading this. So, you need to have this circuitry in place ok. So, you need to connect wires you need to have a hardware like or design some PCB and then get that HCTL chip to interface instead of that in T Y it is happening all internally done you just need to program it and start using ok. So, this is way this way it is so, easy if you have this kind of a interface that is directly available as a as a facility for user to program in the microcontroller itself ok. So, this is good to use this encoders this kind of a microcontroller which will have this QI interface for many mechatronics applications it will be very useful. Because encoders are what like you know give very accurate kind of position estimate we have seen we have seen because of low noise and it is that is why it is more kind of a prominently used in in mechatronics applications and that is where these interfaces or microcontrollers with these interfaces will become you know important for the mechatronic engineer to develop some applications ok. Then velocity capture is is using configurable timer and a counter register and then the count timer this counts number of phase edges in a given time period. So, if you see this block diagram like this is this number of this edges. So, this say we have seen that ok these are the on this line you will have some pulses which are you know coming based on the phase A phase B signals ok. So, these pulses will be typically 4 pulses in one kind of a cycle and these pulses will be counted for a given amount of time and then you will know that ok this is a speed ok. So, that is what is being done and then there is some kind of a velocity pre-divider which will be available in the control QI control register you can set this pre-divider value. So, that you get some kind of a facility of you know reducing the number of counts to do some accuracy or like you know to make sure that the numbers do not overflow the register register that are that are used to store them ok. So, so this this is what is this how this philosophy of velocity capture works ok you the timer will count the number of phase edges in the in a given time period ok. Now the how do you set up this time period for capturing it is QI load register ok. So, this this count in this register will count a number of clock cycles which are there for and then this QI load say suppose like I have QI load value to be 100. So, 100 clock pulses is counted before the timer is before this timer is reset. So, for that 100 clock pulses we see how many edges of the you know microcontroller how many edges of the encoder phase signal they are counted or how many counts of encoder happen in the 100 kind of a value of this QI load ok. So, QI load when it is 100 it will count 100 clock pulses. So, that much is a time that is given for this timer ok that is how one can think about see typically this comes from like you know you cannot say ok I will give some microsecond or millisecond kind of a time in this timer know that time is not typically given. So, everything in the in the microcontroller happens with reference to the clock ok. So, if the clock is running at say whatever frequency number of clock cycles is what you will typically say as a time ok. So, this when timer load register this is see so, typically we deal with all integer values in these registers ok. If you think carefully like you know all these values that we are dealing with are integer values in the register. So, you cannot say like know some unit time you say that unit in terms of like you know number of clock cycles and that will be like a integer value. So, that is how like you specify typically in the microcontroller philosophy these different values of register. Then the count is also pre this pre divided pre division of the velocity count will be possible which can be set in QICTL register ok. And then this value current value will be available in QI count register and once this is timer is finished then that value will be transferred to this QI QI speed register. So, this count is current value and once the count the timer is finished that value will be transferred to QI speed register and it will be available till the next time it is getting reset ok. So, current speed will be taken from this QI speed register and then depending upon how fast you want to update the speed you can like you know put a counter put a timer value accordingly ok. Now, let us see like how do you find the speed of motor shaft in rpm if the counter specifications are known and relevant register values are known. So, this is a question that you need to ponder over ok. I will leave it at this point like you think about suppose I have a motor which is using 1024 kind of a counts in one revolution or now 1024 slits for the one revolution of the motor that is a encoder specification that is given ok. So, we have 1024 slits ok. So, quadrature like you know will have like those be number of counts you know 1024 into 4 counts will be there ok 4096 counts will be there. Now, these kind of counts are coming and then like now we want to know what is a motor rpm when we have set up some we know the clock signal coming at some frequency and we have set up timer for some duration time duration and in that time we are counting like you know how many number of pulses are coming. Then based on some simple mathematics you may be able to estimate this value of a motor rpm ok. So, think about how will you do this ok maybe we can have this as an assignment or you know quiz problem exam problem ok. Then you have again as I mentioned two ways to program QEI interface ok. First is register based programming ok. So, I am giving you the some reference here also. So, that you can go to that you know page 1310 of this microcontroller data sheet that we have shared ok and in that you will find all the details of the different registers that are there ok. And steps that are required to be done to to program this interface ok. And second way is using API libraries ok. So, this again there is this functionalities of this API library are provided in the syntax of API that is again another data sheet that is provided. So, typically microcontroller manufacturers will provide you with this data sheets of you know the details of this how do you microcontroller can be programmed. In some cases you will have this API library files. In some cases you will have to work with only this register for XCP. For example, for XCP 100 kind of microcontroller we have only the like you know this register based programming happening and in TIBA you have possibility of both. And see this API libraries are nothing, but you know if you see these functions if you see the function details you will find the same thing like know that these functions use finally, the register based programming. So, this is like you know the base level programming register based programming ok. Now typical steps that are used in programming this QAI using APIs are you know first you need to have these library files available and initialize these are important so that you can you make use of the functionalities that are provided and then initialize some variables that you want to use in the system. Then for initializing hardware these are the steps for QAI to be followed. So, configure clock frequency this is the typical step for many interfaces like we need to do. Then enable this module ok this peripheral module enabling some functions will be there to you use them to enable the module. Then now see we if you see this map of the pins of this TIBA microcontroller launch pad in these there are programmable GPIO interfaces which can be changed to act as a QI interface or it can be changed to act as some other kind of a interface ok. So, we need to before we start using it as a QI module we need to tell microcontroller that ok look I want to use this particular pin provided for the QI kind of a module ok. So, for example, depot has some pins which are used for QI module ok. We need to enable those particular kind of a ports and then further you know map the pins to act as a QI ok. So, this is done this GPIO pin type is to be defined in some function. So, this is a function that is given for making these pins to act as a QI pins. Then the pin configure which I configure these pins for AB or index kind of a pins ok. So, these are the kind of typical steps that will be given this is all given in the function library data sheet or manual ok. So, you need to find these functions how they are working what is input output and you know all those details you need to find and it will get that. So, see I will give just kind of a brief of some of the things, but you can go ahead and look at this particular you can just search for this function ok in the whole data sheet. Otherwise the data sheet is too huge. So, to find like you can get into QI interface and then like you know start reading some of the part and then you maybe if you want you can search for this particular kind of a phrase and then you will be able to get the details of that particular function. And of course, you will have a sample programs available that also kind of make quite a bit of sense. Once you have this hardware initialization part done then you go to QI module you know function S which are used for QI module programming. So, this is one of first thing you need to do is a configuration ok. You look at this function configure QI configure and see like know it can be configured for mode of operations swapping the input channels required or not required the maximum position value all this kind of things will be put in this function QI configure. Then filter enabling you may need to do ok if you want to use filter ok. Then enable the QI module also you by using QI enable kind of a function. Then you will do some kind of a configuration of velocity capture. So, by using this function. So, pre-divider timer you know those kind of things you can set by using this velocity configuration. And then once this configuration is done you and the QI velocity module also is QI velocity part is also enabled and QI is enabled. Then you will be obtaining position in this QI position get function and QI velocity get function ok. You want to get the direction you can get this in the in this QI direction get function ok. So, these are the ways like you can use these functions to get you the desired output of QI position ok. So, this makes our job quite simple ok. So, by directly using some functionalities you are able to now read encoder and start using that encoder data for further control kind of a programming if you want to use PD control or some kind of a other kind of a control using this data you are you will be able to do that very easily now ok. So, we have seen PWM and we have seen now this QI interface in which by using this now one can start thinking of like you know building like you know entire closed loop system ok. We will talk about that a little bit how do we build a closed loop kind of a system by doing that ok. So, this is just the classification of all these different functions ok. And this is a sample program you can see this part where like you have to initialize add these libraries and get this setup here. Then some of the variables if you want whatever you want to use you can initialize the variables in the in the in here in the main program and then you can initialize hardware and you follow the steps that we just saw ok. So, if you see some of these functions are doing this hardware initiation basically here. So, you are mapping the pins configuring the GPIO pins to act as a as a index pulse or a pulse or B pulse anything like that ok. And you are enabling this QI0 module you are enabling this GPIO D register ok. So, port D we are enabling to kind of make sure that the pins of port D which are used for QI interface are enabled and things like that ok. Then you are doing this configuration of this QI interface here and you can see these are the details of the configuration register QI configure ok. You do all these different different configuration parameters to be set here ok. And then you enable QI interface ok. This is particularly QI0 interface there are QI0 and QI1 two interfaces will be there. Then velocity configuration you are doing here ok. And once this is velocity is configured now you are you will be able to start reading it ok. So, get QI position you say position is equal to so this is from function 0 you are using 0. So, this is from interface 0 with this function by using this interface 0 value can be fetched in this position. So, your position get of QI0 port or QI0 interface you will get you know encoder position of encoder which is connected to this pins corresponding to this QI0 interface. Like that you can have a position QI1 interface position also. So, if you are using two motors at a time you can use this other interface as well. And then position you get position velocity and direction ok. So, this is how typically you go ahead get writing a program to get your QI module working. So, I would suggest that in like you should try this yourself with the with this QI module and the Tiwa launch pad that you might have procured by now and already started exploring different different interfaces. So, use our motor in the kit to do this kind of programming and get a get a feel of what how things are happening. And that is the best learning that will happen if you have doubts clear like you know things you can post and TAs and we can help out with those things ok. So, this how this module is going to work. Now, next we will look at like how do you put together now entire things now on the programming side of the microcontroller ok. The theory part we will look at in the in the future classes to come, but we can now start putting things together once we have we once we know how do you get the position of the motor and once we know how do you run the motor ok. So, we have seen both of these. So, what is that is needed is now to put together. So, what we typically need to do is to run this three operations in a sequence ok. First is a reading of the sensors or reading of encoders, then computation of the control law based on the encoder feedback position and what we want ok. And then finally, using this control law computation you get some kind of a U or output that is going to the motor that is to be implemented on the motor actuator. Typically actuators will be actuated through PWM and then PWM duty cycle is what will change every sample time so to say or every cycle ok. These three operations will go on in a cycle ok. They will keep on repeating with a with some kind of a you know time interval this time interval called the sampling time ok. So, this is a very important concept in in mechatronic systems that you will have some kind of a fixed sampling time that is to be set. So, that these operations like know successfully get carried out every time interval of the sampling time. Now, this time interval needs to be fixed because there are digital implementation of filters that happen in the typically in this case and they depend upon sampling time ok. So, all the implementation digital implementations of the filters will have dependence on the sampling time ok. So, sampling time is very important to maintain in the system. How do you maintain that? One of the ideas to do that is how do you set up that or how do you maintain this sampling time is to write entire program and find the execution time that it takes for this program to run ok. And once we know this is they say it takes 1.5 milliseconds as a time to run the entire program and I want to set 2 millisecond as a sampling time. Then I know like you know 0.5 millisecond needs to be a delay ok. So, I will put some additional delay that is by doing some kind of a delay function and doing I mean keeping microprocessor busy in some some kind of a additional operation in a loop for that much duration and after this delay is performed then again it can start doing this next operation next cycle ok. So, this keep on happening for a infinite loop that is one way of setting up sampling time. But the disadvantage is that there is no flexibility in changing the program easily you need to change program you need to change the delay also. Then there are conditional statements if there are there in the program if else kind of a program then it will change sampling time. So, so it is a it is a it is a cubar some way and then you are keeping your microcontroller busy in doing some delay function ok which are which is of not much of a use it just kind of keeps microcontroller busy you know so as to kind of like know have you give even that much kind of a delay. So, so there should be some there should be a good way out of this we need to use some other way of doing things here and that way is basically by using interrupts ok. So, we recall the philosophy of interrupts where you know say suppose you are reading a novel ok and your mom calls ok. So, you are sitting in basically reading the novel and then the call comes then you you hear the bell ring and then what you do you put a mark in your page wherever you you last year working there and finish the call of course, if you like to many times you may may not like to take a call, but let us say if you want to take a call and you finish the call and come back again start reading the novel ok that is what you do ok. Exactly the same philosophy is there for the interrupt when the interrupt comes on some pin then microcontroller halts whatever it is doing right now and serves something and you know to some run some small other routine that is to be that is programmed to run when that interrupt comes and then again comes back to the main program after finishing that job ok. So, this is a kind of a philosophy of a interrupt that we have seen and if we have this when you come back you may do nothing you may just wait, but to wait for the other signal to come. So, that way that much time is available for microcontroller now to do some other activity if it is to be done ok, but the now the idea is now if we get these pulses coming on this in some kind of a periodic manner ok then this operation same operation can happen again and again and again and again whenever these pulses come ok. So, idea is to use a timer to generate this interrupt pulses every few milliseconds or every whatever sampling time that is needed ok. So, if you want two millisecond kind of a time sampling time you generate this pulse every two milliseconds one pulse comes. This pulse is connected to interrupt pin and at interrupt pin kind of receive this pulse and once it is received the pulse like it starts executing some program which is your program which is doing these three operations that we talked about reading the encoders like computing the control and implementing to the actuator ok. So, this is how it really happens. So, that is what we have seen that we will generate up the pulses every sampling instance or every sampling time and this pulse will trigger the interrupt and start running program called a this piece program that run that we run where we have these three operations are done ok. These three operations that we are writing somebody can write any other kind of a thing in that interrupt service routine but that program is called interrupt service routine ok. So, this is interrupt service routine is a name that is used ISR. So, this is a you know terminology you need to be aware about and the program starts running once the program is finished it will return to the main program if there is any activity remaining to be done in the main program it will continue otherwise it will just wait for the next pulse to come. Then in Tiva this is done increasing again API functions ok and this interrupt service routine is simply predefined name function. So, no nothing needs to be done in the hardware. So, all the things in the hardware are somehow connected in whatever ways it is needed and you do not need to kind of worry about that ok. You just need to use a timer and then like know enable the timer for interrupt kind of operation and that is it you know your job is done. So, we will see the some of the steps here, but the idea here is to do this timer setting. So, typically you will say ok this timer setting will have what all things to be done ok I need to set a time. So, there is I should look for some thing where I can set up the time ok then I should look for that this timer needs to be connected to this interrupt ok. So, it is interrupt enable timer it should happen and then I need to run this ISR. So, I need to look for what is ISR. So, ISR in this case will be simply some predefined name function in which in that function if you write something that whatever we write in that function that will get executed every time the interrupt is happening ok. So, this is how you set up the sampling time in in in the modern kind of like know microcontroller applications ok. So, if you are very you know high fidelity or I would say much better kind of operations of closed loop control can be achieved by using this you know sampling fixed sampling time set up by interrupt based philosophy rather than just using like you know continuously in the loop without really giving any attention to what is the sampling time happening in your system it is better to kind of understand what is this we set what what is the sampling time we want to set and that much sampling time is set properly for the application that application we is going to run much better with a with a higher performance ok. So, this is typically like some functions that are used. So, this timer load set is a function used to you know you can look at this function search for that and like know read the function in API every data sheet and see what are the arguments to this function and what it does and thing like that. Now, for for this this is an example for timer 0 this timer load set function will have these arguments to be used and then this is a period to be set according to sampling time. So, you have again the same philosophy that ok. So, sampling time for example, to be 0.1 second or 100 millisecond with frequency or sampling frequency to be 10 hertz then this will be you know set this value this is like a period value that is set based on the system clock whatever is is a system clock frequency divided by like you know this 10 minus 1 ok. So, this is how like you know this this number which is to be loaded in the in the it is like a loading that is happening in the in some register. This number will be register in some load and it will be count to 0 and then pulse will be generated that is a kind of a philosophy the same way it is used as in the case of timer in the in the QAI module and this is a sample program that you can look at. So, this is peripheral enabling happening for the timer peripheral enable then configuring this timer and then you are setting some kind of a timer frequency and then you are enabling here interrupt enable ok. So, interrupt enable happens here then this timer interrupt enable there is some some interrupt enabling functions are there and then the master enable function happens and then you enable the timer for the timer 0 that is that is what you are using for the interrupt. So, there are some functions you need to read through the details of this function what they are doing and understand and make start making use of them ok. And once you set up this interrupt kind of a routine then you need to look for what is a function in which I should write my interrupt service routine where and how do you how do you look for that ok. So, the interest for a service routine in this case is this particular kind of a name timer 0 interrupt handler and in this function you write some kind of a statements. So, first statement that will write is this clear clearer of this interrupt. So, this clearing is doing some clearing of the interrupt mask this is done so that now the interrupt is ready for the next pulse to receive. So, if the next pulse arrives then like know this will again start reading. If you do not do this command then the operation is run once and it will just kind of a wait because the clearing is not happen this clearing is important to happen. So, once the clearing happens then one can you know the next pulse comes again this is this. So, this command if you miss then like know you may find that ok your system your program is not running you will wonder why. So, this is important concept here the clearing of the interrupt mask ok. So, this is how we will go ahead and put together the things now to really you know read the encoders then compute control and write PWM duty cycle value and now how do you compute control based on the dynamics and control you know some of the theoretical aspects we will look at and give some kind of a practical implications of some of the theoretical results and then we will discuss how do we know. So, we are here basically getting ourselves completely ready now to implement any kind of a closed loop kind of control with a microcontroller. So, some theory we will look at and again we can kind of come back and do this programming or parallely we can do this programming for you know some of the mechatronic applications that is how we will go ahead. Thank you very much.