Chapter2 Lesson1
Chapter2 Lesson1
com
BIHE university
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
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
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
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 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
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 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
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
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
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
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
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