1 / 12

EEE527 Embedded Systems Lecture 8: Practical Interrupts

EEE527 Embedded Systems Lecture 8: Practical Interrupts. "Adapted from the url “ http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/interrupts ”. Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6 th ring

wayne
Download Presentation

EEE527 Embedded Systems Lecture 8: Practical Interrupts

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EEE527 Embedded Systems Lecture 8:Practical Interrupts "Adapted from the url “http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/interrupts” Ian McCrum Room 5B18, Tel: 90 366364 voice mail on 6th ring Email: IJ.McCrum@Ulster.ac.uk Web site: http://www.eej.ulst.ac.uk www.eej.ulster.ac.uk/~ian/modules/EEE527/files

  2. What’s An Interrupt? It’s Halloween and you’re reading Lewis Carroll’s “Alice’s Adventures In Wonderland”. Every time someone knocks at the door you save your location and put down the book, go to the door and give some ghoulies candy, and then resume reading about Alice. And so it goes with embedded interrupts. With an interrupt in the embedded world, some event triggers the processor to very quickly jump to a special section of code called an interrupt service routine, do one thing or another, and then return to the previous location in code and continue with whatever was happening before. Note that this is unlike a standard function which is called by the code itself. An interrupt is generally triggered by some hardware related event and does not care what the non-interrupt code was doing when this event occurred.

  3. Order Of Events 1. An Interrupt Request HappensAn Interrupt Request or IRQ is what happens in the processor based on some trigger. This trigger can be a peripheral (SPI, UART, timers, comparators, etc.), the software, or a fault in the system. We’ll be dealing with interrupts configured by the programmer only even though most microcontroller’s startup code will also configure some interrupts such as exception handlers. In the example code below, the interrupt event is that a timer reaches it’s period value and restarts counting from 0. 2. The Processor Saves Its ContextAfter the IRQ happens, the processor saves its context. The context includes location in code (the program counter) and certain processor registers. Note that the processor registers referred to here are not the special function registers or SFRs we deal with so often with PICs. 3. The Processor Finds The Appropriate Callback FunctionAn interrupt vector table contains the locations of every possible function that can be called from an interrupt event. Based on the IRQ that happened, there will be a specific function or interrupt service routine that corresponds to that IRQ. The vector is just the pointer to that function. 4. The Interrupt Service Routine RunsThe interrupt service routine or ISR is the callback function pointed to by the appropriate vector. The programmer will deal with the event in the ISR whether it’s toggling an LED or loading a buffer with audio data. Since the ISR is disrupting the normal flow of code, please keep it as short as possible and try to avoid modifying any variables that may disruptively affect non-interrupt code! If you must call a function in an ISR, don’t call a function which can’t be called a second time while that function is already running. It can happen and it can cause a system crash. 5. Return To Normal ExecutionRestore the programs context.

  4. Plib.h – portable code – 314 page pdf

  5. Look at the video “Using mplab_x_and_plib_interruptcalls_and_timer1”and the C code Five functions to setup interrupts; INTEnable(INT_T1, INT_ENABLED); INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); INTEnableInterrupts(); and INTClearFlag(INT_T1); // inside the ISR interrupt Service Routine The 314 page pdf of the peripheral libraries has some misprints/old versions documented, use the actual header files as shown in the video. (for example the pdf documents the INTSetPriority function note the INTSetVectorPriority function.

  6. The code in the video has

  7. Look at the data sheet and reference manual This is on page 86 of DS_PIC32MX1xx-2xx__61168E.pdf

  8. http://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/interruptshttp://umassamherstm5.org/tech-tutorials/pic32-tutorials/pic32mx220-tutorials/interrupts Note. For ports you can write to the PORT, or write to the PORTSET or PORTCLR or PORTTOGGLE registers – very handy! Line above only clears bit 9, rest are unaltered

  9. As an exercise, rewrite this weeks code by replacing the INT functions with the SFR bit manipulations given here – adjusted for timer 1 of courseYou should still call SYSTEMConfigPerformance() and INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);

More Related