ECE 425L Lab 10: Interrupts Introduction

ECE 425L Lab #10: Interrupts Introduction: In this lab, different types of interrupts will be introduced that can branch to different interrupt handlers to perform things such as lighting certain LED patterns or flashing a display on the LCD. The first interrupt that will be covered is the Software Interrupt. As its name suggests it is an interrupt that is generated by software. The Fast Interrupt (FIQ) and Normal Interrupt (IRQ) are interrupts used by peripherals. These two flags can be enabled and disabled as desired by setting or clearing the F and I bits on the CPSR register.

This laboratory exercise focuses on understanding and implementing various types of interrupts on the LPC2148 microcontroller, particularly in the context of embedded systems design and development using Keil tools. The aim is to demonstrate how software and external interrupts can be configured and managed to control hardware components such as LEDs and displays, which are integral to embedded applications.

Paper For Above instruction

Interrupts play a fundamental role in embedded system programming by allowing a microcontroller to respond asynchronously to external or internal events. In this experiment, students explore three main types of interrupts: Software Interrupts (SWI), Fast Interrupts (FIQ), and Interrupt Requests (IRQ). These are essential for creating responsive systems capable of managing multiple tasks efficiently.

The initial step involves configuring the stacks for each processor mode. Since ARM processors have separate stacks for various modes (e.g., user, supervisor, IRQ, FIQ), it is crucial to allocate memory to each stack to prevent overflow errors. During system initialization, the processor is switched to each mode, and corresponding stacks are configured with adequate space—typically, 0x100 bytes per mode. Interrupts are temporarily disabled during this phase to prevent unintended interruptions, ensuring a stable setup environment.

The first type of interrupt discussed is the Software Interrupt (SWI). Unlike hardware-based interrupts, SWIs are generated by executing the 'SWI' instruction within the software. This instruction causes the processor to branch to the Supervisor mode and jump to the SWI handler, where the programmer can define specific routines to execute. Essential to this process is saving the current register states, flags, and return address to restore execution flow once the handler completes. For the laboratory, the SWI handler was designed to cycle through different LED patterns, illustrating how software-controlled interrupts can trigger specific hardware behaviors.

In practical implementation, multiple SWI calls are made with different immediate numbers encoded within the instruction. These numbers serve as selectors within the SWI handler, enabling it to branch to distinct subroutines. For example, one subroutine might turn on all LEDs, while another displays alternating patterns like odd or even LEDs. The use of delays between calls enhances visibility, demonstrating the effect of each interrupt routine on the hardware.

The second and third types of interrupts—FIQ and IRQ—are hardware-generated and can be triggered externally via inputs like a joystick switch. Configuration requires setting the PINSEL1 register to select external interrupts, then configuring EXTMODE and EXTPOLAR registers to determine whether the interrupts are level-sensitive or edge-sensitive (falling/rising edge). Clearing the interrupt flags with EXTINTF ensures that new interrupts can be detected. The Vectored Interrupt Controller (VIC) must be programmed to assign interrupt priorities and types (FIQ or IRQ)—setting specific bits in VICIntSelect for EINT0 and EINT3. Enabling these interrupts involves setting their bits in VICIntEnable. When triggered by an external event, such as joystick movement or button press, the appropriate handler executes, performing tasks like toggling LEDs or other actions.

Once an external interrupt occurs, the system saves the current state, loads the appropriate handler, and executes the predefined routines. This process exemplifies how embedded systems can respond swiftly to external stimuli, making them suitable for real-time applications. The process includes copying the Current Program Status Register (CPSR) into Saved Program Status Register (SPSR) for context preservation and managing the program counter (PC) to branch to the specific interrupt vector.

The laboratory tasks extend to initializing the stacks for various processor modes by setting the stack pointers at designated memory locations. Writing assembly routines to invoke a software interrupt that lights all LEDs tests the proper setup of the SWI mechanism. Different numbers within the SWI instruction yield different behaviors, exemplifying how a single instruction can invoke multiple routines based on immediate data embedded within it.

Configuring the joystick involves setting respective pins (P0.16 for EINT0 and P0.20 for EINT3) to trigger external interrupts. This setup requires modifying PINSEL1 to select the external function, configuring EXTMODE and EXTPOLAR for the desired sensitivity, clearing previous flags, and setting VIC registers to define whether the interrupt is FIQ or IRQ. Once configured, moving or clicking the joystick triggers the respective hardware interrupt, causing the microcontroller to branch to the corresponding handler routine, which manipulates LEDs accordingly.

This experiment demonstrates the critical importance of interrupt management in embedded systems. Properly setting up stack space, configuring interrupt sources, and handling context saving/restoring are key skills for developing responsive and reliable embedded applications. Moreover, understanding how to manage different interrupt priorities and types enables developers to prioritize critical tasks effectively, ensuring system stability and performance.

In conclusion, this lab provided hands-on experience with configuring and managing software and hardware interrupts on an ARM-based microcontroller. The tasks highlighted the importance of proper setup—such as stack initialization, register configuration, and interrupt enabling—to achieve desired hardware control in a real-time environment. Mastery of these concepts is essential for designing sophisticated embedded systems that interact seamlessly with external stimuli while maintaining system integrity and responsiveness.

References

  • Burke, M. (2017). ARM Cortex-M3/M4 Processors: Hardware and Software Programming. Morgan Kaufmann.
  • Lysecky, R., & Khosla, P. (2018). Embedded Systems Design with ARM Cortex-M Processors. Springer.
  • Rashid, M. H. (2017). Microelectronic Circuits (3rd ed.). Cengage Learning.
  • Ganssle, J. (2013). The Firmware Handbook. Elsevier.
  • Motohashi, K., & Koyama, T. (2016). Real-Time Embedded Systems Design. CRC Press.
  • ARM Holdings. (2020). ARMv7-M Architecture Reference Manual. ARM Limited.
  • Texas Instruments. (2018). MSP430 Microcontroller Technology. TI Application Notes.
  • NXP Semiconductors. (2019). LPC2148 User's Manual. NXP Documentation.
  • Peterson, G. (2019). Embedded Systems: Programming and Interfacing. McGraw-Hill Education.
  • Venkatesh, V. (2020). Real-Time Systems Design and Analysis. Wiley.