embedded presentation
DESCRIPTION
basic embedded system tutorialTRANSCRIPT
EMBEDDED SYSTEMS
What is Embedded Systems?
• Which is designed/developed to perform one or more(limited) dedicated task
“An Embedded System is a microprocessor/microcontroller based system that is embedded as a subsystem, in a larger system (which may or may not be a computer system)”
• Application Oriented
• Must have Microcontroller/Microprocessor
• Connected Peripherals
• Must have memory ( most of them )
Quiz: Name one without memory?
• Real Time Constraints of System
Application areas
• Automotive electronics
• Aircraft electronics
• Trains
• Telecommunication 3
Application areas
4
AuthenticationAuthentication
Military applicationsMilitary applications
Medical systemsMedical systems
Application areas
Consumer electronicsConsumer electronics
5Smart buildingsSmart buildings
Fabrication equipmentFabrication equipment
• Difference between a Microprocessor and Microcontroller?– Note : RAM, ROM, I/O, Timer, Serial Com port
Quiz :Examples of Both
• How to decide which one to select ?1. Cost
2. Speed
3. Utilization
4. Power Utilization
5. Need of the system/Application
• An arithmetic logic unit (ALU) for processing
• Permanent memory for keeping the program (= ROM)
• Volatile memory for computation (= RAM)
• Rewritable permanent memory for logging, tuning, storing intermediate data (= EEPROM)
• Connectivity to peripherals
• Binary outputs via single chip pins
• Integrated asynchronous and synchronous serial interfaces such as
UART, I2C, RS232, CAN,SPI
What is a Microprocessor ?
8
Embedded System Structure(Generic)
Memory
Processor & ASICsA-DSensor
D-A Actuator
General Characteristics of Embedded Systems
• Perform a single task – Usually not general purpose
• Increasingly high performance and real time constrained
• Power, cost and reliability are important considerations
• HW-SW systems– Software is used for more features and flexibility– Hardware (processors, ASICs, memory etc. are used for
performance and security
9
General Characteristics of Embedded Systems (contd.)
ASIPs and ASICs form a significant component
– Adv: customization lower power, cost and enhanced performance
– Disadv: higher development effort (debuggers, compilers etc.) and larger time to market
10
ASIC s
Processor Cores
Mem
Analog IO
Digital
HARVARD ARCHITECTURE• Harvard Architecture refers to a memory structure where the processor is connected to two different memory banks via two sets of buses• This is to provide the processor with two distinct data
paths, one for instruction and one for data• Through this scheme, the CPU can read both an instruction and data from the respective memory banks at the same time• This inherent independence increases the throughput
of the machine by enabling it to always prefetch the next instruction
• The cost of such a system is complexity in hardware Commonly used in DSPs
VON-NEUMANN ARCHITECTURE• A Von-Neumann Machine, in contrast to the Harvard Architecture provides one data path (bus) for both instruction and data As a result, the CPU can either be fetching an instruction from memory, or read/writing data to it Other than less complexity of hardware, it allows for using a single, sequential memory.• Today’s processing speeds vastly outpace memory access times, and we employ a very fast but small amount of memory (cache) local to the processor• Modern processors employ a Harvard Architecture to read from two instruction and data caches, when at the same time using a Von-Neumann Architecture to access external memory
Little v/s BIG ENDIAN• Although numbers are always displayed in the same way, they are
not stored in the same way in memory• Big-Endian machines store the most significant byte of data in the lowest memory address• Little-Endian machines on the other hand, store the least
significant byte of data in the lowest memory address• A Little-Endian machine stores 0x12345678 as: ADD+0: 0x78 ADD+1: 0x56 ADD+2: 0x34 ADD+3: 0x12• A Big-Endian machine stores 0x12345678 as: ADD+0: 0x12 ADD+1: 0x34 ADD+2: 0x56 ADD+3: 0x78
8051 Flavors ( AT89c51)
• 4 Kbytes of Flash,
• 128 bytes of RAM,
• 32 I/O lines,
• two 16-bit timer/counters,
• 6 Interrupts
• 5V Vcc
• 40 pin Packaging
Pin Description of the 8051
1234567891011121314151617181920
4039383736353433323130292827262524232221
P1.0P1.1P1.2P1.3P1.4P1.5P1.6P1.7RST
(RXD)P3.0(TXD)P3.1
(T0)P3.4(T1)P3.5
XTAL2XTAL1
GND
(INT0)P3.2(INT1)P3.3
(RD)P3.7(WR)P3.6
VccP0.0(AD0)P0.1(AD1)P0.2(AD2)P0.3(AD3)P0.4(AD4)P0.5(AD5)P0.6(AD6)P0.7(AD7)EA/VPPALE/PROGPSENP2.7(A15)P2.6(A14)P2.5(A13)P2.4(A12)P2.3(A11)P2.2(A10)P2.1(A9)P2.0(A8)
8051(8031)
Figure (a). XTAL Connection to 8051
C2
30pF
C1
30pF
XTAL2
XTAL1
GND
Using a quartz crystal oscillator We can observe the frequency on the XTAL2 pin.
Pins of 8051( 1/4)
• Vcc ( pin 40 ):– Vcc provides supply voltage to the chip. – The voltage source is +5V.
• GND ( pin 20 ): ground• XTAL1 and XTAL2 ( pins 19,18 )
Pins of 8051( 2/4)
• RST ( pin 9 ): reset– It is an input pin and is active high ( normally low ) .
• The high pulse must be high at least 2 machine cycles.
– It is a power-on reset.• Upon applying a high pulse to RST, the
microcontroller will reset and all values in registers will be lost.
• Reset values of some 8051 registers
Pins of 8051( 3/4)
• /EA ( pin 31 ): external access
– There is no on-chip ROM in 8031 and 8032 .– The /EA pin is connected to GND to indicate the code is
stored externally.– /PSEN & ALE are used for external ROM.– For 8051, /EA pin is connected to Vcc.– “/” means active low.
• /PSEN ( pin 29 ): program store enable– This is an output pin and is connected to the OE pin of the
ROM.
Pins of 8051( 4/4)
• ALE ( pin 30 ): address latch enable– It is an output pin and is active high.– 8051 port 0 provides both address and data.– The ALE pin is used for de-multiplexing the address
and data by connecting to the G pin of the 74LS373 latch.
• I/O port pins– The four ports P0, P1, P2, and P3.– Each port uses 8 pins.– All I/O pins are bi-directional.
Pins of I/O Port
• The 8051 has four I/O ports– Port 0 ( pins 32-39 ): P0 ( P0.0 ~ P0.7 )– Port 1 ( pins 1-8 ) : P1 ( P1.0 ~ P1.7 )– Port 2 ( pins 21-28 ): P2 ( P2.0 ~ P2.7 )– Port 3 ( pins 10-17 ): P3 ( P3.0 ~ P3.7 )– Each port has 8 pins.
• Named P0.X ( X=0,1,...,7 ) , P1.X, P2.X, P3.X• Ex : P0.0 is the bit 0 ( LSB ) of P0 • Ex : P0.7 is the bit 7 ( MSB ) of P0• These 8 bits form a byte.
• Each port can be used as input or output (bi-direction).
Other Pins
• P1, P2, and P3 have internal pull-up resisters.– P1, P2, and P3 are not open drain.
• P0 has no internal pull-up resistors and does not connects to Vcc inside the 8051.– P0 is open drain.– Compare the figures of P1.X and P0.X.
• However, for a programmer, it is the same to program P0, P1, P2 and P3.
• All the ports upon RESET are configured as output.
Port 0 with Pull-Up Resistors
P0.0P0.1P0.2P0.3P0.4P0.5P0.6P0.7
DS5000
8751
8951
Vcc10 K
Port 0
Port 3 Alternate Functions
17RDP3.7
16WRP3.6
15T1P3.5
14T0P3.4
13INT1P3.3
12INT0P3.2
11TxDP3.1
10RxDP3.0
PinFunctionP3 Bit
Registers
A
B
R0
R1
R3
R4
R2
R5
R7
R6
DPH DPL
PC
DPTR
PC
Some 8051 16-bit Register
Some 8-bitt Registers of the 8051
SP
Memory mapping in 8051
• ROM memory map in 8051 family
0000H
0FFFH
0000H
1FFFH8751
AT89C51 8752AT89C52
4k 8k
• RAM memory space allocation in the 8051
7FH
30H
2FH
20H
1FH
17H
10H
0FH
07H
08H
18H
00HRegister Bank 0
(Stack ) 1Register Bank
Register Bank 2
Register Bank 3
Bit-Addressable RAM
Scratch pad RAM
Stack in the 8051
• The register used to access the stack is called SP (stack pointer) register.
• The stack pointer in the 8051 is only 8 bits wide, which means that it can take value 00 to FFH. When 8051 powered up, the SP register contains value 07.
7FH
30H
2FH
20H1FH
17H10H
0FH
07H
08H
18H
00HRegister Bank 0
)Stack (Register Bank 1
Register Bank 2
Register Bank 3
Bit-Addressable RAM
Scratch pad RAM
Program Counter• The Program Counter is a 16 or 32 bit register which
contains the address of the next instruction to be executed
• The PC automatically increments to the next sequential memory location every time an instruction is fetched
• Branch, jump, and interrupt operations load the Program Counter with an address other than the next sequential location
• During reset, the PC is loaded from a pre-defined memory location to signify the starting address of the code
RestVector• The significance of the reset vector is that it points the
processor to the memory address which contains the firmware’s first instruction
• Without the Reset Vector, the processor would not know where to begin execution
• Upon reset, the processor loads the Program Counter (PC) with the reset vector value from a pre-defined memory location
• On CPU08 architecture, this is at location $FFFE:$FFFF• A common mistake which occurs during the debug phase
– when reset vector is not necessary – the developer takes it for granted and doesn’t program into the final image. As a
result, the processor doesn’t start up on the final product.
Stack Pointer• The Stack Pointer (SP), much like the reset vector, is
required at boot time for many processors• Some processors, in particular the 8-bit microcontrollers automatically provide the stack
pointer by resetting it to a predefined value• On a higher end processor, the stack pointer is usually
read from a non-volatile memory location, much like the reset vector
• For example on a ColdFire microprocessor, the first sixteen bytes of memory location must be
programmed as follows:• 0x00000000: Reset Vector• 0x00000008: Stack Pointer
Infinite Loop
• Embedded Systems, unlike a PC, never “exit” an application• They idle through an Infinite Loop waiting for an event to happen in the form of an interrupt, or a pre-scheduled task• In order to save power, some processors enter special sleep or wait modes instead of idling through an Infinite Loop, but they will come out of this mode upon either a timer or an External Interrupt
Interrupts
• Interrupts are mostly hardware mechanisms which tell the program an event has occurred• They happen at any time, and are therefore asynchronous to program flow• They require special handling by the processor, and are ultimately handled by a corresponding Interrupt Service Routine (ISR)• Need to be handled quickly. Take too much time servicing an interrupt, and you may miss another interrupt.
Compilation of C file
Source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
Breaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
C Preprocessor (.cpp)
• Pass over source– Insert included files– Perform macro substitutions
• Define macros– #define NUM 100– #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR-
>metrics)
• gcc –E example.c sends preprocessor output to stdout
Breaking Down CC
source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
Compiler• gcc actually name of a script
• Compiler translates one language to another (or the same???)
• gcc compiler translates C to assembler
• gcc –S example.c “saves” example.s
• Compiler consists of– Parser– Code generation– Mysticism
Breaking Down CC
Source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
Assembler
• Another translator ??? (as example.s)
• Assembler to (binary) object
• Why not compile straight to binary?
• gcc –c example.c to “save” object
• NM to look at object (nm example.o)
Breaking Down CC
Source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
Linker
• Combine objects, both user .o files and libraries, make an executable
• gcc *.o –lm yields a.out
• gcc –o myExec *.o –lm
• Use nm to look at object
Breaking Down CC
Source
Preprocessed
SourceASM
O
B
J
E
C
T
.s
.o
Preprocessor Compiler Assembler
LinkerLoader
Executable
a.out
Executable
Program
In Memory
Loader
• Gets an address to place program
• Changes necessary addresses (if any)
• Places code into memory
Project development and an Assembler
Note: Let us assume that assembler and programmer driver is
already installed on PC.
Software tools: Editor, Assembler and EPROM driver
Hardware tools: PC and EPROM programmer
Editor
• It is a software tool, used to create, edit and maintain source file.
• It creates a file in an ASCII file format.
• Different types editors are in existence
• They come with different features. E.g. Refer Notepad features
Assembler• What is an assembler?• Types of assembler –Single Pass & two Pass Assembler• Working on Assemblers – procedure
STEP No1: Go to Command line
Open an Editor
>>edit OR /* It opens a new file with name sample.asm */
>> edit sample.asm /* This is a source a file */
STEP No 2: Create, edit and save a source file.
STEP No 3: Assemble a source file
>> A51 sample.asm /* A51.exe is an assembler */
• It creates various files, e.g. sample.hex, sample.lst etc.
STEP No 4: Open EPROM driver, download binary image to the
target board with the help of EPROM Programmer
EPROM Programmer: Model 1
EPROM Programmer: Model 2
EEPROM Programmer: Model 3
Project development and a Compiler: (x)Note: Assume that a compiler and programmer driver is already
installed on PC.
Software tools: Editor, Compiler and EPROM driver
Hardware tools: PC and EPROM programmer
Project development and an IDE
Integrated Development Environment (IDE):• All software tools discussed earlier, are kept under one common
unified user interface, i.e. IDE
• Becomes possible to make a code change and get the modified
code loaded with a few mouse clicks
• A good IDE allows you for example to click on a syntax error
message produced by the compiler and have the source code with
the highlighted offending instruction pop up for editing in the text
editor
• Some IDEs are flexible enough to allow you to incorporate different
choices of third party tools (like compilers and debuggers), others
only work with a manufacturer's own tool chain.
Debugging tools
• Different types of tools – differ greatly in terms of development time
spend and debugging features available e.g.
- Simulators.
- Microcontroller starter kits.
- Emulator.
Simulators• It tries to model the behavior of the complete microcontroller in
software
• No matter how fast your PC, there is no simulator on the market that can actually simulate a microcontroller's behavior in real-time
• A simulator can also not talk to your target system, so functions that rely on external components are difficult to verify
• For that reason simulators are best suited to test algorithms that run completely within the microcontroller
• They are the perfect tool to complement expensive emulators for large development teams, where buying an emulator for each developer is financially not feasible
Microcontroller Starter Kits:• It consists of:
- Hardware board(Evaluation board).
- In system programmer.
- Some software tools like compiler,assembler, linker etc
- sometimes an IDE and code –size limited evaluation version of a compiler
• A big advantage of these kits over simulators is that they work in
real-time and thus allow for easy input/output functionality
verification.
• Starter kits, however, are completely sufficient and the cheapest
option to develop simple microcontroller projects
Emulators• An emulator is a piece of hardware that ideally behaves exactly like
the real microcontroller chip with all its integrated functionality
• It is the most powerful debugging tool of all
Debug board modules: (DBM)• The "debug board" approach combines all of the emulator
electronics and the actual emulation chip onto a single, larger sized PCB.
Machine Cycle VS Clock Cycle
• 4Mhz to 30 Mhz , our case we will be using 11.0592 Mhz crystal.
• one machine cycle lasts 12 oscillator periods.
• Period of machine cycle = 11.0592/12 = 921.6khz
machine cycle is 1/921.6khz = 1.085us.