 So, the next couple of weeks you will get exposed to microcontrollers, ok. So, today we will discuss not specifically the experiment you are going to do tomorrow for which you will be given write up a manual etcetera and it is not difficult to just follow it and during the class, but for you to understand overall what these microcontrollers are, what you can do with them, what sort of resources they offer, what it means to program them, how does it play a role in the context of the course that we are doing experimentation and measurement. So, those sort of things we will discuss today, ok. So, I will not say that you have to do click here, click there, click there, click here and then you will be able to perform the experiment tomorrow that is not what I will do. So, we will have more sort of generic discussion with some question and answers for you to get a feel for what these things are and what microcontrollers are. How many of you have heard of this word microcontrollers before? Everybody is heard of it. How many of you know what they are? Raise your hand like full 180 degrees no elbow bend, 4 points low, how many of you have some vague idea, vague idea of what this stuff is, ok, some 20, 30, 40, ok, that is expected. So, we will get started now. So, those of you who attended the last lecture, I think there is going to be a fair big intersection between those who are sitting here today and those who attended the last lecture. What we are doing as part of learning something about experimentation measurement is processing data from sensors, that is what we have been trying to do over the last 3 or 4 weeks, ok. So, what do we mean by processing data from sensors, it can include things like analog to digital conversion, digital to analog conversion sort of processes. Anything other than that that we will learn today, ok and the reason why we should be able to do that etcetera also we will discuss, ok. So, the context of today's discussion is still remains the same which is processing data from installed sensors, we are not yet touching upon other important issues pertaining to experimentation measurement, ok. So, we had a discussion about engines and sensors etcetera present in engines last time, ok. So, just briefly re jogging your memory from last lecture, data from sensors comes in various forms, ok. And you have been exposed to some of those forms, data can be in the form of analog signals or it can be in the form of digital signals. The data that is presented to you may be may vary in continuous time or in discrete time etcetera. So, you need to be familiar with these ideas analog versus digital continuous time versus discrete time etcetera for you to be able to comfortably involve yourself in a measurement exercise. So, that was the purpose of the last couple of labs, ok. So, comfort level with various forms essential. The other thing you need to be able to do from a skill set perspective not so much conceptually is that you need to be able to deal with these these called microcontrollers, ok. And we will see why you need why you need them because they are very useful resources. So, if you know how to deal with them it will be useful for you, ok. So, I am going to give a parallel. So, it is like it is like any other tool. So, for example, if you are a carpenter, ok. What sort of tools you need to be comfortable with in saw what else hammer, chisel that sort of thing, right. Similarly, if you are a experimentalist today you need to be comfortable with microcontrollers. So, it is like a tool that you use to capture data, ok. Nothing more than that. So, for you need to be able if you do not ever see a chisel or a hammer or a saw and somebody just threw it at you you probably do not know what to do with it, ok. Even if you have seen it you probably do not know what to do with it, but more so if you have not seen it. So, we are going to get familiar with things like microcontrollers mainly in the lab, but today we will start discussing it, ok. So, next couple of weeks we will familiarize or give you an opportunity to familiarize yourself with these devices and then 3 or 4 weeks subsequent to that you will be doing measurement of different physical quantities while utilizing all the stuff that you have learnt about data processing and electronics, ok. So, that is what we will end up doing in this course. So, what are microcontrollers? So, a microcontroller is a general purpose brain. So, we will which can be programmed. It is like the definition of a human being also, right, some general purpose brain into which some stuff can be put and the human being will react in some way. This is very similar except that the programmer is not God or nature as you as the case with us the programmer is a human being. So, human beings have constructed these brains and human beings program them other human beings program them, ok. So, a typical microcontroller looks like this, looks like an electronic device, ok. This is a famous microcontroller, it is a peak microcontroller, lot of pins coming out, black stuff and lot of pins coming out, ok. It is an integrated circuit with lot of computational ability or lot of computational opportunity given for people who want to utilize it, ok. So, in terms of how it is going to look, it is going to look something like this, not necessarily the exact replica, you are going to be using something else, not this microcontroller, but it is basically going to look like lot of pins coming out of a black dubba, ok. That is how a microcontroller is going to look like. Let us have a discussion. So, this will this is where I will spend most of my time maybe 10, 15 minutes. What features you think, so first of all it is important to appreciate that a general purpose brain is useful, ok. So, what do we mean by that? Suppose I had to, suppose I had, I was God, ok and I had to design a human being. The sort of, sort of structure of the brain that I need to put together such that the brain will be able to absorb and operate in an environment that you usually see, right. So, that that goes in, that is what goes into the design of a brain, ok. Similarly, so the brain will have certain features, the brain will have capabilities to do certain things and will not have capabilities to do something else. So, let us have a discussion on what sort of features a programmable brain should ideally have, ok. What should it be able to do? So, I am going to ask 4 or 5 of you to blower whatever comes to your mind. So, take some input from the environment, what else? Memory, that is very good. So, one second, so someone said it has to deal with the external environment, someone else has said it has to have memory, what else? After taking the input it should provide the desired output and it should have some speed, ok, as fast as possible. It should be some fast or something, so don't just throw words here, suppose you had to design a human brain, what capabilities would you want in the human brain? Analyze the input, yes, it is a fairly straightforward question, it is not difficult. Just say whatever comes to your mind. Should be able to differentiate the inputs. Differentiate what? Whatever inputs are there, it should be able to differentiate. Ok, pink shirt there, you, is it pink or what? It should have a program to follow a particular algorithm if it is given an input. You have thrown some words, have a program to follow a particular algorithm if given an input, what other words will you throw, output, yeah that is a programmable, that is a program part of it, right. I am asking for, just look at your brain, what sort of ability does it have? Someone talked about memory, someone else talked about ability to take some signals and give some signals out. What other ability does it have? Keep track of time, that's very important, do you think your brain keeps track of time? How many of you say your brain keeps track of time? Others don't think it keeps track of time. So, I took this off now and I keep blabbering something here, you will sit here for eternity. I will just say 527, you will sit here for eternity. You do keep track of time, but not the sort of time that a clock keeps track of, clock keeps track of, ok. What else is your brain able to do? That's a very good point, brain is able to prioritize, a lot of things that keep coming to you, but you decide what you want to do, your brain decides to accept certain things, reject certain things, ok. So, ability to prioritize, what else? Perform functions on its own, any other basic functionality? Multitasking. Just say whatever you want, I mean it's fine, we are just having a discussion. Multitasking. Multitasking, ok. That's an important point, let's have a discussion on that. What do you mean by multitasking? Someone wants to say something, what do you mean by multitasking? Basically, it's like doing multiple tasks at a single time, but it's not simultaneous, it's slotting the time into slots and. So, you are dividing the time, you are apportioning the time into, you will do this task, then you will do this task, then again you will come back and do this task, again you will come back and do that task, etcetera, right. That's another thing that our brains are able to do, ok. So, suppose I am teaching here, then I get a phone call. Now, my brain recognizes that there is a phone call because my ears tell the brain that there is some sound coming and the brain interprets it as a phone call. So, I can decide to take the phone call, talk to the person, put it back and then come back to you and start lecturing again or I can decide that I won't take the phone call now, ok and continue lecturing. So, the point is that I am able to interrupt my scheme of working, process something and then come back to it, whatever I was doing, ok. That is also a useful feature to have if you want to deal with the real world. So, we are talking about the abilities that you need to deal with the real world. So, if you are a saint going and sitting in Rishikesh somewhere, you don't need all this, you don't need this ability at all, you can just like chill, let the world do whatever it wants to do, right. We are talking about ability to deal with the real world. So, you need memory. So, we list some of them, this is not exhaustive, but we list some of them. All the answers are already out there. One is that you need the ability to compute. If you want a programmable brain, you should be able to, somebody said analyze has something to do with computation, but ability to compute, you should be able to add, subtract, multiply, divide, whatever, ok. You need to be able to execute logic. If I tell you do this, if this happens and not if this happens, you should be able to execute that logic, otherwise dealing with the real world becomes difficult, right. What else? You should, someone already pointed this out, ability to receive and generate signals, ability to keep time, should know knowledge of time, ability to respond to interrupts. If you are not able to respond to interrupts, by interrupts, I mean by interruptions to what you are doing, then you will not be able to multitask. Will you be able to multitask if you are not able to respond to interrupts? You cannot because even if you know seemingly external thing is keeping you from or seemingly external thing is asking you to multitask, you yourself have to know that I am going to apportion this much time for this thing, then I will come back to something else, I am going to apportion that much time to that thing, then I will come back to something else, only then will you be able to multitask, otherwise you will just be executing the same thing, okay. So, these are the abilities that are usually available in microcontrollers, nothing more, okay. So, what you need to be able to do, you are going to be a user of a microcontroller, you are not going to design microcontrollers, you do not need to know the details of the internal circuitry, okay, but you need to know how to utilize them to deal with the real world, okay, that is the context in which we are having a discussion today, okay. So, many of you will, so there are a lot of unknowns that will be thrown at you, because of things to do with the construction of the microcontroller, things to do with abilities being described in a certain way that you need to be comfortable with, need to get used to, but what I am asking of you is the maturity to realize that what you need to be able to do is to utilize a certain subset of the resources provided by a microcontroller to your advantage, okay. So, the last statement I made is a critical statement, most people get overwhelmed by information that is provided when you have to deal with a microcontroller, okay. The trick is in actually understanding the overall sense of what a microcontroller is and utilize only those resources that are required and know that if you want to utilize some other resources, you can always do it, you can always learn it, okay. The idea is not to be exhausted, so please keep that in mind, okay. You do not sit with a microcontroller at data sheet and go pages after pages and 1000 pages and say oh I know this microcontroller fully, it is of no value, okay. What is of value is to realize that there are some resources provided, those resources provided are common usually across microcontrollers and the utilization or the usage of the resources also remain the same. The way to utilize the resources largely remain the same. If you have this sort of a background then you will be, you will find it comfortable for you to deal with different microcontrollers even if you have not experienced them yourself, okay. Clear, any questions about this discussion because this is a central discussion. If you have a reasonable appreciation of what we discussed, then there is a lot of detail which we cannot teach. It is something that you need to experience and learn, okay. But at the same time you need to be aware of what detail is important, what detail is not important for the sort of things that you are doing, okay. So we will come to some of these. So I am now what I am going to do is try and get you familiar with some terminology, okay and marry it with what we just discussed. Some terminology which you are going to repeatedly encounter that you need to get familiar with, okay. So I am just going to throw this picture here. So this is a typical set of resources provided by a modern-day microcontroller, okay. There are lots of words thrown there or lots of symbols, etc. We will discuss a few of them. And they are not difficult to understand from a conceptual angle. On the left side you see an oval. That part, so you see something called flash. Can you see that? The red thing on the left, it says flash. So this is that part of the microcontroller. You just think of a microcontroller as having a whole bag of resources. This is that part of the microcontroller which will accept programs, okay. So you can decide what the resources in the microcontroller need to execute or how they have to work with each other and the outside world. And that program or that set of instructions resides in something called flash. I mean why it is called flash, etc., is something else. It has to do with the technology of how that VLSI element is built. But as far as you are concerned, flash is where the program resides, okay. I am just giving you some terminology. You must have also heard of the term RAM, okay. You probably also know the full form. What is the full form? Random access memory. What is the random access memory? Yellow shirt, you tell me. The part of memory which I use to compute any signal it receives. As in the temporary, whatever. First of all, it's memory. So it has to remember. It's not computing anything. Yeah, but it's not the exact memory. It's a temporary memory which it stores and computes. Okay, anybody else willing to take a shot at it? Okay, so this is one kind of memory. It tends to be volatile in the sense that it's used primarily during runtime. When the microcontroller is powered on, you want to store some information, some variables, some values, etc. in some location for immediate retrieval. It's like when you're trying to do something, suppose you have some two, three numbers that you have to add, subtract, etc. In the middle, suppose you have to say take a number, multiply it by five and then plus three, divide it by four, whatever it is. All the intermediate answers you need to keep track of for you to get the final answer. It doesn't matter after you get the final answer what these intermediate numbers were if you're executing the process properly. So some memory elements are provided in a typical microcontroller for you to be able to do this. So I'm not being very precise here, but I'm just trying to explain in layman's language. So that part of the microcontroller which allows you sort of runtime memory is RAM. It does not compute anything. It only stores information which some other part of the microcontroller can retrieve or put into. At the bottom most you see something called a CPU. The CPU usually has two components. One is what is called an ALU, Arithmetic and Logic Unit. That is the one that computes eight plus three. Those sort of circuitry which do computation. All of you are doing a course in basic electrical engineering, right? So did you do any half adder, full adder circuitry and all that? Not yet. Anyway. So the CPU contains information on or sorry not contains information has ability to compute. It also has ability to store information as well as ability to process information. But the main part of it, one of the main parts of it is the ALU. Another main part of it is the timing and control circuitry. That circuitry is the one which orchestrates the functioning of different things. It is like a manager. Suppose I am a manager and I know that there are four or five people. One person can compute very well. One person can do something else very well. So I am the timing and control guy who will say you compute now give me the result. You take this result and you do this thing. Give me the answer or you put it outside into the real world. Take something else from somewhere, give it to me. I am like the manager. I do not really do anything. I just keep telling other people what to do. So that part of it is there in the CPU. Aside from this, there are some words thrown there which you may be familiar with. One word definitely you should be familiar with. What is it? One word right in the middle of everything that you should be familiar with by now. Time or you are familiar with already in the context of this course. You may be familiar with it from before. It starts with A or the ATD. That is analog to digital converter. That is also sitting inside the microcontroller. Modern day microcontrollers have a lot of features already inside them. You just have to utilize them properly. So you do not have analog to digital converter chips separately. All of that has been integrated into that package. What else? Anything else? Other things seem to be some jargon thrown around. Some of it you will get familiar with. So the purpose of this slide is to tell you that you need to get somewhat familiar with these terms and get familiar with the sort of resources. So a typical microcontroller can talk to the external world if programmed correctly can perform analog to digital conversion. After you get a digital number with the representation of the real world signal you can process that digital number in your CPU produce another digital number which can be converted through a D to A. All of that can be done inside the microcontroller. That is all you need to at this time be familiar with. So much about the resources, I am not going to go into each resource and say that you can do this, you can do that, you can do this, you can do that. One of the resources that you will utilize tomorrow is the timer resource. I will have a brief discussion on the timer resource by pointing to a data sheet of a microcontroller because you need to get familiar with reading data sheets also. So we will do that online now. So a little bit about programming these microcontrollers. So remember microcontrollers is a general purpose brain which can be programmed. The typical sort of resources or the abilities that you need also we have discussed need to keep time, need to have memory, need to be able to compute, need to be able to process interrupts etc. So you need to be able to program for you to exploit these resources. That is what you are doing in microcontroller programming. You are asking, you are creating a set of instructions which the resources which exploit the resources provided by a microcontroller. For example, if you can keep time, suppose you are a clock, you keep counting 1, 2, 3, that's all you can do. And I want to program to find out what the time is. I can poll you, I can say what is the time and you will tell me the time. So programming is basically utilization of resources of the microcontroller. Since the microcontroller can do the typical sort of programming operations that you have been exposed to, data operations, conditional, branching, loops etc. That forms part of microcontroller programming for sure. The other thing that you need to get used to, which you probably have not done in a CS101 sort of course, is to deal with resources with IO resources. IO means input output, stands for input output. IO resources which will deal with the real world. That's the only significant addition on top of whatever programming you already are exposed to. So it's not very complicated and we'll look at... So for tomorrow's lab, what you will end up doing are three things. Two things mainly and one extra. You will generate a one millisecond clock utilizing the timer module. So we'll discuss the timer module shortly. Not specifically the microcontroller you will use, but I will tell you what the timer module is, what it can do, what you are supposed to do to generate a one millisecond clock. You will also generate a one second clock. This is a bonus problem. One millisecond clock means something has to go high and low every one millisecond. Then you will have to generate a one second clock. Something has to go low and high every one second. Both seem to be the same thing, but they are not. You will have to get exposed to some minor tweaks. But that's a bonus. One millisecond clock everybody has to do. One second clock is bonus. And you will also make some LEDs blink. You will put signals out such that some LEDs will blink. This is all you will end up doing tomorrow. But in the process, it is an opportunity for you to learn how to use one resource or one or two resources of the microcontroller. The idea is not the resource itself. The idea is for you to be able to look at a data sheet and say that in order for me to use this resource, I need to look at the data sheet in this way. That is what the learning experience is. It's not about making an LED blink. You don't have to be proud about that. But you can be proud about reading a data sheet and figuring out what needs to be done for a given situation. This is what you will do in tomorrow's lab. Now I will get back a little bit to the timer module. I will show you how a data sheet looks like. What you are supposed to do when you look at a data sheet in sort of big picture advice. Any questions so far? Fairly straightforward stuff. One thing is that there is really nothing conceptual you are going to learn. It's a skill. Lots of pieces of information. If you are a good microcontroller programmer, you end up having to learn lots of different pieces of information. But conceptually, you can't say much. You just know it and you are utilizing that information. So I am going to open up a data sheet of a widely used microcontroller but certainly not of the type that you will see tomorrow. The reason why I am using a data sheet of a different microcontroller is for you to realize that there are different families, different manufacturers of microcontrollers. It does not matter as long as you have the general sense for what microcontrollers do, it does not matter much what set or what family you are dealing with. Tomorrow you are going to deal with a ubiquitous microcontroller. Any guesses on what it is? Those who are already familiar with? Yeah, you will see a ubiquitous microcontroller. I will ask you a question. When I come tomorrow to the lab, first thing I will want to find out is do you know what microcontroller you are utilizing? So that's the first question you have to be able to answer. So today, a typical manual looks like this. A whole bunch of information that is provided to you which will overwhelm you. Usually the first set of pieces of information that is provided is what is called a pin description. So we will go to that. So what this pin description tells you, I will show you the figure soon. It will tell you if you are given a microcontroller, so a black box with lots of pins coming out, what each of those pins are, that's all it is telling you. That you need to be familiar with. You don't need to know exactly what pin is doing what, but let me just show you the picture so that you are comfortable with it. So this sort of description is a pin description. Lots of pieces of information. You are going to get completely psyched out, run away. So your microcontroller is not going to be so involved, so you don't have to worry about it. I will show you the sort of pin description that you will have to deal with. But I want to give you a sense for the pin description that is there in a more useful microcontroller than what you will be dealing with tomorrow. So the first thing, you can note these things down. First thing you will need to be reasonably familiar with is pin description. The second thing you will need to be familiar with is the overall set of resources that are provided. So I will mention those or I will show you the picture that you need to be familiar with. So this sort of a picture. This tells you a whole bunch of resources that are made available to you. We have just discussed some of them. On the left top that you see is the amount of program information the microcontroller can carry. What size of program can you put inside the microcontroller is given 128 k, 64 k pertaining to RAM, 128 k to 1 megabytes of flash. This is the size of the program. Then what you see on your right hand side are analog to digital converter information. On your right hand side top. What sort of how many analog to digital channels are available? What is the bit resolution for the channels? Usually frequency of sampling is also given. So this is like a broad big picture description of the sort of resources that are provided. The bottom left, what is that part of it? Any guesses on what the bottom left part is? Based on whatever we have discussed so far. Some address, some data, something else there. ADR, ADDR. We will come to some of these a little later. The second thing you need to be aware of is the sort of resources that are available in the microcontroller. We will look at one such resource, which is called the timer module. Let me just go back here. If you look at the timer module, what its purpose is, it allows you to time your engagement with the outside world. So what sort of things do you want to do? At this time, accept this input. At this time, give out this input. This is all the timer module is doing. Its ability, you can program it to accept some input from the external world at a prescribed time and you can program it to put something out at another prescribed time. Or you can program it to do something at a certain time that you prescribed. So the program will say what needs to be done, whether you accept inputs or you give outputs at what times. That's what the program needs to say. How to say it? We will take a brief look at it. But basically the timer module allows you to do this. So what should the timer module have? What should the timer module internally contain for you to be able to do, accept something at a certain time, give something out at a certain time. It should have a link to the clock for sure. What else should it be able to do? No idea. I mean for how many people is this completely going like crazy? Raise your hands. 10-15 people. So we are discussing one particular resource of a microcontroller called the timer module. We said that a microcontroller needs to be able to keep time and do something with keeping time. The timer module allows you to work with the external world in accepting inputs and giving outputs. So we are discussing if I am the timer module and I can accept inputs at a prescribed time, somebody can tell me you accept input at this time, give this out at this time. What should I be able to do? Suppose I tell you at 6 o'clock run away from this class, what should you be able to do in order to execute my instruction? You should set an alarm on your mobile phone. What should you be able to do? It's not so difficult for you to tell me what you should be able to do. What else? Suppose I don't have to remember it, you keep shouting to me, leave at 6, leave at 6, leave at 6, read the clock. This is a fairly straightforward question. I don't know what the difficulty is. Maybe it's too straightforward to answer. I am asking this question, what should you be able to do if I tell you to execute the instruction that leave from here at 6 o'clock? So the first thing is that you should be able to read the clock. So you should have information about time. Second, you should be able to count. Suppose I tell you after 120 counts of this clock you run away, you should be able to count. And the third, you should be able to run away. You should be actually able to put some signal out or accept some signal. So the ability to actually do it. These are the only three things that are required. Fourth, you should be able to compare. If I keep counting that's not enough. I should be able to compare at what time I need to do what also. So the timer module has only these things. It has access to a clock. It has access to a counter which counts. It has access to a comparator which will find out if the counter has reached a certain value. It has access to some IO devices. So in order to utilize a timer module, you will have to say what things you will have to say what the clock speed is going to be. Are you counting every one second or are you counting every one microsecond, etc. You have to say what the clock speed is going to be. You will have to say how many counts do you need to count for that clock speed before something happens. When that time happens what do you need to do? Do you need to accept a signal or do you need to give out a signal? These are the only three major things that you will need to set. So that is what a timer module programming turns out to be. You will need to choose these three numbers. Clear? What is the clock speed or what is the count speed that you are going to deal with? How many counts need to elapse before something happens? What will happen when you reach that count? These three things you need to specify. And programming a timer module is only about learning how to specify these things. Clear? Very simple actually in principle and it just takes some practice for you to get used to it. So let us look at it without worrying too much about the detail that is there in this. So this bus clock is the clock information that is provided to you. There is an accumulator or something which is used for counting. Don't worry about the term accumulator etc right now. And a bunch of IO channels either accept input or give out input. Give an output. That is all a timer module is. So I will just describe to you what you will end up having to do. So because a timer module has to deal with some information which are put on some pins because you have to accept input from the external world and put outputs to an external world you will need to decide whether those pins are going to accept input or give an output. So you will have to say that this pin is going to become an input pin. This pin is going to become an output pin etc. So that choice is available to you. So how do you specify this choice? It is through the setting of some numbers pertaining to some registers. So I will just describe what a register is. Register is a set of bits. How many of you don't know what a register is? Don't know what a register is. You know what a bit is. A collection of bits forms a register. Some information is contained in a register. The reason why we are talking about collections of bits is because of the nature of how information is stored inside a microcontroller. So you can have a 8-bit microcontroller you can have a 16-bit microcontroller usually that refers to the register sizes. So what it turns out to be, suppose you have to set a certain register to a certain value and if you set that register to that value internally the hardware circuitry is just going to execute such that one pin is going to be an input pin the other pin is going to be an output pin. So programming a microcontroller or timer module of a microcontroller boils down to setting registers to suitable values. I will tell you what sort of registers you are going to deal with. So for example you will see a section called register description in every module that you go into. So today we are discussing the timer module right now but if you go to the ATD module again you will see a set of registers that you will need to understand. The overall picture should be clear to you. I need to be able to count I need to be able to look at some clock and some scaled version of the clock and I need to be able to either take information or put out information that's all the timer module is doing. Okay? So the main counter register in this case is actually a 16 bit register it is called this T C and T H can you see that T C and T H and T C and T L So T C and T stands for timer counter H stands for the high high bits L stands for the low bit. So if you have a 16 bit register you can count 65536 numbers if you have a single bit register how many numbers can you count 0 and 1 if you have 2 bit register you can count 0 0 1 1 1 0 0 1 4 numbers you can count Okay? So similarly if you have 16 bits you can count 65536 numbers 65536 in decimal Okay? So many numbers you can count So what you will be able to do right? If your count is 1 1s every second it will take 65536 seconds for that counter to go from 0 0 0 all zeros to 1 1 1 1 1 all ones Okay? It's going to take that long for it to count all the way through and see is much smaller than that obviously it is going to take far lesser time for you to reach all the 1 1 1 1 1s Okay? So the timer counter just has information it just keeps counting Okay? Every time it has to increment it will increment but what time it has to increment is decided by a scaled version of the clock Okay? So you will need to know how much to scale the clock by because only that gives you the unit of time this is only going to count every unit of time it increments by 1 So the timer counter is a very important register the T I O S you will see a similar register tomorrow Okay? I am going to leave it to you to find out what what the T I O S register is there are 2 registers required for scaling of the clock Okay? So So I will just describe few registers that you will have to use tomorrow the first register you will have to use is to decide whether a pin is you going to be used for taking input or giving an output Okay? The T I O S register the name may be slightly different depending on the microcontroller you are utilizing for you it will be the same tomorrow the T I O S register allows you to choose that Okay? So that is an important register for you to for you to know about your important register of course is the timer counter that I have already described So that is the T C and T What else do you need to specify? Counter is done What pin is done? One is scaling that is left What else do you need to be able to do? What to do when? When the timer counter reaches a particular value you will have to do something Okay? Is that clear? So what that value is how do you specify that value? So that is done through a bunch of registers that are provided 8 registers that are provided input capture, output compare registers T C X H and T C X L Okay? X stands for 0 to 7 There are 8 of these provided Okay? These registers contain information about what number that it will keep comparing itself to the timer counter When the timer counter reaches a certain number something will happen Okay? So that information is also programmed by you So T I O S, T C and T T C X Forget H and L for now You are going to deal only with 8 bit These 3 are important registers for you to deal with tomorrow Okay? Or equivalent of them What else? Only one thing that is left Scaling Scaling of the bus clock Okay? So the bus clock is made available You cannot go faster than that That is the unit of time cannot be faster than the bus clock It will have to be something that is a scaled version You can scale it down So I will leave it to you how to scale it down because you will have to use that for the 1 second 1 second problem Okay? Your bus clock will be running in megahertz So I am just pointing out the issue Bus clock will be running in megahertz Your timer counter will be 8 bit or 16 bit Let us say it is 8 bit Then you are in more trouble So If you have only 256 numbers and you are running in megahertz You will overcome those numbers or you will go from 0 to 1111 very quickly Okay? So you will need to keep track of how many of these overflows have happened You understand? It goes from 0000 to 1111 and again it comes back to 0000 It keeps counting that way Okay? So if you have to count large amounts of time with very small clock periods then you will have to keep track of overflows That is what the challenge is for the 1 second part of it Okay? If you have to keep track only of small small amounts of time that you will do through just looking at the TCNT and before it gets from 0000 etc to 1111 at some point you will just say if it reaches this value do this thing Okay? So tomorrow you will specify or you will make a choice for what the numbers need to be assigned to each of these registers Okay? That involves only looking at the data sheet and writing the numbers down TIOS equal to some 8 bit value just put the bits information 01111 01 etc If it is this then I have chosen this to be an input that to be an output this to be an input etc primer counter of course you do not have to do anything about it you have to read it The TC registers are the compare registers So if you set let us say you have an 8 bit timer counter So let us do that exercise So this guy is going from 0000 all the way to 1111 Okay? Then again comes back to 0000 and 1111 it keeps doing that just counting If your TC0 is said to be 0010 I am just giving some random example What happens is that when the timer counter reaches this value 00101010 Something will happen What will happen is decided by you whether you will accept an input or give an output That is where the TIOS part of it comes in Is that clear? Any questions about this? This should not be too difficult straight forward thing So you are going to count 1 millisecond So what you have to do program is very simple If you are in state 0 you have to toggle it to state 1 If you are in state 1 you have to toggle to state 0 Okay? So if you are putting an output of 0 equivalent of that is 0 volt will come out in your oscilloscope Then you will have to output a 5 volt at the time that is reached Then if you are at state 1 again you go back to state 0 at the time half millisecond is reached Very simple program that is what you have to construct So what you will end up doing is you will say TIOS is equal to some 8 bit number So I am just going to call it something like this This will imply that some pins are for input some pins are for output TC0 One of the things that are used for comparisons may be something like this Okay? Often times what happens is that you bunch these two things and express this as a hexadecimal number What is the hexadecimal version of this This is A So this becomes AA So you say that TC0 is 0XAA 0X standing for hexadecimal Okay? This program is make such statements That is all you are doing I will now tell you how a typical program looks like What these statements are going to be is something for you to figure out tomorrow by looking at the datasheet So what you are going to be provided with is a cross compiler interface not the same interface that you are seeing here So you are going to be provided with a special program called a compiler You know what a compiler is How many of you know what a compiler is What is it supposed to do Accept your instructions and generate stuff that is closer to what the machine will understand Okay? So it is a special program which translates what you write into closer to what the machine will understand Okay? So an interface will be provided something like this will be provided to you On the right hand side you see a typical microphone This program does nothing It just keeps running What you will have to do is get into this let's say this loop and make statements like TIOS equal to 0XFF Something like that You have to make these series of statements Okay? How does this thing know that TIOS corresponds to that register That information is also contained usually in a .h file Okay? In this case internally information is provided as to what this symbol TC0 stands for The compiler does not If you do not tell the compiler a priori that TC0 that symbol right there corresponds to setting that hardware register Then it will not know that you are actually talking about that register Okay? So that information is usually contained in a .h file which needs to be included Okay? And you will be given a template program Something that compiles so that you don't start fiddling around with something that does not compile You have to make statements TC0 is equal to so much TIOS is equal to so much TIE is the enable register is equal to so much etc That's what you will end up doing Okay? What you will have to produce is signals of this form Very simple On your oscilloscope You have to demonstrate this on your oscilloscope The other thing you will be doing So you will be writing numbers to some input output ports through which you will make some LEDs blink Okay? What sort of numbers to write What ports to write to Again the procedure remains the same Go to the datasheet Look for the resource which corresponds to the port that you want to utilize Ask yourself the question What do I need to know What do I need to be able to do Where to program me What do I need to be able to do To make some numbers go out somewhere The answer to the question will tell you What registers you need to set overall Then go to the module registers Understand the registers Utilize Or set those values of registers in the program This is the procedure for all of microcontroller programming Okay? So I just wanted to give you a brief sense for this Programming does not You cannot sit back and you know read a book and learn programming It does not work like that Only way to learn programming is actually program So this sort of an interaction is to tell you What is it that overall you are doing Okay? The details of that you will obviously get familiar with in your class So this time you will just get exposed to microcontrollers Next time you will write something little more sophisticated Next time you will also be dealing with real data You remember the RC filtering sort of experiment Next time you will try to do filtering But with programming You will take data Do an ATD Then get it into microcontroller Do some filtering there Get it out of a D2A So you will end up doing this whole thing Any broad questions If there are no broad questions How many of you have no clue What has been discussed so far You are still raising your hand Okay, good Who else Okay, so what I will do Is that your RAs and TAs will help in putting together the the manual as well as the sheet that you need to read up before the or when you come for the experiment I will also put resources pertaining to the microcontroller that you will be using on a consistent basis Okay, what you will be Your data sheet, what you need to be looking at Which registers are important I can give you those sort of pointers After that it is up to you For you to take forward and move on Okay, alright