Grundlagen Microcontroller Memory Günther Gridling Bettina Weiss 1
Lecture Overview Memory Memory Types Address Space Allocation 2
Memory Requirements What do we want to store? program constants (e.g. lookup tables) "semi constants" (e.g. configuration parameters) variables (e.g. loop vaiables) 3
Memory Requirements Program requirements permanent storage (available after power up) accessible to CPU (read access) protected against accidental modifications protected against external read accesses (proprietary) 4
Memory Requirements Constants requirements permanent storage (available at program start) accessible to program (read access) protected against accidental modifications 5
Memory Requirements Semi constants requirements permanent storage (available at program start) accessible to program (read & write access) protected against accidental modifications 6
Memory Requirements Variables requirements temporary storage (computed by program) accessible to program (read & write access) fast access 7
Memory Types Different types of memory for different uses 2 major classifications: ROM (read only memory): read access (more or less) RAM (random access memory): read & write access 8
ROM Memory ROM: lots of different types ROM PROM (Programmable ROM) EPROM (Erasable Programmable ROM) EEPROM (Electrically Erasable Programmable ROM) Flash (Flash EEPROM) common feature: retain data even after loss of power 9
ROM Memory ROM programmed at production (with a mask) customer gives desired contents to manufacturer no later changes possible used for mass production (cheap for high quantities) 10
ROM Memory PROM: Programmable ROM array of fuses, can be programmed once customer can program the memory programming: destroy memory cells to create 0's special programming device required (high programming current destroys cells) later changes possible if 1 > 0 (but not 0 > 1) OTP: One Time Programmable 11
ROM Memory EPROM: Erasable Programmable ROM can be erased by UV light quartz window in chip admits light > cells are erased erasure requires UV lightsource can only erase whole chip, not single cells progr. voltage higher than operating voltage about 100 write cycles 12
ROM Memory OTP EPROM: EPROM without a window cheaper (plastic casing instead of ceramic) is used after code is bug free can use same programmer as with EPROM 13
ROM Memory EEPROM: Electrically Erasable PROM can be erased electrically in system programming possible! can erase single cells > can simply write to it writing is slooooow (ms range!) guaranteed endurance of about 100k write cycles guaranteed data integrity typically 10 years 14
Flash: EEPROM with an edge erasure of blocks, not single cells block writes > faster ROM Memory nice for situations where larger portions of memory have to be changed (e.g. program updates) guaranteed endurance of about 1k 10k write cycles guaranteed data integrity typically 10 years 15
RAM Memory RAM: Random Access Memory DRAM (Dynamic RAM) SRAM (Static RAM) NVRAM (Non Volatile RAM) common feature: lose data after loss of power (except NVRAM) 16
RAM Memory DRAM: Dynamic RAM loses data after some time (ms range) needs refreshing every few ms (read contents, write them again) > lower bound on operating frequency! reading a cell destroys the contents > have to write it back inexpensive (only 1 transistor per cell) not used for microcontrollers 17
SRAM: Static RAM RAM Memory retains data during read operation does not require refresh cycles > no lower bound on operating frequency more expensive (4 transistors per cell) commonly used in microcontrollers 18
RAM Memory NVRAM: Non Volatile RAM combination of SRAM and EEPROM read & write operations access SRAM SRAM is copied to EEPROM before power down EEPROM is copied to SRAM after power up restrictions on life time due to EEPROM combines permanent storage with fast access times 19
RAM Memory NV SRAM: SRAM with battery just an SRAM, but with battery during power down, battery power retains data no restriction on number of write cycles data loss if battery dies during power down 20
Memory Characteristics Comparison (AN170 Dallas Semiconductor) Memory read (ns) write (per byte) lifetime EPROM 45 200 100 us 100 cycles EEPROM 70 200 200 us 1 ms 10k 100k Flash 45 200 10 us 1k 10k NV SRAM 70 200 70 200ns infinite ROMs are slow to write compared to SRAM 21
Microcontrollers tend to have Flash EEPROM SRAM We need to store Memory program constants semi constants, variables 22
Memory Possible memory allocations: Flash: Program, Constants EEPROM: Program, (Semi )Constants SRAM: (Program, (Semi )Constants), Variables One limitation: architecture restrictions 23
Memory Architectures von Neumann architecture program and data in same memory and/or accessed through same bus program instruction fetches conflict with data access > von Neumann bottleneck program execution gets slowed down 24
Memory Architectures Harvard architecture program and data in different memories and accessed through different busses no conflicts between program and data access > faster than von Neumann drawback: more complex hardware 25
Memory Address Space one common address space for all memory types same access strategy for all memory types memory allocation under control of programmer one address space per memory type access to program memory is different from access to data memory (e.g. ATmega16: Flash program memory access with special instructions, SRAM data memory with normal addresses, EEPROM with dedicated registers) memory allocation is restricted (e.g. program only in Flash) 26
Memory Allocation Memory Allocation: Program initial value of PC is 0x0000 > either put program there, or put in a jump to program starting address RAM: easy code modifications, no lifetime concerns > for prototyping; program is gone after power loss ROM: when code is finished; program is available after power on Flash: easy update of code (new versions) Harvard: program memory is fixed (e.g. Flash) 27
Memory Allocation Memory Allocation: Constants if really constant (no changes): Flash is nice (implicit write protection) if configuration parameters (change seldomly): EEPROM (data retention) SRAM: possibly during development (faster access, no lifetime concerns); but changes required if no common address space 28
Memory Allocation Memory Allocation: Variables SRAM (easy and fast access) EEPROM: only if there is not enough space in SRAM, beware write lifetime and slow write access! 29
Memory Types: ROM (ROM, PROM, EPROM, EEPROM, Flash): slow writes (finite), retain data after power loss RAM (DRAM, SRAM, NVRAM/NV SRAM): fast writes, lose data if not non volatile Allocation: Lecture Summary Flash: Program and constants EEPROM: configuration parameters SRAM: variables 30
von Neumann architecture: common program and data memory, common bus, von Neumann bottleneck Harvard architecture: separate program and data memory > faster Address space: Lecture Summary all memory modules in one address space each memory has its own address space 31