Sie sind auf Seite 1von 23

PLT206 : Microcontroller

System
Chapter 1:
Introduction To
Microcontroller

ZAID AIHSAN
012 - 4064213
JABATAN TEKNOLOGI KEJURUTERAAN
ELEKTRIK
UNIVERSITI MALAYSIA PERLIS
WHAT IS
MICROCONTROLLER?
The microcontroller is simply a computer on a chip.

Essential for the operation of devices such as mobile


phones, DVD players, video cameras, and most self-
contained electronic systems.

Working sometimes with other chips, but often on its


own.

The MCU provides the key element in the vast range


of small, programmed devices which are now
commonplace.
BASIC MICROCONTROLLER
SYSTEM

Element of Digital System

Basic microcontroller system


contains 3 elements
Processor (Central Processing Unit)
Handle data operations
Make calculations
BASIC MICROCONTROLLER
Memory
SYSTEM
To store program and data
Two types
Volatile
loses its data when switched off, but can be written by the CPU to store
current data
RAM (Random Access Memory)
Non-Volatile
retains its data when switched off
ROM (Read Only Memory)
Input and Output
To communicate with outside world (other devices)
Two types of communication
Serial
Data is transmitted 1 bits at 1 time
Parallel
The data is usually transferred in and out more than 1 bits at a time (8 or 16
bits
Controller has all these in one single chip
PIC 16F877A
MICROCONTROLLER
MCU Features
Things that need to be considered before
selecting the right microcontroller for
application
Program Executions
Overview of how the program being executed
by the microcontroller
RAM File registers
Observe all the registers available in
microcontroller
MCU FEATURES
Some main features to consider are

Numbers of inputs and outputs


Program memory sizes
8k (8096 x 14bits) of Flash ROM program memory

Data RAM sizes


368 x 8 bits RAM

Non-volatile data memory


256 x 8bits EEPROM

Maximum clock speed


20MHz

Range of interfaces
Development system support
Cost and availability
MCU FEATURES
Numbers of inputs and
outputs
5 ports with total 32 I/O
pins
Port A 5 pins
Port B 8 pins
Port C 8 pins
Port D 8 pins
Port E 3 pins
Can operate as 1 pin or
combine as 1 port
Each pins has multiple
functions
PROGRAM EXECUTIONS
This chip has to be programmed via
the serial programming pins, PGM,
PGC and PGD.

The fixed-length instructions


(contains both the operation code
and operand) are being written to
FLASH ROM.
Program Execution Block
RAM FILE REGISTERS
Contains 368 x 8 bits file register
Divided into 4 blocks (known as
register bank)
Including
Special Function Register (SFR)
Have dedicated function
Located at low address at every register
bank
General Purpose Register (GPR)
Used to store variable created in C program
(Start at address 0020H)
RAM FILE REGISTERS
RAM FILE REGISTERS
MCU CONFIGURATIONS
Operational modes (cip configuration
words) must be set prior to the main
program download
Clock oscillator types
Watchdog timers
Power up reset
Brown-out reset
Low voltage programming
Code protection
In-circuit debug modes
CIP CONFIGURATION WORD
The assembler directive __CONFIG is
included at the top of the program,
which sets up aspects of the chip
operation which cannot be
subsequently changed without
reprogramming
The function of each bit is shown in
Table 1.2, along with some typical
configuration settings. Details can be
found in the data sheet
CIP CONFIGURATION WORD
CIP CONFIGURATION WORD
IN-CIRCUIT DEBUGGING (ICD)

The program to be downloaded after the chip has been fitted in


the application circuit, and allows it to be tested with the real
hardware

With ICD, the chip can be programmed, and reprogrammed


during debugging, while avoiding possible electrical and
mechanical damage caused by removal from the circuit.

The normal debugging techniques of single stepping, breakpoints


and tracing can be applied in ICD mode. This allows a final stage
of debugging in the prototype hardware, where problems with the
interaction of the MCU with the real hardware can be resolved.
CIP CONFIGURATION WORD
LOW VOLTAGE PROGRAMMING

When the chip is programmed, a high voltage (1214 V)


is applied to the PGM pin (RB3)

To avoid the need to supply this voltage during in-circuit


programming (e.g. during remote reprogramming), a
low-voltage programming mode is available;

Using this option means that RB3 is not then available


for general I/O functions during normal operation
CIP CONFIGURATION WORD
POWER-UP TIMER
When the supply power is applied to the programmed MCU, the start of program
execution should be delayed until the power supply and clock are stable,
otherwise the program may not run correctly.

The power-up timer may therefore be enabled (PWRTE 0) as a matter of routine.

It avoids the need to reset the MCU manually at start up, or connect an external
reset circuit, as is necessary with some microprocessors.

An internal oscillator provides a delay between the power coming on and an


internal MCU reset of about 72 ms.

This is followed by an oscillator start up delay of 1024 cycles of the clock before
program execution starts. At a clock frequency of 4 MHz, this works out to 256
s.
CIP CONFIGURATION WORD
BROWN-OUT RESET

Brown out refers to a short dip in the power-supply voltage,


caused by mains supply fluctuation, or some other supply
fault, which might disrupt the program execution

If the Brown-Out Detect Enable bit (BODEN) is set, a PSU


glitch of longer than about 100 s will cause the device to be
held in reset until the supply recovers, and then wait for the
power-up timer to time out, before restarting.

The program must be designed to recover automatically.


rown out refers to a short dip in the power-supply
CIP CONFIGURATION WORD
WATCHDOG TIMER

The watchdog timer is designed to automatically reset the MCU if the program
malfunctions, by stopping or getting stuck in loop.

This could be caused by an undetected bug in the program, an unplanned


sequence of inputs or supply fault.

A separate internal oscillator and counter automatically generates a reset


about every 18 ms, unless this is disabled in the configuration word.

If the watchdog timer is enabled, it should be regularly reset by an instruction


in the program loop (CLRWDT) to prevent the reset.

If the program hangs, and the watchdog timer reset instruction not executed,
the MCU will restart, and (possibly) continue correctly, depending on the nature
of the fault.
CIP CONFIGURATION WORD
RC OSCILLATOR

The MCU clock drives the program along, providing the timing
signals for program execution.

The RC (resistorcapacitor) clock is cheap and cheerful, requiring


only these two inexpensive external components, operating with
the internal clock driver circuit, to generate the clock.

The time constant (product R C) determines the clock period.

A variable resistor can be used to give a manually adjustable


frequency, although it is not very stable or accurate.
CIP CONFIGURATION WORD
CRYSTAL OSCILLATOR
If greater precision is required, especially if the program uses the hardware timers to make
accurate measurements or generate precise output signals, a crystal (XTAL) oscillator is needed.

Normally, it is connected across the clock pins with a pair of small capacitors (15 pF) to stabilise
the frequency.

The crystal acts as a self-contained resonant circuit, where the quartz or ceramic crystal vibrates
at a precise frequency when subject to electrical stimulation.

The oscillator runs at a set frequency with a typical accuracy of better than 50 parts per million
(ppm), which is equivalent to / 0.005%.

A convenient value (used in our examples later) is 4 MHz; this gives an instruction cycle time of 1
s, making timing calculations a little easier (each instruction takes four clock cycles).

This is also the maximum frequency allowed for the XT configuration setting.

The PIC 16FXXX series MCUs generally run at a maximum clock rate of 20 MHz, using a high-speed
(HS) crystal which requires the selection of the HS configuration option.
CIP CONFIGURATION WORD
CONFIGURATION SETTINGS

The default setting for the configuration bits is 3FFF, which means that the
code protection is off, in-circuit debugging disabled, program write enabled,
low-voltage programming enabled, brown-out reset enabled, power-up timer
disabled, watchdog timer enabled and RC oscillator selected.

A typical setting for basic development work would enable in-circuit


debugging, enable the power-up timer for reliable starting, disable the
watchdog timer and use the XT oscillator type.

By default, the watchdog timer is enabled. This produces an automatic reset


at regular intervals, which will disrupt normal program operation.

Therefore, this option will usually be disabled (bit 2 0). Conversely, it is


generally desirable to enable the power-up timer, to minimise the possibility
of a faulty start-up

Das könnte Ihnen auch gefallen