tkt-3500 merriam-webster dictionary
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
[Tennenhouse, D. 2000. Proactive computing. Commun. ACM 43, 5 (May. 2000), 43-50]
#6/52
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
CPU+mem+etc
compiler
assembler
interpreter
design-time
run-time
.c, .h
.asm
.java
.hex
Microprocessor Programming(2)Microprocessor Programming(2)
#15/52
Classification of microprocessorsClassification of microprocessorsNumber of bits
4,8,16,32,64...Number of instructions
RISC (Reduced instruction-set computer)CISC (Complex instruction-set computer)
ASIP (Application-specific instruction-set processor)Memory space
von Neumann – same for instr. and dataHarvard – separate addr spaces
Data path – where are the operandsStackAccumulatorRegister-memoryRegister-register (so called load-store)
Integrated peripherals, pipelining, num of ALUs...
#16/52
CPUCPU’’s instructions instruction--set architecture (ISA)set architecture (ISA)
Defines the supported machine-instructionsDefines size of instruction word and its fields
Operation codes (ADD, SUB, JMP...)Parameters (src0, src0, dst)
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
4 clock cycles/instr. in PIC40 MHz clock yields approx. 10 MIPS
Some instructions take over 4 cycles, e.g. operations affecting program counter (PC)
Some CPUs pipeline the execution of instructionsE.g. instr takes 4 cycles but the next finishes after 1 cycle
#19/52
Program flowCPU executes instructions step by stepInstructions are executed consecutively (addresses 0x0, 0x2, 0x4) until
Branch occurs – if-then-else, function call, gotoException occurs – interrupt, div-by-zero
The address of the next instruction is stored into register program counter (PC)Interrupts are function calls made from HW
Timer overflow (1ms passed)Peripheral device (serial IO transmit completed)External pin (from button)Extremely useful concept
#20/52
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
8- ja 32-bit RISC familiesOver 80 models
Texas Instruments (TI)MSP430 – low powerTMS320 – high performanceTMS470 – ARM7-based
RenesasSuperH – High speed / performanceMR32 – 32-bitH8 – low cost
ST microelectronicsAnd many others...
#22/52
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
8-bit volume prices ~2$-12$Minimalist basic ideology
#23/52
88--bit PIC Familiesbit PIC Families8-bit stands for width of data pathPIC10 (and some PIC12 and PIC16)
Baseline architecture, 12-bit program word16-134 Bytes of SRAM 256- 2K Bytes of flash program memory4-32 IO-Pins, 2 level deep stack
PIC12 and PIC16Midrange architecture, 14-bit program word64-368 Bytes of SRAM1 -8 kBytes of flash program memory6-53 IO-pins, 8 level deep stack
26.08.2008 15:09 Copyright © Tampere University of Technology 2006 www.tkt.cs.tut.fi/research/daci/
Images: www.microchip.com
#24/52
PIC18 familyPIC18 familyHigh-tech 8-bit architecture, program word 16-bit
256 bytes – 4kBytes of SRAM4-128 kBytes of program memory15-70 GPIO-pins
Plenty of peripherals, for example:USB, Ethernet, LCD,CAN
75 instuctions (some models have 83)31 level deep stack
26.08.2008 15:09 Copyright © Tampere University of Technology 2006 www.tkt.cs.tut.fi/research/daci/
#25/52
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
26.08.2008 15:09 Copyright © Tampere University of Technology 2006 www.tkt.cs.tut.fi/research/daci/ #26/52
PIC vs. Pentium roughly speakingPIC vs. Pentium roughly speakingPIC
8-bit1-50 MHz5 mW6 €10-80 pinsHarvard arch.1-10 MIPSFew instructionsAccumulator1 instr/4 cyclesno pipeline or very short
Pentium432-bit, 64-bit2-4 GHz150 W150 €~1000 pinsvon Neumann arch.60 000 MIPSZillions of instructionsRegister bank, Superscalar/EPICDeeply Pipelined
#27/52
Platform for exercises Platform for exercises ––Multisensor sensor network Multisensor sensor network nodenode
#28/52
TUT Wireless Sensor Network (TUTWSN)TUT Wireless Sensor Network (TUTWSN)
Very large research project in TUT/DCS since 2002Sensor networks are emerging technology where the network consists of nodes that
measure (”sense”) the environmentcommunicate autonomously and wirelesllyself-organizing topologymay control actuators
Special courses TKT-2300 and TKT-2456
#29/52
TUTWSN NodesTUTWSN NodesMultisensor node
Includes almost all sensorsUsed in TKT-3500
Other nodesPipe NodeLong range pipe nodeBadge nodeWrist nodeEthernet gatewayhttp://www.tkt.cs.tut.fi/research/daci/ra_tutwsn_prototypes.html
#30/52
TUTWSN Multisensor nodeTUTWSN Multisensor node
#31/52
TUTWSN Multisensor nodeTUTWSN Multisensor node
#32/52
TUTWSN Multisensor nodeTUTWSN Multisensor nodeMicrocontroller: PIC18LF8722
256 kbyte external SRAMSensors and modules
GPS (Global positioning system)RadioTemperatureHumidityAccelerometerCompassLuminance
#33/52
TUTWSN Multisensor nodeTUTWSN Multisensor nodeAdd-on modules (not connected)
PIR (passive infrared, motion detector)VGA CameraMicrophone
Interface1 Pushbutton, 1 ledInput/Output
RS-232 serial portMAX3226E is used to convert voltage levels
SPI (Serial peripheral interface), I2C4 input/output pinsADC (analog-to-digital converter)
#34/52
Power controlPower controlPossible power sources
a) DC power supplyb) 2 AA Batteriesc) Solar panelAll sensors can be turned off by uCVoltage after regulation: 3 V/2 V and 2,7 V
2.7 V is used for GPS, 3V/2V (software selectable) for other devices
#35/52
PIC18LF8722PIC18LF87228 bit RISC microcontroller with Harvard architectureHigh End 8-bit microcontrollerAccumulator…
Assembly programming complicated128 kB program memory, 4 kB SRAM, 1kB EEPROMOperating voltage: 2.0 – 5.5 V
Max. Power dissipation 1 WMin. Power dissipation (@1 Mhz): 3 mWCompare: Normal red led 2V and max 20 mA
Image: www.futurlec.com
#36/52
PIC18LF8722PIC18LF8722Plenty of peripherals
SPI, i2c, USART16 channel 10-bit AD-converter5 timers and capture/compare/PWM moduleHW 8-bit multiplierWatchdog, Brown-out
Max. Frequency: 40 MhzMany power management modesClock sources on platform:
Low frequency external clock Internal clock
#37/52
GPS: iTrax03GPS: iTrax03--s+GeoHelixs+GeoHelix––SSFasttrax iTrax03-s
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
#38/52
Radio: nRF24L01Radio: nRF24L01Operating voltage: 1.9 – 3.6 VFrequency: 2.400 – 2.4835GHzCommunication: SPIFully automated packet handlingCurrent consumption:
Power down 900 nAStandby 22 uA or 320 ua (Two standby modes)Transmission < 11.3 mA, Reception < 12.3 mA
Range about 15 meters indoors
Image: www.nordicsemi.com
#39/52
Temperature Sensor Maxim DS620Temperature Sensor Maxim DS620Operating voltage: 1.7 – 3.5 VCommunication: i2cSelectable resolution:
LSB 0.5°C, 0.25°C, 0.125°C or 0.0625°CConversion time depends on accuracy
10 bit 25 ms, 13 bit 200 ms
Continuos conversion and one shot modes
Image: www.maxim-ic.com
#40/52
Humidity: Sensirion SHT1xHumidity: Sensirion SHT1xHumidity AND temperature sensorOperating voltage: 2.4 – 5.5 V
Communication: ”almost i2c”Not compatible with standard i2c interface
Conversion times: 11 ms (8 bit)210 ms (14 bit)
Accuracy: Humidity 2 %, temperature 0.3 °KCurrent consumption: Sleep 0,3 uA, measuring 550 uA
#41/52
Accelerometer: VTI SCA3000Accelerometer: VTI SCA30003D accelerometerOperating voltage: 2.35 – 3.6 V Communication: SPIModes:
Free fall detectionMotion detectionNormal mode
Current consumption 120 uA in active mode
Image: www.vti.fi
#42/52
Compass: Hitachi HM55BCompass: Hitachi HM55BOperating voltage: 4.8 – 5.2 VCommunication: SPI
Transmission length 4 bits (normal SPI 8 bits)Current consumption: Sleep 1 uA, Measuring 9 mAMeasuring time 30 msResolution: 11 bitsMeasures magnetic field strength
Min. value -180 uT max. 180 uT
Image: www.parallax.com
#43/52
Luminance: Luminance: Agilent APDSAgilent APDS--90029002Photosensor: Luminance is relative to currentOperating voltage: 2.4 – 5.5 VConnected to uC’s analog-to-digital converter
Resolution equals AD-converter’s resolution10 bit in PIC18LF8722
Sample rate = ADC’s sample rateIn PIC user selectable, but depends on clock frequency. About 1 Mhz is theoretical maximum
PIC’s AD-converter operates also in idle mode
Completion of conversion can cause an interrupt
Image: www.farnell.com
#44/52
PIR MS300PIR MS300PIR = Passive Infra Red
Connected to uC’s ADC, but needs an operating voltage
Used as motion detectorOperating voltage: 2.6 V – 5.5 VCurrent consumption: ~35 uA
#45/52
VGA C328VGA C328Max. 640x480 pixels, 16 bitFrames/s depends on image quality
JPEG still picture with best quality 0.75 fpsCamera + compression module + EEPROM
No extra components neededConnection: RS-232JPEG picture formatOperating voltage: 3.0 – 3.6 VOperation current: 60 mASuspend current: 100 uA
Image: www.electronics123.net
#46/52
Microphone Microphone AOMAOM--6746P6746P--RRCapacitor microphoneOmnidirectional
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