Sensors, Microcontrollers, ARM
Sensors, Microcontrollers, ARM
Microcontrollers,
ARM
Dr. Jay Joshi
Sensor Interfacing
● What is Sensor Interfacing?
Connecting sensors to a microcontroller to read and process data.
● Why Use Arduino?
○ Open-source and beginner-friendly.
○ Large community support.
○ Wide range of compatible sensors.
Sensor Interfacing
● Analog Sensors:
○ Example: Temperature sensor (LM35), Light-dependent
resistor (LDR).
● Digital Sensors:
○ Example: HC-SR04 Ultrasonic Sensor, DHT11 Temperature &
Humidity Sensor.
● Communication Protocol-Based Sensors:
○ I2C: MPU6050 (Accelerometer + Gyroscope)
○ SPI: RFID Reader
○ UART: GPS Module
IR Sensor
Definition:
"An Infrared (IR) sensor is an electronic device that detects infrared radiation
emitted by objects in its field of view."
Basic Function:
Key Features:
void loop() {
int state = digitalRead(sensor); // Read PIR sensor
if (state == HIGH) {
// Motion detected
Serial.println("Motion detected!");
digitalWrite(led, HIGH); // Turn LED ON
} else {
// No motion detected
Serial.println("No motion detected.");
digitalWrite(led, LOW); // Turn LED OFF
}
● Steinhart-Hart equation:
Steinhart-Hart equation
This equation provides an accurate method to calculate temperature from
resistance:
● T: Temperature in Kelvin.
● T0: Reference temperature (usually 25°C or 298.15 K).
● R: Thermistor resistance at temperature T.
● R0: Resistance at reference temperature T0.
● β: Beta constant (specific to the thermistor).
Circuit Diagram
void loop() {
VRT = analogRead(A0); //Acquisition analog value of
Code
VRT
VRT = (5.00 / 1023.00) * VRT; //Conversion to voltage
VR = VCC - VRT;
RT = VRT / (VR / R); //Resistance of RT
//These values are in the datasheet
ln = log(RT / RT0);
#define RT0 10000 // Ω
TX = (1 / ((ln / B) + (1 / T0))); //Temperature from
#define B 3977 // K
thermistor
Serial.print("Temperature:");
//Variables
Serial.print("\ ");
float RT, VR, ln, TX, T0, VRT;
Serial.print(TX);
delay(500);
void setup() {
}
Serial.begin(9600);
T0 = 25 + 273.15;
//Temperature T0 from datasheet
// conversion from Celsius to kelvin
}
Applications
● Smart Homes:
○ Monitor room temperature for HVAC (Heating, Ventilation, and Air Conditioning)
systems.
● Healthcare Devices:
○ Temperature monitoring in wearable health gadgets and medical instruments.
● Industrial IoT:
○ Temperature regulation in machinery and processes to ensure efficiency.
● Agriculture:
○ Soil temperature monitoring for optimized crop production.
● Automotive:
○ Engine and battery temperature monitoring in connected cars.
Touch Sensor
What is TTP223B Capacitive Touch Sensor?
Applications:
SIG: Signal output pin (provides digital output when touch is detected).
Wearable Devices:
Healthcare:
Security Systems:
Where
Q= Reaction coefficient
E = mV output from the electrode
E0 = Zero offset for the electrode
R = Ideal gas constant= 8.314 J/mol-K
T = Temperature in ºK
F = Faraday constant = 95,484.56 C/mol
n = Ionic Charge
pH Signal Conversion Board
● Converts analog signals from pH electrode to readable voltage.
● Technical Features:
○ Supply Voltage: 3.3V - 5.5V
○ BNC Probe Connector for pH electrode
○ High Accuracy: ±0.1 @ 25°C
○ Detection Range: 0 - 14 pH
○ Temperature Output: For compensation
● Pin Description:
○ V+: 5V DC input
○ G: Ground pin
○ Po: pH analog output
○ Do: 3.3V DC output
○ To: Temperature output
Circuit Diagram
pH Sensor → Arduino A0
#define SensorPin A0 // pH sensor connected to analog pin A0
void setup() {
Serial.begin(9600);
Serial.println("Basic pH Sensor Reading Started");
}
void loop() {
int sensorValue = analogRead(SensorPin); // Read analog value from pH sensor
float voltage = sensorValue * (5.0 / 1023.0); // Convert analog value to
voltage
float pH = 3.5 * voltage; // Basic conversion from voltage to pH value
Serial.print("Voltage: ");
Serial.print(voltage, 2);
Serial.print(" V | pH Value: ");
Serial.println(pH, 2);
delay(1000); // Delay for 1 second between readings
}
Basic Code Overview
● Analog Reading:
Reads raw data from the pH sensor.
● Voltage Conversion:
Converts the analog reading to a voltage (0-5V).
● pH Calculation:
Applies a simple formula pH = 3.5 * voltage to estimate the pH
value. (You can calibrate this based on your sensor.)
● Serial Output:
Displays the voltage and pH value on the Serial Monitor every
second.
Testing PH meter
Tested with:
● Pure Water: pH ~7.0
● Lemon Juice: pH ~2.0
● Soap Solution: pH ~10.0
Application
● Smart Agriculture:
○ Real-time soil pH monitoring.
○ Optimizes irrigation and fertilization.
● Water Quality Monitoring:
○ IoT-enabled water bodies monitoring.
○ Tracks pH in rivers, lakes, and aquariums.
● Industrial IoT (IIoT):
○ Monitors pH in chemical and pharmaceutical industries.
○ Ensures compliance with safety standards.
● Smart Aquaculture:
○ Maintains optimal pH levels in fish farms.
○ Integrates with IoT platforms for remote monitoring.
● Environmental Monitoring:
○ Tracks pH levels in soil and water ecosystems.
○ Helps in pollution control and analysis.
● Home Automation:
○ Monitors pH in swimming pools and home aquariums.
○ Sends alerts when pH levels go out of range.
HC-SR04 Ultrasonic Sensor
● The HC-SR04 is an affordable and precise ultrasonic sensor widely used in
various applications.
● It measures distances by emitting ultrasonic waves and calculating the
time it takes for the echo to return.
Understanding the HC-SR04 Sensor
Features:
● Operating Voltage: 5V DC
● Measuring Range: 2cm to 400cm
● Accuracy: ±3mm
Pin Configuration:
● VCC: Power supply
● Trig: Trigger input
● Echo: Echo output
● GND: Ground
How the HC-SR04 Works
Operating Principle:
● The sensor emits an ultrasonic pulse via the Trig pin.
● This pulse reflects off an object and returns to the sensor.
● The Echo pin outputs the time duration the pulse took to
return.
● Distance is calculated using the formula:
○ Distance = (Time × Speed of Sound) / 2
○ Time in μs
○ Speed of Sound: Sound travels at approximately 343
meters per second in air, which is 0.034 cm/μs.
How HC-SR04 Works
Timing Diagram
Wiring Diagram
Connection
Code
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
int distance;
duration = pulseIn(echoPin, HIGH);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT); Serial.print("Distance: ");
Serial.begin(9600); Serial.print(distance);
} Serial.println(" cm");
delay(500);
}
Code Overview
Key Steps in the Code:
● Initialize Trig and Echo pins.
● Send a 10µs pulse to the Trig pin to initiate
measurement.
● Read the time duration from the Echo pin.
● Calculate distance using the time duration.
● Display the distance on the Serial Monitor.
Application
● Smart Parking Systems:
○ Detect vehicle presence in parking spots.
○ Send data to cloud platforms for real-time monitoring.
● Smart Waste Management:
○ Monitor bin fill levels.
○ Optimize collection routes using IoT networks.
● Home Automation:
○ Implement touchless faucets or smart doors.
○ Integrate with home automation systems.
● Industrial Automation:
○ Track object distances on conveyor belts.
○ Real-time monitoring via IoT dashboards.
● Agriculture:
○ Measure water levels in tanks or reservoirs.
○ Transmit data to centralized control systems.
● Security Systems:
○ Motion detection in restricted areas.
○ Alert systems via IoT networks.
● Robotics:
○ Obstacle detection and avoidance.
○ Data sharing with IoT-enabled control units.
Introduction to DHT11 Sensor
Overview:
● The DHT11 is a basic, ultra-low-cost digital
temperature and humidity sensor.
● It uses a capacitive humidity sensor and a
thermistor to measure the surrounding air.
● It provides calibrated digital output and
operates via a single-wire protocol.
Key Features
● Operating Voltage: 3.3V - 5V
● Temperature Range: 0°C to 50°C (±2°C accuracy)
● Humidity Range: 20% - 90% RH (±5% accuracy)
● Sampling Rate: 1 reading per second
● Interface: Single-wire digital output
● Low power consumption
Pin Configuration of DHT11
Microcontroller Communication with DHT11
● The DHT11 sensor communicates with a microcontroller using a
single-wire digital signal.
● It requires a start signal from the microcontroller to initiate data
transfer.
● The sensor responds by sending 40 bits of data (humidity, temperature,
checksum).
DHT11 Communication Protocol
Start Signal:
● The microcontroller pulls the data pin LOW for at least 18ms to wake up the sensor.
● Then, it pulls the data pin HIGH for 20-40µs and waits for the response.
Response Signal:
● The sensor pulls the line LOW for 54µs and then HIGH for 80µs to indicate readiness.
Data Transmission Format
The DHT11 sends 40 bits of data in the following format:
● 8 bits → Humidity Integer
● 8 bits → Humidity Decimal
● 8 bits → Temperature Integer
● 8 bits → Temperature Decimal
● 8 bits → Checksum (Error detection)
The microcontroller reads the high and low pulse
durations to interpret the data bits.
Timing Diagram
The data signal consists of pulses representing 0s and 1s:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println();
int chk = DHT11.read(DHT11PIN);
Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);
Serial.print("Temperature (C): ");
Serial.println((float)DHT11.temperature, 2);
delay(2000);
}
Applications of DHT11 Communication
● Smart Agriculture: Optimize soil and air conditions
● Home Automation: Control HVAC systems
efficiently
● Industrial Monitoring: Maintain ideal working
conditions
● Weather Stations: Real-time environmental tracking
● Healthcare: Monitor room climate in sensitive
environments
Grove Gas Sensor (MQ2)
What is MQ2 Sensor?
The Grove - Gas Sensor (MQ2) is a gas detection module used to sense gases like
LPG, methane, alcohol, hydrogen, and smoke in the air.
Key Features:
void setup() {
// Variable to store gas sensor reading
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
gasValue = analogRead(MQ2_Pin); // Read gas sensor value
Serial.print("Gas Sensor Value: ");
Serial.println(gasValue);
Code
int zPin = A3; // Z_OUT to A3
void setup() {
Serial.begin(9600);
}
void loop() {
int xVal = analogRead(xPin);
int yVal = analogRead(yPin);
int zVal = analogRead(zPin);
// Convert ADC values to voltage
float xVoltage = (xVal / 1024.0) * 3.3;
float yVoltage = (yVal / 1024.0) * 3.3;
float zVoltage = (zVal / 1024.0) * 3.3;
delay(500);
}
Application
● Vehicle Tracking & Anti-Theft: Detects sudden acceleration, collisions,
or unauthorized movement.
● Smart Home Security: Senses vibrations or door/window movements.
● Wearable Devices: Monitors steps, activity levels, and orientation.
● Industrial Monitoring: Tracks machinery vibrations for predictive
maintenance.
● Gaming & VR: Enhances interactivity through motion sensing.
Soil Moisture Sensors
Definition: Devices that measure the water content in soil.
● One probe connects to a +5V supply through a 10kΩ resistor; the other connects to ground.
● Acts as a voltage divider; output voltage varies with soil moisture levels.
Output Behavior:
● Dry soil (low moisture): Higher resistance, output voltage near 5V.
● Wet soil (high moisture): Lower resistance, output voltage decreases.
Specifications
Operating Voltage: 3.3V to 5V DC.
Output Types:
Indicators:
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensor_value = analogRead(sensor_pin); // Read analog value
float moisture_percentage = 100 - ((sensor_value / 1023.0) * 100);
Serial.print("Moisture Percentage = ");
Serial.print(moisture_percentage);
Serial.println("%");
delay(1000); // Wait for 1 second
}
Applications
● Smart Irrigation Systems: Automates watering based on soil moisture
levels.
● Home Gardening: Remote monitoring and alerts for potted plants and
gardens.
● Precision Agriculture: Optimizes water usage across large fields.
● Greenhouse Monitoring: Maintains ideal soil conditions for different
crops.
● Environmental Monitoring: Tracks soil health in forests and wetlands.
Capacitive Proximity Sensor
What is a Capacitive Proximity Sensor?
● A sensor that detects the presence or absence of solid or liquid objects without physical
contact.
● Works by emitting an electrical field and detecting changes in capacitance caused by
nearby objects.
Applications:
Signal Conversion:
Code
void setup(){
pinMode(Pin, INPUT);
Serial.begin(9600);
}
void loop(){
int sensorValue = digitalRead(Pin);
if(sensorValue==LOW){
Serial.println("no Object");
delay(500);
}
else{
Serial.println("Object Detected");
delay(500);
}
}
Applications
● Smart Homes:
○ Automatic lighting systems triggered by proximity.
○ Touchless control of appliances like fans and TVs.
● Healthcare:
○ Liquid level monitoring in medical devices like IV drips.
○ Proximity-based patient monitoring systems.
● Industrial IoT:
○ Object detection in conveyor belt systems.
○ Monitoring material levels in storage tanks.
● Retail:
○ Smart shelving to detect product placement or removal.
GPS Module
● Global Positioning System
(GPS): GPS is a satellite-based
navigation system that provides
location, time, and speed
information.
● NEO-6M GPS Module: This
module receives signals from
GPS satellites and calculates the
position, speed, and time.
● Data Format: The module
outputs data in standard NMEA
sentences, which include
information like latitude,
longitude, altitude, and time.
How Does It Work?
● Receives signals from multiple GPS satellites.
● Calculates position using triangulation.
● Outputs latitude, longitude, altitude, speed, and time data.
● Sends data via UART (TX/RX) or I2C communication to
microcontrollers like Arduino.
Circuit Diagram
Sample Code:
#include <SoftwareSerial.h>
void setup() {
Serial.begin(9600);
ss.begin(9600);
}
void loop() {
while (ss.available() > 0) {
byte gpsData = ss.read();
Serial.write(gpsData);
}
}
Output on Serial Monitor
What are NMEA Sentences?
● Standard Data Format: NMEA sentences are a standard data format
used by GPS manufacturers to transmit data.
● Structure: Each NMEA sentence starts with a dollar sign ($) and ends
with a carriage return and line feed.
● Types of Sentences: Different types of NMEA sentences provide
various pieces of information such as position, time, and speed.
Common NMEA Sentences
● $GPGGA: Provides 3D location and accuracy data.
● $GPGLL: Provides geographic position (latitude and longitude).
● $GPGSA: Provides GPS DOP (Dilution of Precision) and active
satellites.
● $GPGSV: Provides information about satellites in view.
● $GPRMC: Provides recommended minimum specific GPS/Transit
data.
● $GPVTG: Provides track made good and ground speed.
Structure of NMEA Sentences
● Example Sentence:
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
● Components:
● $GPGGA: Sentence identifier.
● 123519: Fix taken at 12:35:19 UTC.
● 4807.038,N: Latitude 48°07.038' N.
● 01131.000,E: Longitude 11°31.000' E.
● 1: Fix quality (0 = invalid, 1 = GPS fix, 2 = DGPS fix).
● 08: Number of satellites being tracked.
● 0.9: Horizontal dilution of position.
● 545.4,M: Altitude, Meters, above mean sea level.
● 46.9,M: Height of geoid (mean sea level) above WGS84 ellipsoid.
● (empty field): Time in seconds since last DGPS update.
● (empty field): DGPS station ID number.
● *47: Checksum data.
Parsing NMEA Sentences
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial ss(4, 3); // RX, TX
TinyGPSPlus gps;
void setup() {
Serial.begin(9600);
ss.begin(9600);
}
void loop() {
while (ss.available() > 0) {
gps.encode(ss.read());
}
if (gps.location.isUpdated()) {
Serial.print("Latitude: ");
Serial.println(gps.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(), 6);
}
}
Applications of IoT with GPS
● Smart Vehicle Tracking – Real-time car/bike tracking using IoT & Google Maps.
● Logistics & Fleet Management – Monitors trucks and delivery routes.
● Drones & UAV Navigation – Autonomous drone control using GPS data.
● Healthcare & Personal Safety – GPS-enabled wearables for elderly or patient
tracking.
● Smart Agriculture – Precision farming using GPS location tracking for tractors &
equipment.
● Geofencing & Security – Alerts when a device/person exits a predefined zone.
Heartbeat Sensor
● Photoplethysmogram (PPG): The
sensor detects subtle changes in blood
flow through the skin caused by the
expansion and contraction of blood
vessels with each heartbeat.
● Optical Method: A light source (usually
an LED) emits light that penetrates the
skin and blood vessels. A
photodetector measures the amount
of light absorbed or reflected back.
● Signal Processing: The photodetector
converts the light into an electrical
signal, which is then amplified and
filtered to calculate the heart rate.
Heartbeat Sensor Pinout
● VCC (Power Supply Pin): Connect to 5V on Arduino.
● GND (Ground Pin): Connect to GND on Arduino.
● Signal (Analog Output Pin): Connect to an analog input pin on Arduino (e.g., A0).
Circuit Diagram
const int pulsePin = A0; // Pulse sensor connected to A0
int sensorValue = 0;
Code
int threshold = 550; // Adjust based on sensor sensitivity
unsigned long previousTime = 0; // Stores the last beat time
float bpm = 0; // Calculated BPM
void setup() {
Serial.begin(9600);
Serial.println("Heart Rate Monitor Initialized...");
}
void loop() {
sensorValue = analogRead(pulsePin); // Read pulse sensor value
if (sensorValue > threshold) { // If a heartbeat is detected
unsigned long currentTime = millis(); // Get current time
if (currentTime - previousTime > 300) { // Debounce to avoid false beats
bpm = (60000.0 / (currentTime - previousTime)); // Calculate BPM
previousTime = currentTime; // Update last beat time
Serial.print("BPM: ");
Serial.println(bpm); // Print BPM to Serial Monitor
}
}
}
Applications
● Remote Patient Monitoring – Doctors can monitor patient heart rate remotely.
● Fitness Wearables – Smartwatches & fitness bands track heart rate in real-time.
● Cardiac Emergency Alert System – Sends an alert when BPM exceeds normal
limits.
● IoT Health Cloud – Stores patient data securely for analysis & AI-based health
predictions.
● Biomedical Research – Used in clinical studies for heart-related conditions.
Why Microcontroller?
Purpose ?
Microcontroller
• Microcontrollers are important part of
Embedded systems
• To understand Structure & working of
Microcontrollers
• For Designing good Embedded system
complete understanding of
microcontrollers required
Microcontroller
Integrated chip that typically contains integrated CPU,
memory (RAM ROM), I/O ports on a single Chip.
● Microcontrollers
CPU RAM ROM
Serial
Timer I/O
Port
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
● CPU is stand-alone, RAM, ROM, I/O, ● CPU, RAM, ROM, I/O and timer are all
timer are separate on a single chip
● Designer can decide on the amount of ● Fix amount of on-chip ROM, RAM, I/O
ports
ROM, RAM and I/O ports.
● Not Expansive
● Expansive
● For applications in which cost, power
● Versatility and space are critical
● General-purpose ● Single-purpose
Microcontrollers
A microcontroller
interfaces to
external devices
with a minimum of
external
components
Most common microcontrollers
● 8-bit microcontrollers
○ AVR
○ PIC
○ HCS12
○ 8051
● 32-bit microcontrollers
○ ARM
○ PIC32
Intel 51 family (8-bit MC)
● 8051
○ 40 pin DIP
○ 4K ROM
○ 32 I/O lines
○ 5 Interrupt
○ UART
○ Have 40 pins dedicated for various functions such as I/O, RD, WR, address, data, and interrupts.
● Some companies provide a 20-pin version of the 8051 with a reduced number of I/O
ports for less demanding applications
Pin Diagram of the 8051
XTAL1 and XTAL2
● The 8051 has an on-chip oscillator but requires an external clock to run it
○ A quartz crystal oscillator is connected to inputs XTAL1 (pin19) and XTAL2 (pin18)
● We can observe the frequency on the XTAL2 pin using the oscilloscope.
RST
● RESET pin is an input and is active high (normally low)
● Upon applying a high pulse to this pin, the microcontroller will reset and
terminate all activities
● This is often referred to as a power-on reset
● Activating a power-on reset will cause all values in the registers to be lost
RST
● In order for the RESET input to be effective, it must have a minimum duration
of 2 machine cycles.
● In other words, the high pulse must be high for a minimum of 2 machine
cycles before it is allowed to go low.
EA’
● EA’, “external access’’, is an input pin and must be connected to
Vcc or GND
● The 8051 family members all come with on-chip ROM to store
programs and also have an external code and data memory.
External
External
60
K
64 64
K K
SFR
EXT INT 4K
128
EA = 0 EA = 1
Program Memory Data Memory
PSEN’ and ALE
● PSEN, “program store enable’’, is an output pin
● The 8051 multiplexes address and data through port 0 to save pins.
○ Port 2 must be used along with P0 to provide the 16-bit address for the
external memory.
○ P2 is used for the upper 8 bits of the 16-bit address, designated as A8 – A15,
and it cannot be used for I/O.
Port 3
● Port 3 can be used as input or output.
P2.0 - P2.7 I/O Port 2: Port 2 is an 8-bit bidirectional I/O. Port 2 emits the high order address
byte during fetches from external program memory and during accesses to
external data memory that use 16 bit addresses.
P3.0 - P3.7 I/O Port 3: Port 3 is an 8 bit bidirectional I/O port. Port 3 also serves special
features as explained.
Pin Description Summary
PIN TYPE NAME AND FUNCTION
RST I Reset: A high on this pin for two machine cycles while the oscillator is running,
resets the device.
ALE O Address Latch Enable: Output pulse for latching the low byte of the address
during an access to external memory.
PSEN* O Program Store Enable: The read strobe to external program memory. When
executing code from the external program memory, PSEN* is activated twice
each machine cycle, except that two PSEN* activations are skipped during each
access to external data memory.
EA*/VPP I External Access Enable/Programming Supply Voltage: EA* must be externally
held low to enable the device to fetch code from external program memory
locations. If EA* Is held high, the device executes from internal program
memory. This pin also receives the programming supply voltage Vpp during
Flash programming. (applies for 89c5x MCU's)
General Block Diagram of 8051
Interrupt 4K 128 B Timer 0
Control ROM Timer 1
RAM
CPU
Bus Serial
OSC Control
4 I/O Ports
Port
TXD RXD
P0 P1 P2 P3
SECTION 2.1: INSIDE THE 8051
• Registers
Figure 2–1a
Some 8-bit Registers of the 8051
SECTION 2.1: INSIDE THE 8051
• Registers
C AC F0 RS1 RS0 OV F1 P
Carry Parity
Auxiliary Carry User Flag 1
User Flag 0 Register Bank Select Overflow
128 Byte RAM
• There are 128 bytes of RAM in the 8051.
– Assigned addresses 00 to 7FH General Purpose
Area
• The 128 bytes are divided into 3 different
groups as follows: BIT Addressable
1. A total of 32 bytes from locations 00 to 1F hex are 128Area
BYTE
set aside for register banks and the stack. INTERNAL
Reg Bank 3
RAM
2. A total of 16 bytes from locations 20H to 2FH are
set aside for bit-addressable read/write memory. Register
Reg Bank 2
3. A total of 80 bytes from locations 30H to 7FH are Banks
Reg Bank 1
used for read and write storage, called scratch Reg Bank 0
pad.
8051 RAM with addresses
8051 Register Bank Structure
Bank 3 R0 R1 R2 R3 R4 R5 R6 R7
Bank 2 R0 R1 R2 R3 R4 R5 R6 R7
Bank 1 R0 R1 R2 R3 R4 R5 R6 R7
Bank 0 R0 R1 R2 R3 R4 R5 R6 R7
8051 Register Banks with address
SECTION 2.7: 8051 REGISTER BANKS AND STACK
• How to switch register banks
(RISC)
Instruction execute in single cycle
Harvard Architecture
• CPU can read both an instruction and data from memory at the
same time that makes it faster.
Read, Write can`t occur at the same time due to same memory and
signal pathway for data and instructions.
AVR internal architecture
Pin configuration of ATmeag32
•ATMEGA32 has four ports, PORTA,
PORTB, PORTC and PORTD, each one
having 8 pins.
•The remaining 8 are mostly consumed by
supply pins (VCC, AVCC), ground (GND),
reset, XTAL pins, and other minor stuffs.
•Every MCU has an internal oscillator
which determines its frequency of
oscillator. But we can connect an external
crystal oscillator to generate higher
frequencies and clock pulses. This
external oscillator is connected across the
XTAL pins (XTAL1 and XTAL2).
Pin configuration of ATmeag32
•Can you see some things written in the
brackets? Like PA0 (ADC0), PB5 (MOSI),
PC2 (TCK), PD1 (TXD), etc. Well, these are
the extra features that the MCU can offer
you apart from GPIO. In other words,
these pins show dual behavior. If nothing
is specified, they act as GPIO pins. The
secondary features of these pins become
active only if you enable certain bits of
some registers. These are called
peripherals
AVR Peripherals
● There are several peripherals that AVR offers in ATMEGA32, some are as follows:
o ADC – Analog to Digital Converter – usually 10-12 bit
o Timers – 8 bit and 16 bit timers
o JTAG – Joint Test Action Group
o TWI – Two Wire Interface (or) I2C – Inter-Integrated Circuit
o USART – Universal Synchronous Asynchronous Receiver Transmitter
o UART – Universal Asynchronous Receiver Transmitter
o SPI – Serial Peripheral Interface
o WDT– Watchdog Timer …and many more!
AVR Peripherals
● ADC stands for Analog to Digital Conversion. The term is self-explaining. This feature
converts Analog signals into Digital signals. (8-channel ADC for ATmega32)
● JTAG corresponds to testing of the circuit. When we make a circuit and fix the MCU
onto it, we use JTAG to verify whether our connection, soldering, circuit design, etc is
correct or not.
AVR Peripherals
● TWI/I2C (its actually I-square-C) is a revolutionary technology by Philips, in which two devices
are connected and communicate by using two wires.
● USART/UART is related to serial communication in which the MCU sends and receives signals
from another device based on serial protocol.
● WDT (Watch Dog Timer) is something interesting it seems. The name is also quite interesting.
Just like a watchdog always keeps an eye on it’s master to protect him from any harm, WDT
keeps an eye on the execution of the code to protect the MCU from any harm. A WDT is a
computer hardware or software timer that triggers a system reset or other corrective action if
the main program, due to some fault condition, such as a hang, neglects to regularly service
the watchdog (writing a “service pulse” to it, also referred to as “kicking the dog”, “petting the
dog”, “feeding the watchdog” or “waking the watchdog”). The intention is to bring the system
back from the unresponsive state into normal operation.
Brief History of ARM
● First ARM processor developed in 3 micron technology in ‘83-85’ by Acron Computers
Ltd. of Cambridge, England. ARM- Acron RISC Machine.
● Later on ARM (Advanced RISC Machine) Ltd. spun out of Acorn Computers in 1990 and
hence now ARM stands for Advanced RISC Machine.
● Designs the ARM range of RISC processor cores but not fabricate.
● Licenses ARM core designs to semiconductor partners who fabricate ARM core with
other components as per requirements and sell to their customers.
ARM Application Areas
Bit: 31 30 29 28 7 6 5 4 0
N Z C V I F T Mode
3. The PC is forced to a value between 0016 and 1C16, the particular value depending
upon the type of exception.
● The exception handler will user r13_exc, which will normally have
been initialized to point to a dedicated stack in memory, to save some
user registers.