Embedded Systems Prepared By:

Slides:



Advertisements
Similar presentations
The 8051 Microcontroller and Embedded Systems
Advertisements

Review: Interrupts & Timers
Interrupts Chapter 8 – pp Chapter 10 – pp Appendix A – pp 537 &
Chapter 2 HARDWARE SUMMARY
8051 Core Specification.
UBC104 Embedded Systems Review: Introduction to Microcontrollers.
CSC Timers Since this is a microcontroller it mainly finds itself in embedded devices Quite often embedded devices need to synchronize events The.
Interrupt Processing Haibo Wang ECE Department
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Microcontroller / 8051 family
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
1 ECE 263 Embedded System Design Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System.
Architecture of the 8051 INTERNAL DATA BUS Oscillator & Timing Programmable I/O (32 Pins) 80C51 CPU 64K byte Expansion Control Serial I/O 4K Program Memory.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
The 8051 Microcontroller and Embedded Systems
Lecture 9 Timer Operations and Programming. 2  Introduction  Summary of timers  Timer programming sequence  Summary of timer SFRs  Timer 0: 8-bit.
The 8051 Microcontroller architecture
ECE/CS-352: Embedded Microcontroller Systems Embedded Microcontroller Systems.
Introduction to Embedded Systems
Chapter 4 TIMER OPERATION
MICROPROCESSOR INPUT/OUTPUT
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
1. Registers Used in Timer/Counter  TH0, TL0, TH1, TL1  TMOD (Timer mode register)  TCON (Timer control register) 2.
AVR Programming: Interrupts September 17, What are interrupts? An asynchronous signal indicating the need for an event to be handled A synchronous.
8051 Micro controller. Architecture of 8051 Features of 8051.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
MCS51 - lecture 5. Lecture 5 2/28 Interrupts in MCS51 Step work Power consumption reducing.
Intel 8051 Another family of microcontroller is the Intel 8051 family. The basic 8051 microcontroller has four parallel input/output ports, port 0, 1,
Jump, Loop, and Call Instructions
Embedded Systems Design 1 Lecture Set 8 MCS-51 Interrupts.
EE/CS-352: Embedded Microcontroller Systems Part V The 8051 Assembly Language Interrupts.
CS-280 Dr. Mark L. Hornick 1 Sequential Execution Normally, CPU sequentially executes instructions in a program Subroutine calls are synchronous to the.
Networked Embedded Systems Pengyu Zhang & Sachin Katti EE107 Spring 2016 Lecture 4 Timers and Interrupts.
Timer Programming in Assembly and C Prepared By:
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
One more PIC18F252 example and revision for exam B222L Branislav Vuksanovic, UoP, ECE.
Embedded Microcontroller Systems
80C51 Block Diagram ECE Overview.
Microprocessor Systems Design I
Embedded Microcontroller Systems
Timer and Interrupts.
UNIT – Microcontroller.
Computer Architecture
8051 Timers Timers are the peripherals of the 8051 Microcontroller.
Introduction of microprocessor
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Interrupt Source: under
Introduction to Micro Controllers & Embedded System Design Interrupt
UNIT 5 TIMRERS/COUNTERS
The Arduino Microcontroller: Atmel AVR Atmega 328
Timer Operations and Programming
Microcontroller Intel 8051
* * * * * * * 8051 Interrupts Programming.
EMT 348: Microcontroller Timer/counter
Introduction to Microprocessors and Microcontrollers
8051 Timers Prof. Rajiv R Bhandari.
Interrupt.
Timer.
8051 Timers / Counters It has two timers Timer 0 and Timer 1.
8051 Microcontroller.
Interrupt Source: under
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Md. Mojahidul Islam Lecturer Dept. of Computer Science & Engineering
Interrupt Source: under
Wireless Embedded Systems
Compiled by Dr. N.Shanmugasundaram, HOD, ECE Dept, SECE.
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Embedded Systems Prepared By:- 130350111009 130350111005 Review: Introduction to Microcontrollers

Processors General purpose processors: Large number of pins 80386 Pentium Core Duo Large number of pins External memory External peripherals UBC 104 Embedded Systems

General Purpose Registers Registers are dedicated for moving data EAX, EBX, ECX, EDX: general purpose registers EBP: Base pointer ESP: Stack pointer ESI, EDI: Index register UBC 104 Embedded Systems

Microcontrollers Support for peripherals inside uController Limited number of pins Dedicated purpose Controlling devices, taking measurements Controller families: 68H12: Motorola 68H11, 68HC12, … 8051: Intel 8051, 8052, 80251,… PIC: Microchip PIC16F628, 18F452, 16F877, … AVR: Atmel ATmega128, ATtiny28L, AT90S8515,… UBC 104 Embedded Systems

Rita51J 8051 128K of SRAM 128K FLASH ROM Serial port Digital I/O lines * Figure from www.rigelcorp.com UBC 104 Embedded Systems

Motes Sensor nodes based on Atmel ATMega128 UBC 104 Embedded Systems * Figures from CrossbowMPR-MIBUser Manual UBC 104 Embedded Systems

Microcontroller Families 68H12: Motorola 68H11, 68HC12, … 8051: Intel 8051, 8052, 80251,… PIC: Microchip PIC16F628, 18F452, 16F877, … AVR: Atmel ATmega128, ATtiny28L, AT90S8515,…  We are going to look at 8051s UBC 104 Embedded Systems

Typical 8051s 32 input / output lines. Internal data (RAM) memory - 256 bytes. Up to 64 kbytes of ROM memory (usually flash) Three 16-bit timers / counters 9 interrupts (2 external) with two priority levels. Low-power Idle- and Power-down modes UBC 104 Embedded Systems

Datasheets – Your New Friends! * Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

Pin-Out of an 8051 UBC 104 Embedded Systems

8051 Components Ports RAM Interrupt Controller Timer SPI Controller * Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

8051 Internal RAM & SFRs UBC 104 Embedded Systems * Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

Special Function Registers (SFR) * Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

Special Function Registers (SFR) * Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

* Figure from Atmel AT89C51RD2 Datasheet UBC 104 Embedded Systems

Ports Driving low-power peripherals ie. LEDs, relays UBC 104 Embedded Systems

Accessing Ports in C void main (void) { unsigned int i; /* Delay var */ unsigned char j; /* LED var */ while (1) { /* Loop forever */ for (j=0x01; j< 0x80; j<<=1) { /* Blink LED 0, 1, 2, 3, 4, 5, 6 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } for (j=0x80; j> 0x01; j>>=1) { /* Blink LED 6, 5, 4, 3, 2, 1 */ UBC 104 Embedded Systems

Summary General information about 8051 Special Function Registers (SFRs) Control of functionality of uController Ports Input/Output of uController UBC 104 Embedded Systems

Motivation for Next Topics UBC104 Embedded Systems Motivation for Next Topics

Tasks for Microcontroller Controlling of processes (autonomic) e.g. speed of vehicles, chemical processes Control of devices through human operator e.g. remote control, etc UBC 104 Embedded Systems

Example: Controller Engineering UBC 104 Embedded Systems

Topics for the Following Lectures Interrupts & Timers Communication Analog to digital (A/D) conversation Pulse Width Modulation UBC 104 Embedded Systems

UBC104 Embedded Systems Interrupts & Timers

Today’s Topics Interrupts Timers UBC 104 Embedded Systems

Definition of ‘Interrupt’ Interrupts Definition of ‘Interrupt’ Event that disrupts the normal execution of a program and causes the execution of special instructions UBC 104 Embedded Systems

Interrupts Program time t UBC 104 Embedded Systems

Interrupts Interrupt Program time t UBC 104 Embedded Systems

Interrupt Service Routine Program Program Interrupt Service Routine time t UBC 104 Embedded Systems

Interrupt Handling Address space in code space Code that deals with interrupts: Interrupt Handler or Interrupt Service Routines (ISRs) UBC 104 Embedded Systems

Interrupt Handling Code that deals with interrupts: Interrupt Handler or Interrupt Service Routines (ISRs) Possible code: void ISR(void) interrupt 1 { ++interruptcnt; } Interrupt number UBC 104 Embedded Systems

Interrupts Interrupt Program time t fahr= (cent * ) +32 9 5 mov R1, cent mul R1, 9 div R1, 5 add R1, 32 mov fahr, R1 time t UBC 104 Embedded Systems

Interrupt Service Routine Program Program Interrupt Service Routine mul R1, 9 mov R1, cent mov R1, 0x90 mov sensor, R1 ret time t UBC 104 Embedded Systems

Interrupt Service Routine Program Program Save Context Restore Context Interrupt Service Routine mul R1, 9 mov R1, cent time t UBC 104 Embedded Systems

Interrupt Service Routine Program Program Save Context Restore Context Interrupt Service Routine mul R1, 9 mov R1, cent eg push R1 eg pop R1 time t UBC 104 Embedded Systems

Interrupt Overheads Interrupt Latency Interrupt Termination Interrupt arrives Complete current instruction Save essential register information Vector to ISR Save additional register information Execute body of ISR Restore other register information Return from interrupt and restore essential registers Resume task Interrupt Latency Interrupt Termination UBC 104 Embedded Systems

Interrupt Response Time Interrupt Latency Interrupt Response Time= Interrupt Latency + Time in Interrupt Routine UBC 104 Embedded Systems

Interrupts Internal or External Handling can be enabled/disabled Prioritized General 8051: 3x timer interrupts, 2x external interrupts 1x serial port interrupt UBC 104 Embedded Systems

Interrupt Priorities Each interrupt source has an inherent priority associated with it UBC 104 Embedded Systems

Interrupt Priorities Priorities can be adapted by programs Original 8051 provides 1-bit per interrupt to set the priority UBC 104 Embedded Systems

2-bit Interrupt Priorities The 89C52RD2 provides 2bit-interrupt priorities UBC 104 Embedded Systems

2-bit Interrupt Priorities (continued) UBC 104 Embedded Systems

2-bit Interrupt Priorities (continued) UBC 104 Embedded Systems

External Interrupts Pins for external interrupts UBC 104 Embedded Systems

External Interrupts External Interrupts: Level- or edge-triggered UBC 104 Embedded Systems

External Interrupts External Interrupts: Level- or edge-triggered Level-triggered threshold t trigger point UBC 104 Embedded Systems

External Interrupts External Interrupts: Level- or edge-triggered Level-triggered threshold t trigger point Edge-triggered t trigger point UBC 104 Embedded Systems

Timer A timer is a counter that is increased with every time an instruction is executed e.g. 8051 with 12MHz increases a counter every 1.000 µs General 8051 has 3 timer: 2 16-bit timer 1 16-bit timer with extra-functionality (introduced with the 8052) Timer/Counter Mode Control Register TMOD Timer/Counter Control Register TCON UBC 104 Embedded Systems

Timer High- & Low-Registers UBC 104 Embedded Systems

SFR Map – Timer Registers UBC 104 Embedded Systems

Timer Control Timer/Counter Mode Control Register TMOD Timer/Counter Control Register TCON UBC 104 Embedded Systems

SFR Map – Timer Control UBC 104 Embedded Systems

SFR Map – Timer 2 UBC 104 Embedded Systems

Timer Code void TimerInit(void) { // Timer 2 is configured as a 16-bit timer, // which is automatically reloaded when it overflows // This code (generic 8051/52) assumes a 12 MHz system osc. // The Timer 2 resolution is then 1.000 µs // Reload value is FC18 (hex) = 64536 (decimal) // Timer (16-bit) overflows when it reaches 65536 (decimal) // Thus, with these setting, timer will overflow every 1 ms T2CON = 0x04; // Load Timer 2 control register TH2 = 0xFC; // Load Timer 2 high byte RCAP2H = 0xFC; // Load Timer 2 reload capt. reg. high byte TL2 = 0x18; // Load Timer 2 low byte RCAP2L = 0x18; // Load Timer 2 reload capt. reg. low byte ET2 = 1; // Enable interrupt TR2 = 1; // Start Timer 2 running } UBC 104 Embedded Systems

Interrupt Code for Timer 2 void handleTimer2 (void) interrupt 5 { /* execute interrupt code */ } UBC 104 Embedded Systems

Interrupt Flags Bits that are set if the interrupt occurs UBC 104 Embedded Systems

Code for Interrupt Flags /* Configure Timer 0 as a 16-bit timer */ TMOD &= 0xF0; /* Clear all T0 bits (T1 left unchanged) */ TMOD |= 0x01; /* Set required T0 bits (T1 left unchanged) */ ET0 = 0; /* No interrupts */ /* Values for 50 ms delay */ TH0 = 0x3C; /* Timer 0 initial value (High Byte) */ TL0 = 0xB0; /* Timer 0 initial value (Low Byte) */ TF0 = 0; /* Clear overflow flag */ TR0 = 1; /* Start Timer 0 */ while (TF0 == 0); /* Loop until Timer 0 overflows (TF0 == 1) */ TR0 = 0; /* Stop Timer 0 */ UBC 104 Embedded Systems

Summary: Interrupts Definition of ‘Interrupt’: Event that disrupts the normal execution of a program and causes the execution of special instructions Handling can be enabled/disabled Prioritized Internal or External External Interrupts: Level-triggered Edge-triggered 8051: 3 timer interrupts, 2 external interrupts & a serial port interrupt Level-triggered threshold t trigger point Edge-triggered t trigger point UBC 104 Embedded Systems

Real-Time Systems predictable Definition: A real-time system needs to be predictable in terms of values and time Correctness of an RT system depends on functionality as well as temporal behaviour UBC 104 Embedded Systems

Clock Driven Scheduling Decision on what job execute are made at specific time instants chosen a priori before the system starts operation A schedule of jobs is created off-line and used at run time The scheduler dispatches jobs according to the stored schedule at each scheduling decision time Clock-driven scheduling has minimal overhead during run time UBC 104 Embedded Systems

Cyclic Executive #define TASK_MAX 4 typedef void (func_ref)(void); int delay[TASK_MAX]; func_ref task_ref[TASK_MAX]; void cyclic_executive() { int task= 0; while(1) { settimer(delay[task]); taskref[task](); task= (task==TASK_MAX) ? task+1 : 0; clear(time_flag); while (time_flag) enterIdleMode(); } UBC 104 Embedded Systems

Cyclic Executive (continued) void timer(void) interrupt 5 { set(time_flag); } void EnterIdleMode(void) { PCON |= 0x01; Frame Tdelay,1 T1 T2 T3 T1 T2 T3 t IdleMode UBC 104 Embedded Systems

Problems with Cyclic Executives Timing Accuracy Actually constructing the cyclic executive (Typical realistic problem: 40 minor cycles and 400 entries) Inflexibility must reconstruct schedule even for minor changes Incorporating Aperiodic/Sporadic Tasks, or very long period tasks I/O only by polling UBC 104 Embedded Systems

General Embedded Programming Endless loops Idle mode for 8051 Generic main() function UBC 104 Embedded Systems

Endless Loops Two types of tasks: Run-To-Completion tasks Endless-Loop tasks UBC 104 Embedded Systems

Endless Loops Two types of tasks: Run-To-Completion tasks Endless-Loop tasks Interrupt handler are run-to-completion tasks The majority of generic tasks are endless loops UBC 104 Embedded Systems

Endless Loops Two types of tasks: Run-To-Completion tasks Endless-Loop tasks Interrupt handler are run-to-completion tasks The majority of generic tasks are endless loops Example Code: void ExampleTask(void) { while(1) { waitForActivation; doTask; } UBC 104 Embedded Systems

Idle Mode 8051s implement an “idle” mode which consumes less power UBC 104 Embedded Systems

Idle Mode 8051s implement an “idle” mode which consumes less power UBC 104 Embedded Systems

Idle Mode 8051s implement an “idle” mode which consumes less power from Pont: Atmel 89S53 normal mode 11mA idle mode 2mA UBC 104 Embedded Systems

Idle Mode void EnterIdleMode(void) { PCON |= 0x01; } 8051s implement an “idle” mode which consumes less power from Pont: Atmel 89S53 normal mode 11mA idle mode 2mA Example Code: void EnterIdleMode(void) { PCON |= 0x01; } UBC 104 Embedded Systems

Generic main() Function void main(void) { /* initialize system */ /* initialize tasks */ while (1) { /* loop forever */ EnterIdleMode(); /* PCON |= 0x01*/ } UBC 104 Embedded Systems

Summary Cyclic executives Endless loops Idle mode UBC 104 Embedded Systems