Programming Microcontroller uC System 2- 1 Programming Microcontroller uC System Week 1 – Spring Term 2017 32K Byte Burst Flash 64K or 96K Byte SRAM 256K or 512K Byte Burst Flash OTP Mem UART I2C SPI TIM RTC EXT. Bus GPIO USB 2.0FS CAN 2.0B Enet MAC PFQ BC DMA INTR Cntl ARM966E CORE w/DSP 96 MHz CLK Cntl ADC LVD BOD PLL JTAG ETM9
Architecture of uC Systems 2- 2 Only one address space Program instruction Program memory (ROM) Program data Data memory (RAM) Instruction and data are accessed sequentially Information exchange runs over the same bus Program memory Data Periphery CPU
Central Processing Unit uC System Central Processing Unit 2- 3 Core of the computer Interpret the program instructions and process of the data
Control unit is responsible for the execution of the program uC System 2- 4 Control unit is responsible for the execution of the program Instruction unit Interpret and execute the program instructions Program counter Contains the address of the next instruction Task of the control unit Load the program instructions (fetch) Decode the program instructions (decode) Execute the program instructions (execute) Generate the control signals for the other units Address and load the operands Store the result Adapt the program counter
Processing unit contains the following components uC System Processing unit Processing unit contains the following components ALU (Arithmetic Logical Unit) Execute arithmetic and logical operations FPU (Floating Point Unit) Execute floating point operations Register Store the operands and the result Bus interface Activation of the external units Internal bus connects the control unit, processing unit and the bus interface
uC System Bus system 2- 6
The components of the bus system uC System The components of the bus system Address Bus Transfer of address information Use of additional address decoders Data Bus Transfer of program instructions and user data CPU reads from the external units CPU writes in the external units Control Bus Additional control informations Read, Write, Reset, Interrupts, Requests, Acknowledge …
Read the temperature from the sensor “x” uC System Example 2- 8 Read the temperature from the sensor “x” Store its value into the variable “temp” int temp = Temperature_Sensor_x;
Data Transfer CPU sets the address of the program instruction uC System Data Transfer 2- 9 CPU sets the address of the program instruction CPU defines the transfer direction read Program memory outputs the instruction on the data bus CPU reads the instruction to be executed CPU sets the address of the temperature register Peripherals outputs the information to the data bus CPU reads the value of the temperature CPU sets the address of the variable temp CPU defines the transfer direction write CPU places the data on the data bus Data memory takes the data from the data bus
Plan of the memory allocations in a microcontroller system uC System Memory-Map 2- 10 Plan of the memory allocations in a microcontroller system Address fields of the memory components Address fields of the peripheral components Example Adresse A15 A14 A13 A12 Periphery 0xFFFF 1 0xE000 Not used RAM (8kByte) 0xBFFF 0xA000 0x9FFF 0x8000 ROM (32kByte) 0x7FFF
Non-volatile Memory types uC System Memory 2- 11 Non-volatile memory The contents remain after switching off Non-volatile Memory types ROM (Read Only Memory) Masks programmed EPROM (Erasable Programmable ROM) Special programming devices Can be erased with UV light EEPROM (Electrical Erasable Programmable ROM) Electrically erasable and reprogrammable (line by line) Small storage capacity (~ kByte) FLASH Electrically erasable (block by block) Very large storage capacity (~ MByte)
Memory Volatile memory Volatile Memory types uC System Memory 2- 12 Volatile memory The memory contents are lost after switching off Volatile Memory types RAM (Random Access Memory) DRAM (Dynamic RAM) Keep the information in a capacity Must be periodically refreshed SRAM (Static RAM) Complex construction Do not need a refresh cycle SDRAM (Synchronous Dynamic RAM) Clocked variant of the DRAM Clock is specified by the system bus
Each storage technology has its advantages and disadvantages uC System Memory hierarchy 2- 13 Each storage technology has its advantages and disadvantages Memory is therefore organized hierarchically
Fast intermediate memory for frequently required data Cache uC System 2- 14 Fast intermediate memory for frequently required data Between register and memory CPU reads code or data from memory These objects are automatically stored in the cache These objects are read by the cache next Data does not exist in the cache => Cache Miss Data is read from memory and stored in the cache Data is in the cache => Cache Hit Data is read from the cache Cache are typically 100K bytes
Memory for program code (Flash) and data (RAM) PC world uC System Working memory 2- 15 Memory for program code (Flash) and data (RAM) PC world Code is copied from the mass storage into the working memory and executed from there Embedded world Code is executed from Flash Code is copied from flash into the working memory and run from there
Mass storage devices are hard disks, CD, memory sticks etc. uC System Mass storage 2- 16 Mass storage devices are hard disks, CD, memory sticks etc. Embedded system do not contain mass storage Mass storage, however, are found in industrial PCs Following storage media are used because of the mechanical environment CF cards SD cards Memory Sticks
uC System Periphery components 2- 17 The following components are referred to as peripherals Reading external data (sensors) Data output (actuators) Interface between processor and environment Connection to the processor bus
Input and output of digital signals uC System Digital Input / Output 2- 18 Input and output of digital signals Microcontroller Pins (GPIO) Access via register Use of additional peripherals (FPGA, PIO, ...) Access via bus system Use of digital output Indicators (lamps, LEDs, ...) Relay Motor Valves Use of digital input switch Buttons Optocoupler
Digital outputs are used with amplifier stages Using GPIO uC System 2- 19 Digital outputs are used with amplifier stages Control of motors Valves Digital inputs are filtered and protected against overvoltage RC links & Schmitt triggers Transzorb diodes, varistors and gaseous conductors
Data transmission is realized with a serial bit stream uC System Serial interface 2- 20 Data transmission is realized with a serial bit stream RS232, I2C, SPI, FireWire, USB, Fieldbus, ... Convert data format from parallel to serial with shift register Main characteristics Baud rate, voltage level & protocol
Very common in the embedded area uC System RS232 2- 21 Very common in the embedded area Use with LCD display, CLI (Command Line Interface), ... Many microcontrollers already have an RS232 Output level is however TTL RS232 are addressed via registers Send & receive buffer Often both buffers are at the same address Control register for defining the operating mode Baud rate, data, parity, interrupt, ... RS232 Support different modes Asynchronous or synchronous Timer often generates the baud rate
SPI is a serial high-speed bus system uC System SPI 2- 22 SPI is a serial high-speed bus system Use with display, A/D and D/A converters SPI is always operated in the master slave Master is responsible for the clock SPI works full duplex MOSI and MISO
SPI with a Master and 2 Slaves uC System SPI with a Master and 2 Slaves 2- 23
Time basis for the processor or for external components Timer uC System 2- 24 Time basis for the processor or for external components PWM, baud rate for serial interfaces Use of 8 or 16 Bit Timer/Counter Timer operation Timer register is incremented by oscillator Counter operation Timer register is incremented by external signal Overflows of register set a flag signal
Generation of a clock with a defined period duration Timer uC System 2- 25 Generation of a clock with a defined period duration Timer with auto reload
Analog voltage Digital value Most important characteristics A/D Converter uC System 2- 26 Analog voltage Digital value Reading in the result with bus system or serial interface Most important characteristics Size of the result (8, 10, 12 or 16 bits) and conversion time
Digital value Analog voltage Most important characteristics D/A Converter uC System 2- 27 Digital value Analog voltage Most important characteristics Bit width of the digital value (8, 10, 12 or 16 bits) Conversion time