Unit - I: Introduction To Embedded Systems

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

UNIT - I

INTRODUCTION TO EMBEDDED SYSTEMS


MSP-EXP430G2 LaunchPad
Definition
An embedded system is a combination of computer hardware
and software, either fixed in capability or programmable,
designed for a specific function or functions within a larger
system. 

Approaches to Embedded Systems


Timer for an Electric Toothbrush
Small-Scale Integration: The 555
Needs an eight-pin 555, two resistors, and one electrolytic
capacitor.
Medium-Scale Integration: 4000 Series CMOS
A large capacitor is needed with the 555 because the period of
oscillation is so long. A remedy is to reduce the period (increase
the frequency) and feed the output into a counter.

A suitable device for this application is the 4060. It contains a


14-bit ripple counter and an internal oscillator circuit to provide a
clock, which needs either a crystal or two resistors and a
capacitor.
Large-Scale Integration: Small Microcontroller
“computer on a chip”
Embedded Electronic Systems and Microcontrollers

• Small-Scale Integration: The 555


• Medium-Scale Integration: 4000 Series CMOS
• Large-Scale Integration: Small Microcontroller
Electronic Dice
JK flip-flops and gates drive the flip-flops through the correct
sequence and provide the clock. This is a simple example of a
Moore state machine.
A microcontroller is often described as a 'computer-on-a-
chip'. It can be used as an ‘electronic brain’ to control a
product, toy or machine.

The microcontroller is an integrated circuit ("chip") that


contains memory (to store the program), a processor (to
process and carry out the program) and input/ output pins (to
connect switches, sensors and output devices like motors).

Microcontrollers are purchased 'blank' and then programmed


with a specific control program. This program is written on a
computer and then 'downloaded' into the microcontroller chip.
Once programmed the microcontroller is built into a product to
make the product more intelligent and easier to use.
Electronic dice that can be made to generate a random number.
It can be used like a normal dice in games.

The dice works by switching Light Emitting Diodes (LEDs) on


and off in the pattern of dots found on a traditional dice. The
microcontroller is the ‘brain’ of the dice.
Microcontrollers are powerful electronic components that have
a memory and can be programmed to switch things on and off in
any sequence. The microcontroller in the dice can switch the
LEDs on and off to show numbers between one and six.
Larger Systems

 Large embedded systems contain personal computers inside


them e.g. Automatic teller machines (ATMs).

 The advantage is hardware is standard and a huge range of


software is available, including operating systems.

 The systems are large and consume a lot of power. Their


reliability may also be questionable.

 Three general approaches can be taken between this extreme


and small-scale integration.
•Application-specific integrated circuits (ASICs): Specially designed for a
particular application as their name implies. They provide the best
performance but are extremely expensive to design and test.

• Field-programmable gate arrays (FPGAs) and programmable logic devices


(PLDs): Essentially an array of gates and flip-flops, which can be connected
by programming the device to produce the desired function.

• Microcontrollers: These have nearly fixed hardware built around a central


processing unit (CPU). The CPU controls a range of peripherals, which may
provide both digital and analog functions such as timers and analog-to-
digital converters.
Applications of Embedded System
 Digital electronics
 Telecommunications
 Computing network
 Smart cards
 Satellite systems
 Military defense system equipment
 Research system equipment
Small Microcontrollers
 A microprocessor contains a complete digital processor, which
includes at least the arithmetic logic unit and associated registers.

 Large, modern microprocessors need huge heat sinks and fans and
can draw over 100A of current.

 A microprocessor needs many other components to support it. These


include a (large) external memory and the other components that can
be found on the motherboard of a personal computer.

 Microcontroller (MCU or C), which contains all of the functions


needed to make a complete computer system, including memory.

 “small” microcontrollers (MCUs) devices can process 8 or 16 bits of


data and have a 16-bit address bus, which means that they can
address 64 KB of memory.
Anatomy of a Typical Small Microcontroller
Central processing unit:
• Arithmetic logic unit (ALU), which performs computation.
• Registers needed for the basic operation of the CPU, such as the
program counter (PC), stack pointer (SP), and status register (SR).

Figure : Essential components of a microcontroller


 Further registers to hold temporary results.

 Instruction decoder and other logic to control the CPU, handle resets, and
interrupts, and so on.

Memory for the program: Nonvolatile (read-only memory, ROM), meaning


that it retains its contents when power is removed.

Memory for data: Known as random-access memory (RAM) and usually


volatile.

Input and output ports: To provide digital communication with the outside
world.

Address and data buses: To link these subsystems to transfer data and
instructions.

Clock: To keep the whole system synchronized. It may be generated


internally or obtained from a crystal or external source; modern MCUs offer
considerable choice of clocks.
Timers:
Most microcontrollers have at least one timer because of the wide range
of functions that they provide.

 Time at which transitions occur on an input can be recorded. This


may be used to deduce the speed of a bicycle. If the input is driven
by a sensor that gives a pulse every time the wheel completes a
revolution.

 Outputs can be driven on and off automatically at a specified


frequency. This is used for pulse-width modulation to control the
speed of the motor in a washing machine, described previously.

 They provide a regular “tick” that can be used to schedule tasks in a


program. Many programs are awakened periodically by the timer to
perform some action
Watchdog timer:

This is a safety feature, which resets the processor if the program becomes
stuck in an infinite loop
Communication interfaces:

• Serial peripheral interface (SPI), inter-integrated circuit (I²C or IIC),


asynchronous (such as RS-232), universal serial bus (USB), controller
area network (CAN), ethernet, and many others.

Nonvolatile memory for data:


• This is used to store data whose value must be retained when power
is removed. Serial numbers for identification and network addresses
are two obvious candidates.

Analog-to-digital converter: This is very common because so many


quantities in the real world vary continuously.

Digital-to-analog converter: Most analog outputs can be simulated


using PWM. An important exception used to be sound.
Real-time clock:

• These are needed in applications that must track the time of day.
Clocks are obvious examples but data loggers are also an important
case. development.

Monitor, background debugger, and embedded emulator:

• These are used to download the program into the MCU and
communicate with a desktop computer during development.
Memory
Volatile and Nonvolatile Memory
Volatile: Loses its contents when power is removed. It is usually called
random-access memory or RAM.

The memory is usually static RAM, which means that it retains its data even
if the clock is stopped.

Memory in a desktop computer is dynamic RAM. This needs only one


transistor per cell but must be refreshed regularly to maintain its contents, so
it is not used in small microcontrollers.
.

 Nonvolatile: Retains its contents when power is removed and is used for
the program and constant data ROM
There are many types of nonvolatile memory

Masked ROM:
The data are encoded into one of the masks used for photolithography
and written into the IC during manufacture.
This memory really is read-only. It is used for the high-volume
production of stable products, because any change to the data
requires a new mask to be produced at great expense.
Some MSP430 devices can be ordered with ROM, shown by a C in their
part number. An example is the MSP430CG4619.

EPROM (electrically programmable ROM):


it can be programmed electrically but not erased. Devices must be
exposed to ultraviolet (UV) light for about ten minutes to erase them.

OTP (one-time programmable memory):


it cannot be erased.
Devices with OTP ROM are still widely used and the first family of the
MSP430 used this technology.
Flash memory: This can be both programmed and erased electrically.
Individual bytes of EEPROM can be erased but flash can be erased only
in blocks.
Most MSP430 devices use flash memory, shown by an F in the part
number.
 Flash memory is used in portable storage devices—memory cards,
USB drives.
Microcontrollers use NOR flash, which is slower to write but
permits random access. NAND flash is used in bulk storage devices and
can be accessed only serially in rows.
Harvard and von Neumann Architectures

Harvard Architecture
 Many microcontrollers use this architecture, including Microchip
PICs, the Intel 8051 and descendents, and the ARM9. The principal
advantage is efficiency.
 It allows simultaneous access to the program and data memories.
For instance, the CPU can read an operand from the data memory at
the same time as it reads the next instruction from the program
memory.

A problem with the Harvard architecture is that constant data (often lookup
tables) must be stored in the program memory because it is nonvolatile. This
means that constants cannot be read in the same way as volatile values from
the data memory.
von Neumann Architecture

 There is only a single memory system in the von Neumann.


Only one set of addresses covers both the volatile and nonvolatile
memories.
 The architecture is intrinsically less efficient because
several memory cycles may be needed to extract a full instruction from
memory.
No difference between access to constant and variable data.

Examples: MSP430, the Freescale HCS08, and ARM7.


SOFTWARE

Several languages may be used for programming a small microcontroller:

Machine code:
The binary data that the processor itself understands. Each instruction
has a binary value called an opcode. It is unrecognizable to humans, unless
you spent a very long time on low-level debugging.

Assembly language:
The instructions are written as words called mnemonics rather than binary
values and a program called an assembler translates the mnemonics into
machine code.
C:
A compiler translates C into machine code that the CPU can
process.
C++:
An object-oriented language that is widely used for larger
devices.
Embedded C++ is a subset of the language intended for
embedded systems.
Java is another object-oriented language, but it is interpreted
rather than compiled and needs a much more powerful processor.
BASIC:
BASIC language is extended with special instructions to drive
the peripherals.
Disadvantages are the code often runs very slowly and the
hardware is expensive if it includes an interpreter.
MSP430
The MSP microcontrollers (MCUs) from Texas Instruments (TI) are
16-bit and 32-bit RISC-based, mixed signal processors designed for
ultra-low power applications.
 MSP430 device features a powerful 16-bit RISC CPU, 16-bit
registers.
The architecture includes five low-power modes is optimized to
achieve extended battery life in portable measurement applications.
 The digitally controlled oscillator (DCO) allows wake-up from low-
power modes to active mode in less than 1second.
The MSP430 instruction set consists of 27 core instructions that
make it easy to program in assembler or in C, and provide exceptional
flexibility and functionality.
The processors include low-cost sensor systems that capture analog
signals, convert them to digital values, and then process the data for
display or for transmission to a host system.
MSP430G2553
Ultra-low-power mixed signal microcontrollers with built-in
1. 16-bit timers; up to 24 I/O capacitive touch enabled pins;
2. Versatile analog comparator
3. Built-in communication capability using the universal serial
communication interface.
4. 10-bit Analogto-Digital Converter (ADC).
MSP430 Pin-out

• VCC and VSS are the supply voltage and ground for the whole device

• P1.0–P1.7, P2.6, and P2.7 are for digital input and output, grouped into ports P1
and P2.

• TACLK, TA0, and TA1 are associated with Timer_A; TACLK can be used as the clock
input to the timer, while TA0 and TA1 can be either inputs or outputs.

• A0−, A0+, and so on, up to A4±, are inputs to the analog-to-digital converter. It has
four differential channels, each of which has negative and positive inputs. VREF is
the reference voltage for the converter.
• ACLK and SMCLK are outputs for the microcontroller’s clock signals.

• SCLK, SDO, and SCL are used for the universal serial interface, which communicates
with external devices using the serial peripheral interface (SPI) or inter-integrated
circuit (I2 C) bus.

• XIN and XOUT are the connections for a crystal, which can be used to provide an
accurate, stable clock frequency.

• RST is an active low reset signal. Active low means that it remains high near VCC for
normal operation and is brought low near VSS to reset the chip.

• NMI is the nonmaskable interrupt input, which allows an external signal to interrupt
the normal operation of the program.

• • TCK, TMS, TCLK, TDI, TDO, and TEST form the full JTAG interface, used to program
and debug the device.

• SBWTDIO and SBWTCK provide the Spy-Bi-Wire interface, an alternative to the usual
JTAG connection that saves pins.
Functional Block Diagram

Block diagram of the MSP430F2003 and F2013


Memory

Fig. Ordering of bits, bytes, and words in memory

Little-endian ordering: The low-order byte is stored at the lower address and the high-
order byte at the higher address. This is used by the MSP430 and is the more common
format.

Big-endian ordering: The high-order byte is stored at the lower address. This is used by
the Freescale HCS08
Memory Map

 Special function registers:


• Mostly concerned with enabling
functions of some modules and
enabling and signaling interrupts
from peripherals.

 Peripheral registers with byte


access and peripheral registers
with word access:
• Provide the main communication
between the CPU and peripherals.

 Random access memory:


• Used for variables. This always
starts at address 0x0200 and the
upper limit depends on the size of
the RAM. The F2013 has 128 B.
 Bootstrap loader:
• Contains a program to
communicate using a standard
serial protocol.

 Information memory:
• A 256 B block of flash memory
that is intended for storage of
nonvolatile data.

 Code memory:
• Holds the program, including
the executable code itself and
any constant data. The F2013
has 2 KB but the F2003 only
1KB.
 Interrupt and reset vectors:
• Used to handle “exceptions,”
when normal operation of the
processor is interrupted or when
the device is reset. This table
was smaller and started at
0xFFE0.
Central Processing Unit
 The central processing unit (CPU) executes the instructions stored in memory.

 It includes the arithmetic logic unit (ALU), which performs computation, a set of 16
registers designated R0–R15

 The CPU can run at a maximum clock frequency fMCLK of 16 MHz in the
MSP430F2xx family and some newer MSP430x4xx devices, and 8 MHz in the
others.

 The CPU can be stopped and will retain its state until it is restarted
Program counter, PC: This contains the address of the next instruction to be executed.

Stack pointer, SP: When a subroutine is called, the CPU jumps to the subroutine,
executes the code there, then returns to the instruction after the call.

Status register, SR: This contains a set of flags (single bits), whose functions fall into
three categories.

 The most commonly used flags are C, Z, N, and V, which give information about the
result of the last arithmetic or logical operation. The Z flag is set if the result was zero
and cleared if it was nonzero

Constant generator: This provides the six most frequently used values so that they need
not be fetched from memory whenever they are needed. It uses both R2 and R3.

General purpose registers: The remaining 12 registers, R4–R15, are general working
registers. They may be used for either data or addresses because both are 16-bit values,
Memory-Mapped Input and Output

 Simple digital input and output takes place through sets of pins on the package of
the integrated circuit called ports.

 The F2013 has all pins of port P1 available, labeled P1.0–P1.7, but only pins P2.6
and P2.7 of port P2.

 The ports simply appear to the CPU as particular memory registers called
peripheral registers.

 Each port is associated with a byte and each bit corresponds to a pin on the
package. These registers can be read, written, and modified in almost the same
way as simple registers in RAM
 P1IN: Reading returns the logical values on the inputs if they are configured for
digital input and output. This register is read-only. It is also volatile, which means
that it may change at a time that a program cannot predict.

 P1OUT: Writing sends the value to be driven onto the pin if it is configured as a
digital output.

 P1DIR: A bit of 0 configures the pin as an input, which is the default. Writing a 1
switches the pin to become an output.
CLOCK GENERATOR
Clocks for microcontrollers is a crystal with a frequency of a few MHz
would be connected to two pins.
• A fast clock to drive the CPU, which can be started and stopped rapidly
to conserve energy but usually need not be particularly accurate.
• A slow clock that runs continuously to monitor real time, which must
use little power and may need to be accurate.
Several types of oscillator are used to generate the clock signal.
Crystal:
Accurate and stable . Crystals for microcontrollers run at either a high
frequency of a few MHz to drive the main bus or a low frequency of
32,768 Hz for a real-time clock.
Disadvantages
 Crystals are expensive and delicate, the oscillator draws a relatively
large current at high frequency and need two capacitors.
 Crystal oscillators also take a long time to start up and stabilize.
Resistor and capacitor (RC):
Cheap and quick to start but used to have poor accuracy and stability.
 The components can be external but are now more likely to be
integrated within the MCU.
The MSP430 consisting of Three internal clocks:
• Master clock, MCLK, is used by the CPU and a few peripherals.
• Subsystem master clock, SMCLK, is distributed to peripherals.
• Auxiliary clock, ACLK, is also distributed to peripherals.
 SMCLK runs at the same frequency as MCLK, both in the megahertz
range.
 ACLK is often derived from a watch crystal and runs at a much lower
frequency. Most peripherals can select their clock from either SMCLK or
ACLK.
MSP430x1xx and MSP430F2xx families:
• ACLK comes from a low-frequency crystal oscillator, typically at 32 KHz.
• Both MCLK and SMCLK are supplied by an internal digitally controlled
oscillator (DCO), which runs at about 0.8 MHz in the MSP430x1xx and 1.1
MHz in the MSP430F2xx.
ACLK requires an external crystal, which is supplied on most
demonstration boards but not TI’s basic development kits .
No crystal means no ACLK with most MSP430s.
MSP430F2xx family include an internal, very low-power,
low-frequency oscillator (VLO) that can be selected for ACLK if there is
no crystal.
Exceptions: Interrupts and Resets

Interrupts:
 Generated by hardware (although they can be initiated by software)
and indicate that an event has occurred that needs an urgent
response.

Eg. Interrupt service routine (ISR). It returns to its previous activity


when the ISR has been completed. Thus an ISR is something like a
subroutine called by hardware (at an unpredictable time) rather than
software.

 A second use of interrupts, which is particularly important in the


MSP430, is to wake the processor from a low-power state.
Resets:
A reset causes the device to (re)start from a well-defined state.
The CPU must be told where to fetch the next instruction following
an interrupt or reset.
The address of this instruction is called a vector and can be
specified in different ways. A reset causes the device to (re)start
from a well-defined state.
 The address of this instruction is called a vector and can be
specified in different ways.
 A single vector for resets and another for all interrupts.
 Microchip PIC16, which executes the instruction at address
0x0000 following a reset and that at 0x0004 following an
interrupt.
 ARM7TDMI has two interrupts (normal and fast). The problem
with this method is that the interrupt service routine has no idea
what caused the interrupt and must first check all the flags to
determine the source. This can be a lengthy process.
 The MSP430 uses vectored interrupts.
 Each ISR has its own vector, which is stored at a predefined address
in a vector table at the end of the program memory (addresses
0xFFC0–0xFFFF). The address for each interrupt vector is listed in the
data sheet.
 There is no need to hunt for the source of the interrupt in most
cases.
 For example, the interrupt vector for the watchdog timer is
stored at address 0xFFF4. When the watchdog timer
requests an interrupt, the processor fetches the vector from
the word stored at 0xFFF4, loads it into the program
counter, and fetches its next instruction from this address to
start the ISR.
 Reset, whose vector is stored in the very last word of memory at
0xFFFE.
Resets:
A reset causes the device to (re)start from a well-defined state.
The CPU must be told where to fetch the next instruction following
an interrupt or reset.
The address of this instruction is called a vector and can be
specified in different ways. A reset causes the device to (re)start
from a well-defined state.

You might also like