Real-Time Embedded Systems Lecture Notes - Fall 2024 PDF

Document Details

Ontario Tech University

2024

Dr. Mitchell Rushton

Tags

embedded systems real-time systems peripherals electronics

Summary

This document provides lecture notes for a course on Real-Time Embedded Systems, focusing on peripherals like interrupts and timers. The content details the functionality, configuration, and operation of crucial components in the system. Examples of peripherals mentioned in the lecture notes such as Interrupts, External Interrupts, PCINTs, Timers, and PWM signals are also discussed in the document.

Full Transcript

Intro. to Real-Time Embedded Systems Lecture 6: Peripherals II Dr. Mitchell Rushton, Fall 2024 Interrupts Interrupts temporarily halt the main program to execute a specific function (Interrupt Service Routine - ISR) in response to an external or internal event, then resum...

Intro. to Real-Time Embedded Systems Lecture 6: Peripherals II Dr. Mitchell Rushton, Fall 2024 Interrupts Interrupts temporarily halt the main program to execute a specific function (Interrupt Service Routine - ISR) in response to an external or internal event, then resume the main program. Enables execution to respond to events as they occur, rather than polling regularly to see if an event has occurred or not Can be triggered from various sources, internal and external INT pins PCINT pins On-board timers ADC Analog comparator A few other peripherals as well Minimum CPU overheard for servicing an interrupt: 10 CPU cycles (630 ns) Interrupt Execution Process All interrupts are assigned individual enable bits which must be written logic one together with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The I-bit is automatically set when a Return from Interrupt instruction is executed If one or more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set, and will then be executed by order of priority Interrupt Flags can also be cleared manually by writing a logic one to the flag bit position(s) to be cleared Interrupt Vector Table Full version can be found in the datasheet Interrupt priority determined by address location (lower address, higher priority) External Interrupts (INT) Trigger an interrupt on specific pins (INT0-7) when one of four conditions are met: Rising-edge, falling-edge, pin change, low Setup and operation is configured by the following registers: External Interrupt Mask Register (EIMSK): configure which interrupts (INT0-7) are enabled. Setting a bit enables the corresponding external interrupt. External Interrupt Control Register (EICRx): configure the trigger condition for each interrupt External Interrupt Flag Register (EIFR): Contains flags indicating which interrupt has been triggered. Can be manually clearly by writing 0 to the target bits Pin Change Interrupts (PCINT) Trigger an interrupt then the logic level of a pin changes (1 to 0, or 0 to 1) Arduino mega has three separate PCINT groups with each group building 8 pins PCINT0-7 (Group 0) PCINT8-15 (Group 1) PCINT16-23 (Group 2) Three types of registers (5 in total) configure setup and operation: Pin Change Interrupt Control Register (PCICR ): Enables PCINT functionality for pin change interrupt groups. Bits 0,1,2 correspond to a pin groups PCINT0-7, PCINT8-15, and PCINT16-23 Pin Change Mask Register (PCMSKx ): Enables specific pins within a PCINT group to trigger an interrupt. Each bit in the register corresponds to a specific pin. Pin Change Interrupt Flag Register (PCIFR): Contains the flags for triggered pin change interrupts. Flags are set when a pin change occurs and need to be cleared in the interrupt service. Can be manually reset by writing 0 to targeted bits Timers (Counters) Timers are dedicated peripherals that count clock as they occur Key functions include Trigging periodic interrupts Generating PWM-signals Capturing specific timings of events Arduino mega 2560 has 6 separate timer peripherals in total: Two 8-bit timers (count from 0 to 255) Four 16-bit timers (count from 0 to 65535) Each timer is configurable through its internal control registers Once a timer’s count register reaches its max value, it overflows and the count resets to zero Timer Prescaler Arduino mega 2560 clock speed is 16 Mhz (period of 63ns). This is often way too fast to be useful as a reference for use in a timer: 8-bit timer: overflows every 16 𝜇𝑠 16-bit timer: overflows every 4 ms Adjusting the prescaler register settings allows you to decrease the frequency of the clock used for a timer by a factor of 8, 64, 256, or 1024 Using a prescale setting to divide system clock by 1024: 8-bit timer: overflows every 16 ms 16-bit timer: overflows every 4.1 s Timer Generated Interrupts Each timer can generate several types of interrupts, (the specific details of each and which timer they apply to can be found in the datasheet) Overflow: Triggered when the timer reaches its maximum value and resets to 0. Compare Match: Triggered when the timer value matches a preset value Input Capture: Triggered by external events and gives a time-stamp indicating time the event occurred Pulse-Width Modulation (PWM) A technique to control the power delivered to devices by varying the duty cycle of a square wave. Applications of PWM Hobby Servos, Electronic Speed Controllers (ESCs) LED Dimming Power Regulation (buck/boost converters) https://www.mathworks.com/help/soc/ref/pulse-width-modulation-signal-diagrams-average.png Generation of PWM Signals Comparing the timer’s count value with a given reference value enables the generation of PWM signals If count < reference: output 1 If count >= reference: output 0 The output of the comparison is a square- wave whose duty cycle can be reconfigured by adjusting the value stored in the compare register Joseph, Peter K., et al. "Analysis of digital PWM design for zero voltage transition phase shifted full bridge converters for space applications." 2016 International Conference on Emerging Trends in Communication Technologies (ETCT). IEEE, 2016.

Use Quizgecko on...
Browser
Browser