Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arduino Part 1: Topics: Microcontrollers Programming Basics: Structure and Variables Digital Output

Download as pdf or txt
Download as pdf or txt
You are on page 1of 192

Arduino Part 1

Topics:
Microcontrollers
Programming Basics: structure
and variables
Digital Output
What is a Microcontroller

• A small computer on a
single chip
• containing a processor,
memory, and
input/output
• Typically "embedded"
inside some device that
they control
• A microcontroller is often
small and low cost
What is a Development Board

• A printed circuit
board designed to
facilitate work with
a particular
microcontroller.
• Typical components include:
• power circuit
• programming interface
• basic input; usually buttons and LEDs
• I/O pins
The Arduino Development Board

Making-robots-with-arduino.pdf
The Arduino Microcontroller: Atmel ARV
Atmega 328

Specification
What is Arduino?
What is Arduino?

• is a programmable multi-purpose
electronic platform with its hardware
and software designed to run in an open-
source environment.
• Arduino comes with its own open-
source Integrated Development
Environment (IDE)
Why is Arduino Popular?

• Easy installation
• The ease of use
• Simple programming language
• Relatively cheaper access
• Good back-up
• Replaceable processor
• Speed of communication
Flaws of Arduino
• Small resolution
• No debugger
• Limited program execution
• Its programming language
• Small RAM and memory (2 kb of RAM and 3
kb of flash memory)
• Usage of 5V.
Arduino Boards (Types)
 Arduino Leonardo Board
• Among the first developments of Arduino boards
• one of the cheapest and easy to use among all the
boards.
• fully dependent on ATmega32u4 microcontroller with
a “clock speed” of 16 MHz.
• equipped with 2.5 Kb SRAM memory while it sits on
a 32 Kb flash memory.
Arduino Boards (Types)
 Arduino Uno (R3)
• Among the most popular Arduino
boards
• has 14 pins digital input/output
(I/O), with six pins being used as
a “pulse width modulation”
(PWM) output
• come with ATmega328 processor,
a clock speed of 16 MHz
• SRAM memory is 2 KB while the
flash memory is 32 KB.
Arduino Boards (Types)
 LilyPad Arduino Board
• board is wearable, and can be in e-
textile technology
• design is for textiles in particular, and
the board is also washable. It can be
sewed into clothes with tread.
• Everything on this board like the sensor
circuits, power and I/O are specifically
designed to serve this purpose.
• consists of an Arduino bootloader with
variable 2V to 5V power supply sitting
on ATMEGA328 microcontroller.
Arduino Boards (Types)
 Arduino Mega (R3)
• Among the most popular Arduino
boards
• has 14 pins digital input/output
(I/O), with six pins being used as
a “pulse width modulation”
(PWM) output
• come with ATmega328 processor,
a clock speed of 16 MHz
• SRAM memory is 2 KB while the
flash memory is 32 KB.
Getting Started

1. Download & install the Arduino environment


(IDE)
2. Connect the board to your computer via the
UBS cable
3. If needed, install the drivers (not needed in
lab)
4. Launch the Arduino IDE
5. Select your board
6. Select your serial port
7. Write the code in the sketch
8. Upload the program
Try It: Connect the USB
Cable

todbot.com/blog/bionicarduino
Arduino Integrated Development Environment (IDE)
Parts of the IDE

• Compile –Before the program “code” can be sent to the


board, it needs to be converted into instructions that the
board understands. This process is called compiling.
• Stop - This stops the compilation process.
• Create new Sketch - This opens a new window to create a
new sketch.
• Open Existing Sketch - This loads a sketch from a file on
your computer.
• Save Sketch- This saves the changes to the sketch you are
working on.
• Upload to Board - This compiles and then transmits over
the USB cable to your board.
Parts of the IDE

• Serial Monitor
• Tab Button - This lets you create multiple files in your
sketch.
• Sketch Editor - This is where you write or edit sketches
• Text Console - This shows you what the IDE is currently
doing and is also where error messages display if you make
a mistake in typing your program. (often called a syntax
error)
• Line Number -This shows you what line number your
cursor is on. It is useful since the compiler gives error
messages with a line number
Select Serial Port and Board
Status Messages
Add an External LED to pin 13

• File > Examples > Digital > Blink


• LED’s have polarity
– Negative indicated by flat side of the housing
and a short leg

www.instructables.com
A Little Bit About Programming
• Code is case
sensitive
• Statements are
commands and
must end with a
semi-colon
Our First Program
// Example 01
/*
Blinking Onboard LED
Turns on the onboard LED on for one second, then off for one second, repeatedly.
*/
// Digital Pin 13 has an LED connected on your Tinkduino.
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 on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Setup and Loop

Each program must contain at least two


functions. A function is a series of
programming statements that can be called by
name.
1. setup() which is called once when the
program starts.
Setting pin modes or initializing libraries
are placed here
2. loop() which is called repetitively over and
over again as long as the Arduino has
power.
Syntax and Symbols
Comments
Variables
Variables
Variables
Terminology
Digital I/0

www.mikroe.com/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
Arduino Timing

• delay(ms)
– Pauses for a few milliseconds
• delayMicroseconds(us)
– Pauses for a few microseconds
Digital? Analog?
• Digital has two values: on and off
• Analog has many (infinite) values
• Computers don’t really do analog, they quantize
• Remember the 6 analog input pins---here’s how
they work

todbot.com/blog/bionicarduino
Bits and Bytes
Variables

www3.ntu.edu.sg
Putting It Together
• Complete the sketch
(program) below.
• What output will be
generated by this program?
• What if the schematic were
changed? 

www.ladyada.net/learn/arduino
ARDUINO LESSON 2
Variables
 Place for storing a piece of data
 Has a name, value, and type

 int, char, float

 Variable names may not start with a numerical


character
 Example:

 int iamVariable = 9;
 char storeChars;
 float saveDecimal;
Variables

 You may now refer to this variable by its name,


at which point its value will be looked up and
used
 Example:

 In a statement: digitalWrite(13, HIGH);


 Declaring: int inPIN= 13;
 We can instead write: digitalRead(inPIN);
Variables

 Variable Scope
 Global – recognized anywhere in the sketch

 Local – recognized in a certain function only

 Variable Qualifiers
 CONST – make assigned variable value unchangeable

 STATIC – ensure variable will only and always be


manipulated by a certain function call
Variables

 Types
 INT

 UNSIGNED INT

 LONG

 UNSIGNED LONG

 FLOAT

 CHAR

 BYTE

 BOOLEAN
Identifiers and Keywords

Identifiers are the names given by user to


various program elements such as variables,
functions and arrays. The rules for identifiers are
given below.
1.Letters, digits and underscore can be used.
2.Must not start with a digit.
3.Avoid using underscore at the start of identifier
4.Identifier cannot be same as reserved word
(Key Word) or Arduino C library function names
5.Identifiers are Case sensitive. For example
india is different from India.
Identifiers and Keywords

Examples of Valid and Invalid Identifier


Valid Identifiers:
1.X1x
2.Count_2
3.Num1
Invalid Identifiers:
1.5thstandard - first character must be a letter
2.“Sam” - illegal character (“ ”)
3.Emp-no - illegal character( - )
4.Reg no - illegal character (blank space)
Identifiers and Keywords

Keywords

Key words or Reserve words are the words whose


meaning is already defined and explained to the Arduino C
language compiler. Therefore, reserve words cannot be
used as identifiers or variable names. They should only be
used to carry the pre-defined meaning.

For example, int is a reserve word. It indicates the


data type of the variable as integer. Therefore, it is
reserved to carry the specific meaning. Any attempt to use
it other than the intended purpose will generate a compile
time error.
Basic Data Types
C supports five fundamental data types:
 Character
 Integer
 Floating-Point
 Double floating-Point
 Valueless
These are denoted as char, int, float double,
void, respectively, ’void’ is typically used to
declare as function as returning null value.
Basic Data Types
Table 2.1 Fundamental data types
Data Type Description Typical memory
requirements
int integer quantity 2 bytes or one word
(varies from one compiler
to another)
char single character 1 byte
float floating-point number (i.e., a 1 word (4 bytes)
number containing a decimal point
and or an exponent)
double double-precision floating point 2 words (8 bytes)
number (i.e., more significant
figures, and an exponent which may
be larger in magnitude)
Basic Data Types

Modifiers to Basic Data Types


Modifiers are used to alter the meaning of basic data
types to fit various needs. Except the type void, all
others data type can have various modifiers preceding
them
List of modifiers used in C are:
• Signed
• Unsigned
• Long
• Short
Constants

It refers to fixed values that the program may


not alter during its execution. These fixed
values are also called literals.
Constants can be of any of the basic data types
like an integer constant, a floating constant, a
character constant, or a string literal. There are
enumeration constants as well. Constants are
treated just like regular variables except that
their values cannot be modified after their
definition.
Variables

A variable is an identifier that may be used to store


data value. A value or a quantity which may vary
during the program execution can be called as a
variable. Each variable has a specific memory
location in memory unit, where numerical values or
characters can be stored. A variable is represented
by a symbolic name. Thus variable name refers to
the location of the memory in which a particular
data can be stored. Variables names are also
called as identifiers since they identify the varying
quantities.
Variables

For Ex : sum = a+b. In this equation sum, a and b are the identifiers or
variable names representing the numbers stored in the memory locations.
Rules to be followed for constructing the Variable names (identifiers):
1. They must begin with a letter and underscore is considered as a letter.
2. It must consist of single letter or sequence of letters, digits or underscore
character.
3. Uppercase and lowercase are significant. For ex: Sum, SUM and sum
are three distinct variables.
4. Keywords are not allowed in variable names.
5. Special characters except the underscore are not allowed.
6. White space is also not allowed.
Variable Declarations

In the program data types are written as given


below:

Integer - int
Floating point - float
Double floating point - double
Character - char
Variable Declarations

Assigning an identifier to data type is called type declaration. In other words,


a declaration associates a group of variables with a specific data types. All
variables must be declared before they appear in executable statements.
The syntax of variable declaration and some examples are given below.
Syntax :
Data type ‘variable’
For example:
int a;
float c;
char name;
double count;
Variable Declarations

If two are more variables of the same data type has to be declared they can be clubbed as
shown in example given below.

int a; int b; int c;


this is same as
int a, b, c;

float d; float e; float f;


this can be written as
float d, e, f;

short int a, b, c ;
long int r, s, t ;
The above declarations cab also be written as :
short a, b, c;
long r, s, r;
Assigning Values to Variables

Values can be assigned to variables using assignment operator


“=”.
Syntax:
Variable name = value;
For Example:
a = 10; int lvalue = 0;

It is also possible to assign a value to a variable at the time the


variable is declared. The process of giving initial value to the
variable is called initialization of the variable.
For Example:
int a=10, b=5; float x=10.5, y=1.2e-9;
Assigning Values to Variables

The data item can be accessed in the program


simply by referring to the variable name. Data
type associated with the variable cannot be
changed. However, variables hold the most
recently assigned data.
Declaring Variable as Constant

The value of the certain variable to remain constant


during the execution of the program. It can be
achieved by declaring the variable with const qualifier
at the time of initialization.

For example:
const int tax_rate = 0.30;

The above statement tells the compiler that value of


variable must not be modified during the execution of
the program. Any attempt change the value will
generate a compile time error.
Control Structures

 Series of program instructions that handle data


and execute commands, exhibiting control
 DECISIVE – exhibits control by decision making
 RECURSIVE – exhibits control by continuous
execution of commands
 Control element manifests in the form of
CONDITIONS
Control Structures
Syntax:
 If-Else Statement
 Itallows you to if (condition)
make something {
happen or not // do something here
depending on
whether a given
}
condition is true or else
not. {
// do something here
}
Control Structures
Example:
if (val == HIGH)
{
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, HIGH);
}
Control Structures
 If – Else if – Else Statement
Syntax
if (condition)
{
// do something here
}
else if (condition)
{
// do something here
}
else
{
// do something here
}
Control Structures
if ( digitalRead(inpin1) == HIGH)
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}
else if (digitalRead(inpin2) == HIGH)
{
digitalWrite(LED, HIGH);
}
else
{
digitalWrite(LED, LOW);
}
Control Structures
Syntax:
 Switch-Case
Statement switch (var)
{
 Depends on whether
case val01:
the value of a // do something when var = val01
specified variable break;
matches the values case val02:
specified in case // do something when var = val02
statements. break;
default:
// if no match, do default
}
Control Structures
switch (LEDstate)
{
case 0: digitalWrite(ledPin, HIGH);
LEDstate = 1;
break;
case 1: digitalWrite(ledPin, LOW);
LEDstate = 0;
break;
default: LEDstate=0
}
Basic Repetition
• loop

• do while

• for

• while
Basic Repetition
 void loop ( ) { }
Basic Repetition
 void loop ( ) { }
Basic Repetition
 void loop ( ) { }

 The “void” in the header is what the function


will return (or spit out) when it happens, in
this case it returns nothing so it is void
 The “loop” in the header is what the function
is called, sometimes you make the name up,
sometimes (like loop) the function already
has a name
Basic Repetition

 While Loop
 Continue program until a given condition is true
 Syntax:
while (condition)
{
// do something here until condition becomes
false
}
Basic Repetition
void setup()
{
pinMode(outLED, OUTPUT);
int count = 0;
while (count <= 2)
{
digitalWrite(outLED, HIGH);
delay(1000);
digitalWrite(outLED, LOW);
delay(1000);
count++;
}
}
void loop()
{
}
Basic Repetition
Logical Operator
Logical Operator

 Conditional AND
 Symbolized by &&

 Used when all conditions need to be satisfied.

 Conditional OR
 Symbolized by ||
 Used when either of the conditions need to be satisfied.
 Conditional NOT
 Symbolized by !

 Appends to other statements to invert its state


Example

int ledState = LOW;


void loop()
{
ledState = !ledState;
digitalWrite(led, ledState);
delay(1000);
}
Basic Repetition

 Do-While Loop
 Same as While loop however this structure allows the loop
to run once before checking the condition
 Syntax:
do
{
// do something here until condition becomes
false
} while (condition) ;
Basic Repetition
For Loop
 Distinguished by a increment/decrement
counter for termination
 Syntax:

for (start value; condition; operation)


{
// do something until condition becomes
false
}
Basic Repetition
const int led = 12; delay(200);
void setup() digitalWrite(led, LOW);
{ delay(200);
pinMode(led, OUTPUT); }
} delay(1000); }
void loop()
{
for(int i = 0; i < 4; i++)
{
digitalWrite(led, HIGH);
Basic Repitition

 break;
Used to terminate a loop
regardless of the state of the
condition
Required in Switch-Case statements
as an exit command
Timing Controls

 delay()
 Halts the sequence of execution during the time
specified
 Syntax:
 delay(milliseconds);

 milliseconds = the time value in milliseconds


Using digitalRead
 digitalRead(pin)
 Reads HIGH or LOW from
a pin void loop(){
Example: x = digitalRead(button1);
int button1 = 2; if (x == HIGH) {
int led = 10; digitalWrite(led, LOW);
int x = 0; }
void setup() { else {
pinMode(led, OUTPUT); digitalWrite(led, HIGH);
pinMode(button1, INPUT); }
} }
Pull up and Pull down Resister

Pull up resistor - connection results in Pull down resistor - used for the
maintaining high state, when the external devices connection of an input and GND.
are disconnected or do not give signals, and
protects against unknown states.
Variables
 Array – a collection of variables of the same type
accessed via a numerical index
 It is a series of variable instances placed adjacent in
memory, and labeled sequentially with the index
Array
 Array
 An array is a collection of variables that are indexed with an index number

 Example
int timer = 100;
int pins[] = { 2, 3, 4, 5, 6, 7 };
int numpins = 6;
void setup()
{
int i;
for (i = 0; i < num pins; i++) {
pinMode(pins[i], OUTPUT);
}
Latch and Debounce

 Pushbutton Debounce and


Latching
 Debounce – change state
once the output is stable;
filter noise
 Latch – change state and
retain it until the next change
state.
Latching Switch
Example:
FUNCTIONS

 Modular pieces of code that perform a


defined task outside of the main program
 Very useful to reduce repetitive lines of code
due to multiple execution of commands
 Has a name, type, and value – same as

variables?
 Example
ANALOG INPUT
Analog-to-Digital Conversion
Connecting digital circuitry to sensor devices is simple
if the sensor devices are inherently digital themselves.
Switches, relays, and encoders are easily interfaced
with gate circuits due to the on/off nature of their
signals. However, when analog devices are involved,
interfacing becomes much more complex.
Electronically translating analog signals into digital
(binary) quantities is possible with the use of an
analog-to-digital converter.
Analog-to-Digital Conversion
 Analog-to-digital conversion is the process of
converting a continuous quantity to a discrete time
digital representation. The electronic device used
for this process is an analog-to-digital converter
(ADC). ADCs convert an input analog voltage or
current to a digital number proportional to the
magnitude of the voltage or current.
 ADCs are used virtually everywhere where an
analog signal has to be processed, stored, or
transported in digital form.
Pulse Width Modulation (PWM)
 Pulse Width Modulation, or PWM, is a technique for
getting analog results with digital means. Digital control
is used to create a square wave, a signal switched
between on and off. This on-off pattern can simulate
voltages in between full on (5 Volts) and off (0 Volts) by
changing the portion of the time the signal spends on
versus the time that the signal spends off. The duration
of "on time" is called the pulse width.
 To get varying analog values, you change, or modulate,
that pulse width. If you repeat this on-off pattern fast
enough with an LED for example, the result is as if the
signal is a steady voltage between 0 and 5v controlling
the brightness of the LED.
Analog Input

 Arduino can “recognize” analog voltage by converting


it into a digital output
 The Atmel chip has an onboard 6 channel, 10-bit
analog-to-digital converter
 Analog pins also have the same functionality of general
purpose input/output (GPIO) pins
 analogRead() returns a number between 0 and 1023
that is proportional to the amount of voltage being
applied to the pin (0V would read as 0 and 5Vwould
read as 1023.)

 analogRead()
 Function to perform ADC
 Returns value from 0-1023
Syntax:
analogRead(pin)
 Reads the value from the specified analog pin. The Arduino
board contains a 6 channel 10-bit analog to digital
converter (A0 – A5) . This means that it will map input
voltages between 0 and 5 volts into integer values between
0 and 1023. This yields a resolution between readings of: 5
volts / 1024 units or, .0049 volts (4.9 mV) per unit.
Analog Output

 analogWrite()
 Supported pins: 3, 5, 6, 9, 10 and 11
 value: ranges from 0 - 255

 Syntax:
 analogWrite(pin, value)
 pin: the pin to write to
 Ex: analogWrite(9, 255);
 A potentiometer is a simple knob that provides a
variable resistance, which we can read into the
Arduino board as an analog value
Example: Blinking
int sPin = A5; sValue = analogRead(sPin);
int led = 5; digitalWrite(led, HIGH);
int sValue = 0; delay(sValue);
void setup() { digitalWrite(led, LOW);
pinMode(sPin, INPUT); delay(sValue);
pinMode(led, OUTPUT); Serial.print(“delay=”);
Serial.begin(9600); Serial.println( sValue);
} delay(100);
void loop() }
{
Serial Monitor
 All Arduino boards have at least one serial port (also
known as a UART or USART): Serial. It communicates on
digital pins 0 (RX) and 1 (TX) as well as with the
computer via USB. Thus, if you use these functions, you
cannot also use pins 0 and 1 for digital input or output.
 Arduino environment’s Serial Monitor lets you
communicate with the Arduino board. In Serial Monitor
you could see anything the Arduino sends to its serial
port. It is very useful for debugging purposes, like
tracking variable values and reading input and output
values coming to and from the Arduino.
Serial Monitor
The common functions used in Serial Monitor:

 begin(speed) – sets the data rate in bits per second (baud) for serial
data transmission. For communicating with the computer, use one of
these rates: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800,
38400, 57600, or 115200. You can, however, specify other rates -
for example, to communicate over pins 0 and 1 with a component
that requires a particular baud rate. The common setting for the
baud rate is 9600 bps.

 end() - disables serial communication, allowing the RX and TX pins to


be used for general input and output. To re-enable serial
communication, call Serial.begin().
Serial Monitor

 print(val) – prints data to the serial port as human-readable ASCII


text. This command can take many forms. Numbers are printed
using an ASCII character for each digit. Floats are similarly
printed as ASCII digits, defaulting to two decimal places. Bytes
are sent as a single character. Characters and strings are sent as
is. For example:
Serial.print(78) //gives "78"
Serial.print(1.23456) //gives "1.23"
Serial.print(byte(78)) //gives "N" (whose ASCII value is 78)
Serial.print('N') //gives "N"
Serial.print("Hello world.") //gives "Hello world."
 println(val) – prints data to the serial port as human-readable
ASCII text followed by a carriage return character and a newline
character. This command takes the same forms as Serial.print().
int InPin = A5; oValue = map(sValue, 0,
int OutPin = 5; 1023, 0, 255);
int sValue = 0; analogWrite(OutPin, oValue);
int oValue = 0; Serial.print("sensor = " );
void setup() { Serial.print(sValue);
Serial.begin(9600); Serial.print("\t output = ");
} Serial.println(oValue);
void loop() { delay(50);
sValue = analogRead(InPin); }
 map()
 This function re-maps a number from one range to the
other. It is called like map(value, fromLow, fromHigh,
toLow, toHigh).
 This is useful because the analogRead returns a value in
the range of 0-1023. But analogWrite can only take a
value from 0-255.
Analog Output

 Reverse method of analog


read: from a specific value
from a range, produce the
equivalent analog voltage.
 Range: 0 – 255
 Pin is turned on and off
very fast – achieves an
“averaged” effect on the
output side
RGB LED

 An RGB LED is actually three LEDs in one bulb. The


housing contains separate red, blue and green LEDs
which share a common cathode, or negative
terminal. The brightness of each color is determined
by its input voltage. By combining the three colors in
different amounts, you can turn the LED any color
you want. Usually, the output color can be controlled
by sending PWM signals to the leads of the RGB
LED.
Example
int redLED= 2; digitalWrite(greenLED, LOW);
int greenLED= 3; digitalWrite(blueLED, HIGH);
int blueLED= 4; delay(3000);
void setup() digitalWrite(blueLED, LOW);
{ }
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
}
void loop()
{
digitalWrite(redLED,HIGH);
delay(3000);
digitalWrite(redLED, LOW);
digitalWrite(greenLED,HIGH);
delay(3000);
Example:
int potValue1 = 0; potValue2 = analogRead(A1);
int potValue2 = 0; potValue3 = analogRead(A2);
int potValue3 = 0; outRed = map(potValue1, 0, 1023, 0,
int outRed = 0; 255);
int outGreen = 0; outGreen = map(potValue2, 0, 1023, 0,
255);
int outBlue = 0;
outBlue = map(potValue3, 0, 1023, 0,
void setup()
255);
{ analogWrite(11, outRed);
} analogWrite(10, outBlue);
void loop()
analogWrite(9, outGreen);
{ delay(10);
potValue1 = analogRead(A0); }
Computer System
Engr. Liza R. Maderazo
Computer system

A computer system consists of a set of hardware and


software which processes data in a meaningful way.

Computer
is a programmable machine that receives input,
stores and manipulates data, and provides output
in a useful format.

is a device that accepts information (in the form of


digitalized data) and manipulates it for some
result based on a program or sequence of
instructions on how the data is to be processed
Computer system

The two principal characteristics of a computer are:


➢ It responds to a specific set of instructions in a well
defined manner.
➢ It can execute a prerecorded list of instructions (a
program ).

Modern computers are electronic and digital .

The actual machinery wires, transistors, and circuits is


called hardware. the instructions and data are called
software.
ELEMENTS OF COMPUTER SYSTEM

Hardware

are the physical components of the computer


system which can be seen, felt and touched,
while the software are the non-physical
components.
a. Input devices
b. Output devices
c. Storage devices
d. Processing devices
Hardware

All general-purpose computers require the following


hardware components:
• Memory: Enables a computer to store, at least
temporarily, data and programs.
• Mass storage device :Allows a computer to
permanently retain large amounts of data. Common mass
storage devices include disk drives and tape drives.
• Input device: Usually a keyboard and mouse are the
input device through which data and instructions enter a
computer.
Hardware
• Output device: A display screen, printer, or other
device that lets you see what the computer has
accomplished.
• Central processing unit (CPU): The heart of the
computer, this is the component that actually executes
instructions.

In addition to these components, many others make it


possible for the basic components to work together
efficiently.

• For example, every computer requires a bus that


transmits data from one part of the computer to another.
Software

refers to the programs, which are required to operate


the computer.

a. Application software
is computer software designed to help the user to
perform singular or multiple related specific tasks
Examples:
Enterprise software, Accounting software, Office
suites, Graphics software and media players
b. System software
computer software designed to operate the
computer hardware and to provide and maintain a
platform for running application software.
Peopleware
computer operator / user
Procedure
a set of coded instructions that tell a computer
how to run a program or calculation.

Connectivity
how hardware or software devices can
communicate with other devices
COMPONENTS OF COMPUTER SYSTEMc

• Input Unit/Devices
• Output Unit/Devices
• Central Processing Unit
• Memory Unit/Storage Devices
COMPONENTS OF COMPUTER SYSTEM

The Central Processing Unit is made up of


certain functional elements including:

1. Arithmetic Logic Unit (ALU)


2. Control Unit (CU)
3. Registers
4. Buses
5. Clock
Arithmetic Logic Unit
The arithmetic and logic unit of CPU is responsible for all
arithmetic operations like addition, subtraction, multiplication
and division as well as logical operations such as less than,
equal to and greater than. Actually, all calculations and
comparisons are performed in the arithmetic logic unit.
COMPONENTS OF COMPUTER SYSTEM

Control Unit
The control unit is responsible for controlling the transfer of
data and instructions among other units of a Computer. It is
considered as the “Central Nervous System” of computer, as
it manages and coordinates all the units of the computer. It
obtains the instructions from the memory, interprets them
and directs the operation of the computer. It also performs
the physical data transfer between memory and the
peripheral device.
COMPONENTS OF COMPUTER SYSTEM

Registers
Registers are small high-speed circuits (memory locations), which are
used to store data, instructions and memory addresses (memory location
numbers).

Buses

A group of wires on the main circuit board of the computer.


It is a pathway for data flowing between components.
Clock

Clock is another important component of CPU, which measures and


allocates a fixed time slot for processing each and every micro-operation
(smallest functional operation).
Types of Bus
1. Internal bus
Also known as system bus made up of 4 distinct
parts.
a. Power bus
Wires that provide electrical power to every part
of the motherboard
b. Control bus
Sends out timing signals so that other components
on the motherboard can stay in time with the CPU
Types of Bus

c. Address bus – request a memory location from the


memory or an I/O location from the I/O devices.

Ex. If I/O is addressed, the address bus contains a 16 – bit


I/O address from 0000H through FFFFH. The 16- bit I/O
address, or port number, selects one of 64K different I/O
devices.

d. Data bus – r esponsible for transmitting the actual data


between the system components.

Ex. For a data bus, 32-bit means the number of pathways


available, meaning that it has 32 pathways in parallel for
data to travel.
Types of Bus

2. External bus
Known as expansion bus, allows peripherals to connect
and communicate with the motherboard and its
components.
BUS STRUCTURE
Microprocessor System
Introduction
• The word ‘system’ is used to
describe any organization or
device that includes three
features.
• A system must have at least
one input, one output and
must do something, i.e. it
must contain a process.
• Often there are many inputs
and outputs. Some of the
outputs are required and
some are waste products. To
a greater or lesser extent, all
processes generate some
waste heat.
Example

A motor car will usually require fuel, water for cooling purposes and a battery to
start the engine and provide for the lights and instruments.
Its process it to burn the fuel and extract the energy to provide transportation for
people and goods.
The outputs are the wanted movement and the unwanted pollutants such as
gases, heat, water vapour and noise.
The motor car contains other systems within it. An electricity is required as an
input to start the engine and provide the lights
A microprocessor system

Like any other system, a microprocessor has inputs, outputs and a


process.
The inputs and outputs of a microprocessor are a series of voltages that
can be used to control external devices.
The process involves analysing the input voltages and using them to
‘decide’ on the required output voltages.
The decision is based on previously entered instructions that are followed
quite blindly, sensible or not.
Example: Control System for a Fresh
Air conditioner
Terminology

• Integrated circuits
An electronic circuit fabricated out of a solid block of
semiconductor material. This design of circuit, often
called a solid state circuit, allows for very complex
circuits to be constructed in a small volume. An
integrated circuit is also called a ‘chip’.
• Microprocessor (µp)
This is the device that you buy: just an integrated
circuit
On its own, without a surrounding circuit and applied
voltages it is quite useless. It will just lie on your
workbench staring back at you.
Terminology
• Microprocessor-based system
This is any system that contains a microprocessor, and does not
necessarily have anything to do with computing. In fact, despite all
the hype, computers use only a small proportion of all the
microprocessors manufactured. The garage door opening system is
a microprocessor-based system or is sometimes called a
microprocessor controlled system.

• Microcomputer
The particular microprocessor-based systems that happen to be
used as a computer are called microcomputers. The additional
circuits required for a computer can be built into the same integrated
circuit giving rise to a single chip microcomputer.

Microcomputers are designed to be used by individuals, whether in the


form of PCs, workstations or notebook computers.

A microcomputer contains a CPU on a microchip (the microprocessor),


a memory system (typically ROM and RAM), a bus system and I/O
ports, typically housed in a motherboard.
Terminology

• Microcontroller
This is a complete microprocessor-based
control system built onto a single chip. It is
small and convenient but doesn’t do
anything that could not be done with a
microprocessor and a few additional
components.
What is microprocessor?

• A microprocessor is a computer processor on a


microchip. It's sometimes called a logic chip.
• A silicon chip that contains a CPU
• The microprocessor, sometimes referred to as the
CPU (central processing unit), is the controlling
element in a computer system.
• A microprocessor (sometimes abbreviated µP) is a
digital component with miniaturized transistors on a
single semiconductor integrated circuit (IC).
• One or more microprocessors typically serve as a
central processing unit (CPU) in a computer
system or handheld device.
Microprocessor
Microprocessor
• At the heart of all personal computers and most working
stations sits a microprocessor.
• Microprocessors also control the logic of almost all digital
devices, from clock radios to fuel-injection systems for
automobiles.
• Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can
execute.
Bus width : The number of bits processed in a single instruction.
Clock speed : Given in hertz (Hz), the clock speed determines how
many instructions per second the processor can execute.
• In both cases, the higher the value, the more powerful the CPU. For
example, a 32 bit microprocessor that runs at 50MHz is more
powerful than a 16-bit microprocessor that runs at 50MHz.
• In addition to bus width and clock speed, microprocessors are
classified as being either RISC (reduced instruction set computer)
or CISC (complex instruction set computer).
History of Computer
History of Computer
First Generation
Second Generation
Third Generation

Early Intel Microprocessor


Third Generation
Fourth Generation
Fifth Generation
Binary – the way micros
count
• Microprocessors and other digital circuits
use only two digits – 0 and1
Bits, bytes and other things
• All the information entering or leaving a microprocessor is in the
form of a binary signal, a voltage switching between the two bit
levels 0 and 1.
• Nibble - half a byte.
• Byte - simply a collection of 8 bits.
• Word - represents 16 bits or 2 bytes.
• Double Word - represents 32 bits or 4 bytes
• Kilobyte (KB or kbyte) - is 1024 or 210 bytes
• Megabyte (MB) - is a kilokilobyte or 1024 1024 bytes. Numerically
this is 220 or 1 048 576 bytes.
• Gigabyte - 1024 megabytes which is 230 or 1 073 741 824 bytes
• Terabyte (TB) - megamegabyte or 240 or 1 099 511 600 000 bytes
Hexadecimal – the way we
communicate with micros

The advantages of hex


• It is very compact. Using a base of 16
means that the number of digits used to
represent a given number is usually fewer
than in binary.
• It is easy to convert between hex and
binary and fairly easy to go with hex
RISC vs CISC
VON Neumann Computer Harvard Computer ( Mark 1)
CISC – Complex Instruction Set Computing RISC – Reduced Instruction Set
• - CPU Computing
• - Memory
• - I/O • - CPU
• - 1 memory module for data and program • - Primary Storage
• Large variable length instructions • - Secondary Storage
• Multiple addressing mode • - Input / Ouput
• Highly pipelined • - 2 memory modules
• Pipelining : a technique that allows for 1 data
simultaneous execution of parts, or stages, of 1 program
instructions to more efficiently process • Reduced variable length Instruction
instructions • Limited addressing mode
– data and instruction cache for storing the • Small number of internal processor,
most recent instructions and data registers
• Instructions that requires multiple nos. of • Not pipelined or less pipelined
clock cycles for their execution
• Simple instructions taking 1 clock cycle
Pipelining
A conventional computer executes one instruction at a time with a
Program Counter pointing to the instruction currently being executed.
Pipelining is analogous to an oil pipeline where the last product may
have gone in before the first result comes out. This provides a way to
start a task before the first result appears. The computing throughput
is now independent of the total processing time.
RISC
Four types of processor

1. RISC
2. CISC
3. Hybrid processor – combination of RISC
and CISC
4. Special purpose processor – for
networking
Types of Automation

1. PC based - good for database ,


interfacing (CISC)
2. MPU based – ease to troubleshoot, low
power consumption (CISC)
3. MCU based – limited memory, low
power consumption (RISC)
4. PLC based – Programmable Logic
Controller. MCU inside (RISC)
PLC based
A programmable logic controller (PLC) or programmable controller is a
digital computer used for automation of electromechanical processes, such as
control of machinery on factory assembly lines, amusement rides, or lighting
fixtures. PLCs are used in many industries and machines, such as packaging
and semiconductor machines.
Microprocessor
Instruction Register

▪ of a CPU's control unit that stores


the instruction currently being
executed
What are registers for?

• storage areas inside the microprocessor


• store the data that is going to be used,
they store the instructions that are to be
used and they store the results obtained.
• involve tri-state buffers to control the
direction of data flow.
Registers

• The CPU uses registers to store


information temporarily
– Values to be processed
– Address of value to be fetched from memory
▪ In general, the more and bigger the registers,
the better the CPU
▪ Registers can be 8-, 16-, 32-, or 64-bit
▪ The disadvantage of more and bigger registers is
the increased cost of such a CPU
INSIDE CPUs

Program Counter
Program Counter
Inside CPUs
(cont’)
Instruction Register
Flags ALU Instruction Register
Instruction decoder,
Flags ALU timing,
Instruction and control
decoder,
timing, and control
Internal Register A
buses
Internal
buses Register A Register B
Register C
Register B
Register D
Register C
Department of Computer Science and Information Engineering
HANEL Register D
National Cheng Kung University, TAIWAN 30
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
CPU Execution Cycle
INSIDE CPUs
•ALU (arithmetic/logic unit)

Performs arithmetic functions such as add, subtract, multiply,


and divide, and logic functions such as AND, OR, and NOT

•Program counter

Points to the address of the next instruction to be executed


As each instruction is executed, the program counter is incremented
to point to the address of the next instruction to be executed

Instruction decoder

Interprets the instruction fetched into the CPU


A CPU capable of understanding more instructions requires more
transistors to design

Department of Computer Science and Information Engineering


Memories
Memories
ROM
ROM Examples
NVM
RAM
RAM vs ROM
RAM vs ROM
RAM

• Accessing memory
– Each location in a memory is given a number,
called an address
– the 16 locations of memory would be numbered from 0 to
15, or in binary 0000–1111
2

– The maximum number of locations that can be addressed


will depend on the number of bits in the address.
– Example:
• a 4-bit address can access 16 locations.,
• 20 address lines have 220 = 1 048 576 or 1 Meg
locations.
Memory organization

• A memory contains a number of cells or registers that,


themselves store a number of bits.
• The memory organization is always quoted as ‘number
of locations x bits stored in each’ so this memory
would have an organization of anywhere between 16
x 1, 16 x 4 or 16 x 8.
• Number of locations is equal to 2n where n is the
number of address lines.
• For example, the Pentium microprocessor uses 32-bit
addresses for accessing memory words. This
provides a maximum of 2 32 = 4,294,964,296 = 4 GB
of memory addresses, ranging from 00000000, to
FFFFFFFF, in hexadecimal
Memory maps

• A microprocessor has a number of address


lines that can be used to access RAM or
ROM or other devices within the system.
• the total memory addressable by a
microprocessor is found by the formula 2n
where n is the number of address lines.
• Example
– an 8-bit microprocessor generally has 16 address
lines and can access 216 or would have 65 536
or 64 bytes of memory
– Digital Alpha 21064 has 34-bit address lines giving 234or a
little over 17 Gbytes.
MICROCONTROLLER

Clock CPU Memory

Peripheral
devices I/O

input output
Microcontroller
• It is simply a computer on a chip. It is entirely self-contained
computers built on a single piece of silicon that incorporate
all of the functions of a traditional Computer.
• It is a special device generally found in a stand alone system
wherein medium to large scale computing is required. The
microcontroller serve as the data acquisition/analysis and
processing device in such applications

• Its name was derived from the words:

• Micro – which means miniature


• Controller – which is defined as a circuit that manipulates the
behavior of another device or a system
Advantages of Microcontrollers

• microcontrollers are inexpensive allowing students to build and


create individual, take-home projects .
• microcontrollers are inexpensive and easily replaceable in the event
that they are accidentally destroyed
• microcontroller development tools are typically free or significantly
discounted for promotional purposes.
• microcontroller development tools have minimal computing resource
requirements (i.e.Core2 Duo, DOS or Windows 10 depending on the
tools).
• microcontroller I/O ports are easily accessible in comparison with
PC I/O
• microcontrollers easily interface to other electronic circuits and
devices.
Disadvantages of Microcontrollers

• limited programming language and


programming tool choices
• microcontrollers are well suited to simple control
and interface tasks
• programs must be well-planned. Programming a
device with little capability for effective feedback
or debugging becomes an abstract exercise
which quickly frustrates students.
Microcontroller includes:

– a processing unit
– program (permanent) memory
– data (temporary) memory
– a clock/oscillator circuit
– a timer/counter circuit
– general purpose I/O ports
Central Processing Unit (CPU)

• Conduct the basic process of data analysis


• Issue commands to and from the memory
units
• Produce the necessary output for each
operation undertaken

Back
Memory Unit
Memory Chips

Random Access Memory (RAM)

• Serve as the prime storage for each data that shall and has
undergone processing
• Used as the storage register for I/O functions
• Contains the CORE control systems of the microcontroller

Read Only memory (ROM)

• Serve as a secondary storage of data

A memory location wherein the firmware required for processing


and analysis is written and stored. Such firmware dictates the
behavior of all the incorporated devices in the microcontroller
Back
Peripheral Devices (Input/Output Unit)

Devices/sub-circuits primarily used to further enhance the


data acquisition and transmission capability of the entire
microcontroller. It allows the microcontroller to:

• Communicate with other microcontrollers units


• Communicate with other data analysis device
• Acquire both analog and digital data
• Awaken the CPU of the microcontroller when a
sudden change within its port has occurred or an
internal interrupt has been made (assuming the
microcontroller was placed to sleep)
• Control special electric/electromechanical devices
Peripheral Devices (Input/Output
Unit)
Specialized Peripheral Features such as:
• interrupt inputs
• low power and sleep modes
• A/D converters
• analog comparators
• capture/compare modules
• high current outputs
• pulse-width modulation (PWM) outputs
Pulse Width Modulation, or PWM, is a technique for
getting analog results with digital means.
• serial/I2C transceivers
I2C

– also known as I2C or “eyesquared-cee”, which stands


for “inter-intergrated computer communications
– developed originally by Philips in the late seventies as
a method to provide an interface between
microprocessors and peripheral devices without
wiring full address, data, and control busses between
devices
– also allows sharing of network resources between
processors (which is known as multimastering)
What Are The Common Application
Areas Of Microcontrollers?

Industry Application

• Logging Functions
• Control Functions
• Timing Functions
• Display Functions
• Sensor Information Processing

Household Application

• Microwaves
• Televisions
• Television remote control units
Dominant Microcontroller Brands

• Motorola
• Siemens
• ZILOG
• ATMEL
• Microchip

You might also like