Professional Documents
Culture Documents
ES-M1-Notes
ES-M1-Notes
MODULE 1
INTRODUCTION
An embedded system is an electronic/ electro-mechanical system designed to perform a specific function
and is a combination of both hardware and firmware (software).
Every embedded system is unique, and the hardware as well as the firmware is highly specialized to the
application domain. Embedded systems are becoming an inevitable part of any product or equipment in
all fields including household appliances, telecommunications, medical equipment, industrial control,
consumer products, etc.
2. Second Generation: These are embedded systems built around 16 bit microprocessors and 8 or 16 bit
microcontrollers, following the first generation embedded systems. The instruction set for the second
generation processors/controllers were much more complex and powerful than the first generation
processors/controllers. Some of the second generation embedded systems contained embedded operating
systems for their operation. Data Acquisition Systems, SCADA systems. etc. are examples of second
generation embedded systems.
4. Fourth Generation: The advent of System on Chips (SoC), reconfigurable processors and multicore
processors are bringing high pcrfom1nnce, tight integration and miniaturization into the embedded device
market The SoC technique implements a total system on a chip by integrating different functionalities
with a processor core on no integrated circuit. The fourth generation embedded systems are making use of
high performance real time embedded operating systems for their functioning. Smart phone devices,
mobile internet devices (MIDs), etc. are examples of fourth generation embedded systems.
Data Communication
Embedded data communication systems are deployed in applications ranging from complex satellite
communication systems to simple home networking systems. The data collected by an embedded terminal
may require transferring of the same to some other systems located remotely. The transmission is
achieved either by a wire-line medium or by a wireless medium. Wireless medium was the most common
choice in all olden days embedded systems. As technology is changing, wireless medium is becoming the
de-facto standard for data communication in embedded systems. A wireless medium offers cheaper
connectivity solutions and make the communication link free from the hassle of wire bundles. Data can
either be transmitted by analog means or by digital means. Modern industry trends are settling towards
digital communication.
Monitoring
Embedded systems falling under this category are specifically designed for monitoring purpose. Almost
all embedded products coming under the medical domain are with monitoring functions only. They are
used for determining the state of some variables using input sensors. They cannot impose control over
variables. A very good example is the electro cardiogram (ECG) machine for monitoring the heartbeat of
a patient. The machine is intended to do the monitoring of the heartbeat. It cannot impose control over the
heartbeat. Some other examples of embedded systems with monitoring function are measuring
instruments like digital CRO, digital multimeters, logic analyzers, etc. used in Control & instrumentation
applications.
Control
Embedded systems with control functionalities impose control over some variables according to the
changes in input variables. A system with control functionality contains both sensors and actuators.
Sensors are connected to the input port for capturing the changes in environmental variable or measuring
variable. The actuators connected to the output port are controlled according to the changes in input
variable to put on impact on the controlling variable to bring the controlled variable to the specified range.
Air conditioner system used in our home to control the room temperature to a specified limit is a typical
example for embedded system for control purpose.
I/O Pins
In AVR, there are 3 to 86 pins for I/O. The number of I/O pins depends on the number of pins in the
package.
Peripherals
The standard peripherals included in AVR are ADC, timers and USART. In AVR, the ADC is 10-bit.
Depends on the AVR family, the number of ADC channels varies up to 16. There are up to 6 timers
besides the watchdog timer. Most AVRs have I2C and SPI buses. Some of them have USB and CAN
interface.
DATA MEMORY
There are two kinds of memory space in AVR:
• Code memory space
• Data memory space
Data memory is composed of three parts
• GPRs (general-purpose registers)
• I/O memory
• Internal data SRAM
GENERAL-PURPOSE REGISTERS
CPU uses many registers to store data temporarily. The information could be a byte of data or an address
pointing to the data to be fetched. Majority of AVR registers are 8 bit registers. The only data type that
supports in AVR is 8-bit. Any data larger than 8 bits must be broken into 8-bit chunks before it is
processed.
There are 32 general purpose registers in AVR. They are R0 – R31. These registers are located in the
lowest area of the memory address. All the general purpose registers are 8-bit registers. They are same as
accumulator in other microprocessors. They can be used by all arithmetic and logic instructions.
I/O MEMORY
I/O memory is dedicated to specific functions such as status register, timers, serial communication, I/O
ports, ADC and so on. Function of each I/O memory location is fixed at the time of design because it is
used for control of the microcontroller or peripherals. I/O memory is made of 8 bit registers. All AVRs
have at least 64 bytes of I/O memory. The first 64 bytes of I/O memory is called Standard I/O
memory. AVRs with more than 32 I/O pins have an extended I/O memory – registers for controlling the
extra ports and the extra peripherals. I/O registers are also called Special Function Registers (SFRs).
The AVR has a flag register called Status Register (SReg), which indicates the arithmetic conditions. It is
an 8 bit register. The flag bits are C, Z, N, V, S, H, T and I. The bits C, Z, N, V, S and H are conditional
flags.
The carry flag will be set (C = 1) if a carry occurred in addition or borrow from a subtraction; otherwise
carry flag is clear (C = 0). Zero flag is set (Z = 1) when the result of the arithmetic operation zero;
otherwise zero flag is clear (Z = 0). Negative flag is set (N = 1) when bit 7 of the previous operation is set
(i.e. the result is negative); otherwise N is cleared. Overflow flag is set (V = 1) whenever the result of a
signed number operation is too large (i.e. causing the high-order bit to overflow into the sign bit). Sign flag
(S) is is the result of Exclusive-ORing of N and V flags. Hal carry flag is set (H = 1) If there is a carry from
D3 to D4 during an ADD or SUB operation; otherwise, it is cleared. This flag bit is used by instructions
that perform BCD (binary coded decimal) arithmetic. The Bit Copy instructions Bit Load (BLD) and Bit
Store (BST) use the T-bit as a source or destination for the operated bit. A bit from a register in the register
file can be copied into T by the BST instruction and a bit in T can be copied into a bit in a register in the
register file by the BLD instruction. The Global Interrupt Enable bit (I) must be set for the interrupts to be
enabled. If the Global Interrupt Enable register is cleared, none of the interrupts are enabled independently
of the individual interrupt enable settings. The I-bit can be set and cleared by the application with the Set
Global Interrupt Flag (SEI) and Clear Global Interrupt Flag (CLI) instructions.
IO PORTS
The number of ports in the AVR family varies depending on the number of pins on the chip. AtMega32
has four ports. They are PORTA, PORTB, PORTC and PORTD. To use any of these ports as an input or
output port, it must be programmed. In addition to being used as simple I/O, each port has some other
functions such as ADC, timers, interrupts and serial communication pins. Each port has three I/O registers
associated with it as shown in the following table:
Port Address Usage
PORTA 0x3B Output
DDRA 0x3A Direction
PINA 0x39 Input
PORTB 0x38 Output
DDRB 0x37 Direction
PINB 0x36 Input
PORTC 0x35 Output
DDRC 0x34 Direction
PINC 0x33 Input
PORTD 0x32 Output
DDRD 0x31 Direction
PIND 0x30 Input
The port registers are designated as PORTx, DDRx and PINx. For example, for Port B we have PORTB,
DDRB and PINB. DDR stands for Data Direction Register and PIN stands for Port INput. Each of the I/O
registers is 8 bits wide and each port has a maximum of 8 pins. Therefore each bit of the I/O registers
affects one of the pins. The following figure shows the relationship between the registers and the pins:
DDRx Register
Each of the ports in the AtMega32 can be used for input or output. The DDRx register is used solely for
the purpose of making a given port an input or output port. To make a port an output, We write 1s to the
DDRx register. To make a port an input port, we must put 0s into the DDRx register. Upon reset, all ports
have the value 0x00 in their DDR registers. This means that all ports are configured as input.
PIN Register
To read the data present at the pins, we should read the PIN register. To bring data into CPU from pins we
read the contents of PINx register.
PORT Register
To send data out to pins we use the PORTx register. There is a pull-up resister for each of the AVR pins.
If we put 1s into bits of the PORTx register, the pull-up resisters are activated. In cases in which nothing
is connected to the pin or the connected devices have high impedence, the resister pulls up the pins.
If we put 0s into the bits of the PORTx register, the pull-up resister is inactive. The pins of AVR
microcontrollers can be in four different states according to the values of PORTx and DDRx as shown in
the following figure:
Synchronizer delay
The input circuit of the AVR has a delay of 1 clock cycles. In other words, the PIN register represents the
data that was present at the pins one clock ago.
Port A
Port A occupies a total of 8 pins (PA0 - PA7). To use the pins of Port A as input or output ports, each bit
of the DDRA register must be set to the proper value. The alternate functions of the pins of Port A are:
Bit Function
PA0 ADC0
PA1 ADC1
PA2 ADC2
PA3 ADC3
PA4 ADC4
PA5 ADC5
PA6 ADC6
PA7 ADC7
Port B
Port B occupies a total of 8 pins (PB0 - PB7). To use the pins of Port B as input or output ports, each bit
of the DDRB register must be set to the proper value. The alternate functions of the pins of Port B are:
Bit Function
PB0 XCK/ T0
PB1 T1
PB2 INT2/ AIN0
PB3 OC0/ AIN1
PB4 SS
PB5 MOSI
PB6 MISO
PB7 SCK
Port C
Port C occupies a total of 8 pins (PC0 - PC7). To use the pins of Port C as input or output ports, each bit
of the DDRC register must be set to the proper value. The alternate functions of the pins of Port C are:
Bit Function
PC0 SCL
PC1 SDA
PC2 TCK
PC3 TMS
PC4 TD0
PC5 TD1
PC6 TOSC1
PC7 TOSC2
Port D
Port D occupies a total of 8 pins (PD0 - PD7). To use the pins of Port D as input or output ports, each bit
of the DDRD register must be set to the proper value. The alternate functions of the pins of Port D are:
Bit Function
PD0 PSP0/ C1IN+
PD1 PSP1/ C1IN-
PD2 PSP2/ C2IN+
PD3 PSP3/ C2IN-
PD4 PSP4/ ECCP1/ P1A
PD5 PSP5/ P1B
PD6 PSP6/ P1C
PD7 PSP7/ P1D