Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to...

8
1 2005-08-30 Introduction to Microcontroller Systems 1 Dept. of Computer Science and Engineering Introduction to Microcontroller Systems 2005-08-30 Introduction to Microcontroller Systems 2 Dept. of Computer Science and Engineering Sven Knutsson 031-772 57 27 [email protected] www.chl.chalmers.se/~svenk/IT_university 2005-08-30 Introduction to Microcontroller Systems 3 Dept. of Computer Science and Engineering Embedded system Real time • Size • Price Power consumption • User interface • Limited memory • Hardware/software 2005-08-30 Introduction to Microcontroller Systems 4 Dept. of Computer Science and Engineering Assembler or C? Performance (assembler) Development (C) 2005-08-30 Introduction to Microcontroller Systems 5 Dept. of Computer Science and Engineering Datatypes 1 Floating point/fix point • Integer/fractional numbers 2005-08-30 Introduction to Microcontroller Systems 6 Dept. of Computer Science and Engineering Datatypes 2 • Bit Byte (8 bits) Word (16 bits) Double word (32 bits)

Transcript of Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to...

Page 1: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

1

2005-08-30 Introduction to Microcontroller Systems

1

Dept. of Computer Science and Engineering

Introduction to MicrocontrollerSystems

2005-08-30 Introduction to Microcontroller Systems

2

Dept. of Computer Science and Engineering

Sven Knutsson031-772 57 [email protected]/~svenk/IT_university

2005-08-30 Introduction to Microcontroller Systems

3

Dept. of Computer Science and Engineering

Embedded system

• Real time • Size• Price• Power consumption• User interface• Limited memory• Hardware/software

2005-08-30 Introduction to Microcontroller Systems

4

Dept. of Computer Science and Engineering

Assembler or C?

• Performance (assembler)• Development (C)

2005-08-30 Introduction to Microcontroller Systems

5

Dept. of Computer Science and Engineering

Datatypes 1

• Floating point/fix point• Integer/fractional numbers

2005-08-30 Introduction to Microcontroller Systems

6

Dept. of Computer Science and Engineering

Datatypes 2

• Bit• Byte (8 bits)• Word (16 bits)• Double word (32 bits)

Page 2: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

2

2005-08-30 Introduction to Microcontroller Systems

7

Dept. of Computer Science and Engineering

Datatypes 3

• Bit− High or low, one or zero

• Byte (8 bits)− 0 – (28-1) = 0 – 255

2005-08-30 Introduction to Microcontroller Systems

8

Dept. of Computer Science and Engineering

Datatypes 4

− 0 – 255 unsigned− -128 -- + 127 signed− 2-complement

6416 = 011001002 = 10010 signed

6416 = 011001002 = 10010 unsigned

8316 = 100000112 = -12510 signed

8016 = 100000112 = 13110 unsigned

•Signed/unsigned

2005-08-30 Introduction to Microcontroller Systems

9

Dept. of Computer Science and Engineering

Datatypes 5• Word (16 bits)− 0 – (216-1) = 0 – 65535 unsigned− -32768 -- +32767 signed

• Double word (32 bits)− 0 – (232-1) = 0 -- 4294967295 unsigned− -2147483648 -- +2147483647 signed

2005-08-30 Introduction to Microcontroller Systems

10

Dept. of Computer Science and Engineering

Computer Architecturevon Neuman Architecture

2005-08-30 Introduction to Microcontroller Systems

11

Dept. of Computer Science and Engineering

Computer ArchitectureHarward Architecture

2005-08-30 Introduction to Microcontroller Systems

12

Dept. of Computer Science and Engineering

Motorola

PTE

DD

RE

AD

0

AD

1P

TKD

DR

KP

TTD

DR

T

DA

TA0

DA

TA1

DA

TA2

DA

TA3

DA

TA4

DA

TA5

DA

TA6

DA

TA7

DA

TA8

DA

TA9

DA

TA10

DA

TA11

DA

TA12

DA

TA13

DA

TA14

DA

TA15

DA

TA0

DA

TA1

DA

TA2

DA

TA3

DA

TA4

DA

TA5

DA

TA6

DA

TA7

AD

DR

13A

DD

R14

AD

DR

15

AD

DR

12A

DD

R11

AD

DR

10

AD

DR

0A

DD

R1

AD

DR

2A

DD

R3

AD

DR

4A

DD

R5

AD

DR

6A

DD

R7

AD

DR

9A

DD

R8

PB

0 [2

4]P

B1

[25]

PB

2 [2

6]P

B3

[27]

PB

4 [2

8]P

B5

[29]

PB

6 [3

0]P

B7

[31]

PA

0 [5

7]P

A1

[58]

PA

2 [5

9]P

A3

[60]

PA

4 [6

1]P

A5

[62]

PA

6 [6

3]P

A7

[64]

DD

RH

PTH

PTP

DD

RP

DD

RJ

PTJ

PTS

DD

RS

DD

RM

PTM

Mod

ule

to P

ort

Rou

ting

Page 3: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

3

2005-08-30 Introduction to Microcontroller Systems

13

Dept. of Computer Science and Engineering

Processor units

• Central processing unit (CPU)• Registers• Memory• I/O

2005-08-30 Introduction to Microcontroller Systems

14

Dept. of Computer Science and Engineering

Registers

2005-08-30 Introduction to Microcontroller Systems

15

Dept. of Computer Science and Engineering

Memory types• Read only memory (ROM)− Electrically erazable programmable read only memory,

EEPROM− Flash memory

• Read/write memory• Random access memory (RAM)− Static− Dynamic

2005-08-30 Introduction to Microcontroller Systems

16

Dept. of Computer Science and Engineering

Memory

2005-08-30 Introduction to Microcontroller Systems

17

Dept. of Computer Science and Engineering

Peripherial units• Timer/counter• Serial communication interface (SCI)• Serial peripherial interface (SPI)• Analog-to-digital converter (A/D)• Pulse width modulation (PWM)• Controler area network (CAN)

2005-08-30 Introduction to Microcontroller Systems

18

Dept. of Computer Science and Engineering

Timer/counter• Free running counter• Input capture• Output compare• Time measurements• Pulse accumulator

Page 4: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

4

2005-08-30 Introduction to Microcontroller Systems

19

Dept. of Computer Science and Engineering

Serial communication interface (SCI)• Asynchronious• Baudrate (bits/sec)• Synchronisation• Startbit(s)• Stopbit(s)• Parity bit

2005-08-30 Introduction to Microcontroller Systems

20

Dept. of Computer Science and Engineering

SCI pattern

• Odd/even parity

2005-08-30 Introduction to Microcontroller Systems

21

Dept. of Computer Science and Engineering

Serial peripherial interface (SPI)

• Synchronious• Master/slave• Baudrate (bits/sec)• Synchronisation

2005-08-30 Introduction to Microcontroller Systems

22

Dept. of Computer Science and Engineering

Serial peripherial interface (SPI)Configuration

2005-08-30 Introduction to Microcontroller Systems

23

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)

• Uni/bipolar• Resolution• Conversion error• Signal-to-quantization-noise-ratio (SQNR)• Conversion time

2005-08-30 Introduction to Microcontroller Systems

24

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)

Unipolar Bipolar

2n/2-1

In

Out

-Umax (1-2-(n-1))·Umax

-2n/2

Page 5: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

5

2005-08-30 Introduction to Microcontroller Systems

25

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)

Resolution ∆ = Umax/2n

2005-08-30 Introduction to Microcontroller Systems

26

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)Conversion error

2005-08-30 Introduction to Microcontroller Systems

27

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)Signal to Quantisation Noise Error (SQNR)

SQNRunipolar ≈ 6·(number of bits + 1)

SQNRbipolar ≈ 6·number of bits

2005-08-30 Introduction to Microcontroller Systems

28

Dept. of Computer Science and Engineering

Analog-to-digital conversion (A/D)methods

• Integration• Succesive approximation• Flash (direct)

2005-08-30 Introduction to Microcontroller Systems

29

Dept. of Computer Science and Engineering

A/D-conversionIntegrating converter

uinRC

Variable slope Fixed slopeurefRC

Fixed interval Variable interval

2005-08-30 Introduction to Microcontroller Systems

30

Dept. of Computer Science and Engineering

A/D-conversionSuccessive approximation

Page 6: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

6

2005-08-30 Introduction to Microcontroller Systems

31

Dept. of Computer Science and Engineering

A/D-converterFlash converter

2005-08-30 Introduction to Microcontroller Systems

32

Dept. of Computer Science and Engineering

Pulse width modulation (PWM)

• Frequency• Duty cycle

• Driver circuits

2005-08-30 Introduction to Microcontroller Systems

33

Dept. of Computer Science and Engineering

Controller area network (CAN) 1Car without CAN bus

2005-08-30 Introduction to Microcontroller Systems

34

Dept. of Computer Science and Engineering

Controller area network (CAN) 2Car with CAN bus

2005-08-30 Introduction to Microcontroller Systems

35

Dept. of Computer Science and Engineering

Controller area network (CAN) 3• Communication bus• Message based• CSMA/CD− Carrier Sense Multiple Access with Collision Detect

• Arbitration

2005-08-30 Introduction to Microcontroller Systems

36

Dept. of Computer Science and Engineering

Input/output (I/O)• Digital inport• Digital outport• Analog inport (A/D)• Analog outport (D/A)• Serial ports (SCI, SPI)

Page 7: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

7

2005-08-30 Introduction to Microcontroller Systems

37

Dept. of Computer Science and Engineering

User interface• Switch (button)• DIP-switch• LED• Bargraph• LCD− Character/pixel

2005-08-30 Introduction to Microcontroller Systems

38

Dept. of Computer Science and Engineering

Assembler instruction groups 1• Load and store− LDAA, STX

• Transfer and exchange− TAB, XGDX

• Move− MOVB, MOVW

• Add and subtract− ABA, ADDD

2005-08-30 Introduction to Microcontroller Systems

39

Dept. of Computer Science and Engineering

Assembler instruction groups 2• (BCD-instructions)• Decrement and increment− DECA, INC

• Compare and test− CBA, CMPB, TST

• Boolean logic− ANDA, ORAB

2005-08-30 Introduction to Microcontroller Systems

40

Dept. of Computer Science and Engineering

Assembler instruction groups 3• Clear, complement and negate− CLRA, CLC, COMB, NEG

• Multiply and divide− MUL, EDIVS

• Bit test and bit manipulation− BITA, BSET

• Shift and rotate− ASRA, LSL

2005-08-30 Introduction to Microcontroller Systems

41

Dept. of Computer Science and Engineering

Assembler instruction groups 4• Branch− BRA, BEQ, BGE, LBLO, DBEQ

• Jump and subroutine− BSR, JSR, RTS, JMP

• (Interrupt)• Stack handeling− PSHA, PULD

• Condition code− CLI, TPA

2005-08-30 Introduction to Microcontroller Systems

42

Dept. of Computer Science and Engineering

Addressing modes 1

• Inherent• Immediate• Direct/extended• Relative• Indexed− 5/9/16 bit offset− Pre/post inc/decrement

Page 8: Introduction to Microcontroller Systems - Chalmers ·  · 2005-08-302005-08-30 Introduction to Microcontroller Systems 1 ... • Serial peripherial interface (SPI) • Analog-to-digital

8

2005-08-30 Introduction to Microcontroller Systems

43

Dept. of Computer Science and Engineering

Addressing modes 2• Indexed - indirect− 16 bit offset− D accumulator offset