INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming...

24
INFO-0064 Embedded systems Exercise session 1 Introduction to microcontrollers Kevin Hogan [email protected] 25 September 2015

Transcript of INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming...

Page 1: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

INFO-0064 Embedded systems

Exercise session 1

Introduction to microcontrollers

Kevin Hogan

[email protected]

25 September 2015

Page 2: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

First things first!

Contact

[email protected]

Project (APRI0007 and INFO2055-1)

• Built a complete microcontrolled system (chosen freely!)

• Deadlines:

Proposed projects presentation Mon Oct 12

Final project validation Wed Oct 14

Hardware and software architecture report

Wed Dec 02

Final report Fri May 13

Page 3: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

Planning for today

• What’s a microcontroller?

• Microchip PIC18 family

• Exemple: PIC18F4620

Page 4: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

What’s a microcontroller ( )?

A microcontroller is a stand-alone processor intended to be embeddedinto some electronic devices.

It contains three main components:

• A processing unit (CPU)

• Some memory

• A bunch of hardware peripherals

MemoryCPUHardware

peripherals

Page 5: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

What’s a microcontroller ( )?

The central processor unit is the brain of the microcontroller. It controlsand monitors all processes within the μc, and it is composed of severalsubunits:

• Instruction Decoder: it decodes and executes program instructions.

• Arithmetic and Logical Unit (ALU): It performs all logical and mathematical operations

CPU

Page 6: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

What’s a microcontroller ( )?

You have different types of memory:

• Program memory (“flash”): Non-volatile memory containing your program. It stores your program instructions.

• Data memory (Static RAM): Volatile memory containing SFRs (Special Function Registers) and GPRs (General Purpose Registers).

• Data memory (EEPROM): Non-volatile data memory

8/16/32-bit microcontroller = width of registers and busses

Memory

Page 7: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

What’s a microcontroller ( )?

The hardware peripherals allow you to interact with the external world.

• Timers/Counters

• Analog-to-Digital Converter (ADC)

• Master Synchronous Serial Port (MSSP) module (SPI and I2C)

• Enhanced Addressable USART module

• Capture/Compare/PWM (CCP) module

• …

Hardware peripherals

Page 8: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

Many manufacturers of

• Intel 8051

• Atmel AVR

• Microchip PIC

Many (many) different types of microcontroller within each family. So, how do you choose?

It all depends upon your application!

Speed? Power comsumption? Number of pins? Specific hardware peripherals required (PWM, DAC, etc.)?

Page 9: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

Microchip PIC18FXXXX

• Harvard architecture

• 8-bit (byte) wide words

• 16-bit wide instructions

• 75 instructions set (RISC)

• Clock frequency up to 64 MHz (16 MIPS)

• Free programming tools (open-source for some of them)

• C programming language available (XC8 compiler)

• Free chips (you can request samples on microchip.com)

• Good datasheets & Application Notes

CPUData

memoryProgrammemory

data bus instructions bus

8 16

Figure 1 Harvard architecture: two different busses, one for the program memory and one for the data memory.

Page 10: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620

Where do I find information on how to use this microcontroller?

IN THE DATASHEET(http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf)

Page 11: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: overview

• Program memory 64 Kbytes

• Data memory 4 Kbytes

• Data EEPROM memory 1 Kbytes

• 36 General Purpuse Input/Output pins

• 10 bit A/D converter with 13 channels

• Capture/Compare/PWM (CCP) modules, Master Synchronous Serial Port (MSSP) module (SPI, I2C), USART module

• Priority Levels for Interrupts

• Clock frequency up to 40MHz

Figure 2 Microchip PIC18F4620 in 40-pin PDIP package

Page 12: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: overview

Figure 3 Microchip PIC18F4620 pinout

Page 13: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: block diagramdata bus <8>

instructions bus <16>

Program memory

Datamemory

Instruction decoder

I/O ports

Page 14: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

ALU

Hardware peripherals

PIC18F4620: block diagram

I/O ports

Page 15: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Memory organisation

• Program memory (flash) 64 Kbytes

• Data memory (SRAM) ~4 Kbytes

• Data memory (EEPROM ) 1 Kbytes

Page 16: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Data memory

How is the data memory organized?

It contains:- General Purpose Registers (GPR)

used for data storage and scratchpad operations in the user’s application.

- Special Function Registers (SFR)

used for configuration, control and status of the controller and peripheral functions.

It is divided in 16 banks containing 256 bytes each in order to have an efficient addressing scheme

Figure 4 Data memory map

bank 0

bank 1

bank 14

bank 15

000h

100h

FFFhF80h

F00hF7Fh

GPR

GPR

GPR

GPR

SFR

Access RAM

4 K

byt

es

Page 17: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Program memory

How is your program executed by the μc?

The microcontroller reads the program memory and executes each instruction sequentially starting at the Reset Vector.

The Program Counter (PC) specifies the address of the instruction to fetch for execution. The PC increments by 2 at each instruction (except with instructions such as GOTO).

When an interrupt occurs, the microcontroller stops its current operation and jumps to the Interrupt Vector.

Figure 5 Program memory map

64

Kb

yte

s

Page 18: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

Execution time?

4 clock beats = 1 cycle = execution time of most instructionsEXEMPLE: fCLK = 16MHz fcy = 4MIPS tcy = 0,25µs

Figure 6 Clock/Instruction cycle

Page 19: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

What are the instructions that the μc understands?

75 instructions of the PIC18 standard set (RISC)

Page 20: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

Page 21: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

Page 22: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

Page 23: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

What are the instructions that the μc understands?

75 instructions of the PIC18 standard set (RISC)

One-word instruction = 16-bit wide instruction = opcode + operands

There are four categories:

• Byte-oriented operations

• Bit-oriented operations

• Literal operations

• Control operations

Page 24: INFO-0064 Embedded systems - Montefiore Institutekhogan/downloads/ex_sess_1.pdf · •C programming language available (XC8 compiler) ... bank 0 bank 1 bank 14 bank 15 000h 100h FFFh

PIC18F4620: Instruction set

Exemple: INCF