720 likes | 1.06k Views
UBC104 Embedded Systems. Review: Introduction to Microcontrollers. Processors. General purpose processors: 80386 Pentium Core Duo Large number of pins External memory External peripherals . * Figure from Intel 386 DX Datasheet. General Purpose Registers.
E N D
UBC104 Embedded Systems Review: Introduction to Microcontrollers
Processors • General purpose processors: • 80386 • Pentium • Core Duo • Large number of pins • External memory • External peripherals * Figure from Intel 386 DX Datasheet 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 * 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 * 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 */ P1 = j; /* Output to LED Port */ for (i = 0; i < 10000; i++) { /* Delay for 10000 Counts */ wait (); /* call wait function */ } } } } 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
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
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
Interrupts Interrupt 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
9 fahr= (cent * ) +32 5 Interrupts Interrupt Program mov R1, cent mul R1, 9 div R1, 5 add R1, 32 mov fahr, R1 time t UBC 104 Embedded Systems
Interrupts Interrupt Program Program Interrupt Service Routine mul R1, 9 mov R1, cent mov R1, 0x90 mov sensor, R1 ret time t UBC 104 Embedded Systems
Interrupts Interrupt Program Program Save Context Restore Context Interrupt Service Routine mul R1, 9 mov R1, cent time t UBC 104 Embedded Systems
Interrupts Interrupt 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 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