Introduction to
Microprocessor &
Microcontrollers
Components of a
microprocessor/controller
CPU: Central Processing Unit
I/O: Input /Output
Bus: Address bus & Data bus
Memory: RAM & ROM
Timer
Interrupt
Serial Port
Parallel Port
2
General-purpose microprocessor:
CPU for Computers
Commonly no RAM, ROM, I/O on CPU chip itself
Many chips on motherboard
Data Bus
CPU
General-
Purpose Serial
RAM ROM I/O Timer
Micro- COM
Port
processor Port
Address Bus
3
Microcontroller :
A single-chip computer
On-chip RAM, ROM, I/O ports...
Example : Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and PIC 16X
CPU RAM ROM
A single chip
Serial
I/O Timer COM
Port
Port
Microcontroller
4
Microprocessor vs. Microcontroller
Microprocessor Microcontroller
CPU is stand-alone, RAM, • CPU, RAM, ROM, I/O and timer
ROM, I/O, timer are separate are all on a single chip
designer can decide on the • fixed amount of on-chip ROM,
amount of ROM, RAM and RAM, I/O ports
I/O ports. • for applications in which cost,
expensive
power and space are critical
versatility
• single-purpose (control-oriented)
general-purpose
High processing power • Low processing power
High power consumption • Low power consumption
Instruction sets focus on • Bit-level operations
processing-intensive • Instruction sets focus on control
operations and bit-level operations
Typically 32/64 – bit • Typically 8/16 bit
Typically deep pipeline (5-20 • Typically single-cycle/two-stage
stages)
pipeline
5
Some Popular Microcontrollers…
8051
Microchip Technology PIC
Atmel AVR
Texas Instruments MSP430 (16-bit)
6
Introduction
to the
Arduino Uno borad
Topics
The Arduino
Digital IO
Analog IO
Serial Communication
8
Topic 1: Meet Arduino Uno
9
Getting Started
Check out:
[Link]
1. Download & install the Arduino environment
(IDE)
2. Connect the board to your computer via the
USB cable
3. If needed, install the drivers
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Open the blink example
8. Upload the program
10
Arduino IDE
See: [Link] for more information
11
Select Serial Port and Board
12
[Link]/blog/bionicarduino
13
Input/Output
Image from Theory and Practice of Tangible User Interfaces at UC Berkley 14
Topic 2: Digital Input/Output
1
Digital IO is binary
valued—it’s either on or
off, 1 or 0 0
Internally, all
microprocessors are
digital, why?
15
Arduino Digital I/0
[Link]/chapters/view/1
pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Electronic stuff
Output pins can provide 40 mA of current
Writing HIGH to an input pin installs a 20KΩ pullup
16
Our First Program
17
IO Pins
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
18
In-class Exercise 1: Digital IO
Use a push-button to turn ON/Off LED
19
Topic 3: Analog Input
Think about music stored on a CD---an
analog signal captured on digital media
Sample rate
Word length
20
Arduino Analog Input
Image credit: Tod Kurt
Resolution: the number of different voltage levels
(i.e., states) used to discretize an input signal
Resolution values range from 256 states (8 bits) to
4,294,967,296 states (32 bits)
The Arduino uses 1024 states (10 bits)
Smallest measurable voltage change is 5V/1024 or
4.8 mV 21
How does ADC work?
How does ADC work
Excel Demonstration
22
Topic 3: Analog Output
Can a digital devise produce analog output?
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
• Analog output can be simulated using
pulse width modulation (PWM) 23
Pulse Width Modulation
• Can’t use digital pins
to directly supply say
2.5V, but can pulse
the output on and off
really fast to produce
the same effect
• The on-off pulsing
happens so quickly,
the connected output
device “sees” the
result as a reduction
in the voltage
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
24
PWM Duty Cycle
output voltage = (on_time / cycle_time) * 5V
Image credit: Tod Kurt
Fixed cycle length; constant
number of cycles/sec 25
PMW Pins
• Command:
analogWrite(pin,value)
• value is duty cycle:
between 0 and 255
• Examples:
analogWrite(9, 128)
for a 50% duty cycle
analogWrite(11, 64)
for a 25% duty cycle
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
26
Topic 4: Serial Communication
Image from [Link]
27
[Link]/blog/bionicarduino 28
Serial Communication
• Compiling turns your program into
binary data (ones and zeros)
• Uploading sends the bits through
USB cable to the Arduino
• The two LEDs near the USB
connector blink when data is
transmitted
• RX blinks when the Arduino is
receiving data
• TX blinks when the Arduino is
transmitting data
[Link]/blog/bionicarduino 29
Open the Serial Monitor and Upload the
Program
30
Some Commands
• [Link]()
- e.g., [Link](9600)
• [Link]() or [Link]()
- e.g., [Link](value)
• [Link]()
• [Link]()
• [Link]()
• [Link]()
• Example Program
31
Serial-to-USB chip---what does it do?
The LilyPad and Fio Arduino require an external USB to
TTY connector, such as an FTDI “cable”.
In the Arduino Leonardo a single microcontroller runs the
Arduino programs and handles the USB connection.
32