0% found this document useful (0 votes)
3 views60 pages

Micro Controller

A microcontroller is a compact computer on a single chip, integrating a CPU, memory, and I/O peripherals. It features various components such as RAM, Flash, EEPROM, and oscillators, and can be classified based on bus width, memory architecture, and instruction set. Additionally, it contrasts with microprocessors in terms of application specificity, clock speed, and energy consumption.

Uploaded by

ripfoc92
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)
3 views60 pages

Micro Controller

A microcontroller is a compact computer on a single chip, integrating a CPU, memory, and I/O peripherals. It features various components such as RAM, Flash, EEPROM, and oscillators, and can be classified based on bus width, memory architecture, and instruction set. Additionally, it contrasts with microprocessors in terms of application specificity, clock speed, and energy consumption.

Uploaded by

ripfoc92
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/ 60

Microcontroller

Microcontrollers

Please note that many diagrams used in this presentation have been taken from different sources. I am very thankful to the resource
providers as these items have rendered clarity to discussions.
What is a Microcontroller?

● A microcontroller is a small computer on a single VLSI integrated circuit chip.


● A microcontroller contains one or more CPUs along with memory and programmable
input/output peripherals.

Very-large-scale integration
(VLSI) is the process of creating
an integrated circuit (IC) by A transistor is a semiconductor
combining thousands of device used to amplify or switch
transistors into a single chip. electrical signals and power. It is one
VLSI began in the 1970s when of the basic building blocks of
complex semiconductor and modern electronics. It is composed
communication technologies of semiconductor material, usually
were being developed. The with at least three terminals for
microprocessor is also a VLSI connection to an electronic circuit.
device.
What is a Microcontroller?
Basic Components of a Microcontroller

● CPU: It can be thought of as the brain of the device. It processes and responds to various instructions
that direct the microcontroller's function. This involves performing basic arithmetic, logic and I/O
operations.

● RAM: (Random Access Memory) It can read and write data. It is volatile in the sense that it cannot
retain data in the absence of power; i.e., data is lost after the removal of power.

● Flash: It is a long-life and non-volatile storage chip that is widely used in embedded systems. It can
keep stored data and information even when the power is off. It can be electrically erased and
reprogrammed.

● EEPROM: (Electrically Erasable Programmable Read Only Memory) It is a type of non-volatile


ROM that enables individual bytes of data to be erased and reprogrammed. That is why EEPROM
chips are known as byte erasable chips. EEPROM is usually used to store small amounts of data in
computing and other electronic devices.
Basic Components of a Microcontroller

Flash EEPROM
Type NAND-type memory NOR type memory

Erasabilit block-wise erasable byte-wise erasable


y (data block: splitting a unit of data
into multiple fragments)

Write constantly rewritten seldom rewritten

Need used when large amounts are needed used when only small amounts are
needed
Basic Components of a Microcontroller

● Oscillator: Oscillators are responsible for supplying the clock signals in microcontrollers. All the
instructions executed by microcontrollers are in synchronization with clock signals. The timing for different
operations in a microcontroller is assigned with the help of oscillators.

● I/O Pins: These pins allow exchange of data and signals between external devices and a microcontroller.

● Serial Ports: Serial communication enables a microcontroller to communicate with other devices using the
serial RS232 communication protocol.

● ADC: An analog-to-digital converter (ADC) is used to convert an analog signal such as voltage to a digital
form so that it can be read and processed by a microcontroller.

● DAC: A digital to analogue converter (DAC) converts a digital signal from the computer into an electrical
voltage which can be used to drive electrical equipment, for example, a motor.
● 8051 microcontrollers have 4
I/O ports each of 8-bit, which
can be configured as input or
output.

● Hence, total 32 input/output pins


allow the microcontroller to be
connected with the peripheral
devices.

● Pin configuration, i.e. the pin


can be configured as 1 for input
and 0 for output as per the logic
state.
Serial Parallel

Number of bits 1 bit n bits


transmitted at
one clock pulse

Number of 1 line n lines


lines required
to transmit
data

Speed of data slow fast


transfer

Cost of Low as 1 line is Higher as n lines


transmission required are required

Application Long distance Short distance


communication communication
(eg., between two (eg., between
computers) computer and a
printer)
Difference between VCC and
VDD

In an electronic circuit, VCC is the


supply voltage of the circuit, and
VDD is the operating voltage of
the chip.

C=circuit the circuit, that is, the


voltage of the access circuit.

D=device indicates the device, that


is, the working voltage inside the
device.

GND (Ground):
It is considered as the common
reference point to measure
voltage against any point of the
circuit and is considered to have
zero voltage.

It is also the common connection


that all electrical components must
connect to in one way or another in
order to complete the circuit.
IC Packaging
● A dual in-line package (DIP or DIL), is an
electronic component package with a
DIP rectangular housing and two parallel rows of
8 pins electrical connecting pins.
● The package may be through-hole mounted to a
printed circuit board (PCB) or inserted in a
socket.
● A DIP is usually referred to as a DIPn, where n
is the total number of pins. For example, a
microcircuit package with two rows of seven
vertical leads would be a DIP14.

4000-series logic ICs in


0.3" wide 14-pin plastic
DIP packages (DIP-14N),
also known as PDIP
(Plastic DIP)
PCB (Printed Circuit Board)
IC Packaging ● A small outline integrated circuit
(SOIC) is a surface-mounted integrated
SOIC
circuit (IC) package.
Small Outline IC
18 pins ● It occupies an area about 30–50% less
than an equivalent dual in-line package
(DIP), with a typical thickness being
70% less.

● They are generally available in the same


pin-outs as their counterpart DIP ICs.

Basic Assignment!!

● What is a surface-mounted IC package?


IC Packaging
● A quad flat package is a surface-
mounted integrated circuit package
with "gull wing" leads extending
from each of the four sides.

● Socketing such packages is rare and


through-hole mounting is not
possible.

● Versions ranging from 32 to 304


pins.

QFP
Quad Flat Package
32 pins
IC Packaging
● A ball grid array is a type of surface-
mount packaging used for integrated
circuits.

● BGA packages are used to permanently


mount devices such as microprocessors.

● A BGA can provide more interconnection


pins than can be put on a dual in-line or flat
package.

BGA
Ball Grid Array
100 pins Basic Assignment!!

● What are the typical applications (mention


separately) for each IC packages?
Classifications
Classificationsofof
Microcontrollers
Microcontrollers
Classifications of Microcontrollers
Based on Bus Width

● 8 bit (0 to 255) (ex: ATMega328P)


● 16 bit (0 to 65,535) (ex: ST10 series)
● 32 bit (0 to 429,49,67,295) (ex: STM32F10C8T6)

❏ A bus is a pathway for digital signals.


❏ There are three internal buses: the data bus, address bus, and
control bus. Together, these three make up the “system bus”.
❏ The width of the data bus reflects the maximum amount of
data that can be processed and delivered at one time.
❏ A 32-bit microcontroller has a 32-bit data bus and can
communicate 32-bits of data at a time.
❏ Whether the data is read or written is determined by the
control bus.
❏ The physical location of the data in memory is carried by the
address bus. The address bus carries only the information
regarding the address, and is synchronized with the data bus to
accomplish read/write tasks from the CPU.
Classifications of Microcontrollers
Based on Memory Architecture

Harvard Memory Architecture MCU Princeton Memory Architecture MCU (Von Neumann)

● Separate storage and signal pathways for instructions ● Program instructions and data share the same memory and
and data pathways
● An instruction is executed in a single cycle. ● Two clock cycles are required to execute single instruction.
● Increased complexity and development cost ● Issues of Bottleneck (The shared bus between the program
memory and data memory leads to the bottleneck, the limited
throughput (data transfer rate) between the CPU and memory
compared to the amount of memory.)
Classifications of Microcontrollers
Based on Instruction Set

RISC CISC

It is a Reduced Instruction Set Computer. It is a Complex Instruction Set Computer.

It requires multiple register sets to store the instruction. It requires a single register set to store the instruction.

RISC has simple decoding of instruction. CISC has complex decoding of instruction.

Uses of pipeline is simple in RISC. Uses of pipeline is difficult in CISC.

It uses a limited number of instruction that requires less time It uses a large number of instruction that requires more time
to execute the instructions. to execute the instructions.

RISC architecture can be used with high-end applications like CISC architecture can be used with low-end applications like
telecommunication, image processing, video processing, etc. home automation, security system, etc.

It has fixed format instruction. It has variable format instruction.

Program written needs to take more space in memory. Program written tends to take less space in memory.
Classifications of Microcontrollers

Registers in Digital logic


CISC

RISC
Clock Speed

● The clock speed measures the


number of cycles your CPU
executes per second, measured
in GHz (gigahertz).

● In this case, a “cycle” is the


basic unit that measures a
CPU's speed.

● During each cycle, billions of


transistors within the processor
open and close.
Few Common Microcontrollers

● The ATmega328 is a single-chip


microcontroller created by Atmel
in the megaAVR family.

● It has a modified Harvard


architecture 8-bit RISC
processor core.

Arduino UNO

ATMega328P
Clock Speed 16 MHz
5 V Input Voltage
Few Common Microcontrollers
The ESP8266 is a microcontroller with

● low-cost Wi-Fi microchip,

● with built-in TCP/IP networking


software,
● Harvard architecture, 32-bit
RISC implementation, and

● produced by Espressif Systems in


NodeMCU Shanghai, China.

ESP8266
Clock Speed 80 MHz
3.3 V Input Voltage
Few Common Microcontrollers
The ARM Cortex-M is a group of
● Harvard architecture 32-bit
RISC ARM processor cores

● licensed by ARM Limited

● These cores are optimized for low-


cost and energy-efficient integrated
circuits
STM32F10C8T6
“Blue Pill”

ARM Cortex M3
Clock Speed 72MHZ
3.3V Input Voltage
Microcontroller vs Microprocessor
Application Specific General Computational Purpose
Limited Clock Speed (Less-paced High Clock Speed (Fast-paced
Computation) e.g.: Arduino. 16MHz computation) e.g.: Apple M1 3.2GHz
(0.016GHz)
Requires external components to function
Self-sufficient
High Intake of Energy
Low Intake of Energy
High Cost
Low Cost
What about Raspberry Pi??

Raspberry Pi

Clock Speed 1.8GHz


5V Input Voltage
Differences between Raspberry Pi and Arduino
Features Arduino Raspberry Pi

Microcontroller/
Microcontroller board Microprocessor based mini computer
Microprocessor

CPU, RAM and ROM. All the additional hardware


All features of a computer with a processor, memory,
Hardware on Arduino board is for power supply, programming
storage, graphics driver, connectors on the board.
and IO Connectivity.

Doesn’t need any operating system. All you need is


Operating System Needs an Operating System to run.
a binary of the compiled source code.

Clock speed 16 MHz 1.8 GHz

One can power Arduino from the USB port of a It needs more more current than Arduino. So, one
Power requirement
computer. needs a power adapter for Raspberry Pi.

Good for developing software applications (e.g.,


Good for interfacing Sensors and controlling LEDs using Python). It also consists of a 40-pin GPIO,
Applications
and Motors. through which you can connect different electronic
components like LEDs, Buttons, Sensors, Motors etc.
Serial Bus Protocols
Serial Bus Protocols
What is a serial bus protocol?
It is a point-to-point connection from a master to slave.

Why is it called a serial bus?


A serial bus can be defined as a transmission path over which the participants transmit their data serially (i.e. bit after
bit), sequentially in time and using a common medium

What is the example of serial bus?


Universal serial bus (USB) is a common serial bus. Examples of serial buses include the universal serial bus (USB). USB has
an interesting feature in that the bus carries not only data to and from the peripheral but also electrical power.

What is serial vs parallel bus?


Serial connections, which use relatively few wires, are generally simpler than parallel connections. Universal serial bus
(USB) is a common serial bus. Parallel buses have a relatively large number of wires bundled together that enable data to be
transferred in parallel.

Is Serial bus faster than parallel?


Parallel Transmission is faster than serial transmission to transmit the bits. Parallel transmission is used for short distance.
● Inter-integrated circuit (I2C) is a system for serial
Serial Bus Protocols data exchange between the microcontrollers and
specialized integrated circuits of a new generation.

● It is used when the distance between them is short


(receiver and transmitter are usually on the same
printed board).

● Connection is established via two conductors. One is


used for data transfer and the other is used for
synchronization (clock signal).

● The I2C bus consists of two signals − SCL and SDA.


I2C SCL is the clock signal, and SDA is the data signal.
(Inter- Integrated Circuit)

● The current bus master always generates the clock


signal.
I2C is used to connect devices like microcontrollers, EEPROMs,
● Some slave devices may force the clock low at times
I/O interfaces, and other peripheral devices in an embedded
to delay the master sending more data (or to require
system. A microcontroller is often used as the master device, and
other peripheral devices are used as slave devices. more time to prepare data before the master attempts to
clock it out). This is known as “clock stretching”.
Serial Bus Protocols
❏ It is a serial communication protocol that is used to connect
low-speed devices.

❏ It is a full-duplex synchronous serial communication, which


means that data can be simultaneously transmitted from both
directions.

❏ The main advantage of the SPI is to transfer the data


without any interruption. Many bits can be sent or received
at a time in this protocol.

❏ In this protocol, devices are communicated in the master-


slave relationship.

SPI ❏ The simplest configuration of the Serial Peripheral Interface


(Serial Peripheral Interface)
(SPI) is a combination of a single slave and a single master.
But, one master device can control multiple slave devices.
To send data between microcontrollers and small peripherals such
as shift registers, sensors, and SD cards.
❏ MOSI: MOSI stands for Master
Output Slave Input. It is used to
send data from the master to the
slave.

❏ MISO: MISO stands for Master


Input Slave Output. It is used to
send data from the slave to the
master.
❏ SCK or SCLK (Serial Clock): It is
used to send the clock signal.
❏ SS/CS (Slave Select / Chip Select):
It is used by the master to send data
by selecting a slave.
Serial Bus Protocols

● In UART communication, two UARTs communicate directly


with each other.

● Only two wires are needed to transmit data between two


UARTs. Data flows from the Tx pin of the transmitting UART to
the Rx pin of the receiving UART.

● Two extra wires are needed in addition to the data lines. They are
called RTS (Request to Send) and CTS (Clear to Send). These
wires are cross-coupled between the two devices, so RTS on one
UART device is connected to CTS on the remote device and vice versa.
(Universal Asynchronous Receiver/ Transmitter)
● UARTs transmit data asynchronously, which means there is no
clock signal to synchronize the output of bits from the
transmitting UART to the sampling of bits by the receiving
UART.
How UART works?

● UART transmitted data is organized into


packets.

● Each packet contains 1 start bit, 5 to 9 data


bits (depending on the UART), an optional
parity bit, and 1 or 2 stop bits:
How UART works?
Steps of UART Transmission

2. The transmitting UART adds the start bit, parity


1. The transmitting UART receives data in
bit, and the stop bit(s) to the data frame:
parallel from the data bus
4. The receiving UART discards the start bit, parity bit,
How UART works? and stop bit from the data frame:

Steps of UART Transmission

3. The entire packet is sent serially from the


transmitting UART to the receiving UART. The
receiving UART samples the data line at the pre-
configured baud rate:

5. The receiving UART converts the serial data back into


parallel and transfers it to the data bus on the receiving end:
How UART works?
Packet

START BIT
● The UART data transmission line is normally held at a high voltage level when it’s not transmitting data.
● To start the transfer of data, the transmitting UART pulls the transmission line from high to low for one clock
cycle.
● When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at
the frequency of the baud rate.

DATA FRAME
● The data frame contains the actual data being transferred.
● It can be 5 bits up to 8 bits long if a parity bit is used.
● If no parity bit is used, the data frame can be 9 bits long.
● In most cases, the data is sent with the least significant bit first.
How UART works?
Packet

PARITY
● Parity describes the evenness or oddness of a number.

● The parity bit is a way for the receiving UART to tell if any data has changed during transmission.

● Bits can be changed by electromagnetic radiation, mismatched baud rates, or long distance data transfers.

● After the receiving UART reads the data frame, it counts the number of bits with a value of 1 and checks if the

total is an even or odd number.

● If the parity bit is a 0 (even parity), the 1 bits in the data frame should total to an even number. If the parity bit is a 1

(odd parity), the 1 bits in the data frame should total to an odd number.

● When the parity bit matches the data, the UART knows that the transmission was free of errors. But if the parity

bit is a 0, and the total is odd; or the parity bit is a 1, and the total is even, the UART knows that bits in the data

frame have changed.


How UART works?
Packet
STOP BITS
● To signal the end of the data packet, the sending UART drives the data transmission line from a low voltage to a

high voltage for at least two bit durations.

Note:

● Why do we add start and stop bits for UART communication?

UARTs transmit data asynchronously, which means there is no clock signal to synchronize the output of bits from the

transmitting UART to the sampling of bits by the receiving UART. Instead of a clock signal, the transmitting UART adds

start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the

receiving UART knows when to start reading the bits.


How UART works?

Note:

● What is baud rate?

When the receiving UART detects a start bit, it starts to read the incoming bits at a specific frequency known as the baud rate.

Baud rate is a measure of the speed of data transfer, expressed in bits per second (bps). Both UARTs must operate at about

the same baud rate. The baud rate between the transmitting and receiving UARTs can only differ by about 10% before the

timing of bits gets too far off.

● Should both UARTs have same configuration for packet structure?

Both UARTs must also must be configured to transmit and receive the same data packet structure.
How UART works?
Advantages and Disadvantages of UART
No communication protocol is perfect, but UARTs are pretty good at what they do. Here are some pros and cons to help you

decide whether or not they fit the needs of your project:

ADVANTAGES
● Only uses two wires

● No clock signal is necessary

● Has a parity bit to allow for error checking

● The structure of the data packet can be changed as long as both sides are set up for it

● Well documented and widely used method

DISADVANTAGES
● The size of the data frame is limited to a maximum of 9 bits

● Doesn’t support multiple slave or multiple master systems

● The baud rates of each UART must be within 10% of each other
NodeMCU
ESP8266
Pinout
CP2101
USB* to TTL** converter Flash Button
NodeMCU ESP8266 Parts

Voltage Regulator
Reset Button

ESP8266 Chip

2.4 GHz Antenna

*USB: Universal Serial Bus


**TTL: Transistor-transistor Link
NodeMCU ESP8266 Pinout
NodeMCU ESP8266 Pinout
GPIO Pins (General Purpose Input Output)
● 17 GPIO Pins
● GPIO 16:- Deep Sleep Wake Ability
● GPIO 0:- Connected to Flash
● GPIO 6 to GPIO 11:- Connected to Flash.
Shouldn’t be used.

■ GPIO 06 : SDCLK
■ GPIO 07 : SDD0
■ GPIO 08 : SDD1
■ GPIO 09 : SDD2 (can be used)
■ GPIO 10 : SDD3 (can be used)
NodeMCU ESP8266 Pinout

Grounds and Power Pins

● 3 3.3V Pins (for output)

● One Vin Pin (for input)

● Can be powered using micro-USB as well

● 4 GND Pins
NodeMCU ESP8266 Pinout

Enable and Reset Pins

● RST is always high (pulled LOW: resets)

● GPIO 16 can send LOW to RST pin to wake

it from deep sleep

● EN is always high (pulled LOW: low power)


NodeMCU ESP8266 Pinout

SPI Protocol
MOSI: Master Out Slave In
CS: Chip Select
MISO: Master In Slave Out
CLK : Clock

1. MOSI, CS, MISO, SCLK


2. HSCLK, HMISO, HMOSI, HCS
NodeMCU ESP8266 Pinout

I2C Protocol
SDA: Serial Data
SCL: Serial Clock

1. GPIO 5 (SCL) & GPIO 4 (SDA)


NodeMCU ESP8266 Pinout

UART Protocol
TX: Transmitter
RX: Receiver
CTS: Clear to Send
RTS : Ready to Send

RXD2 (CTS), TXD2 (RTS)

1. RXD0, TXD0
2. TXD1
NodeMCU ESP8266 Pinout

Analog Pins

Only one Analog Read Pin ADC 0

10 bit resolution
NodeMCU ESP8266 Pinout

PWM and Interrupts

All GPIO pins except 16 allows software PWM

All GPIO pins except 16 supports Interrupts


Interrupts
Interrupts
● Interrupts are the events that temporarily suspend
the main program, pass the control to the external
sources and execute their task.
● It then passes the control to the main program
where it had left off.
Difference between Hardware and Software (PWM)
Hardware PWM Software PWM

● Generated using in-built timer, ● Generated using Software


oscillator ● Not very accurate
● Very Accurate ● Any GPIO can used to create SW
● Only select GPIO support HW
PWM
PWM
● Eg:- LED brightness is controlled but
● Eg:- Seamless control of a LED’s
prone to glitches
brightness
Difference between Hardware and Software (Interrupt)

Hardware INTERRUPT Software INTERRUPT

● Generated from external device, ● Generated internally in the software


hardware ● Does increment the timer
● Doesn’t Increment the timer ● Synchronous
● Asynchronous ● Eg:- Pin Change Interrupt

● Eg:- Interrupt using external switches,


triggers
WiFi
Facilities
WiFi facilities on NodeMCU

● Add #include <ESP8266WiFi.h> at the top ● Can act both as a Wifi Station and Wifi

● Add Wifi.softAP(); line in void setup to Access Point


● Can send and receive data from
connect external devices to esp8266
websites/internet
● Add Wifi.begin(); line in void setup to
● Can be used to connect different MCU
connect to esp8266 a modem
● Can be used for automation purposes
THANK
YOU!

You might also like