TKT TKT - - 3500 3500 Microcontroller Microcontroller systems systems Lec 1 Lec 1 – – Introduction to Introduction to Microcontrollers Microcontrollers Erno Salminen Erno Salminen Institute of Digital and Computer Systems Institute of Digital and Computer Systems Tampere University of Technology Tampere University of Technology Fall 2008 Fall 2008 #2/52 Microcontroller Merriam-Webster dictionary: microcontroller [\mī-krō\\-kən-trō-lər\ ] Function: noun, Date: 1971 a microprocessor that controls some or all of the functions of an electronic device (as a home appliance) or system micro - very small controller - one that controls or has power or authority to control control - to exercise restraining or directing influence over #3/52 Microcontroller (2) Microcontroller (2) Microcontrollers are used in automatically controlled products and devices such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toys i.e. in embedded systems Microcontroller chip includes, for example an integrated microprocessor memories (RAM, Flash, EEPROM etc.) input and output peripherals timers, event counters, PWM generators etc. clock generator many include analog-to-digital converters in-circuit programming and debugging support A PIC 18F8720 microcontroller in an 80-pin TQFP package. #4/52 Microcontroller (2) Microcontroller (2) It emphasizes high integration, in contrast to a microprocessor which only contains a CPU (and cache) functional computer system-on-a-chip Difference between uproc and ukontr is blur Modest processing capability Adequate for simple control applications Usually not meant for heavy number crunching Low power consumption Cheap unit price, high volumes Programmable devices
13
Embed
TKT-3500 Merriam-Webster dictionary - TUT Program flow CPU executes instructions step by step Instructions are executed consecutively (addresses 0x0, 0x2, 0x4) until ...
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
TKTTKT--3500 3500 Microcontroller Microcontroller systemssystemsLec 1 Lec 1 –– Introduction to Introduction to MicrocontrollersMicrocontrollers
Erno SalminenErno Salminen
Institute of Digital and Computer SystemsInstitute of Digital and Computer SystemsTampere University of TechnologyTampere University of Technology
Fall 2008Fall 2008
#2/52
MicrocontrollerMerriam-Webster dictionary:microcontroller [\mī-krō\\-kən-trō-lər\ ]Function: noun, Date: 1971a microprocessor that controls some or all of the functions of an electronic device (as a home appliance) or system
micro - very smallcontroller - one that controls or has power or authority to controlcontrol - to exercise restraining or directing influence over
#3/52
Microcontroller (2)Microcontroller (2)Microcontrollers are used in automatically controlled products and devices
such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toysi.e. in embedded systems
Microcontroller chip includes, for examplean integrated microprocessormemories (RAM, Flash, EEPROM etc.)input and output peripheralstimers, event counters, PWM generators etc.clock generator many include analog-to-digital convertersin-circuit programming and debugging support
A PIC 18F8720 microcontroller in an 80-pin TQFP package.
#4/52
Microcontroller (2)Microcontroller (2)It emphasizes high integration, in contrast to a microprocessor which only contains a CPU (and cache)
functional computer system-on-a-chipDifference between uproc and ukontr is blur
Modest processing capabilityAdequate for simple control applications
Usually not meant for heavy number crunching
Low power consumptionCheap unit price, high volumes
Programmable devices
#5/52
Where are the processors [Tennenhouse00]Where are the processors [Tennenhouse00]
Interactive 2% denotes PCs and serversPortable devices (cell phones etc) have spread after 2000
Embedded systems (1)Embedded systems (1)Application specific electronic sub-system used in a larger system such as an appliance, an instrument or a vehicleNot User-Programmable
System needs to implement only a limited function whose characteristics are known at design timeThe design can take advantage of the specification’s characteristics in ways that general-purpose computing systems cannot
Targeting certain performance level instead of maximumBased on both hardwired and programmable components
e.g. CPU, DSP, custom HW
#7/52
Embedded systems (2)Embedded systems (2)
Fig: [Pinello, TVLSI08]
Hardware/Software co-design requiredResemble distributed systems
multiple tasks are running on multiple processing elements (PE)interprocess communication and synchronization critical
Are subject to external timing constraints Hard real-time – missed deadlines are fatal
e.g. ABS brakes, safety system of nuclear plantSoft real-time – missed deadlines cause degraded quality or inconvenience
e.g. video frames are dropped
#8/52
Embedded systems (3)Embedded systems (3)Reactive Real-Time Systems
Continuous interaction with external environmentIdeally never terminate
while (1) {read the sensorscontrol the actuatorssleep()}Where would execution
go after main()?
#9/52
Examples of embedded systemsExamples of embedded systemsasdcarcar
digital digital cameracamera
mobile phonemobile phone
harvesterharvester
robotrobot
Figures from Wikipedia
network routernetwork router
elevatorelevator
washing washing machinemachine
PDAPDA
game consolegame console
printerprinter medical medical equipmentequipment
microwave ovenmicrowave oven
factory automationfactory automation#10/52
Stored program conceptStored program conceptProgram’s instructions (control statements) are stored in memory
In contrast to e.g. ASIC, in which the control is hard-wired during manufacturingCPU repeats fetch-execute cycle for every instruction
Originates from Turing machine (1936) that manipulates data based on the instructions and state of the machine
The behavior can be programmedAn universal machine – it can simulate the behavior of any other machineTheoretical concept that assumes infinite memory capacity
#11/52
Memory typesMemory typesEvery microprocessor needs some memory
May be internal (on the same chip), external, or combination
1. Instruction memoryStores the program’s inctructionsNon-volatile – keeps the information when powered off
mask-programmed read-only memory (ROM)(electronically) erasable programmable ROM (EEPROM/EPROM)Flash memory
2. Data memoryStores the program’s variables and statusMost parts volatile – contents lost when powered off
static random access memory (SRAM), dynamic RAM (DRAM)
Some parts may be non-volatileEEPROM, Flash, (in principle also hard-disk)
#12/52
Memories (2)Memories (2)Memory type affects cost, speed, area, and power consumption notably
E.g. SRAM is expensive, fast, area- and power consuming technology
The program may be copied from non-volatile mem to faster RAM during initalization
The same RAM may contain both program and data sections as well (classical von Neumann architecture)Whereas Harvard architecture separates program and data address spaces
#13/52
Microprocessor ProgrammingMicroprocessor ProgrammingA program is a set of instructions written in a specific sequence for a processor to accomplish specified tasksAn instruction is defined as a simple task (such as addition) performed by the microprocessor
To the microprocessor, instructions must be supplied in binary, i.e., as machine languageInstruction-set is processor-specific (PIC, x86, MIPS…)
Assembly language is a symbolic language which represents machine-language instructions with short human-readable mnemonics
For example, in PIC assembler a null operation or ‘no operation’is represented by the mnemonic ‘NOP’One-to-one correspondence between the assembly language mnemonics and the machine code instructions
An assembler is a software tool that converts assembler source programs into machine language object files
#14/52
Machine and assembly languages are referred to as low-level languages
Generally faster and more compact than higher-level language programsNot portable to other processors, tedious to write
High-level languages are machine-independent
E.g. C/C++, Java Program’s source codes are translated by compilers or interpreters into machine languageThe translated code is called object codeEasier to debug and port
Whther params are in registers or in memoryAddressing types (direct, indirect...)
add/sub/AND/XOR/OR...
src0 src1 dstinstr type 1
instr type 2add/sub/AND/XOR/OR...
src0
(also dst)
immediate
add reg0, reg5, reg3i.e. reg3 ← reg0 + reg5
and reg0, 0x500i.e. reg3 ← reg0 & 0x500
instr type 3jmp address goto Nevada
i.e. PC ← address of label Nevada...
015 347811
#17/52
MicroMicro--architecturearchitectureDefines the HW resources that implement ISA
arithmetic-logic unit (ALU) performs the actual computationcontrol logic fetches the instructions, decodes them and passes to ALUregisters store temporary data(optional) internal memories store instructions and/or datamemory and IO buses provide connection to outisde world Peripherals perform supplementary tasks
There may be several micro-architectures for the same ISA
digital IO
instr. fetch ext. mem IO
instr. mem
data mem
instr. decode
oscillator
register filepipeline ctrl ALU
timer
power ctrl analog IO
watchdog
CPU
peripherals
micro-controller
multiplier
#18/52
Clock cycle and Instruction cycleMachine operations are sequenced by clock signal
Provided by external or internal oscillator (RC circuit, INV-loop, quartz crystal)Oscillator signal may multiplied/divided by constant (e.g. 10 MHZ * 4 = 40 MHZ)
Execution of machine instruction may take more one clock cycle
Program flow (2)After reset, PC gets the value of reset vectorUsually rst vec points to some sort of (ccompiler-generated) initialization function that will call the user’s main functionCall graph shows which functions are called and their order (nesting)Interrupt service routine (ISR) may be called ”anywhere”
After that execution continues from the interrupted point
init(){ ... main()}
main(){ ... foo() ... while(1){}
foo() { ... bar() ... return
bar(){ ... return
isr() { ....
return from int}
0x0rst vec
#21/52
Example microcontrollersExample microcontrollersAtmel AVR
PIC microcontrollersPIC microcontrollersDesigned and sold by Microchip Corporation http://www.microchip.comPIC = initially Programmable Interface Controller
then Programmable Intelligent ComputerMany configurations of 8-, 16- and 32-microcontrollers
PIC18LF8722PIC18LF8722Used on this courseSymbol L stands for Low Power - Operating voltage 2-5.5 V,
normally 4.2-5.5 VF for Flash memory (?)
Accumulator machine Accumulator= special register for storing resultsMakes assembly and high level compiler writing complicatedW-register= ALU’s working register (WREG)Many operations can be done only in W-register
Includes lots of functionality: only few extra components neededCommunication: USART with NMEA (National Marine Electronics Association)messagesOperating voltage: 2.7 – 3.3 VMax power dissipation 500 mW
Sarantel GeoHelix-SActive GPS antennaOperating voltage: 2-3.5 VTypical current 15 mA
Picks up sound evenly from all directionsConnection: ADC
PIC18LF8722 has 16 ADC channels, but one converter
Image: www.farnell.com
Image: www.farnell.com
#47/52
ProgrammingProgrammingMicrochip ICD2
In-Circuit DebuggerIncludes 5V Power supply
Not used with TUTWSN nodes due to lower voltages -> External voltage source needed
Works fine with MPLAB IDE
Image: www.microchip.com
#48/52
At firstAt first
Make sure that simple things work before even trying more complex ones
HUOM! OBS!
Muy importante!
#49/52
Two great truths in designTwo great truths in design
1.If it's not tested, it's broken
2.If it's not simple, it's broken[M. Keating, ISQED, 2006]
#50/52
ConclusionsMicroprocessors/controllers are used practically everywhere
High volume necessitates cheap price per deviceThis allows only modest performanceControllers integrate several peripherals into same chip with processor
In embedded systems, designers target certain performace level, not for max. perf.
System is optimized (made maximally cheap) while still meeting the requirements
Programmability allows faster development and upgrades also after shippingConnectivity of components is the key in many projects
Exercise platform integrates many sensors. Extremely good for educational purposes
Portability and shorter dev.time favor using high-level languages (C/C++) instead of assembly