1. introduction to microcontroller

39
Introduction to Microcontroller MK-4306 SISTEM MIKROKONTROLER Microcontroller System PROGRAM STUDI TEKNIK MEKATRONIKA D-IV JURUSAN TEKNIK ELEKTRO POLITEKNIK NEGERI BATAM 2013 HENDAWAN SOEBHAKTI, ST., MT.

Upload: pavelnedve

Post on 17-Jul-2016

46 views

Category:

Documents


6 download

DESCRIPTION

mikro

TRANSCRIPT

Page 1: 1. Introduction to Microcontroller

Introduction to Microcontroller

MK-4306 SISTEM MIKROKONTROLERMicrocontroller System

PROGRAM STUDI TEKNIK MEKATRONIKA D-IVJURUSAN TEKNIK ELEKTROPOLITEKNIK NEGERI BATAM2013

HENDAWAN SOEBHAKTI, ST., MT.

Page 2: 1. Introduction to Microcontroller

Topics

1. Introduction

2. Microcontroller architecture

3. Arduino

MK-4306 SISTEM MIKROKONTROLER - HENDAWAN SOEBHAKTI, ST., MT. 2

Page 3: 1. Introduction to Microcontroller

1. Introduction

3

Page 4: 1. Introduction to Microcontroller

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

Page 5: 1. Introduction to Microcontroller

Microcontroller vs Microprocessor

General Purpose

Microprocessor

RAM ROM TimerSerialCOMPort

IO Port

Data BUS

Address BUS

Control BUS

CPU RAM ROM

I/OTimerSerialPort

• General Purpose Microprocessors

• Microcontrollers

5

Page 6: 1. Introduction to Microcontroller

Microcontroller Type

• 8-bit microcontrollers

– AVR

– PIC

– HCS12

– 8051

• 32-bit microcontrollers

– ARM

– PIC32

6

Page 7: 1. Introduction to Microcontroller

AVR Microcontroller

• AVR = Advanced Virtual RISC.

• RISC = Reduced Instruction Set Computer.

• The founder are Alf Egil Bogen and VegardWollan, students at Norwegian Institute of Technology on 1994.

7

Page 8: 1. Introduction to Microcontroller

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

Page 9: 1. Introduction to Microcontroller

AVR Classic Family

9

Page 10: 1. Introduction to Microcontroller

AVR Mega Family

10

Page 11: 1. Introduction to Microcontroller

AVR Tiny Family

11

Page 12: 1. Introduction to Microcontroller

AVR Special Purpose Family

12

Page 13: 1. Introduction to Microcontroller

AVR Part Numbers

ATmega128

ATtiny44

Atmel groupFlash =128K

AtmelFlash =4K

AT90S4433

Atmel Classic group

Flash =4KTiny group

13

Page 14: 1. Introduction to Microcontroller

2. Microcontroller Architecture

14

Page 15: 1. Introduction to Microcontroller

ATmega328 Pin Configuration

15

Page 16: 1. Introduction to Microcontroller

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

Page 17: 1. Introduction to Microcontroller

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

Page 18: 1. Introduction to Microcontroller

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

Page 19: 1. Introduction to Microcontroller

19

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

Page 20: 1. Introduction to Microcontroller

3. Arduino

20

Page 21: 1. Introduction to Microcontroller

Arduino

21

• 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.

Page 22: 1. Introduction to Microcontroller

Some Arduino Boards

22

Uno Duemilanove

Leonardo Mega

Nano

Page 23: 1. Introduction to Microcontroller

Specs Compare

23

Name ProcessorOperating

Voltage/Input Voltage

CPU Speed

Analog In/Out

Digital IO/PWM

EEPROM [KB]

SRAM [KB]

Flash [KB]

USB UART

Uno ATmega328 5 V/7-12 V 16 Mhz 6/0 14/6 1 2 32 Regular 1Due AT91SAM3X8E 3.3 V/7-12 V 84 Mhz 12/2 54/12 - 96 512 2 Micro 4Leonardo ATmega32u4 5 V/7-12 V 16 Mhz 12/0 20/7 1 2.5 32 Micro 1Mega 2560 ATmega2560 5 V/7-12 V 16 Mhz 16/0 54/15 4 8 256 Regular 4Mega ADK ATmega2560 5 V/7-12 V 16 Mhz 16/0 54/15 4 8 256 Regular 4Micro ATmega32u4 5 V/7-12 V 16 Mhz 12/0 20/7 1 2.5 32 Micro 1Mini ATmega328 5 V/7-9 V 16 Mhz 8/0 14/6 1 2 32 - -

NanoATmega168ATmega328

5 V/7-9 V 16 Mhz 8/0 14/60.512

112

1632

Mini-B 1

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 - 1Fio ATmega328P 3.3 V/3.7-7 V 8 Mhz 8/0 14/6 1 2 32 Mini 1Pro (168) ATmega168 3.3 V/3.35-12 V 8 Mhz 6/0 14/6 0.512 1 16 - 1Pro (328) ATmega328 5 V/5-12 V 16 Mhz 6/0 14/6 1 2 32 - 1

Pro Mini ATmega1683.3 V/3.35-12 V

5 V/5-12 V8 Mhz16Mhz

6/0 14/6 0.512 1 16 - 1

LilyPadATmega168VATmega328V

2.7-5.5 V/2.7-5.5 V

8 Mhz 6/0 14/6 0.512 1 16 - -

LilyPad USB ATmega32u4 3.3 V/3.8-5V 8 Mhz 4/0 9/4 1 2.5 32 Micro -LilyPadSimple

ATmega3282.7-5.5 V/2.7-

5.5 V8 Mhz 4/0 9/4 1 2 32 - -

LilyPadSimpleSnap

ATmega3282.7-5.5 V/2.7-

5.5 V8 Mhz 4/0 9/4 1 2 32 - -

Page 24: 1. Introduction to Microcontroller

Arduino Shield

24Adafruit motor shield

Protoboard shield

Adafruit data logging shield

Page 25: 1. Introduction to Microcontroller

Arduino Uno

25

• The Arduino Uno is a microcontroller board based on the ATmega328.

• It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button.

Page 26: 1. Introduction to Microcontroller

Arduino Uno Board Features

26

Features

Microcontroller : ATmega328

Operating Voltage : 5V

Input Voltage (recommended) : 7-12V

Input Voltage (limits) : 6-20V

Digital I/O Pins : 14 (of which 6 provide PWM output)

Analog Input Pins : 6

DC Current per I/O Pin : 40 mA

DC Current for 3.3V Pin : 50 mA

Flash Memory used by bootloader : 32 KB (ATmega328) of which 0.5 KB

SRAM : 2 KB (ATmega328)

EEPROM : 1 KB (ATmega328)

Clock Speed : 16 MHz

Page 27: 1. Introduction to Microcontroller

Schematic Diagram

27

Page 28: 1. Introduction to Microcontroller

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

Page 29: 1. Introduction to Microcontroller

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

Page 30: 1. Introduction to Microcontroller

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

Page 31: 1. Introduction to Microcontroller

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

Page 32: 1. Introduction to Microcontroller

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

Page 33: 1. Introduction to Microcontroller

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

Page 34: 1. Introduction to Microcontroller

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

Page 35: 1. Introduction to Microcontroller

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

Page 36: 1. Introduction to Microcontroller

Software

• The Arduino integrated development environment (IDE) is a cross-platformapplication 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

Page 37: 1. Introduction to Microcontroller

Example : LED Blink

37

// Pin 13 has an LED connected on most Arduino boards.// give it a name:int led = 13;

// the setup routine runs once when you press reset:void setup() { // initialize the digital pin as an output.pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:void loop() {digitalWrite(led, HIGH); // turn the LED ondelay(1000); // wait for a seconddigitalWrite(led, LOW); // turn the LED offdelay(1000); // wait for a second

}

Page 38: 1. Introduction to Microcontroller

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

Page 39: 1. Introduction to Microcontroller

39

Any Question?