View
221
Download
3
Category
Preview:
Citation preview
INFO-0064 Embedded systems
Exercise session 1
Introduction to microcontrollers
Kevin Hogan
kevin.hogan@ulg.ac.be
25 September 2015
First things first!
Contact
• kevin.hogan@ulg.ac.be
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
Planning for today
• What’s a microcontroller?
• Microchip PIC18 family
• Exemple: PIC18F4620
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
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
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
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
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.)?
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.
PIC18F4620
Where do I find information on how to use this microcontroller?
IN THE DATASHEET(http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf)
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
PIC18F4620: overview
Figure 3 Microchip PIC18F4620 pinout
PIC18F4620: block diagramdata bus <8>
instructions bus <16>
Program memory
Datamemory
Instruction decoder
I/O ports
ALU
Hardware peripherals
PIC18F4620: block diagram
I/O ports
PIC18F4620: Memory organisation
• Program memory (flash) 64 Kbytes
• Data memory (SRAM) ~4 Kbytes
• Data memory (EEPROM ) 1 Kbytes
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
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
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
PIC18F4620: Instruction set
What are the instructions that the μc understands?
75 instructions of the PIC18 standard set (RISC)
PIC18F4620: Instruction set
PIC18F4620: Instruction set
PIC18F4620: Instruction set
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
PIC18F4620: Instruction set
Exemple: INCF
Recommended