Académique Documents
Professionnel Documents
Culture Documents
Microcontroller System
Introduction to Microcontroller
HENDAWAN SOEBHAKTI, ST., MT.
3
What is microcontroller?
• Microcontroller is an integrated chip that
typically containts integrated CPU, memory
(RAM, ROM), I/O ports on a single chip.
• Microcontroller is designed to execute a
specific task to control a single system.
• Differs from microprocessor :
General purpose chip, require multiple chip to
handle various tasks.
4
Microcontroller vs Microprocessor
• General Purpose Microprocessors
Data BUS
General Serial
IO
Purpose RAM ROM Timer COM
Port
Micro Port
processor Address BUS
Control BUS
• Microcontrollers
CPU RAM ROM
Serial
Timer I/O
Port
5
Microcontroller Type
• 8-bit microcontrollers
– AVR
– PIC
– HCS12
– 8051
• 32-bit microcontrollers
– ARM
– PIC32
6
AVR Microcontroller
• AVR = Advanced Virtual RISC.
• RISC = Reduced Instruction Set Computer.
• The founder are Alf Egil Bogen and Vegard
Wollan, students at Norwegian Institute of
Technology on 1994.
7
AVR Microcontroller Family
• Classic AVR
– e.g. AT90S2313, AT90S4433
• Mega
– e.g. ATmega8, ATmega32, ATmega128
• Tiny
– e.g. ATtiny13, ATtiny25
• Special Purpose AVR
– e.g. AT90PWM216,AT90USB1287
8
AVR Classic Family
9
AVR Mega Family
10
AVR Tiny Family
11
AVR Special Purpose Family
12
AVR Part Numbers
ATmega128
Atmel group
Flash =128K
ATtiny44 AT90S4433
Atmel Atmel
Flash =4K Classic
Tiny Flash =4K
group
group
13
2. Microcontroller
Architecture
14
ATmega328 Pin Configuration
15
Pin Descriptions (1)
• VCC
Digital supply voltage.
• GND
Ground.
• Port B (PB7:0) XTAL1/XTAL2/TOSC1/TOSC2
– Port B is an 8-bit bi-directional I/O port with internal pull-up resistors.
– Depending on the clock selection fuse settings, PB6 can be used as input
to the inverting Oscillator amplifier and input to the internal clock
operating circuit.
– Depending on the clock selection fuse settings, PB7 can be used as output
from the inverting Oscillator amplifier.
– If the Internal Calibrated RC Oscillator is used as chip clock source, PB7..6
is used as TOSC2..1 input for the Asynchronous Timer/Counter2 if the AS2
bit in ASSR is set.
16
Pin Descriptions (2)
• Port C (PC5:0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistor.
• PC6/RESET
– If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin.
– If RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low
level on this pin for longer than the f the minimum pulse length will
generate a Reset, even if the clock is not running.
• Port D (PD7:0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors.
• AVCC
– AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It
should be externally
– connected to VCC, even if the ADC is not used. If the ADC is used, it should be
connected to VCC
– through a low-pass filter. Note that PC6..4 use digital supply voltage, VCC.
17
Pin Descriptions (3)
• AREF
AREF is the analog reference pin for the A/D Converter.
• ADC7:6 (TQFP and QFN/MLF Package Only)
– In the TQFP and QFN/MLF package, ADC7:6 serve as analog inputs to the
A/D converter.
– These pins are powered from the analog supply and serve as 10-bit ADC
channels
18
Block Diagram
Features :
•32K bytes of In-System Programmable Flash
•1K bytes EEPROM
•2K bytes SRAM
•23 programmable I/O lines
•Two 8 bit Timers/Counters
•One 16 bit Timer/Counter
•Six PWM channels
•6 channels 10 bit ADC
•External and internal interrupts
•Programmable serial USART
19
3. Arduino
20
Arduino
• Arduino is a single board microcontroller to
make using electronics in multidisciplinary
project more accessible.
• The hardware consists of an open-source
hardware board designed araound and an 8
bit Atmel AVR or a 32 bit Atmel ARM.
• Arduino started in 2005 as a project for
students at the Design Instutute of Ivrea, Italy.
21
Some Arduino Boards
Uno Duemilanove
Nano
Leonardo Mega 22
Specs Compare
Operating
CPU Analog Digital EEPROM SRAM Flash
Name Processor Voltage/Input USB UART
Speed In/Out IO/PWM [KB] [KB] [KB]
Voltage
Uno ATmega328 5 V/7-12 V 16 Mhz 6/0 14/6 1 2 32 Regular 1
Due AT91SAM3X8E 3.3 V/7-12 V 84 Mhz 12/2 54/12 - 96 512 2 Micro 4
Leonardo ATmega32u4 5 V/7-12 V 16 Mhz 12/0 20/7 1 2.5 32 Micro 1
Mega 2560 ATmega2560 5 V/7-12 V 16 Mhz 16/0 54/15 4 8 256 Regular 4
Mega ADK ATmega2560 5 V/7-12 V 16 Mhz 16/0 54/15 4 8 256 Regular 4
Micro ATmega32u4 5 V/7-12 V 16 Mhz 12/0 20/7 1 2.5 32 Micro 1
Mini ATmega328 5 V/7-9 V 16 Mhz 8/0 14/6 1 2 32 - -
ATmega168 0.512 1 16
Nano 5 V/7-9 V 16 Mhz 8/0 14/6 Mini-B 1
ATmega328 1 2 32
Ethernet ATmega328 5 V/7-12 V 16 Mhz 6/0 14/4 1 2 32 Regular -
Esplora ATmega32u4 5 V/7-12 V 16 Mhz - - 1 2.5 32 Micro -
ArduinoBT ATmega328 5 V/2.5-12 V 16 Mhz 6/0 14/6 1 2 32 - 1
Fio ATmega328P 3.3 V/3.7-7 V 8 Mhz 8/0 14/6 1 2 32 Mini 1
Pro (168) ATmega168 3.3 V/3.35-12 V 8 Mhz 6/0 14/6 0.512 1 16 - 1
Pro (328) ATmega328 5 V/5-12 V 16 Mhz 6/0 14/6 1 2 32 - 1
3.3 V/3.35-12 V 8 Mhz
Pro Mini ATmega168 6/0 14/6 0.512 1 16 - 1
5 V/5-12 V 16Mhz
ATmega168V 2.7-5.5 V/2.7-
LilyPad 8 Mhz 6/0 14/6 0.512 1 16 - -
ATmega328V 5.5 V
LilyPad USB ATmega32u4 3.3 V/3.8-5V 8 Mhz 4/0 9/4 1 2.5 32 Micro -
LilyPad 2.7-5.5 V/2.7-
ATmega328 8 Mhz 4/0 9/4 1 2 32 - -
Simple 5.5 V
LilyPad 2.7-5.5 V/2.7-
ATmega328 8 Mhz 4/0 9/4 1 2 32 - -
SimpleSnap 5.5 V
23
Arduino Shield
Protoboard shield
26
Schematic Diagram
27
Power
• The Arduino Uno can be powered via the USB
connection or with an external power supply. The
power source is selected automatically.
• External (non-USB) power can come either from an
AC-to-DC adapter (wall-wart) or battery.
• The board can operate on an external supply of 6 to 20
volts. If supplied with less than 7V, however, the 5V pin
may supply less than five volts and the board may be
unstable. If using more than 12V, the voltage regulator
may overheat and damage the board. The
recommended range is 7 to 12 volts.
28
Power (2)
• VIN. The input voltage to the Arduino board when it's
using an external power source (as opposed to 5 volts
from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if
supplying voltage via the power jack, access it through this
pin.
• 5V.This pin outputs a regulated 5V from the regulator on
the board. The board can be supplied with power either
from the DC power jack (7 - 12V), the USB connector (5V),
or the VIN pin of the board (7-12V). Supplying voltage via
the 5V or 3.3V pins bypasses the regulator, and can
damage your board. We don't advise it.
• 3V3. A 3.3 volt supply generated by the on-board
regulator. Maximum current draw is 50 mA.
• GND. Ground pins.
29
Memory
• The ATmega328 has 32 KB (with 0.5 KB used
for the bootloader). It also has 2 KB of SRAM
and 1 KB of EEPROM (which can be read and
written with the EEPROM library).
30
Input and Output
• Each of the 14 digital pins on the Uno
can be used as an input or output,
using pinMode(), digitalWrite(), and
digitalRead() functions.
• They operate at 5 volts.
• Each pin can provide or receive a
maximum of 40 mA and has an
internal pull-up resistor (disconnected
by default) of 20-50 kOhms.
31
Input and Output (2)
In addition, some pins have specialized functions:
• Serial: 0 (RX) and 1 (TX).
Used to receive (RX) and transmit (TX) TTL serial data. These pins are connected to
the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip.
• External Interrupts: 2 and 3.
These pins can be configured to trigger an interrupt on a low value, a rising or
falling edge, or a change in value. See the attachInterrupt() function for details.
• PWM: 3, 5, 6, 9, 10, and 11.
Provide 8-bit PWM output with the analogWrite() function.
• SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK).
These pins support SPI communication using the SPI library.
• LED: 13.
There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the
LED is on, when the pin is LOW, it's off.
32
Analog Inputs
• The Uno has 6 analog inputs, labeled A0
through A5, each of which provide 10 bits
of resolution (i.e. 1024 different values).
• By default they measure from ground to 5
volts, though is it possible to change the
upper end of their range using the AREF pin
and the analogReference() function.
• Additionally, some pins have specialized
functionality:
• TWI: A4 or SDA pin and A5 or SCL pin.
Support TWI communication using the Wire
library.
33
Other Pins
• AREF. Reference voltage for the analog inputs.
Used with analogReference().
• Reset. Bring this line LOW to reset the
microcontroller. Typically used to add a reset
button to shields which block the one on the
board.
34
Communications
• The ATmega328 provides UART TTL (5V) serial communication, which is
available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on the board
channels this serial communication over USB and appears as a virtual com
port to software on the computer. The '16U2 firmware uses the standard
USB COM drivers, and no external driver is needed.
• The Arduino software includes a serial monitor which allows simple
textual data to be sent to and from the Arduino board. The RX and TX LEDs
on the board will flash when data is being transmitted via the USB-to-
serial chip and USB connection to the computer (but not for serial
communication on pins 0 and 1).
• A SoftwareSerial library allows for serial communication on any of the
Uno's digital pins.
• The ATmega328 also supports I2C (TWI) and SPI communication. The
Arduino software includes a Wire library to simplify use of the I2C bus; see
the documentation for details. For SPI communication, use the SPI library.
35
Software
• The Arduino integrated development
environment (IDE) is a cross-platform
application written in Java. It is
designed to introduce programming
to artists and other newcomers
unfamiliar with software
development.
• A program or code written for
Arduino is called a "sketch“
• Arduino 1.5.3 (release notes)
• http://arduino.cc/en/Main/Software
36
Example : LED Blink
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
37
LED on Arduino board
• It is a feature of most Arduino boards that they have an LED and load
resistor connected between pin 13 and ground; a convenient feature for
many simple tests. 38
Any Question?
39