Foundation of Microcontrollers - Masterclass | Akshay Gill | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Foundation of Microcontrollers - Masterclass

teacher avatar Akshay Gill, Ex-Tesla Firmware Engineer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

26 Lessons (2h 16m)
    • 1. Introduction to Microcontrollers

    • 2. History, Princeton and Harvard

    • 3. MCU Overview

    • 4. CPU Overview

    • 5. Memory Overview

    • 6. How does the MCU boot up?

    • 7. Instruction Set Architecture (ISA)

    • 8. Addressing Modes

    • 9. Logic levels

    • 10. Introduction to communication protocols

    • 11. I2C - Inter Integrated Circuit

    • 12. SPI - Serial Peripheral interface

    • 13. UART - Universal Asynchronous Receiver Transmitter

    • 14. Interrupts

    • 15. Reset sequence and watchdog timer

    • 16. JTAG - Joint Test Action Group

    • 17. Timers and Counter

    • 18. Prescalers

    • 19. PLL - Phase Locked Loop

    • 20. ADC - Analog to Digital Converter

    • 21. DAC - Digital to Analog Converter

    • 22. AC - Analog Comparator

    • 23. Input Output Ports

    • 24. How to choose a microcontroller

    • 25. Execution process of blocks inside a microcontroller

    • 26. Power up a microcontroller on a breadboard - Hands on exercise

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

Welcome to this course on the Foundations of Microcontrollers. This course will teach you the fundamentals of microcontrollers with to get you comfortable with these devices and whats inside them.

Who am I?

I’m Akshay, and I’ll be your instructor for this course. I have been fascinated with micro controllers since I was a child, and now I consider it lucky to have it as my profession. I currently write firmware for safety critical systems that go inside electric cars. With my knowledge of embedded systems over the past 10+ years, and working in Silicon Valley, I have gained a unique insight into what the industry needs and what the students are lacking.

How is this course different from other embedded systems courses?

This course is built from ground-up with a focus on microcontroller basics and it will teach you essential things that are often missed when learning the fundamentals of these devices.

With this understanding, you will be able to start working with microcontrollers in your own projects with confidence. I’m always available to help you through this journey if you have questions along the way.

Is this course for me?

If you are an embedded systems enthusiast, professional or student who is struggling to start working with microcontrollers this course if for you. This course does not have any pre-requisties and will build a strong foundation for you while teaching you things that one learns from many years of experience.

My personal guarantee

I am proud to say that I stand behind this course 100%, and guarantee you that you will get valuable information from this course.

With this, you can feel confident about your purchase and know that it is a valuable find.

Planned updates to this course

There will be quizzes and assignments added to this course on a regular basis to help you test your skills as you progress through the course material.

Who is the target audience?

  • Electrical, computer and software engineering students
  • Embedded systems professionals
  • Electronics systems professionals

Meet Your Teacher

Teacher Profile Image

Akshay Gill

Ex-Tesla Firmware Engineer


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction to Microcontrollers: welcome to discourse on the foundation off microcontrollers. In this course, you will get comfortable with my controller basics and learn how to start using them in your projects. Micro controllers can also be referred to as emcee use, which is short for micro control unit. Let's first start with what NMC you actually is. It is a miniature computer, which is found in all kinds of electronic devices. When you observe an electronic device around you, how can you tell if it has a micro controller inside it? If the device has some intelligence off its own than it usually has a my controller inside it, for example, air conditioners, mobile phones, dishwashers, refrigerators, microwave ovens, washing machines, gaming controllers and promotes all these devices are able to sense certain parameters of the environment around them and adjust their function accordingly. Now that we have identified some devices where my controllers air used, let's see what they're made off. Simply put em issues are made off the central processing unit, memory and some peripherals. Emcees performed two important roles monitoring and control tasks. One of the main components often EMC you is memory memory consists of RAM, random access memory and wrong read only memory ram in M. C. U is also known as data memory, and it is volatile in nature, which means that once the data is written in Ram, it'll be a raised as soon as you remove power to the device. Rome is also known as program memory. And as we know, Rahm is non volatile memory, which means that once data is flashed into the rum, it will not be erased. After many power cycles, the wrong can Onley be rewritten by re flashing the data onto the wrong. The function that your ensue performs is always flashed into the wrong. So it so that your device does not forget the function that it has to perform after a power cycle. How is the data containing the function that the device has to perform loaded into the flash memory? It is done by the I. C S P headers, which is short for in circuit cereal programming headers. These were based on communication protocols like S P I or J tied interfaces which will be studying later in this course. Now let's focus on types of EMC, you architectures to have a better understanding of what is actually inside it. There are two main types of architectures available. The first is Princeton or von Neumann architecture, and the second is known as Harvard Architecture. 2. History, Princeton and Harvard: let's dive a little bit into the past to know how these two architectures were created and how they got their names. It started back in late 19 forties, when the U. S government asked Harvard and Princeton University's to come up with a computer architecture. The US government used it to measure or compute the distances of naval artillery shells for defense applications. The Princeton University architecture is named after the chief scientist of the project, whose name is John von Neumann. Now let's talk about the two architectures in more detail. In Princeton architecture, a single memory interface is implemented. Single memory means that the memory is divided into two parts that is, program memory or wrong and data memory or RAM. Now what do you think? Single memory interface actually means well in terms of Princeton architecture. Er, as you can see the diagram, there's a single data line or a single interface between the CPU Central processing unit and the memory for data transfer. This makes the architectures simple and easy to implement. Let's not taken example to see how code execution is done in this architecture. Let's consider a case where we have to read a data bite from memory and store it in the accumulator. If you are thinking what isn't act, what actually is an accumulator, then just as a basic definition, remember that accumulator is a register inside the CPU, which is used for quick access of intermediate data. So whenever the CPU needs to access something really quickly and it's in the middle of a certain function and stored some data into immediately, this is what the task of the Q Miller is. So it's a register where the intermediate data is stored. Now back to our example. One thing to note is that there are basically two operations here. The first operation is to read the data bite, and the second operation is to move the data to the accumulator in Cycle one, which means in one clock cycle were able to execute one operation on Lee. That is, we have to read the data from RAM. In the second cycle or the next clock cycle, we will be able to execute the second operation, which is to read the data out of Ram and put it into the accumulator. So each operation takes one clock cycle. Now let's see What is Harvard architecture in this architecture? A separate program and data memory interfaces implemented Different memory means that the memory has separate space for program memory or Ron and data memory, or RAM, as we can see in the diagram. What this means is that the program, memory and data memory have a different interface, which is different data lines to the CPU. Harvard architecture became popular later due to the parallelism off instruction execution . Now you must be thinking, What is parallelism off instruction? Execution? So let's take a simple example to understand what this means, considered three operations that are shown on your screen right now, If you look at the third operation, you can see that it cannot be executed until we know the value of E and F. But Operation one and two I don't have any restrictions on them. As we have already defined the value of a B, C. D. In the code summer, consider if each operation can be completed in one unit of time or in one clock cycle, then in Harvard, architect texture. Due to the parallelism of instruction execution, Operation one and two will be completed in one unit of time or in one clock cycle, Operation three will be executed in two steps. The first step will be to read the values of E N F, and the second step will be the multiplication. All of this is done in another unit of time or in another clock cycle. So the total time taken to execute three operations here is just two units of time or to clock cycles, whereas in Princeton architecture it took one unit of time or one clock cycle to execute one simple operation. Let's take a look at another example to deepen our understanding. The task at hand is to read a data bite from memory and save it in the accumulator. If a previous operation is currently running than in the first clock cycle, the previous operation is completed and then in the same clock cycle. We also read the operation that is to move the data to the accumulator. So it means that in Harvard architecture, in one clock cycle, more than one operation is executed, whereas in Princeton architecture, in one clock cycle, only one operation is executed in cycle to we execute the second operation, which is to move the data to the accumulator and the next operation from the program. Memory is also pre fetched in the same clock cycle. So again you can see that in Harvard architecture, more than one operation is executed in one clock cycle, and due to this, each instruction is effectively executed in one instruction cycle. Instruction cycle here is different than a clock cycle. According to our examples, we can say that in Harvard, architecture to instruction cycles are executed in one clock cycle, and in Princeton architecture, only a single instruction cycle is executed in one clock cycle. Hence, we can say that Harvard architecture executes more instructions in the given time compared to the Princeton or Von Neumann architecture. 3. MCU Overview: Let's now see the basic architecture often EMC you. The diagram represents how an emcee was internally connected and what different parts the emcee constitutes off. Take some time and try to identify the blocks we've already discussed about. It's okay if something's feel new to you. For example, we all already know a little bit about the program memory, and we know that it is flashed by the I CSP interface. You can see this in the diagram as well. There is a bi directional arrow connected to the program memory on one end and on the other end, the I. C s P block is there. The bi directional arrow represents the bi directional flow of data. We also know about the data memory, and it's shown in the diagram as well. It's also known as S RAM, which stands for a static random access memory. Can you identify what type of M c you architecture is shown on your screen? If you guessed Harvard architecture than you guessed right, this indeed is Harvard architecture. As we can see, the wrong and ram are represented by separate blocks, which represents that our memory space isn't divided. The blocks inside the dotted lines represent the CPU. Next, you see this big bi directional arrow, which is known as the internal data bus off the emcee. You, in simple terms, A bus is a communication system that transfer data between competence inside a computer. Let's answer the next question. Why is there need for a bus? Well, we know that the emcee you is a combination of the CPU memory and peripherals, and all these things need to be internally connected to transfer data between them. This is where a bus is useful and provides the physical connection to transfer data between the different components inside the EMS. You on the right side of the emcee and there are a lot of different blocks that you can see . All of these blocks could be termed as features or purples of the MTU. These features are peripherals can be divided into different sub categories. So the first subcategory is the communication protocols and under which weaken group the blocks of ice core. C T w I s p i u art USB Ethernet in peril. And put up it in the second subcategory weaken group. The analog peripherals that is dak and 80 C In the third, subcategory weakened Group Way formed generation peripherals that is PW and the fourth subcategory weaken group timing and measurement peripherals, that is, timers, counters and the watchdog timer. Now let's talk about the block that's termed OSC. This is known as the as the oscillator, or clock generator. An oscillator or clock generator, is a circuit that produces a timing signal known as a clock signal Clock signal is used to synchronize a circuits operation. Let's not see the in circuit debug block. This block connects the emcee you to the PC via a special debug and programming interface. This programming interface provides a window into the internal workings of the MSU. The D bugger can control the CPU to run, stop or single step, and we'll read out riel time data from all of the emcee memories, and I o registers. This data is then shown on your screen on your debug screen to help you see what's happening inside the microcontroller at different points inside your code. 4. CPU Overview: take a look at the picture on the right. I've basically cropped out the CPE you part from the emcee Architecture Diagram. Let's understand three things here. How the blocks are connected aren't internally how the data is transferred between different components and how the code is being executed. Most of the internal blocks are connected through buses, which allow a flow of data from one block to the other. As we know, our code is flashed into the wrong. First, let's talk about the program counter, which is a register that holds and stores the address of the next instruction to be executed by the CPU. You can see the direction of the era from the program. Counter is towards the Rome, which shows that the program Cantor Counter can read data from it. But the wrong cannot write anything to the program counter. Now let's talk about the instruction register. This register holds the instruction currently being executed or decoded. Thanks. Thing you see on your screen is the instruction decode logic. This block decodes your instruction, which is sitting in the instruction register to to the machine level language, which is the language that the emcee on your stents and then uses this to drive the arithmetic logic unit. So this block received the instruction from the instruction register, decodes it and then sends it to the E l. You the arithmetic logic unit. In some cases, according to the code, the instruction decode logic can read or write the data on the data memory as well as you can see in the diagram. The S Ram and general purpose registers are two different parts, but in reality they're actually one unit which is also known as data memory or RAM. They're organized as shown below from address zero x 00020 x 400 The general purpose registers are there and from address zero x for a 1 to 0 x 100 to the S ram is accessible. These numbers zero x followed by a number shows a hex A decimal address space 0020 x 400 is an address space where the general purpose registers can be found and similarly for one to ones there is air to is the address space. Where s room is accessible whenever our code is uploaded to the emcee you. And as each of the statements in our code is compiled one by one, the variables are loaded into the data memory according to what the instructions are currently being executed. One thing to note is that the data memory is read or write accessible, which means we can read and write data onto the data memory. This data memory is also accessible to the e L. You as well, which means that the ale you can read or write data on it. So till now we've seen how the data is flowing among the wrong program. Counter instruction, register instruction, decode logic and data memory blocks. Now let's see how the emcee who knows where to store the data. This is where the stack pointer comes in, and it's a register that can hold or store either the memory address of the last location of the stack where the data was stored, or the memory address of the next available location on the stock to store the data. As you can see, the direction of the arrow from the stack pointer is towards the Ram or general purpose registers in the diagram, which means that the stack pointer can read and store the address where the data was last written or can be written on the data memory. But the data memory cannot write anything onto the stack pointer register. Also, one thing to note here is that the stack pointer is read or write accessible to the program . The next block is the Alieu like we talked about before, or the Arithmetic Logic unit. This is responsible for carrying out arithmetic and logical operations and modern MSU's have alia use, which can also perform bit functions. Ale use air directly connected to the general purpose registers for fast read or write access. This means that the aliens can read the data from the general purpose registers and can also write the data to the general purpose registers. Finally, the last block is a status register. This register can hold or store the information about the state off the processor. The status register is updated after all the Alieu operations air completed 5. Memory Overview: Now let's learn about memory off the microcontroller unit in detail. There are three types of memory found on the EMC. You rum read only memory or program memory RAM, random access memory or data memory E prom electrically erase Herbal program. Read only memory. So let's look at the e prom first. The E prom is a special type of rahm that can be erased and rewritten again. You must have learned before that wrong, once written to can't be rewritten or erased In modern days, we used the e prom electoral electrically erase herbal and the flash memory, which is another type of Abram. Let's see why we use E problems in microcontrollers. Consider the E prom like a tiny as D card, which is used to store configuration or other data, which you want to keep across. EMC reboots. So when we power cycle of microcontroller, we still want to keep that data. No, I have a question for you. Do you think the emcee you can use the E prom as program memory? The answer to that question is no, because the ensues do not use the E Prum as program memory. The prom is only used to provide external or extra storage options in your design. We don't want to use the E prom as program memory due to their slow read or write speeds, and also because the specified life off any problem is somewhere between 201,000 race cycles. Which means that after such numbers, say, after 100,000 raise cycles, we won't be able to write our erase the prom to change the code that we have set for the macron troller. So what type of room could be put US programmer memory? Well, this is where the flash memory comes in. This has better read or write speeds than a prom and also has a specified life of exceeding 10 million right or race cycles as compared to be prom, which was only 100,000 and recycles No. Let's talk about the program memory in some data sheets you'll find for MSU's. The program memory is also referred to as the flash wrong or flash memory. And as we know, Rahm is non volatile in nature, which means that the data is not erased after humorous amounts of power cycles. We also know that our code is stored and wrong, and if you want to run a new code, then the wrong has to be re flashed. Now let's take a look at how the wrong space is divided. Rahm is divided into two parts. First is known as a code or application flash section, and 2nd 2nd is known as the boot flesh section. And as you can see on your screen, the program memory, which is itself Rahm has a certain address as well. Address space In our diagram. We have considered a program memory off 12 kilobytes. Secrecy. The addressing of the program memory starts from the code application flash section and ends at the boot end of boot Flash section. The code or application flash section is where the code that you write sits in and also defines what the function the microcontroller has to perform. Before we talk about the boot flash section, let's first understand what a boot loader is. And as the name suggests, the boot loaders job is to assist the emcee you in booting up or starting up. It does two things. First, it looks to see if an external computer is trying to program the emcee you. If it is, then the boot loader gets the code and uploads the code into the code or application flash section of themes. You If a computer is not trying to upload a new code onto the into you, then the boot loader runs the startup code and tells the emcee you to run the user code, which is the function basically function code that you wrote previously, which is stored in the application of Flash section. So the boot loader tells the my controller to start running that code from the start. The boot loader is flashed in the boot flash section of the M. C. You when you open a boot loader foot, file one of the things you will see that it contains a small program, which has instructions to receive Data V, a predetermined interface like you art. So it copies this data to the starting address of the code or application flash section. And this is how the boot loader assists re flashing off the application flash section. If we look at the boot flesh section, which is where the boot loader sits in rum, it's the space defined to store the boot loader it's usually defined at the end of the program. Memory, for example, is you can see in the diagram are boot Flash Section starts from zero x 2800 and ends at zero x two F F F 6. How does the MCU boot up?: Now let's see how the emcee you boots up to understand the process. Let's use a flow chart. So when we plug in our board or the emcee you as soon as you power on the board errands you a reset sequences executed, which initialize is the program counter, and the initialization of the program counter is with the starting address off the boot flash section. Then the CPU executes the boot loader program and checks of the code if, like a new code is being uploaded to the microcontroller or not. If a new code is being uploaded than the boot loader up loads that code to the application flash section and then loads the address of the beginning of the application flash section to the program counter. Then the CPU executes the code from the starting address of the application flash section. If a new code is not being uploaded, then the boot loader loads theatrics of the beginning of the application section to the program counter, and then the CPU executes the code from the starting address of the application section. With this now, you have a high level understanding of the how the emcee boots up, and we'll read about this a little bit more in detail later on in the course 7. Instruction Set Architecture (ISA): Now let's talk about the instruction set architecture before we start. Let's talk about what is an instruction. An instruction is a command to the MTU. The program we write in C language eventually gets compiled down to instructions or commands that the emcee you understands. Let's assume that the emcee you understood the English language. In this case, an instruction would be a word, and the instruction set would be the vocabulary of the English language. A basic instruction structure is shown on your screen. When you send an instruction to the emcee you. It is divided in five parts. The first is the up coat. The second is the address of the operator, and one and the third is the address of the operate and to the fourth is a destination address, and the fifth is the address of the next instruction. The up code is known as the portion of the instruction, which specifies the emcee you operation to be performed. It can be arithmetic logical or a simple data manipulation or storage instruction. Once the instruction is defined, then we need to know how many operations do the instructions require. Let's first understand what an operator is in operation specifies what data is to be manipulated or operated on in an instruction, the address of the opera and defines from where the CPU will fetch of the operation and execute the instruction, then save the result to the destination address. The last part is the address of the next instruction, which has to be loaded onto the program counter the program counter. I've just as we talked about before is a special register inside the into you end the function on this registers to keep track off where we are in the program or where the emcee you is in the program. So loading the address of the next instruction onto the program counter lets the empty you execute the next instruction. Now, let's see what an instruction set architecture is, or I s a We know that I essay contains the vocabulary of the emcee language, but I s A is also a translator between the hardware and the software elements. It defines the data transfer and control mechanisms like branch jump and so on and also defines how to access the data. Most importantly, I said, defines the operations that the processor can execute So to sum it up, if a programmer does not know, I say, then he or she cannot write the programs in machine level language, I say also plays a huge role in M CR design and the implementation perspective off the empty you. So there are three possible data transfer techniques registered to memory, which is known a store memory to register, which is known as load or registered to register, which is known as move. We discussed earlier how the instructions air formatted, but we didn't talk about the size of the format. The instruction size can be of two types in variable or fixed invariable format. The instruction size can be 8 16 or 32 bit in fixed format. The instructions are of the fixed size, which is decided by the emcee of designer Now. First, let's talk about these two things called Sisk and risk. So Sisk means complex instruction. Set computer In general Sisk has a variable instruction format. Variable instruction format takes more time to decode instructions. It also has a smaller number off registers and no or none or inefficient pipe lining insist the instruction execution usually takes more machine cycles. The second is RISC reduced instruction Set computer. In this, Both operations are taken from the register and the result is also stored in registers. It is also known as load or store architecture. This is because you have to load operations to the registers from the memory and then have to store the result from the register to the memory. Usually risk has more or equal number of instructions, as in comparison to Sisk. 8. Addressing Modes: Now let's take a look at the address ing moans. Address ing modes. Describe how an instruction confined location off its operations in different address ING modes. We try to identify the effective address the effective addresses the actual memory address specified by an address ING mode. It is divided in the falling parts inherent, immediate, direct, indirect register, register, indirect paged, indexed based relative and stack in inherent address ing mode. You have nothing but the op code, and the rest of the things are implicit. We consider the operation is in the accumulator so it can involve an accumulator based instruction, for example, increments or detriment the value of the content of the accumulator. In such case, it involves Onley one ah, print. So if it's in the accumulator that that is increment ID or detriment ID, then the result will also be in the accumulator. There is no need to have any opera and address. That's why it's called Inherent or zero address. The next is immediate. In this mode, the operations are a part of the instruction. For example, consider we want to execute an addition instruction. So one operandi is in the accumulator and the second opera is in the instruction itself. This type of ad dressing is known as immediate in an addressing mode, absolute or direct address ing. In this mode, the instruction contains the address of the second operate, which which is stored in the memory. It is assumed that the first operation is stored in the accumulator indirect. In this mode, instead of specifying the address of the operandi which is stored in memory, we specify a unique address off the memory in the instruction and such. A unique address, in turn, has the address of the operation, which is stored in memory. Let's try to understand this better with the help of a diagram. So an instruction there is an address of the memory. Let's call it a one. When you check in location a one, you will find the address of a memory location called a two. Now, if you go to the owners eight to, you'll find the ah print so you can see an indirect link between a one and the ah perent and then Thus this is known as indirect address ing in register address ing. The operandi is stored in a particular register off a Register Bank, and the instruction specifies the register name or register address where we can find the opera and in register indirect. Instead of specifying the address of the operandi, which is stored in memory, we specify a unique address of the registered pair in the instruction. A unique address, in turn, has the address of the operandi, which is stored in the memory. Now let's try to understand this better with the help off a diagram. So in the instruction, there is an address off the register pair. Let's call it are one. When you check at location are one, we'll find another address of the memory, called a one. If you check the address a one, you will find the opera, and hence you can see an indirect link between are one and the ah print. This is known as register in direct address ing. Why do we need an address of register pair? We need the reddest repair because sometimes the address where the operetta stored can be variable, which is it could be 16 bit or 32 bit. In the paged address ING mode, the instruction has an offset, and an extra base address is provided which together gives the address of the ah print with that is stored in memory. Let's consider an example. Consider the offset as pages 0 to 9 in a book, and the base address can be 0 10 20 or 30. So generally paging divides your memory into equal sized memory locations. In this address ING mode, when you say in operandi is at address 11 than its base address is 10 and offset is one. This is used to reduce the size of instructions. There's no specific direct page register. There is no specific direct page register. Special function registers are also used to implement them as a direct page register an indexed addressing mode. Well, you we use this to implement data structures. In this mode, we use a special purpose Register X, which gives us an offset value from the index Registers of base. Address is also defined in the instruction, so these two things together give you the location on the ah print in the memory, and this is useful to access. The elements often array in based index addressing mode. A constant value is given in the instruction, and the base address has changed these two together, it gives us the address of the opera and in the PC relative address ing mode. We find the location of the opera and by providing address the address with respect to the program counter. So an instruction contains the relative address and the op code, and by the address in the program counter and the relative address both of these together, we're able to find the location off the ah print when a normal register is used instead of a program counter, it is also known as relative ad dressing room. In Stack, we have a stack pointer, which usually points to the top of stack. So when we say push G, then the value of the stack pointer is Decker minted and data is stored in the previous location pointed to by the stack pointer. Then if we again push a value H, then again SP value will be the stack pointer. Value will be detrimental and the value will be stored on the previous location Off the stack pointer, the stack pointer value is increment increment ID. When a pop command is executed 9. Logic levels: Now let's look at what our logic levels. You might have heard that a particular device, like an MSU, works on signals digital signals that are either low or high. Let's see what this means. Been working with an M. See you. They rely on binary logic to store process and transmit data or information binary logic for first to one of the two states on or off, which could be commonly translated as binary one or mine reserve. A binary one is also referred to as, Ah, high signal or represents on, and a boundary zero is referred to as a low signal or represents off. Simply put, a logic level is a specific voltage or a state in which a signal can exist. These air usually represented by the voltage differences between the signal and ground, but who defines the high and low signal. It's usually specified in the specifications sheet off that particular device. Another thing that is important to know is that what is active, high and what is active low. You must have heard about this in some microcontroller pins are active high, and some are active low. This just means that how you can activate that particular pin. If a pin is active low, it means it could be pulled low by connecting it to ground, which means that if you connected to ground, it's considered to be active. If a pin is active high, it must be pulled high by connecting it to high voltage. And high voltage is usually the supply voltage off your microcontroller, which is somewhere between 3.3 volts and sometimes it's also five holds. 10. Introduction to communication protocols: Until now, we have understood the internal architecture of the MSU and also understood what the logic levels are. Now let's see how microcontrollers talk to peripherals like sensors, devices except for their own connected to the external. Off the microcontroller communication protocols is a system of rules that allow the devices to transfer data in between the emcee you and an external device so communication protocols can be parallel or serial. Let's talk about parallel communication. These interfaces transfer multiple bits at the same time and usually require buses of data transmitting across 8 16 or more wires simultaneously. The data is transferred across all the wires simultaneously in waves of ones or zeros, and the data is usually transferred with the tick off a clock signal. Let's consider an example. Think off a parallel interface as a stream of cars where peril communication will be. An eight plus lane mega highway, which costs a lot of funds to build and over set him on a time, gets a lot of people to their destination. That air some problems is associated with the parallel communication. The first problem is that it takes a lot of funds to build or in the micro fuller language . It takes a lot of pins or takes a lot of wires. This will be a big limitation when you require the pins to be used to connect to other devices. If most of your pens already consumed by the peril communication, you have less normal amount of pence to connect to other external devices. The second is the length of the wires in peril. Communication would be usually shorter. This is because, as a left of the wire increases, the chances of the data getting corrupted also increases. This happens because the band, with of the wire decreases as the length of wire increases. Another way to think of this is that when you have so many wires, there's capacitance between any of two of these wires. So eight wire highway or eight wire peril. Communication has a lot of capacitance between each of these wires, which is why they can't go as far or communicate as far so the parent from occasional length has to be shorter to keep it from being noise free. Now, let's compare this to serial communication. In serial communication, we stream the data one single bit at a time, these interfaces can operate on as little as one wire even let's take a look at the advantages of serial communication. First, the length of the wire does not limit the data transfer. Ethernet, which is an example of serial communication, can work well with the length of wire is 300 meters. The data is not corrupted when it is transferred over long distances. Due to this on most my controllers, you will find different types of serial interfaces. Now, let's see, what are the major serial interfaces available on the EMC, You and how they're classified. Serial interfaces are divided in two categories that is, asynchronous serial and synchronous. Zero asynchronous serial means that the data will be transferred without the clock and synchronous cereal means that data will be transferred with a clock signal. Now let's talk about this ear is the synchronous serial interface, which includes two major serial interfaces like I square see eye to see an SP. I 11. I2C - Inter Integrated Circuit: I two C stands for Inter integrated circuit. It is also known as T. W. I, which stands for two wire interface, is called to wire interface as there are two pins through which the data is transferred, namely cereal clock line, SCL and serial data line SDA. One thing to note here is that the S D A line is bi directional, which represents the data can be transferred either way. On the right side of the screen, you will see a picture which shows an end channel mosque vet and an NPM transistor I to see pins are open drain or open collector. The two pins of the ice core see interface air connected to either a mosque fit or a transistor. When the SCL and SDA pins are connected to the mosque fit, it is called an open dream because the drain is left unconnected. When SCL and SDA lines are connected to a transistor, it is called open collector because the collector is left unconnected. I score C is known as an active low device, which simply means that the device works when the signal is low. Well, this is because if we look at the transistor of Moss Vet. In the diagram, you will find that for the mosque fit, the source is grounded. And for the transistor, the emitter is grounded. This is done so that I square seat works when the signal is low. This set up has another advantage. Due to this at a time on Lee, a single device can control the bus. Also I square see is half duplex, which means that at a time either it can send the data or receive it. Next thing to note is that on the ice core C bus, Each device has has its unique address on your screen, you can see different parts inside and I square See device. The CoreLogic represents what type of device it is on the master's side. It could be a micro controller and on the slave side, it could be a type of sensor. The data register is used to hold the data on both the slave and the master side. The data type is dependent on the type of the device. You can see that there is a clock generator on the master device, but there is no clock generator on the slave device. This is because the master controls the flow of data on the ice core C bus hence Onley Master can put produce the clock signal according to which the slave device Consent the data or receive it. Next you can see that there is an end channel moss vet for each pin and on each device every mosque fit source pin is grounded and drain is left unconnected which in turn now is connected to the same pin off the slave device. So SCL of the master to s seal of the slave and SDA of the master to SDA off the slave. Next, let's see why they're resisters on the ice core c bus These resistors are used to do two things. First is to control the speed of the drink data transfer. The second is to pull the ice core c bus high. Let's now take a look at the basic internal structure of the SDA or a seal line. You can see that the mosque fit is connected with an input buffer on the same line which allows a single data line to be used for bi directional data flow. Let's see how the ice core see did it transfer takes place. Consider there are three slaves connected on the ice Chrissy bus, as shown on your screen. In this diagram, we have considered that the electrical characteristics for all master and slave devices are the same. Next, we know that the I Square see sends data when the logic level is low. So let's take an example of how I score. See works by seeing an example of the SCL pin. It works the same for the SDA pin. Suppose that there is no resistors that are connected on the ice core seed bus. In that case, the logic on the Ice Square C bus is floating, which means that the bus is in active and the mosque fits are working as an open switch. But now if you need to talk to a slave, so how do you do that? We'll consider that the resisters air connected on the SCL and as DEA lines, These resistors will always make the ice core see line high. So whenever a signal is applied, which means when we want to receive or send the data, then the mosque. It works as a closed switch, which makes the logic level go low for the ice Chrissy bus. Many slave devices will require configuration upon startup to set the behavior of the device. This is typically done when the master accesses the slaves, internal register maps and these internal register maps have unique register addresses. They're sometimes referred to as the control register. A device can have one or multiple registers where the data is stored, written or red. The general procedure for a master to access a slave device is the following. Suppose a master wants to send the data to a slave. The master transmitter sends a start condition and addresses the slave receiver. The master transmitter now sends the data to the slave receiver. The master now terminates the transfer with a stop condition. If a master wants to receive the data from the slave, the master receiver sends a start condition and addresses off the slave transmitter. The master receiver now sends the requested register to be read from the slave transmitter . Now the master receives the data from the slave transmitter. And finally the master terminates the transfer with stop condition. I square see, slaves can have an address ing, which is seven minutes or 10 bit in seven mid address ing. The slave address will be a seven bits, and the eighth bit represents whether it's a read operation or a right operation. So in seven, but address immune connect up to 127 devices. There's also an eight bit address ING mode. Sometimes you'll come across and in eight bit address ing. It's just like seven. But address ing where the 1st 7 bits has the address of the slave in the eighth bit represents the read or write operation. Now the 2nd 1 is the 10 bit. Addressing. Your slave address in this case will be 10 bits, so the data will be sent in two bites. The 1st 5 bits of the first bite will include some special indicator. If you want to talk to a 10 bit I square, see slave and then the form out of the data will be shown like it isn't figure. The read or write bit will represent whether it's a read operation or write operation, and then the rest of the address will be sent. 10 bit address. ING provides support to connect up to 10 to 3 1000 and 23 devices on the same to wire bus 12. SPI - Serial Peripheral interface: Now let's talk about asynchronous serial, Also known as you Art. You are stands for universal asynchronous receiver transmitter, and as the name suggests, it works without a clock signal and you aren't communication to U Arts. Communicate directly with each other. You are acts as an intermediary between parallel and serial interfaces. Now let's see how you are. Devices can be connected to connect to you our devices to each other. You always have to connect the Rx off the first you are to the T X of the second you art and T X of the first you art is connected to the Rx of the second you art. Now let's see how the data is transferred between two. You are devices your devices or asynchronous serial devices generally fall. This some rules to send nervously the data, and these are barred great data bits, synchronization bits and parity bits. Badr eight specifies how fast the data is sent over a serial line. It's usually expressed in units of bits per second or bps. Badr Aid can be just any value within reason. The only requirement is that the both both the devices operate at the same rate usual bod rates are 1,606,000, 809,600 706,601 15 200. The higher the Badr Aid goes, the faster the data is sent or received. Now let's see what happens if you don't follow this rule, which is that the bawd rates of the two devices that are talking on you art is not the same . If the two devices air not set at the same Badr ate, it simply means that the two devices aren't speaking of the same speed. Because of this, the data will be misinterpreted or completely missed. And if you try to see the data when the body rate isn't the same than it looks something like this, you can see how important it is to follow the Badr eight rule. Now let's see how the data is framed. Each block, which is usually a bite of data, is transmitted and actually sent in packets or frame of bits. Frames are created by data bits, synchronization bits and parody mitts on your screen. You can see how the date is framed and the usual size of different parts. Now let's get into details of each of these frame pieces. First, let's talk about data bits. This is the most important part of every cereal packet. We can also call this part as data chunk because its size isn't specified. It can be between 5 to 8 bits. Once the data length is decided, both serial devices also have to agree to an Indian ness of the data, which means how the data is sent. Is it MSB first, most significant bit first or least significant bit first. Now let's see. Why does this matter? Suppose you want to send 11001101 on the zero line, then in MSB. First, it'll be sent as 11001101 But in L SB. First, it will be sent as 10110011 So, in l s B, the data is simply reversed. It's the least significant bit is sent first and then the most significant bit is sent last . Next is the synchronization bits These air two or three special bits, which were transferred with each chunk of data. There's a start bit. And to stop it. As the name suggests, these bits mark the beginning and the end of the packet. There is one start bit, but the stop. It can be configured to either one or two bits. The start bit is always indicated by an Idol data line, going from 1 to 0, while the stop bit will transition back the Idol state by holding the line that one. Next, let's see the parity bits. Parody is a form of a very simple, low level air checking mechanism. It comes in two flavors, odd or even to produce the parity bit. All 5 to 8 bits of the data bite are added up, and the even ness of the some decides whether the bit is set or not. For example, assumed that parody is set to even and now we have a date. A bite like zero B, which means it's binary. 11001101 So if we add all these bits together, we can see that the there's an odd number off ones. So the so if we add all of them, it'll be five. So now that the pet. So now we can see that the parity bit would be set to one. Considering the above case, if the parody mode was odd instead of even then, the parity bit would be zero. The parity bit is optional and not widely used because it slows. Your data transfer also requires both sender and receiver to implement air handling. Now let's see an example to understand all the rules discussed above, and the most common example you will find is ninety six hundred eight and one 9600 represents your body rate. Eight represents the size of data and represents no parity and one represents to stop it. Let's consider if a device is sending characters A and B and how is it sent over the serial line. Two packets will be needed to send this data. It will be converted to binary first before the data is sent, so the value of upper case A in binary is 01000001 and the value of upper case C and winery 01 000011 No, If the Indian ness of the data isn't specified, then always consider that the data is sent ls be first, least significant bit first. So when the first pack is a sent, it starts with the start bit that is zero. Then did Obits, which is in l is be first means 10000010 Then comes to stop it. That is one and this represents one bite of data is sent. Now, the second byte of data is sent after this, which again starts with start bed zero. Then comes the data in L S B format, which is 11000010 And after that comes to stop it. This is how the data is transferred in the U art or asynchronous serial interface. Now let's see what will happen if we connect multiple devices on the you are lines. Asynchronous serial communication is designed to allow just two devices to communicate. Communicate across one serial bus. If more than one device is trying to transmit on the same serial line, you could run into something called bus contention. Bus contention means that two devices are trying to access the bus at the same time. There's still ways to get around this and you can connect multiple devices on you art. So let's see what type of configurations first will never work. So consider you have multiple transmitting devices on you art and a single the receiving device on the U art bus. The connection for this case is shown on your screen now, and this configuration will not work because there are two devices transmitting across the bus at the same time, which is not good at all. This will cause bus contention. So in this case, basically no device will be able to send its did across. And even if the data is sent somehow, the receiver will receive a scrambled version off the two transmitters. The data from the two transmitters Let's see a case now where a single device is transmitting and there are two devices that are receiving the connection for this case is shown on your screen. This could be done after looking at the data sheets off the particular device you're trying to connect to. For example, if you're connecting a serial LCD up to an artery, no, the easiest approach, maybe to connect the LCDs module Rx line to the artery noti Exline. The Arctic Arduino TS line is already connected to a USB Programmers are Exline internally on the board that still leaves just one device and control of transmission line. So although this type of connection is not recommended, but it still might work, the only problem is that when the master is sending the data out on the U art lines, the receiver, the two receivers don't know like who the data is. Four. Was it for the USB programmer, or is it for the L City assistant concept causing problems? 13. UART - Universal Asynchronous Receiver Transmitter : Now let's see the S P I protocol, which is cereal peripheral interface. This is an interface bus commonly used to send data between micro controllers and small purples such as shift registers, sensors and SD cards. It uses a separate clock and also separate data lines. It also has a select line which chooses the device that you want to talk to or the microcontroller wants to talk to. And it has four pins. SCK cereal clock. Mos i mosey m I s O miso. So mostly stands for master out. Slavin and Miso stands for Master enslave out. And finally it's CS Chip Select or slave Select SS in the SP I type of communication as well. Only the master has the capability to produce the clock signal and control the data flow. S C K stands for Syria clock and as the name suggests, it is the clock signal mostly stands for master out. Slavin, this is the data line which is used to send the data from the master to the slave Miss O stands for Master enslave out. This is also a data line which is used to send the data from the slave to the master Next is S s, which stands for slave Select or sometimes referred to a C s, which stands for Chip Select. This is important because we we can connect multiple slaves on the same SP I bus as well. So the master has toe have a way of selecting which slave it wants to talk to. And it does that using the SS line a simple master to slave connection is now shown on your screen. Let's see how the data is received in SB I communication. So SP has a full duplex communication because has separate send and receive lines, and thus you can transmit and receive data at the same time. As a master controls the data flow and generates the clock signal, it can send the data to the slaves very easily. The problem occurs when a slave has to send the data back to the master and in this case, the master generates a prearranged number of clock cycles, and the slave will put the data onto the third line called M I S O miso. The master generates a clock signal and it must know in advance when the slave needs to return data and how much data will be returned in practice. This isn't really a problem as s b. I is generally used to talk to sensors that have a very specific command structure. For example, if you send the command for re data to a device, you know that the device will always send you, let's say two bites in return. In cases where you might want to return a variable Mount data, you could always return one or two bites specifying the land for the data and then have the master retrieved the full data. Let's now see the s s line. Uh, and what it does. This pin is used to select a slave that should wake up or receive or send the data from the master. And it's especially useful when multiple slaves air connected on the same bus. The S is line is normally held high, which disconnects the slave from the SP I bus. The SS line is normally held high, which tells a slave that it is in normal mode, which is it's not being talked to right now. Just before the master data is sent to the slave, the line is brought low for that specific slave that the master is sending the data to. This activates the slave, and it's ready to receive the data. Once the master is done talking to that slave, it makes the slate and makes the SS line high again. Let's see how he can connect multiple slave devices on SP I. There are two methods to connect multiple slave devices to a single master. The 1st 1 is the bus type connection. Each slave will need a separate SS line to talk to a particular slave. The master will make that slaves SS line low and keep the rest of them high. But lots of slaves will require lots of SS lines. The other method is to connect multiple slaves in a daisy chain fashion. In this, the me so off one is going to the most see line off the next, and a single SS line goes to all of the slaves. So since the SS line is going to all the slaves, pulling it low will activate all the chips simultaneously. In this layout, the data flows from one slave to the next 14. Interrupts: Now let's talk about interrupts like the name suggests is something which breaks the continuity off a process but the rule. But what role does it play in the M. C. You interrupts? Stop the flow of code execution and bring another process or set of instructions, which need to be processed urgently to the CPU. So if it's running a certain piece of code and interrupt happens now, the CPI will stop what it was running and not to start processing. The interrupt. The code that runs when an interrupt occurs is defined in the I s are or interrupt service routine. Notre two types of interrupts harbor and software that's first look at hardware interrupts hardware interrupts are those which are generated by harbor devices. For example, when you move your mouse or press a key on your keyboard, it is known as a hardware interrupt on microcontrollers. Most commonly found hard rain Trump's are reset power on reset and external in trips. Hardware and Trump's are asynchronous most of the time, which means that they occur in the middle of an instruction execution from the normal process or a number normal code flow, and hence they require additional care in programming. Now let's look at software in Trump's Soften Trump's air those which are deliberately introduced by softer instructions to generate user defined exceptions. Also, software trips can be used can be caused by an exception as well. For example, if we divide a number by zero, this will generate an exception, which is a type of software in trucked. In this case, the user will see an error message displayed in the D Bugger console. It's offering. Trump's are synchronous as they're executed when the code is being executed. Now let's see what an interrupt vector table is. As the name suggests, it's a table, which shows all the sources of the interrupts in a micro controller. An interrupt vector table shows the address of these interrupts sources as well. One thing to note is that the interrupt the lowest address will have the highest priority. And as the addresses increase the priority of the interrupted decreases, The interrupt, which is at the end of the interrupt vector table, will have the least least priority. Now let's take a look at an example of two in Trump's of decreasing priority reaching the CPU at the same time and see how the CPU handles the situation. We will consider from this figure that PC and zero and 80 see in Trump reaches the CPU at the same time, in this case, to see pure first handle to the PC interrupt zero. And once the PC in Trump zero is executed by the CPU, then it starts to execute the 80 c Interrupt. Interrupts are important because by using them we can prioritise the tasks assigned to the emcee you to perform. Now let's take a look at the difference between polling and interrupts. Polling essentially means that there's a loop running inside your code that is checking a certain statement, and if that statements true, then it runs a certain task. If it's not true, it keeps pulling. Now you can see, probably liken evident problem with this. The problem is that it consumes to seep you. Clock cycles are or the CPI is actively checking over and over again a certain condition, whether it's true or not, whereas the CPU resource is could be better used to run some other operation during this time, so a polling operation or if you set up on operation to be in a polling format, you would set up a loop, and then a certain condition is checked over and over and over again and interrupt. On the other hand, the CPI is running their its own task, running some task and interrupt happens and then on Lee. When the interrupt happens, that's that Interrupt task, which is defined in the IAS, are interrupt service routine is run, so the very evident difference over here is that the CBO is able to do all the other tasks that it needs to until the interrupt happens. When the interrupt happens, it handles that interrupt by running the code that's defining the interrupt service routine and then goes back to running the previous task. So you can see how that the interrupt way is a little bit more advantage advantageous than the polling way. In the interrupt way, the the CPU is not wasting clock cycles by over by checking a certain condition over and over again. It only runs the code when the interrupt happens, so this is a difference between pulling and interrupt 15. Reset sequence and watchdog timer: Until now, we have learned a lot of things about microcontrollers and how they work, and we also learned about different features the microcontrollers have, As we know, any electronic device can sometimes stop working, and during that time we either switch it on or off or we perform a reset. Same goes for the microcontrollers as well. But MSU's have different sources from which a reset can occur. Let's talk about the different research sources that are present in the M. C. You the's air also defined in the vector table. One thing to note here is that they're these recent sources work like in Trump's. They tell the answer to stop what it's working on currently and start again from the beginning to be able to achieve all of this in the microcontroller. Different types of reset sources are termed under hardware interrupts. One thing to note over here is that hardware interrupts always have high priority because of that different type off. Recent sources comptel the microcontroller to stop the code execution and restart itself. We know that dearing code execution microcontrollers always have some values in the registers, namely the stack, pointer, accumulator and so on. But what happens to these values in the registers right after a reset occurs on your screen , you have a table which shows the values of different registers in an 80 51 basic microcontroller. Just after a reset occurs from this, you can see that after a reset, the value in these registers is also reset to their respective default values, as shown in the table. Let's not talk about the most common types of recent sources that are present in the MSU. The pin that is used to reset is called the reset pin of the emcee You. Most of the emcee you boards in the market provide reset functionality every time when you open the serial port on your laptop or PC, the MSU is reset using the reset pin that is present on the MSU. Most of the emcee boards also have a reset button on them, and then Button also provides the user to be able to reset at their demand. To understand, reset ruble taken example off an Arduino Oh no board. One of the hardware flow control lines DT are off the 80 mega eight u two or 16 year two. Microcontroller is connected to the reset line of the 80 mega 3 28 via a 100 Nana fared capacitor. When this line is pulled low, the reset line drops long enough to reset the trip. The artery No I d. Uses this compatibility to allow you to upload code by simply pressing the upload button in the interface toolbar. This means that the boot loader can have a shorter time out as lowering off the DT are can be well coordinated with start of the upload. If we were to understand this in simpler words, the signal on the reset pin is high, which usually means that reset is not activated and to implement a reset. The signal on the pin is made low for a short period of time, and that's how the microcontroller knows that a reset needs to happen. Now let's talk about another popular reset source, which is known as power on Reset. This reset type is inbuilt in the microcontroller itself and does not require any extra pin or any extra circuit to be air faced with. This is used to reset the microcontroller when the voltage supplied to the microcontroller is less than the operating voltage off the EMS you so power on Reset provides a way to the MSU to self check whether the emcee who is receiving proper power or not as an as the name suggests, power on Reset is also activated. As soon as you power on your M. See you. Let's see the most common circuit you can implement for power on reset. This circuit usually includes a resistor and capacitor, which is connected to a Schmitt trigger that serves two purposes. A Schmitt trigger is a special type of op. AMP. The first purpose is to convert the analog signal to a digital signal, and the second purpose is that it is used as a comparator circuit as well. Power on Reset provides a self check solution to the MSU to check whether the voltage applied to it is greater or equal to the operating voltage off the emcee You If the emcee who is receiving less power than the operating voltage then the power on reset circuit, which we saw will hold the power on reset line low until the operating voltage supplied to the emcee is above the threshold, the minimum threshold that it needs to operate when the operating voltage goes above the threshold, Then the power on reset also goes Hi, which tells the M soon. Now we have enough power to start running the code execution. Now let's talk about another feature in microcontrollers, which is an one more source of a reset. It's known as the Watchdog Timer. We need embedded devices to be self reliant because they're usually sitting somewhere out in the field and you can't have access to them. So watch dog timer is, ah, hardware timer that automatically generates a system reset. If he CPU fails to periodically reset the wash talk timer, it automatically resets an embedded device that hangs or stops executing. Because of a software fault. A watchdog timer is clocked from a separate on ship oscillator, which creates a clock signal for the watchdog timer on Lee, the CPU is clocked from separate oscillator. Let's see a typical watchdog timer set up. The CPU has to restart the watchdog timer periodically to hold off the system reset from the watchdog timer due to a software fault. If the CPU is not able to restart the Washington timer, then the Wash Doc timer has an internal recent line to the CPU, which tells the CPU. Now you have to reset to fix the problem. Some EM seu manufacturers use the wash stock timer to issue an interrupt and also provide a safe shutdown procedure for the emcee. You in case off a software fault, let's consider an example to understand why the watchdog timer is important. Say there's a space probe and its out somewhere in deep space. And due to some software fault, the CPU stops working as it should. Now, if the CPU stops working and it's remote now, you can't even remotely access that space probe. So in this case, the wash talk timer will notice that the CPU hasn't reset the timer in a long time, and because of this, it will cause a safe shutdown for the probe and then do a restart for the probe in the hope to get or fix the problem that had occurred. So in this way, the watchdog timer is able to save the space probe from being unusable when it's far away from any human contact are from anyone to be able to service it 16. JTAG - Joint Test Action Group: Now let's learn about another feature that is found in today's microcontrollers, which is called J Tag. This stands for Joint Test Action Group. It was made by the collaboration from different manufacturers and was accepted as the industry standard. Later, J Tag was conceptualized to solve the problem of how to wear if I designs and how to test printed circuit boards after their manufactured. But now J tag is also used to a lot of a lot of other things, like debugging J. Tag replaced the in circuit debunker, which was the previous debugging way. Now, in most modern microcontrollers, we used J Tactic debug. So J Tech is used as the primary means of accessing sub blocks off the ICI's and making it another essential mechanism for debugging embedded systems, which may not have another debug capable, capable communications channel. On most systems, J tag based debugging is available from the very first instruction after CP reset, and this assists with development of early boot software, which rent runs and before any set up are any other code is inside the microcontroller. The second use of J tag is storing for more, so Jay Tag also allows device programmer hardware to transfer data or write software into flash memory. Also, internal monitoring capabilities such as temperature, voltage and current readings may be accessible via the J attack port. Another use of J tag is boundary scan testing. J tag Boundary scan technology provides access to many logic signals off the complex. I see, including the devices pins. This permits testing as well as controlling the states of the signals for testing and debugging. And through this, both software and hardware manufacturing false can be located easily. So this type off use of J tag is really, really helpful in production or manufacturing tests. So J Tech interface has five pence. Tedy, I test data in T o. Test data out TCK test clock T. M s test mode. Select T R S T test reset, which is an optional pin now figure is shown on your screen so you can recognize what a J Tack port looks like on your board. 17. Timers and Counter: Now that we have learned the internal workings off a microcontroller, let's venture into the world of peripherals. So peripherals just means the extra features that are microcontroller has, and one of the things peripherals do as well is let the microcontroller core interface with the outside world. So start. Let's start with the timers. Encounter peripheral. The emcee timer counter range includes eight bit, 16 bit, 32 bit and 64 bit timers. Encounters eight bit timer counters can count up to two to the power 8 16 bit timer counters can count up to two to the power 16 through two bit timer counters can count to two to the power of 32 similarly 64 bit timer counters can count up to two to the power of 64. So more commonly found timer encounters on the Emcor limited to eight bit, 16 bit and 32 minutes so timers encounters can count up or countdown. And what happens when they reached their threshold? Well, it restarts again from zero. So we taken example. We know that an eight the timer counter can count up to two to the power of eight, which is 256 and the counting actually starts from 0 to 255 Then, after counting till 255 the timer counter restarts from zero again. But it also raises an interrupt to the CPU and this interrupt tell to seep you'd that the counter has reached its threshold. Timers are typically constructed using oclock source and a counter counters count clock periods that are input to them. Timers are typically constructed using oclock source and a counter counters, cup count clock periods that are input to them. Some counters count up and some counters count on down. A typical representation off a timer counter is shown on your screen right now, and we have so So we have an and gate and the counter gonna connected at the output of the and gate at one terminal of the engage the clock signals applied and at the other terminal of the N Gate, let's consider a signal. T is applied. Signal T can have two states high and low when signal T is high. The overlapping part of the clock signal is produced at the output, so consider make signal T high for three clock cycles. Then, at the output of the and gate three clock cycles air produced. This output is now fed into the country unit. The counter unit now counts the three clock cycles and gives the output of three. Now let's see how we can use the timer counters in our applications. A micro controller uses the timer counter for the falling major applications for measuring time to trigger interrupts at a specified time interval and for way form generation, the timer counter blocks can generate and interrupt when the timer contra overflows or when the timer counter is used in. Compare Mota's Well, this is another feature off the timer profile. In this way, you can define a value to which the timer or counter will count up or countdown. And when that value is reached, it'll given interrupt to the CPU, telling that that amount of time has been passed. So now the interest CPU takes that interrupt and does whatever periodic task has to be handled. My CPU 18. Prescalers: Let's not talk about pre scale er's. We know that the timer counter counts according to the clock cycle, so of one clock cycle is completed, then the timer counter will have the value one. But what if you want the timer counter to count one after every eight clock cycles? This is where Preece killer comes in. The timer counter in the Emcor is connected directly or indirectly to the system Clock Pre scaler divides the clock signal by producing a pulse. Say every two to the power off P where P is the number off pre scaler bits. And this is defined in the emcee data sheet. This is how we can reduce ah high frequency clock signal to a lower frequency clock signal by integer division. So let's consider an example. The problem that we saw before that is to count one after every eight clock cycles. So if P value is three, this means that the priest killer is set to tutor the free, which is eight. Then the pre scaler would divide the clock by eight, which simply means that when eight clock cycles air completed, then the timer counter will count toe one and after the eight clock cycles, its value another eight clock cycles its value would be to. So you can see how using the priest killer we were able to slow down by an interviewer. Amount of time, how the timer counts up or count stone. 19. PLL - Phase Locked Loop: Now let's talk about a peripheral or a block inside the EMS. You called the P L L. Now let's say our emcee works on 16 megahertz clock, but our USB interface for the microcontroller works at 48 megahertz. There's no external oscillator on the board, which is producing the 48 megahertz clock. Then how is it possible to have these two different clock signals inside the MSU? So in this case, the MSU code execution still works on the main 16 megahertz clock, but the USB interface gets the 48 megahertz clock through the P L O PLL stands for phased locked loop, and this block takes the 16 megahertz signal in, boosts it to 48 megahertz and feeds it to the U. S. Be powerful. For example, if you take an emcee like an 80 mega 16 you to microcontroller. If you look at the data sheet of this emcee year, you'll find at the MSU itself works on 16 or eight megahertz, and the USB works on the 48 megahertz clock. So if we look at the block diagram, the clock signal produced from the external loss later can be between 2 to 16 megahertz. So between two and 16 megahertz, let's consider the clock signal is 16 megahertz. So to boost the signal to 48 megahertz in the microcontroller, we passed the clock signal to the priest killer first, which devised the clock signal in half. And since oclock single off eight megahertz to the P l O, the PLL now boosts the signal six times, which in turn makes the clock signal eight times six equals 2 48 megahertz. So this is how the priest killer and the pillow blocks are used to reduce or increase the clock frequency as needed by the blocks inside our microcontroller. 20. ADC - Analog to Digital Converter: Now let's venture into analog and digital digital conversion. A. D. C. Stands for analog to digital converter, and, as the name suggests, this peripheral converts the analog signal to a digital signal. Most sensors, like the temperature sensor and pressure sensors, generate an analog signal. But to get the sensor values inside the microcontroller, we need to convert it to a digital signal. And this is where an 80 C comes in. An 80 C can vary greatly between different microcontrollers. Different. 80 Cesaire available like 18 8 bit, 10 bit, 12 bit and 16 bit 80 sees 80 C of eight bit. Has the ability detect two to the power of eight, which is 2 56 and discreet analog levels. This is also termed as the resolution of the 80 C A 10. But a sea similarly can detect to power 10 which is 10 24 discrete analog levels. Similarly, 12 bit can do 4096 and 16 bit can do 65,005 and 36 discreet analog levels, so as we're increasing from eight bit to a 16. But 80 C were increasing the resolution of the 80 C, which basically means that we can detect very small changes in a 16 but 80 C, but we won't be able to take those changes of voltage in any ABC there a few different ways to achieve the analog to digital conversion. One common feature is called Sample and Hold. So in sample and hold, we used the analog voltage to charge up an internal capacitor and then measure the time it takes to discharge across an internal resistor. The microcontroller monitors the number of clock cycles that pass before the capacitor is discharged. The number of cycles that it takes is then given to the CPU, and then, and that's how it computes what the digital value is. So this is known as sample and hold Most. MSU's also have an a ref pin, which is the analog reference pin, and this is really useful for a D. C conversion. You can change this value from zero volts to the maximum operating voltage of the EMC, which is usually 3.3 to 5 balls, and this is the reference based analog reference based on which the analog voltage will be compared to and converted to digital. So it's very important when you're doing a TC conversion to make sure that you know exactly what the analog references and to have a noise free source for the analog reference. And thirdly, you should make sure that it doesn't exceed the maximum operating voltage off the emcee. You. Let's take an example to understand this better consider, you have a 10 bit 80 c and you're a ref is five volts. Now we want to measure an analog voltage off 2.5 holes. The 80 c reading will be calculated by the Formula two to the power and minus one divided by the system Voltage, which would be equal to the 80 c reading of the analog voltage measured so two to the power end minus one and divided by system, voltage or era fault Ege equals the 80 c reading divided by the analog voltage. So end here or two to the power in where end means and would be 10 s were using a 10 bit 80 c so digital value will be 10 23 multiplied by 2.5 and this whole thing is divided by five , which comes out to 5 11 If you change the voltage on the air. If pin, then you're 80 c reading will change as well. So it's important to make sure that a ref pain is connected to a stable voltage source that does not have noise. 21. DAC - Digital to Analog Converter: Now let's talk about the opposite. So converting digital to analog. So for additional to analog converter, it's called a dac. And, as the name suggests, the perfect converts a digital signal to analog signal. It's a little digital to analog is mostly used when you want your emcee, you microcontroller toe output. Some kind off analog way form could be sound or could be some other type of analog way form . Let's see a simple block diagram off a deck. ADAC takes a digital signal as input and converts that to produce an analog signal. But as you can see the pins on the left, it starts to count from zero to N number of bits. This is because we feed binary values hair or the emcee you feats binary values here in terms of zero and one, an end represents the number of bits you're sending to it. So as we're sending a binary number, then it must have LS be at least significant bit and an MSB. Most significant bit different docks are available where you can send an eight bit 10 bit 12 it, or also 16 bit eight bit Dax have the ability to send binary values up to two to the power eight. That is 2 56 which means that you can send values between 0 to 255 10 bits. Consent boundary values up to to the power 10 which means 10 24 and similarly for 12 bit and 16 bit. Will be 4095 and six, wife, 65,005 and 35. There's also a V ref pin, which defines the maximum and log out, but you can generate the maximum analog output cannot be greater than the operating voltage of the emcee you, and it's important not to provide voltage more than the operating voltage of the emcee on the V breath pin. So now let's take an example. Consider you have a 10 bit back and your V ref is five goals. We have a binary of value 550 that we need to convert to an analog level or analog voltage . So for me to do that would be analog. Output is equal to V ref multiplied by the binary number, and the whole thing is divided by two to the power end, where n represents the number of minutes off the dock, which in our case is a 10 bit Dac. So it's 10. So if you calculate this, you'll get 2.68 volts, corresponding to the binary value of 5 50 a very F off five volts. So analog upper voltage. If you measure with the multi meter out, that pin would be 2.68 volts. 22. AC - Analog Comparator: Now let's talk about analog competitors or a C. They have two inputs and one output and Allah. Comparator is a device that compares the voltage on its to input pins and produces additional output signal on the output pin. The output signal produced will be based on which input voltage is greater, so the analog comparator is used in the falling purposes. So if a comparison is is made, for example, if one of the analog pins is at 2.5 volts and the other pain of the Comparator is now at three volts and say we configure the comparator peripheral to detect if the voltages creator or less than the reference voltage the reference voltage being 2.5 and the provided voltage being three, yes, it's greater. So the and luck output would be the comparator output would be one, and this could be used to trigger and interrupt to the CPU. An analog comparator can also be used as a trigger source to different peripherals. For example, you can use the analog output to trigger for a timer to capture the current time or the P W M duty cycle that you were running you can also use an analog comparator to trigger and 80 C sample, for example, so any time there's a comparison of voltages that needs to happen then and low compared to peripheral is used. 23. Input Output Ports: Now let's talk about input output. Ports microcontrollers provide pins to take in and out information from the outside world in the form of logic values. And these pins are usually organized in groups of eight and referred to as a port for an eight bit MSU. A port mostly consists of eight pins for a 32 bit EMS. You report consists of eight or 16 pins. Most MSU's use alphabets to name the reports. For example, port a poor beat port, see a special registered controls. Whether the pin behaves like an input are an output. Let's understand what a floating pin is. So Pin is termed as floating if, for example, it's configured to be an input. But it's neither driven high to logic one nor driven low. So the input or whatever is connected. The pin is not deterministic, so we don't know the pin value could be zero. Could be one could be anywhere in between. So this is termed as a floating pin, and as a general rule of thumb, you don't want floating pins in your design. This is because if there's an undetermined input connected the microcontroller, then whatever coat is using that input then that code is also now under terminus Tick. So how do you solve this? What? Use the pull up or pull down resistor on that pin so the pull up and pull down resistors can be internal or external to the emcee You for the internal pull ups, you can't change the value of the pullup resistor. But using a special register, you can enable the internal pull up or disable it. External pullup resistors can be connected to the pin as shown in the figure. The voltage applied should not be greater than the operating voltage of the emcee you because you don't want the pin to go to a level where its value is exceeding the operating voltage off the emcee. You so say the emcee is operating at five volts. Then you can connect the pullup resistors to five volts like shown now your pin is pulled up and no longer floating. So now whatever is connected to that pin. If that device leaves it in an under terminus tick state, then we know at least that are pull ups will pull it high regardless so there. So we know that for the input We only have to consider an input when we see the signal on that pain going from a high level, which is our pullup level to a low level which could be close to ground. So this way we have added determinism toe our design and we have taken away the under terminus tick input that was connected. So in a similar fashion, you can also pull down your pin and this you could do by connecting a resistor to ground. In this case, the pin would be active when it goes from 0 to 1 or ground to B. C C or the supply voltage of the emcee you. So whenever a pull down pin is zero, which means that nothing is happening at the input. As soon as that pin is driven high about whatever is connected to it, we know that something's trying to activate it. Some MSU's offer additional features like P W M pulse with modulation on the pins, and to enable such features, you will have to write to special registers inside the microcontroller, which can configure the pain as an input output or enable its special function like a P W m . So with the P W M. You can generate special way forms like a square wave in which a signal is switched between on and off and on and off pattern can simulate the voltages between full on, which is five volts and off, which zero holds by changing the portion of the time the signal spends on. So the portion off time that the signal spends on with respect office called the duty cycle off the P W M. The duration of the on time itself is called the pulse, with in the image on the screen, the green lines represent a regular time period. The duration or appeared is the inverse off the PW. In frequency, you can see in the image different duty cycles, which means how much time the signal was high as compared to lo. So the P W m. You could do something like control. The brightness often led, so you don't have a paedo PM. You cannot only have the led as on or off. What if you want something in the middle? You wanted to be slow, like less bright and more bright, or maybe transition from a complete off state to a full on state but slowly you can slowly increase the intensity of the brightness of the led and you can use this. Use the Pwr block to do that. The intensity would be the change into intensity would happen when you change the duty cycle off the Pwr. You can also use a P in the peat OPM to, for example, control the speed for a motor or motor control that's connected at the output of the Metro controller. So those were some of the main peripherals off my controller that we talked about. So now let's zoom out and now see from a top level Ah, using a block diagram how really the execution off the processes happens inside the CPU. 24. How to choose a microcontroller: to say You start working on the project, you've been given a specific task that you need to accomplish with a microcontroller. How do you choose if you should go with an eight bit, 16 bit or 32 bit microcontroller? Well, there's a few things to consider. The first is the impact off the architecture. No one has the time to implement or write instructions in machine language. Today, it's a fast moving world, and the timeline from prototyping to the final product is always decreasing. So now the emcee use are coated with the help of tool chains, which are sometimes even graphical. The two co two chains help you generate pre written libraries, but generate it for your specific purpose without actually having to write any code. You go to a graphical interface or a text based interface. You tell that interface. Okay, these are the pins I need, and this these air. The functions of these pins should perform, and the tool chain itself will generate the low level drivers that are needed for you to write the application on top of it. And so these tool chains are different for different manufacturers. Like tea. I will have their own. Texas Instruments will have their own S t will have their own at mill and microchip for the same company. They will have their own and so on. So if you need to see which one you can work with, which one you're comfortable with, but you should not be limited. Essentially, as as a programmers and embedded programmer. You should be comfortable using these different ideas because they're pretty much similar. Once you know how to work with one, you should know how to work with all of them. So for performance, you can see the benchmarks that are given in the data sheets for different microcontrollers . And you can see em i, ps or megahertz to get a better understanding off the performance of the emcee. You ah, higher number written before the M I. P. S or megahertz means there's a higher clock or it operates at a higher speed, so your instructions will be executed at a higher speed. But the drawback here would be that there's would be usually ah, higher power consumption associated with it. So you have to see and mold this according to what the application needs. So the next Israel time considerations. Do you need to run an operating system on this microcontroller or urine? Right? Low level drivers are gonna write simple application code on it. So if you need, for example, a large operating system that's gonna sit on the mat controller, you need more flash memory. You need more RAM, so it's probably better to go with a 32 bit system if you're running an OS on it as compared to an eight bit, which can be used for simpler applications and running in 32 bit. My controller on a simple application would be an overkill and too expensive for the application. So there's a trade off again. Most eight bit and issues you'll see cost wise are cheaper than the 32 bit ensues. So if you have a cost constraint, which is very tight and the application simple, then you should go with an eight bit microcontroller. Peripherals will be different for different manufacturers. So say you selected that you wanted to use the processor as an arm cortex M, which is one of the mainstream arm cortex processor out there, And, uh, so you know what the processor you need. But now this processor is Can is provided by S T. It's provided by Atmel. Insults are provided by T I. Which one do you choose? Well, one of the things they'll do differently all these manufacturers is that they will provide different peripherals or different features around this processor. So the processor, the core might be the same arm cortex M core. But peripherals features number of pens. What special functions of these pins have could be different depending on the different manufacturers. So this is how you can see. Say you need three SP I interfaces on your for your application and on Lee, the S T microcontroller will give you, for example, three sp I interfaces on the same microcontroller and the admiral one and say gives you to Then you know you have to go with S t because that's the one with the three sp i peripherals and the Atmel one doesn't satisfy your application. So this is how you can choose based on peripherals, Um, which manufacturer to go with and also which how many bits like you want to go with an eight bit or a 16 bit or a 32 bit microcontroller, and one of the other things is power consumption eight. But MSU's usually consumed last power. So if your application is a simple application and it needs to be very power conservative, for example, if it's running on a battery, then it's probably better to use an eight bit microcontroller. But if you still have to use a 32 bit microcontroller, you should look into sleep functionality off the my controller, which will let, which will allow you to sleep the microcontroller to conserve this power when it's not actively working on a task, but as a rule of thumb. Usually, if it's a lower power application and it's a simple application, then definitely eight bit microcontrollers is the way to go. So now you have a few ways of knowing which microcontroller to go with. And as an engineer, it's always about tradeoffs. You have to find your constraints that the application has, which could be cost to be performance. It could be the development environment that you need to use, or it could be, ah, requirement that's coming from the customer that No, no, no. We need to use a 32 bit controller and has to be from Admiral. So these are things you have to consider. You have to consider the peripherals. What? What interfaces with the microphone in tow have to the outside world. And not just today, but maybe expansion possibilities in the future as well. So with all this in mind, then you can decide as an engineer, okay. Like this Is that my control? We should go with it. It allows all the features of any today and I was enough. Flash enough ram enough performance. And it allows expansion capabilities for future designs future design improvements as well . So hopefully that gives you and kind of engineers industrial engineers perspective on how we make choices between different types of microcontrollers based on our application. 25. Execution process of blocks inside a microcontroller: After you upload your program to the emcee you, the CPU starts to execute your program. Let's see how this process works. First, the program counter is initialized with the address at the beginning of the code application section. In the beginning of the code, flash section, interrupts are defined as as we saw in the interrupt Specter table. Then the instruction, which is to be executed, is sent to the instruction register. The instruction register now sends the instruction to the instruction decode logic. The next block is the control unit, which handles the execution of the instruction. We'll consider that there is no interrupt triggered in that case. We now check the type of instruction that we have, whether it's a data storage instruction, did a manipulation instruction or an arithmetic or logical instruction. If it's a data storage or data manipulation instruction, then according to the instruction, we can save the data either in ram or general purpose registers. If it's an arithmetic, a logical instruction, then the instruction is passed on to the Alieu, which executes the instruction. If after execution a result is produced, then the emcee, you saved the result in general purpose registers once the Alieu has executed the instruction and also has to right to this day Tous register which indicates to the control unit that the Alieu has successfully executed the instruction and is ready to execute the next instruction. The control unit then increments the program counter to load the address of the next instruction. No, let's see what happens when it interrupt is triggered during program execution. In that case, if any instruction is being executed, then we wait for that instruction to execute the control unit handles, interrupt after the execution of the previous instructions complete and stores the current address of the program counter, which is basically the address where we are in the code application flash section. So the program counter is stored in a general purpose register. Now the control unit gives the signal to handle the interrupt. When you set up interrupts you define an I S R interrupt service routine and this is where the instructions that are to be run in that interrupt are there. So when the interrupt has triggered, the eyes are address is loaded onto the program counter, which means that the CPI will start executing the first instruction that is in the eyes are once the interrupt is executed, then the status bit tells the control unit that the Alieu is ready for the next instruction . How the instructions are handled inside the ice are is same the same procedure as what we discussed before. So the CPU now loads the program counter with the value that we saved in the general purpose. Register to Brink after completion of the ice are to bring the program back to where it was before the interrupt was triggered. So it's taken. Example. Suppose your program was being executed at the address zero x seven. During that process, and interrupt is triggered, then the PC program counter will save the address. Zero x eight, which is the either something next instruction. Now let's say that Interrupt, which is triggered, is located at zero x four. The program counter is loaded with zero x four, and so the program counter goes to Xerox for and finds that there is a jump instruction with an address. The address inside the jump destruction is actually the address of the I s are, which is defining your program. So let's consider the IAS are sitting at zero x 12. Now the code execution starts from zero x 12 and the instructions inside the I start will be handled sequentially. Offers is completed. The PC is again loaded with zero x eight to resume where we were in the coat and start running the instructions in the main code. 26. Power up a microcontroller on a breadboard - Hands on exercise: So let's make a microcontroller circuit now on the bread board, A bread board allows you to quickly connect different components in the circuit without making permanent connections between them. So this is what bread board looks like right in front of you. So we have to vertical lines on the top and two vertical lines on the bottom. Any point on one vertical line is connected to any other point as shown in yellow. Similarly, for the blue vertical line, any point on this vertical line is connected to another point on that same article line. Similarly, on the bottom, any point on the red vertical line is connected to any of the other points on the same article line. And on the blue, the same thing applies. So these are used as the power rails for our bread board. So we're gonna connect positive on the red side of the vertical line and negative to the, uh to the blue side of the vertical line. And what this lets us do say we have we connect five goals over a year and ground over here . Now, any of these points will be five volts and any of the bottom points would be ground. So say I want to put five volts down onto this part of the circuit. Aiken do so easily by just tapping into any, um, a vertical red line or vertical Redpoint. So now you can see that all the more points marked in yellow are five volts. Similarly, Aiken do for ground. Now we have also these horizontal pins. Now we also have these horizontal holes in their bread port and for the horizontal holds. Any of these five horizontal holes are connected to each other. So roll one. These five would be connected and wrote to These five are connected, wrote three. Those five are connected. Similarly, Row 17 these viral connected. There's a gap in the middle where there is no connection after that. And then on this other side, we also have roll one where these five are connected, wrote two of these, five are connected. So anything that connects on pin one over here, for example, let's connect this capacity here. So I've connected a capacitor now on row one and row two, So Pin one of the capacitor is connected to row one. So any of these five points will be connected to the pin of the first point of the capacitor, but nothing on this side. So these points are not connected to the capacitor and similarly on road to we've connected to pin two of the capacitor. But this side off the red board is not connected. So hopefully that gives you an understanding of how the bread Board board works. And now let's start building our circuit. So the first component that we're gonna put so the first component we're gonna put on the bread board is a voltage regulator. The voltage regulator lets us choose an input voltage which is greater than five volts to say around 12 volt and put source on that's connected over here to pin one and for the voltage regulators job is to convert it down to a five volt power supply. So if we have a 12 both power supply or a nine volt power supply available to us, but for the microcontroller, we know we need a five old power supply. So this is where the voltage regulator it comes in handy. So pin, one of the Walter Regulator would be the voltage input where we would connect say a 12 volt input source pin too would be ground and pin three is our five volt input or a five volt output. So we have connected are told and put to row one and row two, which is in turn connected to pin one and pin two of the voltage regulator. And now we should supply the five volt output of the world's regulator to our power ales. So how can we do that? We can do that bit connecting this point which is road number three to our power. Real positive, connected any point on the power of positive and the ground to the ground rail. So now when I plugged the voltage regulator here. Now, basically I have 12 volt coming in and five holds coming out of the voltage regulator now going into the power ales. So we have positive five here and ground over here on the blue side. Now I'm gonna connected this side of the power ill to the other side as well, so I have power on both sides. So that's my positive connection and this will be my negative connection. The next component we're gonna put is a capacitor and you can notice that we have this band over here on the capacitor, which shows a negative leg of the capacitor. This is a polarised capacitor to make sure not inserting it the wrong way. Whereas the positive input, the one without the band goes into the positive side of the five volts and the negative input the one with the band goes into the ground. So this capacitor is called a filter capacitor and it helps in removing noise from our five volt power supply over here on the power lines. And similarly, we're gonna put another one on the input to remove any noise that's coming in from the 12 volt input to connect again posited a positive and a negative to ground. So we have our to filter capacitors connected. The next thing we're gonna connect is our microcontroller. We've chosen the 18 mega 3 28 p microcontroller for this demonstration and you can see that my controller has many pins. The first point of the microcontroller is denoted by a dot So where the dot is, that is pin one off your microcontroller. So I've connected pin one to row 11 off the bread board And this way, Pin 14 will be connected to road number 24 of the bread board. You can see how inserted the U micro control in the middle of the bread board. That's because we want on one side. Now we have access to pin one on all these Spence pin to on all these pins. Been three all not only spins before on all these pens and so on, so forth. And similarly, we have access to pin 15 on all the spins and the last pin, which is pin 28 of the microcontroller on all of these pins over here. So if I were to put the mic control in the middle over here, what would be the problem? Well, we have shorted pin one and pin 28 of the my controller. You don't want to do that. Now let's see what's connected to pin one off our microcontroller on Penn one. We have a 10 kilo ohm resistor going to B C C, which is five volts, and we have a reset switch that's going to ground. So on pin one on row 11 we're gonna connect first a resistor, and this is a 10 kilo ohm resistor that is going to VCC and a reset switch. So we have a reset switch that's going to ground. So one part one leg of the reset switch is connected to pin one and the other leg is connected to Around Over here, I've used a four pole switch, but when you're gonna build it, you can only use a true pole switch. That's all you need. So basically, when you press the button, this contact and that contact are connected, and that's all you need to bring this pin one connected to ground. So just because this software that I'm using doesn't have a to pole switch. So I've shown a 44 pole switch, but I hope you get the point. The next thing we're going to connect is the 16 megahertz crystal on pins nine and 10 off the microcontroller, and the 2 22 p compared capacitors on each leg of the crystal, going to ground right, so we have our 16 my guards crystal that goes between pin nine and pin nine of the microcontroller is connected to pin 19 of the Red Board, set up in 19 goes to one Inc end off the 16 mega rich crystal and Pin 20 which is our road 20 of the bread board, which has been 10 of the microcontroller goes to the other leg. So now the 16 megahertz crystals connected. The next thing that you do is connect. Two of these 22 people fared capacitors. So one end of the 2022 people very capacitor goes to pin 10 of the micro, which is a road number 20 of the bread board and the other leg goes to ground and similarly , the other one one leg goes to in 19 of the are rolled 19 other bread board and the other leg goes to ground. So next thing we're gonna do is we're gonna connect our two grounds and the VCC. So we have vcc connected to pin 2120 and to pin 777 is connected to row number 17 on the bread boards in Row 17 goes to VCC, and we have been number 20 and 21 which are connected to VCC, Aun said. On one side of the microcontroller, we have pin one, two and 14 and then the pin number 15 is right opposite to pin number 14 and this is pen 15 of the microcontroller. Soap in 20 is over here, and Pin 20 is connected to grow number 19 of the bread board. So Row 19 or pin 20 ghosts to VCC and pin 21 also goes to B C C. Now let's connect to ground. So we have pin number 22 as a ground and pin number eight as ground open. Number eight is connected to Row 18 of the bread Board, so row 18 goes to ground and pin number 22 is connected to row number 17 of the bread board , and that also goes to ground. - Now let's do a quick check on our schematic so we have the 10 cologne resistor connected to B. C. C. We have the reset switch connected to ground. We have the 7805 regulator that gives us ah, 12 volts input and brings five bolt into our power rails. We have the 16 megahertz crystal that's connected with 2 22 people fares to ground, and we have our VCC connections on pin 20 and 21 and on Pin seven, and we have our ground connection on Pin eight and in 22 So everything looks good so far. Actually, we're ready to power on the microcontroller and the way to power it on would just to give the 12 volt input into our bread board. That troubled input comes in five volt output, goes to the power ales and starts powering up the microcontroller before we power up the microcontroller. It's always good to make sure the connections air right. Somehow, this offer removed the connections of the resistor. See, it's it's always good to check that. So let let me connect the resistor again. So the resistor goes to pin 1 10 kilo homes and the other end goes to VCC, and we have a switch that I had connected one end to pin one and the other end and goes to ground. So now this is our switch and irresistible to connect. It's a good thing we checked, Um and yeah, So before we power this on, we need some way of telling if the microcontroller is working right? How do we know if it's working? Well, if you purchase the kit from us, then the microcontroller is already programmed with a blinky code which will blink an led to let you know that it's functioning properly. So the microcontroller has been programmed to blink an led on a pin. Number 19 pin number 19 of the microcontroller is connected to roll number 20 of the bread board. So I'm gonna connect a resistor and the resistor one another resistor is gonna be connected to and number 19 or Road 20 of the Red Board and the other end will be the positive side of the led. How do we know the positive and negative? Well, inside the led look at the smaller ah metal part inside the led and knew the smaller metal part is the positive terminal and the bigger metal part denotes the negative leg. So the part of positive leg off the led goes to the other end of the resistor, which I have on Roe number 30 over here. So there we go. We have the led one pin connected to a resistor and the other end of the resistor, then goes to pin number 19 of the microcontroller, which is on road number 20 other bread board and the other end of the led just goes to the ground power. So now a new power on the circuit, the led should start flashing, which will indicate that the microcontroller is powered up properly and it's clocked properly and it's running the application code that's pre programmed into the micro. So hopefully this gives you an understanding off what is needed to get a microcontroller working on a bread board set up. And how do we make it run our application code that we have programmed into the flash memory?