Mechatronics Systems

Download Report

Transcript Mechatronics Systems

15: Microprocessor and
microcontroller
Lecture 14
15.1: Control
•
•
•
•
µprocessor systems – use as control
system and are term as embedded
microprocessor
Dedicated to controlling a specific function
Self-started, self-contained with own
operating program
Requiring no human intervention
15.2: Microprocessor systems
• Have 3 parts:
1. Central processing unit (CPU) – recognise
and carry out program instruction
2. Input/output interface – handle
communication between computer and
outside world
3. Memory – to hold program instructions
and data
•
µprocessor with memory and various
input/output arrangement all on the same
chip - microcontroller
15.2.1: Busses
•
Digital signals move from one section to
one another along paths called buses
1. Data bus – data associated with processing
function of CPU
2. Address bus – indicate where data to be
found, selection of memory or input/output
ports
3. Control bus – carry out signals related to
control actions i.e. READ, WRITE
General form of microprocessor system
15.2.2: General architecture of µp
• Arithmetic and logic unit (ALU) – to
perform data manipulation
• Register – temporarily hold internal data
that CPU is currently used
• Control unit – determine timing and
sequence of operations
General internal architecture of microprocessor
system
Registers – temporary storage
1. Accumulator – data for i/p to ALU
2. Status register – flags, indicate status of latest
operation
3. Program counter (PC) or instruction pointer (IP)
– keep track position of instruction in a program
4. Memory address – address of data
5. Instruction register (IR) – store instruction
6. General purpose register – temporary storage
for data or address
7. Stack pointer register (SP) – form address
which defines top of stack in RAM
15.2.3: Memory
•
1.
2.
3.
4.
5.
•
Memory unit – stores binary data and takes the
form of one or more integrated circuits
ROM – read only memory, fixed program i.e.
operating system
PROM – programmable ROM, used for ROM
chip that can be programmed by user
EPROM – erasable and programmable ROM,
EEPROM – electrical and erasable PROM,
erasure b high voltage
RAM – random access memory, temporary data
Programs stored in ROM – firmware, RAM used
program storage - software
15.3: Microcontroller
• Integration of a microprocessor and
input/output interfaces and other peripherals
such as timers, on a single chip
• Has pins for external connections –i/o,
power, clock, control signals
• i/o ports – single port 8-bit word or two ports
16-bit word
Block diagram of a microcontroller
Micro
Controller
Small, Compact
Read inputs

Process

Produce output
Applications of Microcontroller
•
•
•
•
•
•
•
Electronic gadget
Mobile phone
Toys
Robotics
Radio
DVD player
etc
• There are a lot of different microcontrollers
available in the market. For example, Atmel,
Motorola, Intel and PIC.
• Each one has its own advantages and
disadvantages.
• There are a lot of similarities between the
microcontrollers.
• Emphasis on PIC16F877A.
15.3.3: Microchip microcontroller
• PIC microcontroller – Peripheral Interface
Controller
• E.g. PIC16AXX, PIC16FXX,
• Harvard architecture – instruction are
fetched from program memory using
busses that are distinct
Harvard architecture
PIC16C74A
Why PIC?
• Easy to buy, inexpensive, low cost development
tools and powerful.
• You can get from Farnell, RS and Hitectron. You
can even get free sample from Microchip website.
• The development software is distributed as
freeware (MPLAP, PCCLITE and ICPROG).
• One basic microcontroller system cost less than
RM 50.
PIC FAMILY
CORE
PICs come with 1 of 4 CPU ‘cores’:
• 12bit cores with 33 instructions: 12C50x, 16C5x
• 14bit cores with 35 instructions:
12C67x,16Cxxx,16Fxxx
• 16bit cores with 58 instructions: 17C4x,17C7xx
• ‘Enhanced’ 16bit cores with 77 instructions:
18Cxxx, 18Fxxx
PIC FAMILY
PACKAGING
PICs come in a huge variety of packages:
8 pin DIPs, SOICs:
18pin DIPs, SOICs:
28pin DIPs, SOICs:
40pin DIPs, SOICs:
44 - 68pin PLCCs*:
12C50x (12bit) and 12C67x (14bit)
16C5X (12bit), 16Cxxx (14bit), 16Fxxx (14bit)
16C5X (12bit), 16Cxxx (14bit), 16Fxxx (14bit)
16Cxxx (14bit), 17C4x (16bit)
16Cxxx (14bit), 17C4x / 17Cxxx (16bit)
PIC FAMILY
SPEED
PICs require a clock to work.
• Can use crystals, clock oscillators, or even an RC circuit.
• Some PICs have a built in 4MHz RC clock. Not very accurate,
but requires no external components!
• Instruction speed = 1/4 clock speed (Tcyc = 4 * Tclk)
• All PICs can be run from DC to their maximum spec’d speed:
12C50x
12C67x
16Cxxx, 16Fxxx
17C4x / 17C7xxx
18Cxxx, 18Fxxx
4MHz
10MHz
20MHz
33MHz
40MHz
PIC FAMILY
MEMORY
PIC program space is different for each chip.
Some examples are:
12C508
16C71C
16F84A
16F877
17C766
512 12bit instructions
1024 (1k) 14bit instructions
1024 (1k) 14bit instructions
8192 (8k) 14bit instructions
16384 (16k) 16bit instructions
PIC FAMILY
PROGRAM MEMORY
PICs have two different types of program storage:
1. EPROM (Erasable Programmable Read Only Memory)
• Needs high voltage from a programmer to program (~13V)
• Needs windowed chips and UV light to erase
• Note: One Time Programmable (OTP) chips are EPROM chips,
but with no window!
• PIC Examples: Any ‘C’ part: 12C50x, 17C7xx, etc.
2. FLASH
•
•
•
•
Re-writable (even by chip itself)
Much faster to develop on!
Finite number of writes (~100k Writes)
PIC Examples: Any ‘F’ part: 16F84, 16F87x, 18Fxxx (future)
PIC FAMILY
DIGITAL I/O PORT
• All PICs have digital I/O pins, called ‘Ports’
–
–
–
–
the 8pin 12C508 has 1 Port with 4 digital I/O pins
the 18pin 16F84A has 2 Ports with 13 digital I/O pins
the 40pin 16F877A has 5 Ports with 33 digital I/O pins
the 68pin 17C766 has 9 Ports with 66 digital I/O pins
• Ports have 2 control registers
– TRISx sets whether each pin is an input or output
– PORTx sets their output bit levels
• Most pins have 25mA source/sink (directly drives LEDs)
15.4.2: Application- Domestic
washing machine
A.Inputs
• water temperature, motor speed – ADC
• Water level switch – Port A
B.Outputs
• Hot/cold water valve
• Water pump control
• Door lock
• Buzzer
• Motor direction
• Heater control
15.4.2: Application- Domestic
washing machine (cont.)
C. Outputs
• Displays
• Inputs from keyboards
D. Others
• PWM – provide signal to motor
• Interrupt – stopped if interrupt i.e. door opened
Domestic washing machine
15.5: Programming steps
1. Define problem – function to perform, i/o
required, constraints – speed, accuracy,
memory size, etc.
2. Define algorithm – sequence of steps
3. Flowchart and pseudo code –steps and
program flow
4. Translate flow chart/algorithm into
instruction using language – assembly, C
5. Test and debug program
Flow chart symbols
Flow chart
Sequence
WHILE-DO
IF-THEN-ELSE
End of Lecture 14