Embedded Systems ICT211a

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 63

Embedded Systems (211a)

Engr. Jerry B. Halibas


What is a Microcontroller?
• A digital computer consist of Interconnected systems
of processors, memories and input /output devices

• A microcontroller is indeed a computer wherein the


processor, memories and input/output devices are all
embedded in a chip

• Microcontrollers function as a small computer


Complete General-Purpose Computer
(Desktop Personal Computer)

Complete Small Computer


(Embedded System / Microcontroller)
General-Purpose Computer System Architecture
Embedded Computer Architecture
What is the difference?
• Embedded System VS Microprocessor System

• Microprocessor
• CPU that is generally concerned with efficient processing (computing) and
data management.

• Microcontroller
• CPU that is generally concerned with efficient control of input and output
devices
Arduino Architecture
Inherent Characteristics of Microcontrollers
1. Embedded
2. Dedicated to one task and run one specific program
3. Often low power devices, a battery operated microcontroller will
consume 50 milliwatts while desktop computers might consume 50
watts
4. Microcontrollers has dedicated input and output devices
5. Often small and low cost
6. Often but not always ruggedized
Sample Applications
• Microwave Oven
Microwave Operation
Car Engine Controller
TV remote control
Lighting Controls
Exercise Machines
Lawn Mower
Vacuum Cleaner
And so much more
Arduino Microcontroller Platform

• What is an Arduino ?
• Arduino is an open-source electronics prototyping platform based on
flexible, easy-to-use hardware and software. It's intended for artists,
designers, hobbyists, and anyone interested in creating interactive
objects or environments. (http://www.arduino.cc)
• It is using the Atmel microcontroller.
Arduino Microcontroller Platform
• The boards can be built by hand or purchased preassembled;

• The software can be downloaded for free. It can support different OS namely:
Windows, MacOSx and Linux. http://arduino.cc/en/Main/Software

• The hardware reference designs (CAD files) are available under an open-source
license, you are free to adapt them to your needs.
Arduino Microcontroller Platform
• Arduino received an Honorary Mention in the Digital Communities
section of the 2006 Ars Electronica Prix.

• The Arduino team is: Massimo Banzi, David Cuartielles, Tom Igoe,
Gianluca Martino, and David Mellis.
Arduino Variants
Arduino Variants
Filipino Microcontroller Platform
• What is Gizduino?
• Gizduino is an Arduino Clone and based on the popular
Arduino Uno (Arduino Diecimila) developed by e-gizmo a Filipino
Company. It has all the basic features of an Arduino.
Arduino’s Instruction Set
• Structure

• setup()
• The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using
libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.
• loop()
• After creating a setup() function, which initializes and sets the initial values, the loop()
function does precisely what its name suggests, and loops consecutively, allowing your
program to change and respond. Use it to actively control the Arduino board.
Arduino Microcontroller Platform
• Arduino Nano has 14 digital input/output pins (of
which 6 can be used as PWM outputs), 6 analog
inputs, a 16 MHz crystal oscillator, a USB
connection, a power jack, an ICSP header, and a
reset button.

• It contains everything needed to support the


microcontroller; simply connect it to a computer
with a USB cable or power it with a AC-to-DC
adapter or battery to get started.
Arduino Nano V3 Components
Microcontroller Atmega 328P (Atmel AVR) 8-bit
Operating Voltage 5V
Supply Voltage 6-20V
Digital I/O pins 14 (6 provides PWM output)
Analog Input pins 8
Memory Flash Memory:32 KB (2 KB used by
bootloader)
SRAM: 2KB
EEPROM: 1KB
Clock Speed 16MHz Crystal Oscillator
DC Current per I/O Pin 40mA
DC Current for 3.3V 50mA
Atmega328P Microcontroller Pin Map
Arduino Nano V3 Components
• The Power pins are as follows:
• 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. The regulated power supply used to power the
microcontroller and other components on the board. This
can come either from VIN via an on-board regulator, or be
supplied by USB or another regulated 5V supply.
• 3V3. A 3.3 volt supply generated by the on-board FTDI chip.
Maximum current draw is 50 mA.
• GND. Ground pins.
Arduino Nano V3 Components
• Memory
• The ATmega328P has 32 KB of flash memory for
storing code (of which 2 KB is used for the
bootloader).
• It has 2 KB of SRAM and 1KB bytes of EEPROM
(which can be read and written with the EEPROM
library).
Arduino Nano V3 Components
• Input and Output
• Each of the 14 digital pins on the Gizduino 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. 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 FTDI USB-to-TTL Serial
chip/Prolific/CH340
Arduino Nano V3 Components
• Input and Output
• 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, which, although provided by
the underlying hardware, is not currently included in the
Arduino language.
• 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.
Arduino Nano V3 Components
• Input and Output
• The Arduino Nano has 8 analog inputs, 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
some low-level code. Additionally, some pins have
specialized functionality:
• I2C : 4 (SDA) and 5 (SCL). Support I2C (TWI)
communication using the Wire library
(documentation on the Wiring website).
Arduino Nano V3 Components
• There are a couple of other pins on the board:
• 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.
Arduino Nano V3 Components
• Communication

• The Arduino Nano has a number of facilities for


communicating with a computer, another Arduino, or
other microcontrollers. The ATmega328P provides UART
TTL (5V) serial communication, which is available on
digital pins 0 (RX) and 1 (TX).

• An FTDI FT232RL/Prolific/CH340 on the board channels


this serial communication over USB and the FTDI drivers
(included with the Arduino software) provide a virtual
com port to software on the computer.
Arduino Nano V3 Components
• Communication

• The Arduino software includes a serial monitor


which allows simple textual data to be sent to
and from the Arduino Nano board.

• The RX and TX LEDs on the board will flash when


data is being transmitted via the FTDI
chip/Prolific/CH340 and USB connection to the
computer (but not for serial communication on
pins 0 and 1).
Arduino Nano V3 Components
• Communication

• A Software Serial library allows for serial


communication on any of the Arduino Nano 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 on the Wiring website for details. To
use the SPI communication.
Arduino Nano V3 Components
• USB Overcurrent Protection
• The Arduino Nano has a resettable polyfuse that protects your computer's
USB ports from shorts and overcurrent.

• Although most computers provide their own internal protection, the fuse
provides an extra layer of protection. If more than 500 mA is applied to the
USB port, the fuse will automatically break the connection until the short
or overload is removed.
Arduino Nano V3 Board Layout
Arduino’s Instruction Set
• The open-source Arduino environment makes it easy to write code
and upload it to the i/o board. It runs on Windows, Mac OS X, and
Linux. The environment is written in Java and based on Processing,
avr-gcc (C/C++), and other open source software.

• Arduino programs can be divided in three main parts: structure,


values (variables and constants), and functions.
Arduino’s Instruction Set
• Functions

• Digital I/O
• pinMode()
• digitalWrite()
• digitalRead()

• Analog I/O
• analogReference()
• analogRead()
• analogWrite() - PWM
Arduino’s Instruction Set
• pinMode()
• Description
• Configures the specified pin to behave either as an input or an output. See the
description of digital pins for details.
• Syntax
• pinMode(pin, mode)
• Parameters
• pin: the number of the pin whose mode you wish to set
• mode: either INPUT or OUTPUT
• Returns: None
Arduino’s Instruction Set
• digitalWrite()
• Description
• Write a HIGH or a LOW value to a digital pin.
• Syntax
• digitalWrite(pin, value)
• Parameters
• pin: the pin number
• value: HIGH or LOW
• Returns:none
Arduino’s Instruction Set
• digitalRead()
• Description
• Reads the value from a specified digital pin, either HIGH or LOW.
• Syntax
• digitalRead(pin)
• Parameters
• pin: the number of the digital pin you want to read (int)
• Returns :HIGH or LOW
Arduino’s Instruction Set
• analogWrite() - PWM
• Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying
brightness or drive a motor at various speeds.

• After a call to analogWrite(), the pin will generate a steady square wave of the
specified duty cycle until the next call to analogWrite() (or a call to digitalRead()
or digitalWrite() on the same pin). The frequency of the PWM signal is
approximately 490 Hz.
Arduino’s Instruction Set
• analogWrite() - PWM
• Syntax
• analogWrite(pin, value)
• Parameters
• pin: the pin to write to. (3,5,6,9,10 & 11 only)
• value: the duty cycle: between 0 (always off) and 255 (always on).
• Returns:nothing
Example Program 1
/*Blink
Turns on an LED on for one second, then off for one second, repeatedly. */

void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH); // set the LED on, HIGH is same as 1
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off, LOW is same as 0
delay(1000); // wait for a second
}
Example Program 2
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
}
void loop()
{
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
}
Example Program 3
/*Blink
Turns on an LED on for one second, then off for one second, repeatedly. */

void setup() {
// initialize the digital pin as an output.
// Pin 11 must be connected to a LED
pinMode(11, OUTPUT);
}

void loop() {
analogWrite(11, 255); // set the LED on in Full Brightness(0-255)
delay(1000); // wait for a second
analogWrite (11, 0); // set the LED off
delay(1000); // wait for a second
}
Arduino’s Instruction Set
• Control Structures
• if
• if...else
• for
• switch case
• while
• do... while
• break
• continue
• return
• goto
Arduino’s Instruction Set
• Further Syntax
• ; (semicolon)
• {} (curly braces)
• // (single line comment)
• /* */ (multi-line comment)
• #define
• #include
Arduino’s Instruction Set
• Arithmetic Operators
• = (assignment operator)
• + (addition)
• - (subtraction)
• * (multiplication)
• / (division)
• % (modulo)
Arduino’s Instruction Set
• Comparison Operators
• == (equal to)
• != (not equal to)
• < (less than)
• > (greater than)
• <= (less than or equal to)
• >= (greater than or equal to)
Arduino’s Instruction Set
• Boolean Operators
• && (and)
• || (or)
• ! (not)
Arduino’s Instruction Set
• Bitwise Operators
• & (bitwise and)
• | (bitwise or)
• ^ (bitwise xor)
• ~ (bitwise not)
• << (bitshift left)
• >> (bitshift right)
Arduino’s Instruction Set
• Compound Operators
• ++ (increment)
• -- (decrement)
• += (compound addition)
• -= (compound subtraction)
• *= (compound multiplication)
• /= (compound division)
• &= (compound bitwise and)
• |= (compound bitwise or)
Arduino’s Instruction Set
• Variables
• Constants
• HIGH | LOW
• INPUT | OUTPUT
• true | false
• integer constants
• floating point constants
Arduino’s Instruction Set
• Data Types
• void
• boolean
• char
• unsigned char
• byte
• int
• unsigned int
• word
• long
• unsigned long
• float
• double
• string - char array
• String - object
• array
Arduino’s Instruction Set
• Variable Scope & Qualifiers
• variable scope
• static
• volatile
• const
Arduino’s Instruction Set
Advanced I/O
tone()
noTone()
shiftOut()
shiftIn()
pulseIn()
Time
millis()
micros()
delay()
delayMicroseconds()
Math
min()
max()
abs()
constrain()
map()
pow()
sqrt()
Arduino’s Instruction Set
Trigonometry

sin()

cos()

tan()

Random Numbers

randomSeed()

random()

Bits and Bytes

lowByte()

highByte()

bitRead()

bitWrite()

bitSet()

bitClear()

bit()

External Interrupts

attachInterrupt()

detachInterrupt()

Interrupts

interrupts()

noInterrupts()

Communication

Serial
Arduino IDE
• The open-source Arduino
environment makes it
easy to write code and
upload it to the i/o
board. It runs on
Windows, Mac OS X, and
Linux. The environment
is written in Java and
based on Processing, avr-
gcc (C/C++), and other
open source software.

You might also like