0% found this document useful (0 votes)
9 views26 pages

Chapter2 Lesson1

Chapter 2 of the document provides an overview of microcontroller (MCU) hardware, focusing on AVR microcontrollers, their architecture, and key features such as ports, registers, GPIO, and ADC/DAC functionalities. It discusses criteria for selecting microcontrollers, including efficiency, cost, and availability of development tools. The chapter also covers the internal architecture of AVR microcontrollers, highlighting the Atmega32 model and its capabilities in handling digital and analog signals.

Uploaded by

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

Chapter2 Lesson1

Chapter 2 of the document provides an overview of microcontroller (MCU) hardware, focusing on AVR microcontrollers, their architecture, and key features such as ports, registers, GPIO, and ADC/DAC functionalities. It discusses criteria for selecting microcontrollers, including efficiency, cost, and availability of development tools. The chapter also covers the internal architecture of AVR microcontrollers, highlighting the Atmega32 model and its capabilities in handling digital and analog signals.

Uploaded by

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

www. Micro Digital Ed.

com
BIHE university

Chapter 2 MCU Hardware Overview

Lesson-1 : MCU Hardware Overview:


Ports, Registers, GPIO, Analog I/O, ADC/DAC

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Lesson-1 Outline
www. Micro Digital Ed. com
BIHE university

• Most common microcontrollers


• Criteria for choosing a Microcontroller
• Some facts about AVR µc’s
• AVR internal architecture
• Atmel Atmega32 highlights
• AVR different groups
• Registers
• Ports
• GPIO
• Analog I/O
• ADC

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
2
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Most common microcontrollers
www. Micro Digital Ed. com
BIHE university

8-bit microcontrollers
• Atmel AVR
• Microchip’s PIC
• Freescale Semiconductor’s HCS08
• Intel’s 8051
• Zilog’s Z8
32-bit microcontrollers
• AVR32
• ARM
• PIC32

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
3
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Most common microcontrollers
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
4
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Criteria for choosing a Microcontroller
www. Micro Digital Ed. com
BIHE university

1. Meet the task at hand efficiently and cost


effectively.
a) Speed- highest speed µc supports
b) Packaging- DIP, QFP, etc., space required while
assembling
c) Power consumption- critical for battery-powered
products
d) Amount of RAM & ROM on the chip
e) I/O –number of I/O pins and the time on the chip
f) Ease of upgrade to higher performance, lower
power consumption versions
g) Cost per unit.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
5
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Criteria for choosing a Microcontroller
www. Micro Digital Ed. com
BIHE university

2. Availability of development products, such


as, Assembler, debugger, code-efficient,
compiler, emulator, technical support,
both in-house and outside expertise, third-
party vendor support

3. Ready availability of µc in quantities both


present and future.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
6
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Some facts about AVR µc’s
www. Micro Digital Ed. com
BIHE university

• AVR basic architecture:


– Alf-Egil Bogen and Vegard Wollan
(Norwegian Institute of Technology (NTH))
• AVR ≡ Advanced Virtual RISC
• Except for AVR32, all other AVR’s are 8-bit µc’s.
• In terms of software Atmel µc’s are not 100%
compatible.
• Atmel have all dedicated massive resources to
ensure wide and timely availability of their
products.
• They are stable, mature and single sourced.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
7
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture
www. Micro Digital Ed. com
BIHE university

RAM EEPROM Timers

PROGRAM
ROM

Program
Bus Bus
CPU

Interrupt Other
OSC Ports
Unit Peripherals

I/O
PINS

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
8
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture
www. Micro Digital Ed. com
BIHE university

AVR inside Arduino circuit board


AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
9
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
10
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture - pins
www. Micro Digital Ed. com
BIHE university

Power and Ground Pins


•VCC: Power supply pin (typically +5V).
•GND: Ground reference pin.
Clock and Reset Pins
•XTAL1: External crystal oscillator input pin 1.
•XTAL2: External crystal oscillator input pin 2.
•RESET: Reset pin (active low).
Digital I/O Pins
•PA0-PA7: General-purpose digital I/O pins, also used as ADC (Analog to Digital Converter) input
channels.
•PB0-PB7: General-purpose digital I/O pins with various alternate functions like timers, USART
(Universal Synchronous/Asynchronous Receiver Transmitter), and SPI (Serial Peripheral
Interface).
•PC0-PC7: General-purpose digital I/O pins, also used for TWI (Two-Wire Interface) and JTAG
(Joint Test Action Group) pins.
•PD0-PD7: General-purpose digital I/O pins with functions like USART, external interrupts, and
timers.
Analog and Reference Pins
•AVCC: Power supply pin for the ADC (Analog to Digital Converter).
•AREF: Analog reference pin for the ADC.
•ADC0-ADC7: Analog input channels for the ADC.
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
11
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture
www. Micro Digital Ed. com
BIHE university

Communication Pins
•RXD: USART receive pin.
•TXD: USART transmit pin.
•MOSI: SPI master out, slave in pin.
•MISO: SPI master in, slave out pin.
•SCK: SPI serial clock pin.
•SS: SPI slave select pin.
Timer and Counter Pins
•T0: Timer/Counter0 external counter input pin.
•T1: Timer/Counter1 external counter input pin.
•ICP: Timer/Counter1 input capture pin.
•OC1A/B: Timer/Counter1 output compare match pins.
•OC2: Timer/Counter2 output compare match pin.
Interrupt Pins
•INT0: External interrupt 0 input pin.
•INT1: External interrupt 1 input pin.
•INT2: External interrupt 2 input pin.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
12
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR internal architecture
www. Micro Digital Ed. com
BIHE university

Example: Led blinking hardware connection


AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
13
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Atmel Atmega32
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
14
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Registers
www. Micro Digital Ed. com
BIHE university

• AVR’s CPU
– ALU
– 32 General Purpose
registers (R0 to R31)
– PC register
– Instruction decoder
– SREG

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
15
Assembly and C Upper Saddle River, NJ 07458. • All Rights
GPIO
www. Micro Digital Ed. com


BIHE university

AVR ATmega32 has 32 IO pins constituting four ports. The ports are listed
below :
1. PORT A
2. PORT B
3. PORT C
4. PORT D.
• Each port has 8 pins.
• The pins of these four ports can be used as general-purpose
inputs/outputs.
• These pins can be configured as input or output using the three I/O registers
for each port. These registers are listed below :
• 1. DDRxregisters: These are used to decide the direction of the pins, i.e.
whether the pins will act as input pins or as output pins
• 2. PINxregisters: These are used to read the logic level on the port pins.
• 3. PORTxregisters: These are used to set the logic on the pins HIGH or LOW.
• (Where x can be A, B, C, or D depending on which port registers are being
addressed).
• Each pin also has some special functionality associated with it as well.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
16
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Example 1
www. Micro Digital Ed. com
BIHE university

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
17
Assembly and C Upper Saddle River, NJ 07458. • All Rights
ADC
www. Micro Digital Ed. com
BIHE university

• Analog-to-digital converters(ADC)are among the most widely


used devices for data acquisition
• Digital computer use binary (discrete), but physical world
everything is analog (continuous).
• Thus, a device called transducer(sensor) is needed to
convert physical quantities (i.e. temperature, pressure, etc)
to electrical (voltage/current) signal.
• ADC is used to translate the analog signals to digital signal.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
18
Assembly and C Upper Saddle River, NJ 07458. • All Rights
ADC
www. Micro Digital Ed. com
BIHE university

• Atmega32 has 10 bit ADC, which means we


will get digital output 0 to 1023.
i.e. When the input is 0V, the digital output
will be 0V & when input is 5V (and
Vref=5V), we will get the highest digital
output corresponding to 1023
steps, which is 5V.

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
19
Assembly and C Upper Saddle River, NJ 07458. • All Rights
ADC
www. Micro Digital Ed. com
BIHE university

Example
Let's assume the following:
• Vref = 5V
• Resolution = 10 bits (1024 levels)
• Input Voltage (Vin) = 2.5V

Step-by-Step Conversion
1.Step Size Calculation:
1. The step size is calculated as Vref / (2^resolution - 1) = 5V / 1023 ≈ 4.88 mV per
step.
2.Quantization:
1. Vin = 2.5V
2. The ADC determines how many steps fit into 2.5V by dividing Vin by the step size.
3. Number of steps = Vin / Step Size = 2.5V / 4.88mV ≈ 512
3.Digital Output:
1. The ADC converts the 512 steps into a binary value.
2. For a 10-bit ADC, the binary representation of 512 is 1000000000 (in binary).

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
20
Assembly and C Upper Saddle River, NJ 07458. • All Rights
AVR simplest connection
www. Micro Digital Ed. com
BIHE university

• external crystal,
• external RESET button,
• additional components for AD converter
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
21
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Driving Loads – source or sink configurations
www. Micro Digital Ed. com
BIHE university

• An output pin not connected to anything is not of


much interest. To do something useful it must be
connected to another device, referred here simply
as a “load”.
• A real world load could be an LED, a lamp, a
transistor, or some other circuit element.
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
22
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Driving Loads – source or sink configurations
www. Micro Digital Ed. com
BIHE university

• Generally there are two ways to connect an output pin


to a load.
1. The first is where the microcontroller supplies the current
to drive the device. The microcontroller is referred to as the
source. Current flows from the microcontroller power to the
output pin, through the load and to ground.
2. A microcontroller I/O pin can be set by the program to
operate as an output. The output voltage will be close to
the supply voltage when the output is set to a logical 1.
The output voltage will be close to 0 volts when the pin is
set to a logical 0.
3. The microcontroller pin can also “sink” the current as
shown in Figure. Here the current flows from the power
supply through the load and through the output pin to
ground. It is important that the load be connected to the
same power supply line as the microcontroller, otherwise
destroy the IC.
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
23
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Digital input – pull up or pull down resistor
www. Micro Digital Ed. com
BIHE university

• Sometimes you want an input to read as a 1 or 0 as a


default. Suppose you have a sensor on a cable that
plugs into your device. It is possible that the user will
disconnect the cable. If the input pin is left floating, it
might sometimes read as a 1, sometimes as a 0. Your
code might interpret this as changes from a sensor
and not act the way you want.
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
24
Assembly and C Upper Saddle River, NJ 07458. • All Rights
Digital input – pull up or pull down resistor
www. Micro Digital Ed. com
BIHE university

• Putting a pull up resistor will set the input voltage


near Vcc and it will read as a 1. A pull down
resistor will bring the voltage near 0V, and it will
read as a zero. Figure shows pull up and pull down
resistors. The switch, sensor, or other component that
generates the normal 1 and 0 voltages must be able
to over drive the resistor.
AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
25
Assembly and C Upper Saddle River, NJ 07458. • All Rights
www. Micro Digital Ed. com
BIHE university

More on GPIO ports and registers in AVR

https://www.electronicwings.com/avr-atmega/atmega1632-
gpio-ports-and-registers

End of Lesson-1

AVR Microcontroller and Embedded System Using © 2011 Pearson Higher Education,
Assembly and C Upper Saddle River, NJ 07458. • All Rights

You might also like