Lecture: 4
Estimated read time: 1:20
Summary
This lecture by DSP Coding explores the intricacies of microcontroller resets and interrupts. Starting with the types of resets such as watchdog timer and power on reset, the session transitions into the detailed operation of watchdog timers, which monitor code execution quality. The discussion moves to interrupts, emphasizing their role in managing tasks and avoiding conflicts through interrupt enable registers and peripheral interrupt expansions, effectively handling up to 192 interrupts for various modules.
Highlights
- Explore the different resets available in a microcontroller including watchdog timer and power on reset 💡.
- Watchdog timers monitor code execution and can reset the system if the code doesn't execute properly 🤖.
- Interrupts allow microcontrollers to pause a task to execute another in real-time, enhancing multitasking 🎛️.
- Leveraging interrupt enable and flag registers helps avoid conflicts between simultaneous interrupts 🚦.
- The Peripheral Interrupt Expansion module helps manage more tasks and interrupts in a microcontroller by expanding its interrupt capacity 📈.
Key Takeaways
- Learn about four types of resets in microcontrollers: watchdog timer, power null reset, hibernate reset, and active low pin reset 🔄.
- The watchdog timer ensures your microcontroller code runs smoothly, acting as a watchdog for code execution 🕵️♂️.
- Understanding interrupts is crucial for managing tasks and timing in microcontrollers ⌛.
- Avoid interrupt nesting using enable registers and flags 🚫.
- Peripheral Interrupt Expansion can increase interrupt handling capacity up to 192 to manage more modules efficiently ⚙️.
Overview
In the world of microcontrollers, resets and interrupts are fundamental concepts that determine how efficiently a system runs. This lecture dives deep into the types of resets, such as watchdog timers that monitor the execution of your microcontroller's code and initiates a reset if something goes awry. It's like having a reliable watchdog that ensures everything is running smoothly.
Moving on to interrupts, these are pivotal for tasks and timing management within a microcontroller. They allow a system to pause a running task and execute a different one when necessary. This is especially useful in real-time applications where multiple functions might need to happen almost simultaneously. The lecture thoroughly explores how to manage these interrupts using enable registers and the importance of avoiding the nesting of interrupts.
Finally, the lecture elaborates on Peripheral Interrupt Expansion, a technique to manage more tasks and modules by expanding a microcontroller's interrupt handling capacity. This expansion increases the capacity to handle up to 192 interrupts, ensuring that your system can manage various tasks concurrently without any hitches. Overall, understanding these concepts is crucial for anyone designing systems that rely on effective multitasking and time management.
Chapters
- 00:00 - 01:30: Microcontroller Resets and Watchdog Timer This chapter introduces the concept of four types of resets in a microcontroller: watchdog timer, power-on reset, hibernate reset, and XRS bar (active low pin) reset. The focus is on understanding that users can only manually control the power-on reset by toggling a switch. Additionally, the chapter discusses the role of the watchdog timer reset.
- 01:30 - 04:30: Interrupts in Microcontrollers This chapter discusses the concept of interrupts in microcontrollers, focusing on the role of a watchdog timer. It functions like a timer designed to monitor the correct execution of code within the microcontroller. The watchdog timer ensures that all instructions provided to the microcontroller are executed properly by maintaining regular intervals, such as one second or a few milliseconds, to check the CPU clock. If the microcontroller fails to serve the watchdog timer in the specified time, it indicates an issue in the execution, thereby providing a mechanism to handle errors and ensure system reliability.
- 04:30 - 07:30: Nesting of Interrupts and Interrupt Enable Register The chapter discusses the 'Nesting of Interrupts and Interrupt Enable Register.' The key focus is on the functioning of the watchdog timer, which generates an interrupt as a form of a software reset when certain conditions are not met. This mechanism ensures that if the code is not executing correctly or if the CPU fails to provide a clock signal within a specified timeframe, the system will automatically reset. This feature acts as a safeguard to maintain the stability and proper functioning of the system.
- 07:30 - 10:30: Global Interrupts and Peripheral Interrupt Expansion Module This chapter introduces the concept of interrupts and their significance in program execution. Specifically, it highlights the role of interrupts in 8085 microprocessor architecture, explaining that interrupts are mechanisms that allow the processor to pause its current execution flow to execute a higher priority service. The chapter emphasizes the importance of understanding interrupts for writing effective code, as they ensure that critical tasks are addressed in real-time amidst running instructions. The chapter also briefly mentions the types of interrupts available in the older 8085 system, referencing the RST (Restart) interrupts such as 7.5, 6.5, and 5.5, which are hardware interrupts used for handling emergency or time-sensitive tasks in legacy systems.
- 10:30 - 18:00: PIE Assignment Table and Control Registers The chapter discusses how programs execute certain algorithms and operations, such as adding two numbers, through functions. When a function is called, the program immediately executes that function. Similarly, interrupts can be triggered to shift the microcontroller's attention to execute specific blocks of code. The focus is on understanding the behavior and management of executing functions and triggering interrupts within a program.
- 18:00 - 22:00: Programming Interrupts and Acknowledgment The chapter explains how programming interrupts allow specific functions or blocks of code to execute precisely when needed, using interrupts to trigger functions at specific times. It uses the example of a clock running at 200 MHz to demonstrate how interrupts can be used to execute a function after a set period.
Lecture: 4 Transcription
- 00:00 - 00:30 so i will start with the reset you can see here there are four types of reset available in a microcontroller one is watchdog timer another one is power null reset third one is hibernate reset and xrs bar inactive so active low pin reset so you just have to understand one thing in here that you in your hand only power on reset is there you can just switch that button on and off and you have to reset your board one thing uh that is there in the module that is watchdog timer reset watchdog
- 00:30 - 01:00 timer uh it's like a timer which is actually there in order to see whether your code is running properly or not like you to ensure your proper execution of all the instructions that your feed to a microcontroller in an algorithm that is actually i uh monitored by this watchdog timer it's like your cpu clock is will be serving this watchdog timer every certain uh time period let's say one second two second three millisecond it is serving certain clock to this watch type project timer
- 01:00 - 01:30 if that input is not received by this watchdog timer it will create an interrupt and then your code will stop running so it's a kind of reset button which is a software reset which is done if your anything is wrong in your algorithm if anything is missing we'll see one exercise on that how this watchdog timer will work so it is a kind of software reset that happens if your code is not running properly or if your cpu is not able to provide a clock after particular period of time to that
- 01:30 - 02:00 particular time okay so uh before going into the interrupt you need to understand that uh everything whatever we are writing into this code it depends on the interrupt why i am saying like this is an interrupt is like something which is serviced when your all the instructions are running simultaneously in the sense like in your 8085 there were certain interrupts like rst 7.5 6.5 5.5 so what exactly interrupt means is let's say you have a certain set of instruction you
- 02:00 - 02:30 have written in your main program and you have written certain set of instruction that your algorithm has to execute now you have to perform certain other operation like adding of two numbers so what you do is you put a function and you call that particular function and it will immediately go to the uh that particular function and it will execute that function in the same way you can actually trigger an interrupt so that your microcontroller which will shift its attention to that particular block and then it will
- 02:30 - 03:00 execute that particular block that particular function whenever you are going to call it so you can call that particular function with the help of interrupt as well like let's say you are creating an interrupt and by with the help of creating that interrupt you can call that function at any particular time like if your clock is running at 200 megahertz frequency main clock system clock and if you want to call any particular function after a certain period of time let's say after certain milliseconds you want to execute certain
- 03:00 - 03:30 code so you can actually write that in your cpu timers as well or in your interrupts as well in order to call that particular function if that particular function is called then that particular instruction will be executed for now you just have to understand this thing when you will see the code you will understand what exactly i mean by calling of any function with the interrupts okay so interrupts are there in order to call any function in between whenever you want to call them whenever at particular schedule time you want to
- 03:30 - 04:00 call them or you can say you want to execute that particular thing so if you want to call that you can call it with the interrupt like your microcontroller is running certain set of instruction and you want your microcontroller to jump to another function in order to have that thing you can use interrupting between okay that is the use of interrupt now the interrupt in this particular microcontroller is is on through a particular logic actually i didn't want to make it very complex for you but they have done this
- 04:00 - 04:30 logic in order to avoid the nesting of inter what's the listing of interrupts see i can't cannot have only one interrupt like if i have to perform one task i can have one interrupt okay let's have an interrupt after this period of time and i will execute certain tasks but what if i have another task as well how can i have i how can i have that task at particular scheduled time so in order to have that i need to have more interrupts so there will be 14 core interrupts available into this microcontroller and the logic of interrupt flag register interrupt enable
- 04:30 - 05:00 register and interrupt global switch is designed in order to provide the nesting of interrupt nesting of interrupt in the sense let's say interrupt one is serving if flag bit is on flag is something which can store your bit you know one and zero so flag is related to that then you have a switch which will actually decide enable and disable so if this switch is enabled and your global switch is enabled and interrupt one is having one inter flag register in interrupt one is having one bit it will service this interrupt one it means your core is
- 05:00 - 05:30 servicing interrupt one now let's say at the same time at the same time another interrupt is coming okay and this global switch is on and let's say this ier is not there let's see let's consider an example that i year is not here and interrupt one is serving through this global switch only so if this interrupt two is also gets activated and your global switch is on so directly this interrupt two will also service at a time which is not possible because microcontroller cannot perform two tasks at a time you have to assign
- 05:30 - 06:00 its one task and then it will go to another task after certain scheduled period of time so you don't want this nesting to happen that's why this interrupt enable resistor is provided in order to avoid nesting of interrupt like when interrupt one is setting interrupt two should not come in between interrupt three should not come in between okay so it is like that so there are 14 core interrupts and to provide nesting this one this logic is given so why what is this logic ifr ifr ier intm these are just the
- 06:00 - 06:30 resistors and it has certain bits so if you put certain value into this registers it will be enabled and it will be disabled okay so through this procedure we go in every code in order to enable any interrupt if it is existing okay so it is like that these are the about maskable interrupt okay software interrupts so uh this is about the interrupt enable
- 06:30 - 07:00 register so this is how you can enable and disable you can see here there are 15 this is a 15 bit resistor okay interrupt enable resistor is a 15 bit so in order to set any bit of this resistor you have to put one value on over there in order to clear any bit you have to put zero value over there so this vertical line equal to it is basically logical or operation and this ier and equal to is basically logical and operation so this is a
- 07:00 - 07:30 hexadecimal value triple zero eight so whenever you convert this value into your into your binary format you can see i can show you over here so if you let's say if you convert it triple zero eight what will happen is it will show you one triple zero one triple zero means what one triple zero means what this one triple zero is now going to going to insert into this particular
- 07:30 - 08:00 resistor so it will be 1 and it will be triple 0. so you can see when interrupt 4 block is 1 you are enabling interrupt 4 in ier interrupt enable register now if you want to disable all the interrupts you can use logical and operator and you can use triple f7 now what is triple f7 so we can see from here you use triple f7 you will get this number so this number is putting once in all the bits and just
- 08:00 - 08:30 0 in the fourth bit so whenever you're putting 0 in the fourth bit it means you are putting 0 over here so you are disabling interrupt 4 so these 12 interrupts which i have this 14 core interrupts which i told you you can enable and disable it like this okay this is a global interrupt intm as i told you it's very easy in order to enable it since it is an active low resistor
- 08:30 - 09:00 yeah can you make it full screen yeah yeah is it is it okay now yeah okay so this is a global interrupt you can see interrupt intm bar so it is active low interrupt so if you put 0 over here you can enable this interrupt if you put 1 over here you have to disable this interrupt so before writing any code you have to disable first all the register and the then then you have to enable so certain global interrupt here assembly language code is given in asm so this will directly have access to this intm
- 09:00 - 09:30 register so you can use this as well so it's assembly language instruction which can actually execute this particular thing set c and clear c clear c will actually enable and set c will actually disable your global interrupt so it's like a switch you are turning on this main switch then you are turning on this other auxiliary switches and then you are putting your values into the flag and then you are able to assign any of the interrupt okay so it is a conceptual overview how we can program any of the interrupt
- 09:30 - 10:00 now ei has given a extension extension in the sense 14 core interrupts were not sufficient because there were different modules there were different modules there were different peripherals and every peripheral wanted an interrupt in order to execute its certain task so for executing those certain tasks when another module is being provided which is called as peripheral interrupt expansion module so peripheral interrupt expansion module is an expansion of this interrupt in the sense the same logic
- 10:00 - 10:30 that we saw before that will be in a cascaded way once again from this peripheral expansion yeah yeah yeah i will request i will repeat soon i will do it okay so you understood the logic of main core block right how exactly an interrupt is being serviced so the same logic has been cascaded by ti it's a peripheral interrupt expansion model what this module does is it actually divides your
- 10:30 - 11:00 core interrupt into more number of interrupt how it does that we'll see right now you just need to understand that there are two cascaded version or two cascaded logic of this thing whatever we saw maskable interrupt processing in this way we are able to achieve total 192 number of interrupts now how is that possible that i will tell you see peripheral interrupt expansion model it's basically expanding your number of
- 11:00 - 11:30 interrupts let's say you have 14 group of in 12 group of core interrupts okay exactly we have 14 but 13 and 14 are timer interrupt like cpu timer interrupt 1 cpu timer interrupt 2 but 12 interrupts are core interrupts okay that you can use for dividing this pi module so this pi module is connected to your main core interrupt group and it is subdivided into 16 sub groups like every one interrupt will have another 16 logic another 16 interrupt so again second
- 11:30 - 12:00 interrupt group will have another 16 logic third interrupt group will have another 16 logic so the logic we saw in the in the previous that is flag interrupt enable and global switch that will be same the core interrupt logic will be there for pi interrupt logic but it is just a cascaded version in order to increase the number of interrupts so that you can serve the different peripherals which is available into this microcontroller okay so if you multiply this 1 into 16 2
- 12:00 - 12:30 into 16 3 into 16. so 12 group of interrupts are divided into 16 subgroups which is equal to 192 interrupts the total you have 192 interrupts now how do we identify this many number of interrupts and how do we actually you know program this interrupts so to that you have given a pi assignment table it is also called as a pi vector table that is peripheral interrupt expansion table so in this table you can see there are
- 12:30 - 13:00 12 interrupts on my left side and in horizontal i have another 8 subgroups since 16 are not you know visible i mean 16's are not you know properly could adjust here so he has put it in another table so you can see here from interim number 1 to 12 okay these are your main interrupts and from interrupt number 1 to 8x these are your sub groups of the interrupts we can call this as a groups and you can call this above as a subgroup so whenever you are
- 13:00 - 13:30 clicking on whenever you are clicking on interrupt one main group if you are enabling interrupt one core interrupt and interrupt let's say eight sub group then it will have this wake interrupt on let's say then you are calling interrupt wayne one group and sub group you are calling interrupt six you can on adc one interrupt let's say i have to assign an interrupt on pwm eight why pw might interrupt how pwm it will create an interrupt that will see but for now you just have to understand that there
- 13:30 - 14:00 are different modules or peripherals like you can see ecap peripheral is there sci peripheral is there adc is there a cla vcu fpu so all these are creating an interrupt and if they can create an interrupt with the help of this particular logic with the help of group and subgroup logic understood so whenever you are going on group three sorry main group three and sub group let's say this one three then you are enabling e pwm three interrupt so before
- 14:00 - 14:30 programming any interrupt before calling any interrupt you have to go into the pi assignment table you have to check which interrupt you are programming and then you have to program that particular interrupt okay so this was about eight and this is about another eight that is nine to 16 and these are ipc flag interrupts pwm 11 trip zone interrupts adc interrupts auxiliary phase lock loop interrupts okay so all these kind of interrupts are over here so similarly as we saw in that one that
- 14:30 - 15:00 normal resistor on and on was on and off was there similarly you can see here okay so you can see here it is in a pi control register everything is related to register as i told you before uh like for programming more uh core interrupts you you were using this ier and ifr that is that is core interrupt logic now whenever whenever you are going to
- 15:00 - 15:30 you know program this pi register you have to use pi control register that is peripheral interrupt expansion control register so in this one there is one module called as peripheral interrupt expansion module and interrupt flag register so ifr ier this logic will be same so in order to turn on a particular bit let's say you are you have to on a sub group four okay so for ordering or for turning on that sub group four you have to put one over there then you have to let's say
- 15:30 - 16:00 but how i am saying that group and subgroup okay that is that is first you need to understand see whenever am putting here ifr 1 and sub group 4 it means i am turning on the group 1 and sub group 4 interrupt okay so in that way i am turning on x interrupt 1 what is this x interrupt 1 we look into one main group and four subgroup into the pi table so we can see here one main group and four sub group x interrupt one is
- 16:00 - 16:30 serving okay so through ier what we are doing is we are serving main one group and sub group for x interrupt one external interrupt one okay so this is how you can turn on main group one and sub group four x interrupt one like that you can select any of the interrupt okay then you have interrupt enable register now you can see this is your main group 3 and subgroup 2 main group 3 and subgroup 2 which interrupt pwm 2 so we have to see pwm 2
- 16:30 - 17:00 so pwm 2 is here so you can see main group 3 and sub group 2 so which interrupt we are serving we are serving interrupt number pwf2 okay so this is how you can enable this particular interrupt but you have to remember you have to write ifr ier and acknowledge for serving any of the interrupt okay like if you are serving group 1 and sub group 4 you have to also use ier instruction in order to turn that particular on and you have to also use global instruction one more thing is
- 17:00 - 17:30 that in order to enable this pi module peripheral interrupt expansion mode this instruction is necessary that pi control register pi control bit enable pi enable pi indices enable peripheral interrupt expansion module so en pi is instruction in order to enable your peripheral interrupt expansion model then you have a acknowledge register peripheral acknowledge register if you have to acknowledge group three interrupt okay then you will put here zero zero zero four if you convert this into the binary
- 17:30 - 18:00 it will actually acknowledge this interrupt number four or three i guess okay so in sorry interrupt number group three or two maybe so what it will do exactly is acknowledging means whenever you are serving any interrupt let's say if somebody is doing some task for you you say thank you to him in return so acknowledges is that kind of thing if interrupt is serving any task for you you are just putting you are just acknowledging him once without this acknowledge another interrupt will not be serviced
- 18:00 - 18:30 so it is mandatory for you whenever you are programming any interrupt you need you need to acknowledge that particular interrupt so you can see in all bit we are acknowledging this particular group 3 interrupt okay so how this actually is done will see through exercises and through that you will understand what is happening here so this is a kind of interrupt signal flow that summary of what we saw you can see here this is a pi vector table over here okay and then you have a core interrupt logic
- 18:30 - 19:00 and you have a peripheral interrupt expansion logic so if your flag bit is one and you are enabling pi module after that your core logic will be served and if your core logic on then you can select a pi vector table and through pi vector table you are servicing particular interrupt and then you are calling a function with the help of that interrupt okay so till here somebody has any doubt understanding this pi table you can see i can show you a little bit about this is my screen visible to
- 19:00 - 19:30 everybody yes okay so before that you can see that uh this is an instruction d interrupt this instruction is used in order to clear all the interrupts now why we are using this instruction we are using this instruction in order to clear all the bits in interrupts if some bits are stored previously so we want to reset all the bits we want to put it at zero so whenever you are starting a code you have to put b interrupt it will disable all the interrupts if any interrupt is
- 19:30 - 20:00 serving okay next thing is you are calling this particular function predefined function which is initialize pi control initialization of pi control means initialization of peripheral interrupt expansion control so in this particular if you just click on this this code will appear okay and yeah so from here you can see
- 20:00 - 20:30 that in this one before calling this one it has disabled all this function it has you know a in pi control register enable pi it has first put it to zero so that it has disabled everything then you have your ir resistors which are first disabled that is clear 0 0 0 so this is group 1 group 2 group 3 from pi control register by referral interrupt expansion interrupt enable register group 1 all the bits in this registers are cleared this is what it
- 20:30 - 21:00 means by this particular instruction similarly you can see all the 12 interrupts they are being cleared after that flag so all the flags are also disabled so this pi control is an api which is called by this particular predefined function initialize pi control and in this particular one disabling of all the interrupts has been carried out in order to first set an interrupt you need to clear everything out so for this this particular you know function has been called
- 21:00 - 21:30 after that you can see that here also we have disabled externally all the interrupts interrupt enable this is core logic so that was about pi vector so this is about core logic so this core logic also we saw previously interrupt enable register interrupt flag resistor we are disabling this we are clearing this so this is a mandatory procedure whenever you are writing any code you have to clear all the registers which are available to you then you are initializing pi vector table pi vector table is peripheral interrupt expansion vector table so which group and which
- 21:30 - 22:00 subgroup interrupt has to serve it has been done through this particular pi vector table instruction so i'll wait for a minute so
- 22:00 - 22:30 so this is a api which is related to pi table okay it is there in pi vector dot c previous api we saw was pi control dot c okay so this was related to peripheral interrupt expansion mode so in this api you can see as we saw previously that we are enabling pi module first we are clearing all the bits that is core logic ir resistor and as well as flag resistor okay then what we have done is we have
- 22:30 - 23:00 enabled pi after that when we are enabling interrupt we have called this function and i will interrupt and then we have acknowledged all of them we have put one one one and we have acknowledge all the bits of this pie acknowledge register and then we have enable interrupt okay so this is a pie control dots it's an api so whenever you are calling that particular function whatever code is stored over here okay that will get called into your main function next is your pi vector dot c so in this pi vector dot c you can see pi vector table okay so for this pi vector table
- 23:00 - 23:30 this many of the interrupt service routines are there which are to serve so whenever you are calling any interrupt and interrupt service routine will be served interrupt service routing in the sense whenever you are certainly serving that particular interrupt you can call an isr and with that isr you can execute any of the code okay so this is a pi vector table api you don't have to modify anything in here sorry so whenever you have to modify anything you can modify into the main code itself okay so this was about the
- 23:30 - 24:00 pi vector table oh this instruction is for cpu timers okay so understanding this code i hope a little bit portion you have understood till here okay now you can see