0% found this document useful (0 votes)
44 views

IoT Unit 2

The document discusses various microcontrollers and sensors. It provides an overview of microcontrollers and lists some examples. It then discusses the Arduino Uno board, its components and the Atmega328p microcontroller. Finally, it describes several sensors - MQ-02/05 gas sensor, obstacle sensor, ultrasonic distance sensor and LDR sensor - and how to interface them with Arduino.

Uploaded by

Rohit Khairnar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

IoT Unit 2

The document discusses various microcontrollers and sensors. It provides an overview of microcontrollers and lists some examples. It then discusses the Arduino Uno board, its components and the Atmega328p microcontroller. Finally, it describes several sensors - MQ-02/05 gas sensor, obstacle sensor, ultrasonic distance sensor and LDR sensor - and how to interface them with Arduino.

Uploaded by

Rohit Khairnar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Unit-2

Sensors, Microcontrollers
and their
Interfacing
Overview of Microcontrollers
� Microcontroller is a digital device consisting of CPU, peripheral I/Os, memories,
interrupts, etc. in a single chip or IC.
� Microcontroller is a compact integrated circuit designed for a specific operation
in an embedded system.
� The examples of various microcontrollers are given as:

Atmel AVR Microchip – PIC Intel 8051


AtMega8 PIC18F452 AT89C51
AtMega328P PIC16F877 AT89S52
AtMega16 PIC16F676 AT89c2051
AtMega2560 PIC16F72 P89V51
Introduction to Arduino Uno
USB Socket Digital Pins • Atmega328p Microcontroller inside
• The operating voltage is 5V which is given by
• USB socket or
• External power socket
• DC Current for each input/output pin is 40 mA
• Digital input/output pins are 14 to interface digital
input or output devices
• There are 6 Analog i/p pins used for interfacing
analog input devices.
• What is Digital and Analog?
• Memory Components:
• 32KB flash (program) memory
External Power socket Atmega328p Analog Pins
• SRAM is 2 KB
• EEPROM is 1 KB
Components in Arduino Uno
6 2 3 1. Atmega328p Microcontroller: The heart of the board.
2. On-board LED interfaced with pin 13.
3. Power LED: Indicates the status of Arduino whether it
is powered or not.
4. GND and 5V pins: Used for providing +5V and ground
to other components of circuits.
5. TX and RX LEDs: These LEDs indicate communication
between Arduino and computer.
6. Reset button: Use to reset
the ATmega328P microcontroller

5 4 1
Sensors and Their Interfacing
Definition of Sensor
� Sensor is a device that detects or measures a physical property and records,
indicates, or otherwise responds to it.
� A sensor is a device that measures physical input from its environment and
converts it into data that can be interpreted by either a human or a machine.
� Normally, the sensors are input devices and there are two types of sensors.
� Analog Sensors
� Digital Sensors
List of Sensors
� The list of sensors which is to be covered in the chapter is as follows:

MQ-02/05 Gas Sensor Obstacle Sensor Ultrasonic Distance Sensor

LDR Sensor Heartbeat Sensor Gyro Sensor

GPS Sensor Color Sensor pH Sensor


MQ-02/05 Gas Sensor
� MQ -02 sensor is used to detect smoke.
� H2, LPG, CH4 alcohol and smoke can be
detected by MQ-02.
� MQ-05 is not sensitive to smoke, hence less
used in the application.
� Pinout of MQ-02 sensor module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� D0 – Digital output pin
� A0 – Analog output pin
MQ-02/05 Gas Sensor – Working principle
� When any flammable gas passes through the coil of the sensor, the coil burns and
internal resistance decreases.
� This results in an increased voltage across it. Hence we get variable voltage at A0
pin of MQ-05 gas sensor.
� If gas present -> voltage is high.
� If gas is not present -> voltage is low.

Smoke/Gas MQ-05 Gas Sensor Variable Voltage


MQ-02/05 Gas Sensor – Interfacing with Arduino
� The interfacing of MQ-02 with
Arduino Uno is as shown in the
figure.
� Here, Vcc and Gnd pins of MQ-02
are connected to 5V and GND of
Arduino board.
� We want to take the input from a
Gas sensor in an analog format so
pin A0 is connected to one of the
analog pins of Arduino i.e. A0.
MQ-02/05 Gas Sensor – Code explanation
� The code in Arduino for MQ-02 gas sensor can be written as following
gas_sensor.ino
1 int gas_level;
2 void setup() { Initialize the serial communication between
3 pinMode(A0, INPUT); Arduino and computer with baud rate 9600.
4 Serial.begin(9600);
5 } Reads the analog value from specified pin and
6 stores it in the mentioned variable.
7 void loop() {
8 gas_level = analogRead(A0); Prints data on the serial port in ASCII text given in
9 Serial.print("Gas Level : "); double quotes.
10 Serial.println(gas_level);
11 delay(500); Prints the data of specified variable on the serial
12 } port and also prints new line at the end.
Functions in Arduino IDE
� Serial.begin( ): It is used to start serial communication between Arduino board and
other device. Normally, it is connected with computer for monitoring the data.
Serial communication uses pin 0 and 1 also working as Rx and Tx respectively.
� Syntax : Serial.begin(baud_rate)
� Parameters :
▪ baud_rate: It defines the speed of data transfer rate between Arduino and other device. It is
compulsory to set this baud rate same at both the side for proper transfer of data.
� Serial.print( ) : Print the data from Arduino to other device.
� Syntax : Serial.print(“text”)
� Parameters :
▪ The text which is to be printed by Arduino board is written in double quote so as to convert it in its
ASCII values.
� Serial.println( ) : Print the data with newline from Arduino to other device.
� Syntax : Serial.println(“text”)
� Parameters :
▪ The text which is to be printed by Arduino board is written in double quote so as to convert it in its
ASCII values.
Functions in Arduino IDE (Cont.)
� analogRead( ): The syntax reads analog value from specified pin and converts it
into 1024 levels or in 0 to 1023 range. The values is stored into specified variable
in the code statement. The value is converted into 1024 levels because Arduino
has 10 bit built in A-D converter unit.
� Syntax : analogRead(pin)
� Parameters :
▪ pin: The Arduino analog pin number.
MQ-02/05 Gas Sensor – Output
Obstacle Sensor
� Obstacle sensor is used for detection of
obstacle.
� It is a digital sensor, hence gives binary
output ‘1’ or ‘0’.
� The range for detection of obstacle can be
changed by potentiometer given.
� Pinout of obstacle sensor module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� Out/D0 – Digital output pin
Obstacle Sensor – Working principle
� IR emitter transmits IR signals and IR receiver receives those signals from
reflection.
� If the obstacle is present then the transmitted signals are reflected back by
obstacle and if they have amplitude greater then threshold the output signal will
be ‘0’.
� If the obstacle is not present then the transmitted signals are not reflected and
the output signal will be ‘1’.

Obstacle in the way Obstacle IR Sensor Digital Output


Obstacle Sensor – Interfacing with Arduino
� The interfacing of obstacle sensor
with Arduino Uno is as shown in
figure.
� Here, Vcc and Gnd pins of obstacle
sensor is connected to 5V and Gnd
of Arduino board.
� The output of obstacle sensor is in
digital form. So it is connected to
digital pin 2 of Arduino.
HC-SR04 Ultrasonic Sound Sensor
� Ultrasonic Sound Sensor is used to measure
the distance of an object.
� The sensor can only measure the distance of
object. It can not identify the type of
object.
� It is also known as Ultrasonic distance sensor.
� Pinout of HC-SR04 module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� Trigger – Generates the transmit pulse
� Echo – Receives echo from obstacle
HC-SR04 Ultrasonic Sound Sensor – Working principle
� The emitter transmits ultrasonic sound waves which are reflected by near by
objects.
� The reflected pulse is received by sensor.
� Some mathematical operations are performed to obtain the distance value.
� The distance value is converted into desired unit.

Ultrasonic waves Mathematical operations Measurement of distance


HC-SR04 Ultrasonic Sound Sensor– Interfacing with Arduino
� The interfacing of HC-SR04 sensor
with Arduino Uno is as shown in
figure.
� Here, Vcc and Gnd pins of HC-SR04
sensor are connected to 5V and
Gnd of Arduino board.
� The trigger and echo pin is
connected to (any) digital pins of
Arduino board.
� In this case, trigger is connected
to 11 and echo is connected to 12.
Functions in Arduino IDE
� delayMicroseconds( ): It pauses the program for amount of time in microseconds
specified as the parameter.
� Syntax : delayMicroseconds(μs)
� Parameters :
▪ μs : The number of microseconds to pause.
� pulseIn( ) : Reads a pulse HIGH or LOW from specified pin and wait for the time to
go the pulse from HIGH to LOW or LOW to HIGH. It returns the time required to
transit the pulse in variable.
� Syntax : pulseIn(pin, value)
� Parameters :
▪ Pin: The number of the Arduino pin on which you want to read the pulse.
▪ Value: The type of pulse that you want to read.
HC-SR04 Ultrasonic Sound Sensor – Output
LDR Sensor
� LDR is known as Light Dependent Resistor.
� The internal resistance of LDR changes with
respect to light intensity.
� Normally LDR works with voltage divider
network.
� The LDR is used in the application where
the task is performed with light intensity as
input.
LDR Sensor – Working principle
� The LDR works on principle of Ohm’s law.
� As the light intensity on LDR is higher, the resistance of LDR decreases.
� The decreased resistance will drop more voltage across LDR according to Ohm’s
Law.
� The presence of light can be identified by the value of voltage across LDR.

Light Intensity to be measured Output voltage measurement Calculate the intensity


LDR Sensor– Interfacing with Arduino
� The interfacing of LDR sensor with
Arduino Uno is as shown in figure.
� Here, one terminal of 10kΩ resistor is
connected to 5V of Arduino and
second terminal is connected to A0
pin.
� One terminal of LDR is connected to
A0 pin of Arduino and other is
connected to Gnd.
� This creates a voltage divider network
between fixed resistor and LDR.
� The voltage at A0 pin remains near to
5V when LDR is in dark (high
resistance).
� The voltage at A0 pin remains near to
0V when LDR is in Bright light (low
LDR Sensor – Output
Heartbeat Sensor
� Heartbeat sensor is having typical
application in health care domain.
� This is mainly used in wearable devices to
monitor the heart beat / heart rate of the
person.
� The sensor is inexpensive and generates
square waves for each pulse. The averaging
of pulses gives analog voltage according to
the heartbeat.
� Pinout of heartbeat sensor module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� A0 – Analog output pin
Heartbeat Sensor – Working principle
� The sensor senses the heartbeat as per blood circulation in the body.
� It generates the output pulse signal according to the rate at which heart beats.
� The output pulses are considered as PWM waves. Hence they are converted into
analog signals.
� This analog signal is converted to digital which gives the output beat rate.

Heartbeat input Generation of Digital Pulse Calculates the BPM


as output
Heartbeat Sensor – Interfacing with Arduino
� The interfacing of Heartbeat
sensor with Arduino Uno is as
shown in the figure.
� Here, Vcc and Gnd pins of
heartbeat sensor are connected to
5V and GND of Arduino board.
� We want to take the input from
the sensor in an analog format so
the signal pin of the sensor is
connected to one of the analog
pins of Arduino i.e. A0.
Heartbeat Sensor – Output
Colour Sensor
� Colour sensor is used to detect the RGB
colour coordinates of a particular colour.
� The colour sensor module has TSC3200 IC
that converts colour to frequency by
enabling a particular colour diode turn by
turn.
� The colour sensor is mainly used in the
application where the objects are identified
by their colour.
� Pinout of colour sensor module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� S0, S1 – Used for output frequency scaling
� S2, S3 – Type of photodiode selected
� (OE)’ – Enable for output
� OUT – Output frequency (fo)
Colour Sensor (Cont.)
� The combination of S0 and S1 are used for Output Frequency Typical full-scale
S0 S1
output frequency scaling. Scaling (f0) Frequency
� The different microcontrollers have different L L Power Down ———
counter functionality and limitations. Hence, L H 2% 10 – 12 KHz
we need to scale the frequency according to
microcontroller used. H L 20% 100 – 120 KHz

� The percentage of output scaling for H H 100% 500 – 600 KHz


different combinations of S0 and S1 are
shown in the table. S3 S4 Photo Diode Type
� The S3 and S4 pins are used for photodiode
L L Red
selection. The photodiodes are associated
with different colour filters. L H Blue
� The table shows combinations of S3 and S4 H L Clear(No Filter)
for different photodiodes. H H Green
Colour Sensor – Working principle
� The sensor works by imparting a bright light on an object and recording the
reflected colour by the object.
� The selected photodiode for colour of red, green and blue converts the amount of
light to current.
� These RGB values are further processed to identify the exact colour combination.

Input to photodiode Output RGB colour values Calculation of actual


of colour sensor colour of object
Colour Sensor – Interfacing with Arduino
� The interfacing of Colour Sensor
with Arduino Uno is as shown in
figure.
� Here, Vcc and Gnd pins of Colour
Sensor are connected to 5V and
Gnd of Arduino board.
� As we need to enable the sensor
OE’ is connected to GND.
� All selection pins S0, S1 S2 and S3
are connected to digital pins of
Arduino that is 9,8,11 and 12
� The output of colour sensor are taken as a pulse count. So OUT pin is also connected to digital
respectively.
pin. In our case it is connected to pin 10.
Functions in Arduino IDE
� map( ): The syntax maps a number from one range to another.
� Syntax : map(value, fromLow, fromHigh, toLow, toHigh)
� Parameters :
▪ value: the number or variable to map.
▪ fromLow: the lower bound of the value’s current range.
▪ fromHigh: the upper bound of the value’s current range.
▪ toLow: the lower bound of the value’s target range.
▪ toHigh: the upper bound of the value’s target range.
GPS Sensor
� GPS sensor is used to get the location data of
the place where sensor is situated.
� The data from sensor is acquired in National
Marine Electronics Association (NEMA) format.
The format is used by marine department for
communication.
� There are multiple variants of GPS sensors
available in the market. We can select based
on our requirements.
� Here, the given sensor is GY-GPS6MV2 as
shown in the image.
� Pinout of GPS sensor module are
� Vcc – Connected to 5V
� Gnd – Connected to ground
� Tx – Serial Data Transmit
� Rx – Serial Data Receive
GPS Sensor – Working principle
� The sensor is placed in the system whose location is to be tracked.
� The GPS device communicates with GPS satellite and the satellite returns its
current location in form of latitude and longitude.
� The sensor transmits the data to the microcontroller in a predefined format from
which we can extract the tracked location.

Latitude
Longitude

GPS device with antenna Returns latitude and longitude Tracked Location
for communication as output
GPS Sensor – Interfacing with Arduino
� The interfacing of GPS Sensor with
Arduino Uno is as shown in figure.
� Here, Vcc and Gnd pins of GPS Sensor
are connected to 5V and Gnd of
Arduino board.
� As the GPS communicates with
Arduino serially, we need to connect
Tx and Rx pin of GPS with serial pins
of Arduino.
� But, we want the data received from
the GPS sensor in serial monitor also
to read the current location.
� Therefore, we need to use any digital
pins of Arduino as serial transmit and
� Here, the Txpins
receive and Rxwhich
pins of GPS
is are connected
done by with pins 3 and 2 respectively.
software serial.
GPS Sensor – Output
Gyro Sensor
� The Gyro sensor is very useful in wearable devices.
� It is used to find the position or angle of rotation of
the body.
� It mainly senses
� Rotational motion
� Changes in orientation
� The Gyro sensor communicates with microcontroller
with I2C (Inter-Integrated Communication).
� I2C is the most sophisticated two-wire
communication protocol.
� It works with the device address and its respective
data frames.
� Normally, I2C is used when more numbers of
devices are connected.
Gyro Sensor (Cont.)
� The pin out of Gyro sensor MPU6050 are as
following.
� Vcc – connected to 5V
� GND – connected to ground
� SCL – Serial Clock Line
� SDA – Serial Data Line
� XDA – Auxiliary Serial Data
� XCL – Auxiliary Serial Clock
� AD0 – This pin can be used to vary the address
incase of multiple sensors used
� INT – Interrupt pin available for certain
application
MPU-6050 Gyro Sensor – working principle
� The MPU 6050 senses the gravitational force applied to it.
� Place the sensor in device whose inclination is to be measured.
� Obtain the values of x, y and z coordinates.
� Determine the elevation angle by performing mathematical caluculations

x,y,z : 507 506 617


x,y,z : 507 504 616
x,y,z : 506 505 617
x,y,z : 506 506 618

Sensor placed for x, y, and z coordinates Determination of Angle


finding Inclination
MPU-6050 Gyro Sensor – Interfacing with Arduino
� The interfacing of MPU-6050 with
Arduino Uno is as shown in figure.
� Here, Vcc and Gnd pins of
MPU6050 is connected to 5V and
Gnd of Arduino board.
� The SCL and SDA pins are used for
I2C communication. These pins are
available in Arduino with A5 and
A4 pins as second functionality.
� Hence, SCL and SDA are connected
to A5 and A4 pins of Arduino.
� The INT pin of MPU6050 gives interrupt when angular velocity increases than defined threshold
value. So interrupt pin of MPU6050 is connected to external interrupt by Arduino supported at
digital pin 2.
PH Sensor
� The pH sensor is used to detect hydrogen ions concentration of a liquid.
� pH sensor are mostly used in laboratories to test the acidity of solution.
� By the use of pH sensor we can identify the pH of a solution and whether it is acid
or base.
pH Sensor – Working principle
� When this sensor is placed in a solution, the smaller ions penetrate the boundary
area of glass and the lager ions remain in the solution. This creates potential
difference.
� The pH meter measures the difference in electrical potential between the pH
electrodes.
� The potential difference generates different analog values for different liquids.
� By knowing the analog value of standard water, the pH value of other liquid can be
determined.

pH Sensor with Output Voltage Determination of alkalinity


Electrodes of the liquid
pH Sensor – Interfacing with Arduino
� The interfacing of pH sensor with
Arduino is as shown in figure.
� Here, Vcc and Gnd pins of pH Sensor
are connected to 5V and Gnd of
Arduino board.
� The output pin of pH sensor is
connected to analog pin of Arduino.
� The connection of pH sensor is done
with voltage converter via BNC pin.
8051 Microcontroller Architecture
� 8051 was built by Intel but other companies are also permitted to make 8051 microcontrollers
with same features and compatible set of instructions.
Externa Count
� The diagram shows l er
Architectural representation of Interru Input
pt
8051 microcontroller. Interrupt 128 Byte Timer 1
4K Flash
Control RAM Timer 0

CPU

Bus
Oscillator I/O Ports Serial Port
Control

P P P P
0 1 2 3
Features of 8051 Microcontroller
1. 8- bit microcontroller.
2. Many general purpose and few special function registers (SFRs).
� Two major 8 bit registers. A and B. Both are used in arithmetic operations mainly.
� A is accumulator and it addressable.
� There are 21 SFRs among them few are bit addressable. SFRs perform various dedicated
operations.
� Also, some control registers for timer, counter and interrupt fall in category of SFRs.
3. Four register banks having 8 registers in each bank.
4. Data pointer register which is 16 bit made from combinations of two 8 bit
registers – DPH and DPL.
5. 16 bit Program Counter.
6. 8 bit Program Status Word(PSW) and used as Flag register.
7. Internal ROM and EPROM.
8. Internal user accessible RAM of 128 Bytes
Features of 8051 Microcontroller
9. There are four ports P0, P1, P2 and P3 that can be configured as input and
output.
10.Two 16 bit timer/counter – T0 and T1.
11.Full duplex serial communication and dedicated serial buffer register SBUF.
12.Supports interrupt programming.
13.Oscillator and Clock circuits are built in.
14.Easier and simpler instruction set.
Memory organization in 8051
� There are two categories of memory – program
memory and data memory.
FFh
1. Program memory
� In 8051, 4K bytes of program memory is available.
� It is normally referred as ROM and non volatile in nature. Special function registers
� It is used to store following:
(80 – FFh)
1. Boot up programs
2. Interrupt Service Routines (ISR)
3. Macro Functions
2. Data memory
� Data memory is used to store temporary data.
� 8051 has 256 byte data memory neatly organized for Internal RAM
various operations.
� The 256 byte data memory is divided into two parts (00 – 7Fh)
1. First 128 Bytes – Internal user accessible RAM
2. Last 128 Bytes – Special Function Registers (SFRs).
00h
R7 1Fh
.
Register Bank 3 .
. Data Memory Organization
R0 18h
► The first 32 Bytes 00h to 1Fh FFh
R7 17h are allocated for register
. banks.
Register Bank 2 . Special function registers
.
► There are four register banks –
R0 10h register bank 0,1,2 and 3. (80 – FFh)
R7 0Fh
► Each register bank has 8
. registers R0 to R7.
Register Bank 1 .
.

R0 08h
R7 07h Internal RAM
.
Register Bank 0 .
(00 – 7Fh)
. 1Fh
R0 00h 00h 00h
Bit b7 b6 b5 b4 b3 b2 b1 b0
Addresses
7F 78 2Fh
77 70 2Eh Data Memory Organization
6F 68 2Dh
67 60 2C h ► 20h to 2Fh are bit FFh
addressable RAM.
5F 58 2Bh
57 50 2Ah ► Each bit of each Special function registers
register can be set or
4F 48 29h
reset. (80 – FFh)
Bit 47 40 28h
Addressable 3F 38 27h ► The bits have also
different address.
37 30 26h
2F 28 25h
27 20 24h
2Fh Internal RAM
1F 18 23h
20h (00 – 7Fh)
17 10 22h
0F 08 21h
07 00 20h 00h
► The last 80 bytes of Internal RAM that is 30h to 7Fh are used as Data Memory Organization
General purpose RAM Area.
FFh
► Any general purpose data is stored in this area.

Special function registers


7Fh
(80 – FFh)

General Purpose
RAM Area 7Fh
80 Bytes
30h
Internal RAM
30h
(00 – 7Fh)

00h
Special Function Registers
� There are 21 SFRs in 8051microcontroller.
� They are important set of registers used for dedicated operations in 8051
microcontroller.
� Some of the SFRs are bit addressable while others are not.
� The following list explains the register and their function. The bracket is
representing its address in RAM.
1. Accumulator – A (E0h)
� It is 8 bit register used in each Arithmetic and Logical operation.
� It is bit addressable.
� All the results of arithmetic or logical operations are stored in Accumulator
� One operand in all operations such as addition, subtraction, division and multiplication will
be accumulator.
2. Register B (F0h)
� It is 8 bit register used in multiplication and division mainly.
� It is bit addressable.
Special Function Registers (Cont.)
3. PSW Register (D0h)
� PSW (Program Status Word) is consisting various flags of 8051.
� These flags indicate whether the microcontroller works as expected or something is going
wrong.
� The format of PSW register is as shown in figure.
� It is 8 bit register.
� Also PSW is bit addressable and its bits are represented by PSW.X, where X represents bit
number.
� Bit 0 is LSB
MSBand bit 7 is MSB. LSB
PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

CY AC F0 RS1 RS0 OV - P

D7 D6 D5 D4 D3 D2 D1 D0

Carry Auxiliary Flag - 0 Register Bank Overflow Unused Parity


Carry Select
Special Function Registers (Cont.)
3. PSW Register (D0h)
� P – Parity Flag (PSW.0)
▪ It is D0 bit of PSW register. The parity flag is set or reset based on the result stored in accumulator.
For odd number 1s in result, the flag is set otherwise it is reset.
� PSW.1
▪ It is not used and reserved for future usage
� OV – Overflow Flag (PSW.2)
▪ When the result of signed arithmetic operation is very large OV will be set.

PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

CY AC F0 RS1 RS0 OV - P

D7 D6 D5 D4 D3 D2 D1 D0

Carry Auxiliary Flag - 0 Register Bank Overflow Unused Parity


Carry Select
Special Function Registers (Cont.)
3. PSW Register (D0h)
� RS0 and RS1 – Register Bank Select (PSW.3 and PSW.4)
▪ The four register bank available in Internal RAM area can be selected by RS0 and RS1 bits. The table
shows combination of RS1 and RS0 to select a particular register bank.
RS1 RS0 Bank Selected
0 0 Register Bank 0
� F0 – Flag 0 (PSW.5)
0 1 Register Bank 1
▪ It is a general purpose bit that can be used by a user as per requirement.
1 0 Register Bank 2
1 1 Register Bank 3

PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

CY AC F0 RS1 RS0 OV - P

D7 D6 D5 D4 D3 D2 D1 D0

Carry Auxiliary Flag -- 00 Register Bank Overflow Unused Parity


Carry Select
Special Function Registers (Cont.)
3. PSW Register (D0h)
� AC – Auxiliary Carry (PSW.6)
▪ It is used in BCD operations. When there is a carry from D3 to D4 bit this flag is set otherwise it
remains reset.

� CY – Carry (PSW.7)
▪ Carry flag is set to one when the arithmetic operation has carry generated from D7 bit. It is also used
in shift operations.

PSW.7 PSW.6 PSW.5 PSW.4 PSW.3 PSW.2 PSW.1 PSW.0

CY AC F0 RS1 RS0 OV - P

D7 D6 D5 D4 D3 D2 D1 D0

Carry Auxiliary Flag - 0


Auxiliary Register Bank Overflow Unused Parity
Carry
Carry Select
Special Function Registers
� Timer and Counter registers related to timer and counter programming
4. TCON (88h) (Timer Control Register)
5. TMOD (89h) (Timer Mode Register)
6. TL0 (8Ah) (Timer0 Lower Byte)
7. TL1 (8Bh) (Timer1 Lower Byte)
8. TH0 (8Ch) (Timer0 Higher Byte)
9. TH1 (8Dh) (Timer1 Higher Byte)
� PORT register – These registers are used for PORT programming.
10.P0(80h) 11. P1(90h) 12. P2(A0h) 13. P3 (B0h)
� Interrupt programming registers
14.IE (A8h) (Interrupt Enable)
15.IP (B8h) (Interrupt Priority)
Special Function Registers
� Power control register
16.PCON (87h) (Power Control)
� Serial Communication Registers
17.SCON (98h) (Serial Control)
18.SBUF (99h) (Serial Buffer)
� Data Pointer Registers (DPTR) – This register is combination of two 8 bit registers
DPH and DPL. It is used when data is to be stored in memory pointing out a
particular location.
19.DPH (83h) (Data Pointer Higher byte)
20.DPL (82h) (Data Pointer Lower byte)
� Stack Pointer – It is used while storing the data into stack memory.
21.SP (81h) (Stack Pointer)
Advanced RISC Machine (ARM)
� An Advanced RISC Machine (ARM) is a processor which is family of CPUs based on
Reduced Instruction Set Computer.
� The ARM processor is 32 bit processor developed for high-end applications that
involve more complex computations and calculations.
� The ARM is based on RISC but has been enhanced for usage in embedded
applications.
Features of ARM
� It has large uniform register files with load and store architecture. The load-store
architecture allows a single instruction to perform load operation from main
memory into register and store operation from a register into main memory.
� ARM is 32 – bit processor with reverse compatibility. So it has 16-bit and 8-bit
variants embedded into 32 – bit processor.
� It has very good speed v/s power consumption ratio and high code density.
� It has a barrel shifter in the data path, which can maximize hardware usage
available on the chip.
� Built in auto-increment and auto-decrement addressing modes.
� It has conditional execution instructions.
ARM Core Data Flow Model
Address
� Figure shows ARM core
flow diagram where Address Register
the functional units Incrementer
are connected by data PC-r15

buses.
Control
� The important blocks Register file (r0 – r15)
can be explained as Rm Rn B
Result Rd

following. A
ACC
Instruction
� Instruction Decoder Barrel shifter MAC Decoder
� It decodes the N and
instruction before Control
execution. ALU
� There are three kinds
of instruction set
supported
1. ARM Instruction set Data Out Data In
2. Jazelle Instruction
set
ARM Core Data Flow Model
Address
� Rm, Rn and Rd
� ARM has two source Address Register
registers Rm and Rn
Incrementer
and one destination PC-r15
register Rd.
� A and B buses Register file (r0 – r15)
Control

� A and B buses are Result Rd


used to fetch the data Rm Rn B
ACC
from source register A
Instruction
and provides for Barrel shifter MAC Decoder
further operation.
N and
� ALU and MAC Control
� The computation is ALU
carried out in ALU or
MAC (Multiply
Accumulate) unit.
Data Out Data In
ARM Core Data Flow Model
Address
� Barrel Shifter
� Barrel shifter is often Address Register
used for shift and
Incrementer
rotate operation in a PC-r15
single clock cycle.
� Address register Register file (r0 – r15)
Control

� The address register is Result Rd


used to hold the Rm Rn B
ACC
register and the A
Instruction
address bus will carry Barrel shifter MAC Decoder
the current address.
N and
� Incrementer Control
� The incrementer is ALU
used for auto-
increment of address
and stored back in the
address register. Data Out Data In
ARM Register Organization
� ARM has 13 general purpose registers (r0 to r12)
� All the registers are 32 bit in size.
� There are 3 SFRs in ARM
� r13 (Stack Pointer)
� r14 (Link Register)
� r15 (Program Counter)
� There is one more important register in ARM – CPSR (Current Program Status
Register).

r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15

Stack Pointer Program Counter


CPSR
Link Register
ARM Register Organization - SFRs
1. Stack Pointer (SP/r13)
� The stack pointer holds the address of the top of the stack.
� It is used for accessing the stack memory.
2. Link Register (LR/r14)
� This register stores the address of next instruction to be executed when the interrupt is
generated and the processor will jump to execute the service routine or subroutine.
� After executing the subroutine, this register will return the address from where the program
was interrupted.
3. Program Counter (PC/r15)
� The program counter is used to sequence the flow of execution of program.
� It holds the address of the next instruction to be executed.
Current Program Status Register (CPSR)
� CPSR is the status register or flag register equivalent to PSW in
8051 but CPSR is of 32 bits.
� The format of CPSR register is shown in figure.
� Among 32 bits, 20 bits are unused or reserved for future
expansion.

31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode

Zero Overflow IRQ FIQ Mode selection bits

Negative Carry Thumb mode selection


Current Program Status Register (CPSR)
� Mode selection bits
� ARM can operate in seven different modes. Total 5 bit 0 to 4 are
assigned for mode selection.
� T – Thumb mode selection
� If this bit is set to 1, ARM works in Thumb mode else ARM works in
normal mode.
� F – FIQ Interrupt Mask
� This bit is set to zero to enable FIQ interrupts.
� I – IRQ Interrupt Mask
� This bit is set to zero to enable IRQ or normal interrupts.
31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode

Zero Overflow IRQ FIQ Mode selection


selection bits
bits

Negative Carry Thumb mode selection


selection
Current Program Status Register (CPSR)
� V – Overflow Flag
� When result of a signed operation results in an overflow, this flag is set
to 1.
� C – Carry Flag
� This flag is set to 1 if the result of an ALU operation generates carry.
� Z – Zero Flag
� This flag is set to 1 if the result of an ALU operation is zero.
� N – Negative Flag
� This flag is set to 1 if the result of an ALU operation is negative.

31 30 29 28 27 8 7 6 5 4 0
N Z C V Unused I F T Mode

Zero Overflow IRQ FIQ Mode selection bits

Negative Carry Thumb mode selection


Difference between Microprocessor and Microcontroller

Difference between Microprocessor and Microcontroller


Microprocessor Microcontroller
Application It is used in applications of General purpose. It is used in specific applications.
Peripheral devices (like memory, I/O ports,
Peripherals ADC/DAC etc.) are required for the operation of Peripheral devices are not required to operate.
Microprocessor based system.
Microprocessor based system will have large Microcontroller based system will have smaller
Size of memory
size of RAM and program memory (MB/GB). size of RAM and program memory (KB/MB).
The cost of the microprocessor is high
Cost It is cheaper than Microprocessor.
compared to the microcontroller.
The structure of Microprocessor based system The structure of Microcontroller based system
Complexity
is complex compared to Microcontroller is simpler.
Power The power consumption for the microprocessor The power consumption for the microcontroller
Consumption is high. is less.
Difference between Analog and Digital

Difference between Analog and Digital Signal


Analog Signals Digital Signals
Analog signals can have any possible values in the given Digital signals can have only discrete values in the given
range. range.
Examples: All physical quantities (like temperature, light
Examples: Count of persons entered in premises, roll
intensity) measured by different analog sensors, sound
numbers etc.
waves
Comparison of Flash, SRAM and EEPROM
� Flash memory is also known as program memory where the program for any
microcontroller or IC is stored.
� SRAM (Static Random Access Memory) is where the program creates and
manipulates variables and stores temporary data.
� EEPROM(Electronically Erasable Programmable Read Only Memory) is the space
where programmer need to store long term information.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy