Introduction to Embedded Systems

Similar documents
Programming Microcontroller

CN310 Microprocessor Systems Design

Microprocessors & Interfacing

Interrupts (I) Lecturer: Sri Notes by Annie Guo. Week8 1

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Architecture of Computers and Parallel Systems Part 6: Microcomputers

INTERRUPTS in microprocessor systems

Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

8-bit Microcontroller with 1K Byte of In-System Programmable Flash AT90S1200

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash. ATtiny22 ATtiny22L. Preliminary. Features. Description

AGH University of Science and Technology Cracow Department of Electronics

INTERRUPT, TIMER/COUNTER. KONKUK UNIV. VLSI Design Lab. LSI Design Lab

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2313

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

SH69P48A EVB. Application Notes for SH69P48A EVB SH69V48A JP2 J4(ICE_J4) S1 IDD TEST JP1 74HC273 JP4 JP3 74HC273 JP6 STKOVE JP7 SW1 J5(ICE_J5)

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

8-bit Microcontroller with 2K Bytes of Flash. ATtiny28L ATtiny28V

AGH University of Science and Technology Cracow Department of Electronics

8-bit Microcontroller with 2K Bytes of In-System Programmable Flash AT90S2323 AT90LS2323 AT90S2343 AT90S/LS2323. Features.

8-bit Microcontroller with 8K Bytes Programmable Flash AT90C8534. Preliminary

PIC Microcontroller Introduction

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

AVR Microcontrollers Architecture

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Course Introduction. Purpose: Objectives: Content: 27 pages 4 questions. Learning Time: 20 minutes

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

Module 3. Embedded Systems I/O. Version 2 EE IIT, Kharagpur 1

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

SquareWear Programming Reference 1.0 Oct 10, 2012

8051 Microcontroller

AVR XMEGA TM. A New Reference for 8/16-bit Microcontrollers. Ingar Fredriksen AVR Product Marketing Director

Arduino Uno R3 INTRODUCTION

EE 308 Spring Lecture 28 March 30, 2012 Review for Exam 2. Introduction to the MC9S12 Expanded Mode

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Software debouncing of buttons

Lecture-55 System Interface:

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

Microcomputer Architecture and Programming

Processor and compiler dependent

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

MCU: Interrupts and Timers. Ganesh Pitchiah

8-bit Microcontroller with 1K Byte Flash. ATtiny11. ATtiny12

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

These three counters can be programmed for either binary or BCD count.

Fundamental concept in computation Interrupt execution of a program to handle an event

Ali Karimpour Associate Professor Ferdowsi University of Mashhad

CHAPTER 11 INTERRUPTS PROGRAMMING

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

8-bit Microcontroller with 1K Bytes Flash. ATtiny10 ATtiny11 ATtiny12. Preliminary. Features. Pin Configuration

ARDUINO MEGA INTRODUCTION

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers


CENG-336 Introduction to Embedded Systems Development. Timers

Introduction to the MC9S12 Hardware Subsystems

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

Introduction to general architectures of 8 and 16 bit micro-processor and micro-controllers

Chapter 2. Overview of Architecture and Microcontroller-Resources

Microcontrollers. Microcontroller

8-bit Microcontroller with 4K/8K bytes In-System Programmable Flash AT90S4414 AT90S8515. Features. Pin Configurations

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

Lecture 14. Ali Karimpour Associate Professor Ferdowsi University of Mashhad

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

Module 2: Introduction to AVR ATmega 32 Architecture

EE 308: Microcontrollers

EE 308 Spring A software delay. To enter a software delay, put in a nested loop, just like in assembly.

COMP2121: Microprocessors and Interfacing

MICROPROCESSOR BASED SYSTEM DESIGN

538 Lecture Notes Week 5

General Purpose Programmable Peripheral Devices. Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

Timers and Interrupts. Mark Neil - Microprocessor Course

Course Introduction. 2009, Renesas Technology America, Inc., All Rights Reserved

SH69P21 EVB. Application Note for SH69P21 EVB SH69P21 EVB SH69P21

8-bit Microcontroller with 4K Bytes In-System Programmable Flash. ATtiny40. Preliminary

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

538 Lecture Notes Week 5

AVR ISA & AVR Programming (I) Lecturer: Sri Parameswaran Notes by: Annie Guo

EE251: Thursday November 30

AVR MICROCONTROLLER ARCHITECTURTE

8-bit Microcontroller with 8K Bytes In-System Programmable Flash. ATmega8515 ATmega8515L. Features

Microprocessors B (17.384) Spring Lecture Outline

MICROCONTROLLER AND PLC LAB-436 SEMESTER-5

_ V Intel 8085 Family In-Circuit Emulation. Contents. Technical Notes

8-bit Microcontroller with 4K Bytes of In-System Programmable Flash AT90S4433 AT90LS4433. Features. Not Recommend for New Designs. Use ATmega8.

Question Bank Microprocessor and Microcontroller

Microcontroller Overview

8051 Microcontroller Interrupts

SH69P55A EVB. Application Note for SH69P55A EVB SH69P55A EVB SH69V55A

SECURE DIGITAL ACCESS SYSTEM USING IBUTTON

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

8-bit Microcontroller with 8K Bytes In-System Programmable Flash AT90S8515

AVR ISA & AVR Programming (I)

VCC PB2 (SCK/ADC1/T0/PCINT2) PB1 (MISO/AIN1/OC0B/INT0/PCINT1) PB0 (MOSI/AIN0/OC0A/PCINT0)

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

8. Power Management and Sleep Modes

Interrupt/Timer/DMA 1

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Interrupts, timers and counters

ECE332, Week 8. Topics. October 15, Exceptions. Hardware Interrupts Software exceptions

Transcription:

Stefan Kowalewski, 4. November 25 Introduction to Embedded Systems Part 2: Microcontrollers. Basics 2. Structure/elements 3. Digital I/O 4. Interrupts 5. Timers/Counters

Introduction to Embedded Systems Part 2: Microcontrollers Slide 2 Difference between microprocessors and microcontrollers? Microcontroller: - stand-alone device for embedded applications - low-end microprocessor + memory + I/O + additional peripherals - not a general-purpose device - cost-optimized control unit for particular application area (but more general than Application Specific Instruction Set Processors (ASIPs) and Systems-on-Chip (SoCs) Compared with high-end microprocessors: - no pipelining, cache etc. - predictable timing Microcontroller family: - Same microprocessor - Scalability w.r.t. memory, I/O capabilities, on-chip peripherals, etc.

Introduction to Embedded Systems Part 2: Microcontrollers Slide 3 Basic structure of a microcontroller Processor core Memory other on-board peripherals (or on-chip with processor) Internal bus I/O

Introduction to Embedded Systems Part 2: Microcontrollers Slide 4 Basic structure of a microcontroller - refined Processor core Volatile memory (SRAM) Non-volatile memory (EEPROM, Flash) Counter, Timer Clock Watchdog Internal bus Digital I/O (parallel) Serial interface Interrupt controller A/D converters D/A converters, PWM output Bus controller External bus

Introduction to Embedded Systems Part 2: Microcontrollers Slide 5 How to access internal blocks? - memory Processor core Volatile memory (SRAM) Non-volatile memory (EEPROM, Flash) Counter, Timer Clock Watchdog Internal bus Digital I/O (parallel) Serial interface Interrupt controller A/D converters D/A converters, PWM output Bus controller External bus Memory: - all memory types share a common address range or - different memory types are mapped into one address range (if you use C the compiler handels most of it)

Introduction to Embedded Systems Part 2: Microcontrollers Slide 6 How to access internal blocks? - digital I/O & on-chip peripherals Processor core Volatile memory (SRAM) Non-volatile memory (EEPROM, Flash) Counter, Timer Clock Watchdog Internal bus Digital I/O (parallel) Serial interface Interrupt controller A/D converters D/A converters, PWM output Bus controller External bus Digital I/O and on-chip peripherals are accessed by dedicated registers.

Stefan Kowalewski, 4. November 25 Introduction to Embedded Systems Part 2: Microcontrollers. Basics 2. Structure/elements 3. Digital I/O 4. Interrupts 5. Timers/Counters

Introduction to Embedded Systems Part 2: Microcontrollers Slide 8 Basic structure of a microcontroller - refined Processor core Volatile memory (SRAM) Non-volatile memory (EEPROM, Flash) Counter, Timer Clock Watchdog Internal bus Digital I/O (parallel) Serial interface Interrupt controller A/D converters D/A converters, PWM output Bus controller External bus

Introduction to Embedded Systems Part 2: Microcontrollers Slide 9 Digital I/O pins Basic means to monitor and control external hardware. Usually, digital I/O pins - are grouped into ports of 8 pins (byte access). - are bidirectional (i.e., can be used as input or output pins) - can have alternate functions (i.e., can be used for purposes different than digital I/O, e.g., as analog I/O pins) Monitoring, access and control of digital I/O pins is done via three special registers for each port: - Data Direction Register (DDR) - Port Register (PORT) - Port Input Register (PIN)

Introduction to Embedded Systems Part 2: Microcontrollers Slide Control of digital I/O pins via registers Data Direction Register (DDR): - read/write - specifies for each bit of the corresponding port whether it is an input or an output bit Port Register (PORT): - read/write - specifies for the output pins whether the output value is high or low - ATmega6: also used for controlling pull-up resistors for input pins (see next slides) Port Input Register (PIN): - read only - contains the current value (high or low) of all pins (input and output) - usual purpose: reading values of input pins

Introduction to Embedded Systems Part 2: Microcontrollers Slide Example: turn on an LED 5V 5V DD RA PO RT A Signal on PINA PinA Pin = (V) LED PortA PortA= Z PortA X: don t care U: unknown LED is on!

Introduction to Embedded Systems Part 2: Microcontrollers Slide 2 Example: turn the LED off 5V 5V DD RA PO RT A Signal on PINA PinA Pin = (5V) LED PortA PortA= Z PortA X: don t care U: unknown LED is off!

Introduction to Embedded Systems Part 2: Microcontrollers Slide 3 Example: Reading Input 5V DD RA PO RT A Signal on PINA PinA S closed: S open: U S closed: S open: PortA PortA= Z S PortA GND X: don t care U: unknown Input is not defined if S is open!

Introduction to Embedded Systems Part 2: Microcontrollers Slide 4 Example: Reading Input 5V DD RA PO RT A Signal on PINA PinA S closed: S open: U S closed: S open: PortA PortA= Z S PortA GND X: don t care U: unknown Input is now also defined if S is open!

Introduction to Embedded Systems Part 2: Microcontrollers Slide 5 Digital input: Sampling Sampling with every clock cycle causes a worst-case delay of ~ clock cycle. Impulses shorter than a clock cycle may be undetected. clock signal PIN register worst-case delay cycle missed impulse one cycle

Introduction to Embedded Systems Part 2: Microcontrollers Slide 6 Digital input: Sampling (2) Problem: Signal does not always have a well-defined level. V CC +.5 V v input high Operating voltage V CC [4.5V, 5.5V].6 V CC undefined.2 V CC -.5 V low Remedy: Schmitt-trigger

Introduction to Embedded Systems Part 2: Microcontrollers Slide 7 Digital input: Sampling (3) Noisy signals noise Bouncing Button pressed Button released Solutions: - by hardware: a) Low pass filter b) built in noise cancellation - by software: read signal twice or more

Introduction to Embedded Systems Part 2: Microcontrollers Slide 8 Digital output If DDR bit of a pin is set to output, the controller will drive the pin according to the corresponding PORT bit. The controller applies the corresponding voltage. The maximal current is depending on the external circuit (could be shortcircuited). External current protection is necessary.

Stefan Kowalewski, 4. November 25 Introduction to Embedded Systems Part 2: Microcontrollers. Basics 2. Structure/elements 3. Digital I/O 4. Interrupts 5. Timers/Counters

Introduction to Embedded Systems Part 2: Microcontrollers Slide 2 Why Interrupts? Microcontrollers have to react to events (internal external) How to ensure proper and timely reaction?. Polling - Periodically check for event - Disadvantages: Waste of CPU time if the event occurs infrequently Polling sequence has to fit in the rest of the code (hard to modify or extend) 2. Interrupts (IRs) - MCU polls the signal and interrupts the main program if a state change is detected. - MCU calls an interrupt service routine (ISR) which handles the event

Introduction to Embedded Systems Part 2: Microcontrollers Slide 2 Interrupt Control To use Interrupts they have to be activated by modifying the according registers. Usually there is a - global activation for all interrupts (global IE) and - an individual activation for each interrupt. Mapping of interrupts on the according ISR is done by an Interrupt Vector Table: Vector No. 2 3 Source Reset External Interrupt External Interrupt Prg. Addr. $ $4 $8 A jump instruction to the according ISR has to be placed at each prg. address

Introduction to Embedded Systems Part 2: Microcontrollers Slide 22 Interrupt Handling Detecting the Interrupt condition - If interrupts are enabled all according signals will be monitored - If an IR condition is detected the interrupt flag will be set - Then the interrupt logic will call the according ISR if the according IR is enabled and no other IR with higher priority is pending. Calling the ISR - It is more than just a jump to the appropriate address - Save the return address & some registers on the stack - MCU generally disables interrupts (global) - Nested interrupts are possible but should be avoided - The individual IR-flag is cleared by entering the according ISR.

Introduction to Embedded Systems Part 2: Microcontrollers Slide 23 Interrupt Handling (2) Executing the ISR - After the actions described before the execution in the ISR is like a normal subroutine - ISR must be exit with a special return from interrupt (RETI) instruction which undoes what the controller has done before calling the ISR Some controllers, like the ATmega6 make sure that after returning from an ISR, at least one instruction of the main program is executed before the next ISR is called. In C there are often some predefined ISR bodies and the compiler helps you with some of the work (see example next slide)

Introduction to Embedded Systems Part 2: Microcontrollers Slide 24 Example: External IR 2 //LEDs at PORTA to 5V & Switch at PINB2(external IR2) to GND int main (void) { outp(xff,ddra); //PORTD: output outp(x,ddrb); //PORTB: input outp(xff,portb); //PORTB: Pull-ups activated cbi(mcucsr,6); //IR2 with falling edge (default) sbi(gicr,5); //ext. IR2 activated (individual IR enable) sbi(sreg,7); //Global IR enable (global IR enable) while() {} //some main program } SIGNAL (SIG_INTERRUPT2) //ISR Interrupt 2; is executed as soon as a falling edge is detected at the according PIN (PORTB2) { //alternative: SIGNAL(_VECTOR(8)) if(porta==xff) { outp(x,porta); //Pin=low => LEDs on } else { outp(xff,porta); //Pin=high => LEDs off } }

Introduction to Embedded Systems Part 2: Microcontrollers Slide 25 Interrupt Control (2) IR Sources - External Interrupts (button, external communication controller ready, ) - Timer Events (Overflow, Compare, ) - Analog to Digital Conversion ready - Communication event (message in input buffer, EEPROM ready, ) - IR Priorities - Usually the interrupt vector No. is used as an indication to the priority - Some controllers allow individual settings of priorities - Usually the priorities are static, - Some controllers allow dynamic assignments of priorities

Introduction to Embedded Systems Part 2: Microcontrollers Slide 26 Interrupt vs. Polling Hard to decide, but the following should give some hints: Interrupts should be favored if - Event occurs infrequently - Long intervals between two events - The state change is important (time critical) - Short impulses, polling might miss them - Nothing else to do in main, could enter sleep mode Polling might be a better choice if - No precise timing is necessary - The state is important - Impulses are long - The signal is noisy (debouncing etc. is easier here)

Introduction to Embedded Systems Part 2: Microcontrollers Slide 27 Interrupts final remarks A long ISR delays the main program for a long time! - Sometimes it is useful to move some of the ISR code to the main routine. If more than one IR is used the side effects have to be considered. - The execution of an ISR delays the reaction on all other IRs. - The order of IR events may have influence on the behavior. If IRs are enabled the main program can be interrupted everywhere. - For some (short!) parts of the program is might be necessary to disable IRs.

Stefan Kowalewski, 4. November 25 Introduction to Embedded Systems Part 2: Microcontrollers. Basics 2. Structure/elements 3. Digital I/O 4. Interrupts 5. Timers/Counters

Introduction to Embedded Systems Part 2: Microcontrollers Slide 29 Timer/Counter On chip peripherals (dedicated hardware) Counter: - counts external events - e.g. number of rising edges at PINB2 Timer: - counts clock cycles (with or without prescaler) Each timer is basically a counter Most controllers provide one or more timer/counter with 8 and/or 6 bit resolution.

Introduction to Embedded Systems Part 2: Microcontrollers Slide 3 Timer/Counter Each Timer/Counter unit is based on a counter register, which can be incremented or decremented. Important for the behavior of the Timer/Counter is (are) the according control register(s) - mode of operation - which prescaler to use (timer) - start & stop counting - enable/disable interrupts Often there is also a compare register, which can be used to generate an interrupt if its content is equal to the counter register.

Introduction to Embedded Systems Part 2: Microcontrollers Slide 3 Timer/Counter (ATmega6) Control Register Timer Overflow IR Counter Register Compare Register

Introduction to Embedded Systems Part 2: Microcontrollers Slide 32 Timer/Counter (ATmega6) Control Register Timer Overflow IR Counter Register Compare Match Output Mode clock select Compare Register

Introduction to Embedded Systems Part 2: Microcontrollers Slide 33 Timer/Counter (ATmega6) Control Register Counter Overflow IR Counter Register Compare Register

Introduction to Embedded Systems Part 2: Microcontrollers Slide 34 Timer/Counter More than just counting events and measuring time. Other features - Input capture Used to timestamp (mostly external) events Whenever the event occurs, the timer automatically copies its current count value to an input capture register - Output compare Used to generate signals Whenever a certain timer value is reached, the output compare event is triggered (can automatically set or clear an output line). - Pulse Width Modulation (PWM) Special case of output compare Timer generates a periodic digital output signal with configurable high-time and period.

Introduction to Embedded Systems Part 2: Microcontrollers Slide 35 Watchdog Timer (WD) Special Timer; used to monitor software execution If enabled it counts down and resets the controller as soon as the count value zero is reached. During SW execution the WD has to be reset to its initial value before it reaches zero. If this fails the WD resets the controller. Useful if the program execution hangs and a restart solves the problem. However the WD can also be the source of problems (see Pathfinder problem)

Introduction to Embedded Systems Part 2: Microcontrollers Slide 36 More information about Interrupts and Timer&Counter can be found in any microcontroller data sheet like the one used in the exercise.