Microcontrollers. 2IN60: Real-time Architectures (for automotive systems) Mike Holenderski,

Similar documents
2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Exam I Review February 2017

ECE331 Handout 3- ASM Instructions, Address Modes and Directives

EE4390 Microprocessors

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

Programming the Motorola MC68HC11 Microcontroller

EE 3170 Microcontroller Applications

COSC345 Software Engineering. Basic Computer Architecture and The Stack

EE319K Final Fall 2005 Solution C. (3) Question 1. (3) Question 2. short function(const short in){ return in+5; } const

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Table 1: Mnemonics Operations Dictionary. Add Accumulators Add B to Y. Add with carry to B. Add Memory to B. Add 16-bit to D And B with Memory

The Motorola 68HC11 Instruc5on Set

Most of the HC12 s instructions access data in memory There are several ways for the HC12 to determine which address to access

Addition and Subtraction of Hexadecimal Numbers Simple assembly language programming

Lecture 9 Subroutines

ECE 3120 Computer Systems Arithmetic Programming

Chapter 2: HCS12 Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Introduction to the 9S12 Microcontroller

COE538 Lecture Notes Week 3 (Week of Sept 17, 2012)

0b) [2] Can you name 2 people form technical support services (stockroom)?

Coe538 Final Study Guide 2016 (Questions & Answers)

Sample Problem Set #1

Chapter 2 HCS12 Assembly Language

Chapter 1. Microprocessor architecture ECE Dr. Mohamed Mahmoud.

Outline. 2.8 Stack. 2.9 Subroutines

EE319 K Lecture 3. Introduction to the 9S12 Lab 1 Discussion Using the TExaS simulator. University of Texas ECE

ME4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 7

Disassembly of an HC12 Program It is sometimes useful to be able to convert HC12 op codes into mnemonics. For example, consider the hex code:

Introduction to Embedded Systems and Chapter 1: Introduction to HCS12/MC9S12. EE383: Introduction to Embedded Systems University of Kentucky

Addressing Mode Description Addressing Mode Source Format Abbrev. Description

2) [ 2 marks] Both of the following statements cause the value $0300 to be stored in location $1000, but at different times. Explain the difference.

Using the stack and the stack pointer

Introduction to Programming

Microcontrollers and the Freescale/Motorola HC11

Wed. Aug 23 Announcements

Lecture 5 Assembly Programming: Arithmetic

538 Lecture Notes Week 3

N bit is set if result of operation in negative (MSB = 1) Z bit is set if result of operation is zero (All bits = 0)

A Simple MC9S12 Program

MIGRATING TO THE 68HC12 IN C

Wed. Sept 6 Announcements

ECE 372 Microcontroller Design Assembly Programming. ECE 372 Microcontroller Design Assembly Programming

538 Lecture Notes Week 2

Reading Assignment. 68HC12 Instruction Set. M68HC12 Instruction Set Categories. Some Tips. Endianness (Byte Order) Load and Store Instructions


Introduction to Computers - Chapter 4

Fri. Aug 25 Announcements

Lab 7: Asynchronous Serial I/O

Lecture 6 Assembly Programming: Branch & Iteration

Ryerson University Department of Electrical and Computer Engineering ELE 538 Microprocessor Systems Final Examination December 8, 2003

CHAPTER 8. Solutions for Exercises

HC11 Instruction Set

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

Exam 1 Feb. 23, 25, 27?

538 Lecture Notes Week 5

538 Lecture Notes Week 5

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3. You will be able to use all of the Motorola data manuals on the exam.

EE345L Spring 2006 May 10, 2006, 2-5pm Page 1 of 8

Department of Computer Science and Engineering

Microcontrollers. Microcontroller

CodeWarrior. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1. Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University

Motorola HC11. Fun with Microcontrollers and Embedded Systems

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-470/570: Microprocessor-Based System Design Fall 2014.

Chapter 2: Instructions How we talk to the computer

SECTION 6 CENTRAL PROCESSING UNIT

ECE 4510/5530 Microcontroller Applications Chapter 1

Lecture 11: Advanced Arithmetic Instructions

ECE 367 -Experiment #1 Fall 2012

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Introduction to Embedded Microcomputer Systems Lecture 8.1. Computers in the future may weigh no more than 1.5 tons Popular Science, 1949

Microcontrollers and Embedded Systems. Fun with Motorola/Freescale HC11

EE319K Fall 2007 Quiz 1A Page 1. (5) Question 2. What will be the value of the carry (C) bit after executing the following? ldab #210 subb #60

MC9S12 Address Space

538 Lecture Notes Week 3

C SC 230 Computer Architecture and Assembly Language April 2000 Exam Sample Solutions

Introduction to Microcontroller. Systems. Embedded system. Assembler or C? Datatypes 2. Datatypes 1

AN1064. Motorola Semiconductor Application Note. Use of Stack Simplifies M68HC11 Programming By Gordon Doughman. Introduction

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

COMPUTER ORGANIZATION & ARCHITECTURE

Module 1-G. Marcos and Structured Programming

Chapter 4: Advanced Assembly Programming. EE383: Introduction to Embedded Systems University of Kentucky. Samir Rawashdeh

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Computer Organization MIPS ISA

ECE L A B 1 Introduction ASSEMBLY PROGRAMMING WITH MINIIDE

ME 4447/6405. Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics. Instructor: Professor Charles Ume LECTURE 6

Instruction Sets: Characteristics and Functions

Instruction Set Architecture. "Speaking with the computer"

Chapter 7 Central Processor Unit (S08CPUV2)

EE 3170 Microcontroller Applications

HC 11 Instructions! From Alex Hollowayʼs notes with! many thanks!

CMPEN 472 Sample EXAM II

Lecture #3 Microcontroller Instruction Set Embedded System Engineering Philip Koopman Wednesday, 20-Jan-2015

ECE3120: Computer Systems Hardware & Software Development Tools

1 Execution of main program is suspended. 2 All registers are pushed onto the stack. 3 The ISR, or background thread, is executed.

Cross Assembly and Program Development

Introduction to Programming the 9S12 in C Huang Sections 5.2 and 5.3

Transcription:

Microcontrollers 2IN60: Real-time Architectures (for automotive systems)

Goals for this slide set Describe the architecture of a microcontroller Explain the purpose of an Instruction Set Architecture and what it is Summarize how programs are executed on a microcontroller Describe how programs can communicate with external devices 2

Outline Brief history of microcontrollers Example of an ECU Instruction set architecture (ISA) Input and output (I/O) Example 3

Why electronics? Difference Engine No. 2 (1849) Designed by C. Babbage 4000 moving parts 2.6 tons 3m wide, 2m high Easier to move information than physical objects 4

From hardware to software Evolution of hardware Tubes transistors integrated circuits Moore s law: Transistor density doubles every 1.5 years Problem: complexity Large number of applications, performing increasingly complex tasks Can t afford dedicated hardware for individual apps too many apps, large design cost Multiplex several applications on the same hardware Solution: reuse general-purpose components Generic controllers customized with memory (hardware) Memory contains a program (software) Stored-program concept (code + data in memory) Example: Fuel injection (see Introductory slides) 5

Use abstraction to hide complexity, while keeping the essentials Define an interface to allow people to use features without needing to understand all the implementation details Works for hardware and software Stable interface allows people to optimize below and above it Fighting complexity 6

Why should I care how a computer works? Understand the limitations of hardware and its abstractions Understand the performance bottlenecks Help write better programs (fewer bugs, more efficient) Understanding the machine-level execution model is critical for: Understanding the source of common challenges, such as race conditions in concurrent systems Understanding behavior of programs in the presence of bugs (when higher-level models brake down) Tuning program performance (understanding sources of program inefficiency) Writing critical code still programed in assembly 7

Outline Brief history of microcontrollers Example of an ECU Instruction set architecture (ISA) Input and output (I/O) Example 8

An ECU and its interfaces Power CAN port FlexRay port Digital and Analogue I/O ports 9

Example ECU (Freescale board EVB9512XF) Power CAN controller CAN port Reset button FlexRay port Digital and Analogue I/O ports Microcontroller (CPU + memory) LEDs 10

Outline Brief history of microcontrollers Example of an ECU Instruction set architecture (ISA) Input and output (I/O) Example 11

Instruction Set Architecture (ISA) CPUs only work with binary signals (bits) Machine instructions: strings of bits telling hardware what to do Machine code: sequence of machine instructions ISA is the interface between hardware and software Maps between program text and bits Defines what instructions do Syntax defined by assembly language Symbolic representation of the machine instructions Examples: MIPS, x86, PowerPC, ARM 12

Running an application High Level Language Program Compiler Assembly Language Program Machine Language Program Control Signal Specification Assembler Machine Interpretation temp = a[0]; a[0] = a[1]; a[1] = temp; LDD 6,-SP STD 4,SP LDX 2,SP STX 0,SP STD 2,SP 11101100 10101010 01101100 10000100 11101100 10000010 01101100 10000000 01101100 10000010 temp = a[0]; a[0] = a[1]; a[1] = temp; High/Low on control lines 13

Central Processing Unit (CPU) Control unit (CU) organizes everything, i.e. fetching, decoding and executing instructions: the so-called fetch-decode-execute cycle Arithmetic logical unit (ALU) performs operations to carry out the instructions Registers are fast (and small) memory program counter (PC): points to the next instruction to be executed general/special registers: to store temporary results 14

Memory 0 Instruction execution 1. Fetch the instruction from memory (pointed to by PC) 2. Fetch the data from memory into internal CPU registers (specified by instruction operands) 3. Execute the instruction 4. Store the results at the proper place (memory or registers) 5. Change PC so that it points to the following instruction 6. Go to step 1 to begin executing the following instruction. 1 2 3 4 5 64K -1 5 ADDA $1 CCR PC SP Instruction Data1 Data2 X Y A 9 Registers 4 43 D B ALU 16

Load-store ISA Why not operate directly on memory operands? Accessing memory is slower than CPU registers, so instructions would take longer to execute Load-store ISA Data is loaded into registers, operated on, and stored back to memory or registers Freescale HCS12 ISA Arithmetic operators can use register and memory operands E.g. ADDD $20 Add the value at address 20 to the value in register D and store the result in D Memory Registers ALU 17

Assembly instructions (Freescale HCS12) Assembly instruction format: <operation name> <operand1>, <operand2> Examples MOVB $20, PC Move the byte at memory location 20 to PC ADDD $20 Add the two bytes at memory location 20 to register D, and store in D ABA Add the byte in register B to the one in A, and store in A Break larger expressions into multiple instructions a = b + c d; (Result a will reside in the D register) LDD b ADDD c SUBD d 18

Example ISA: Freescale HCS12 Registers Memory Data types C local variables global variables int, char, float, unsigned, struct, pointer Freescale program counter (PC), stack pointer (SP), condition code register (CCR), accumulators (A,B), index registers (X,Y) Linear array with 64KB byte (8b), word (16b) Operators +, -, *, /, %, ++, <, etc. ABA, ADDA, SBA, SUBA, MUL, EDIV, INCA, CMPA, ANDA Memory access Control a, *a, a[i], a[i][j] LDS, LDAA, LDAB, STS, STAA, STAB, MOVB, MOVW, TFR, PSHA, PULA If-then-else, while, procedure call, return BEQ, BLE, BLT, LBEQ, LBLE, LBLT, DBEQ, JMP, JSR, RTS, SWI, RTI 19

Outline Brief history of microcontrollers Example of an ECU Instruction set architecture (ISA) Input and output (I/O) Example 20

Input / Output (I/O) Device is a physical thing in the outside world Outside world = outside CPU and memory E.g. a pressure sensor or brake connected via an analogue port, or another ECU connected via CAN port Controller connects device and CPU Electrical conversion and ( intelligent ) control E.g. the CAN controller Interface is an agreement for the connection Physical (plug!), electrical and functional (protocol) Standardized for exchangeability 21

Input / Output (I/O) Program can communicate with external devices by reading and writing data to the input and output ports Digital devices are connected to the digital ports Analogue devices are connected via an Analogue-to-Digital (ATD) converter Converts voltage to a discrete value Each port is mapped to a memory address Some devices need to be setup and controlled by writing to special memory addresses (control registers) Embedded FlexRay and CAN microcontrollers provide higher level communication between several processing boards 22

Outline Brief history of microcontrollers Example of an ECU Instruction set architecture (ISA) Input and output (I/O) Example 23

Example: reading a light sensor (Freescale MC9S12XF512) Memory ATDCTL1 PAD14 ATD converter ATDCTL5 CPU ATDSTAT0 ATDDR0 MC9S12XF512 24

Example: reading a light sensor We want to read the light sensor The light sensor is connected via an ATD converter on the I/O port PAD14 We need an ATD driver, providing a method which can be called from a C program, e.g. int light = ATDReadChannel(PAD14); 25

Example: reading a light sensor (Freescale MC9S12XF512) Memory ATDCTL1 PAD14 ATD converter ATDCTL5 CPU ATDSTAT0 ATDDR0 MC9S12XF512 26

Example: reading a light sensor (Freescale MC9S12XF512) Implementation of ATDReadChannel(): Conversion parameters (controlled by registers ATDCTL1 ATDCTL5): Sample resolution (8, 10, or 12 bits) Sample duration (44 2688 cycles) Number of consecutive samples Conversion is started by writing to ATDCTL5 When conversion is finished a bit in ATDSTAT0 is set Results are stored in registers ATDDR0 ATDDR15 27

Example: reading a light sensor (Freescale MC9S12XF512) MOVB #$10,ATDCTL1 MOVB #$88,ATDCTL3 MOVB #$05,ATDCTL4 MOVB PAD14,ATDCTL5 SCF: BRCLR ATDSTAT0,#$80,SCF BSET ATDSTAT0,#$80 LDX ATDDR0 set A/D resolution to 8 bit set conversion sequence length to 1 set sampling time to 264 cycles set which channel to read wait for the result clear the ATD result flag load the result into register X 28

References D.Patterson and J. Hennessy, Computer Organization & Design, 3 rd Edition, 2005 Niklaus Wirth, Algorithms and Data Structures, Prentice-Hall, 1985 29