Search This Blog

Thursday, June 16, 2011

Inside a PIC Microcontroller

Although there are many models of microcontrollers in the PIC family, they all share some
common features, such as program memory, data memory, I/O ports, and timers. Some
devices have additional features such as A/D converters, USARTs and so on. Because of these
common features, we can look at these attributes and cover the operation of most devices in
the family.

The PIC microcontroller family

The PIC microcontroller family is manufactured by Microchip Technology Inc. Currently
they are one of the most popular microcontrollers, used in many commercial and industrial
applications. Over 120 million devices are sold each year.
The PIC microcontroller architecture is based on a modified Harvard RISC (Reduced Instruction
Set Computer) instruction set with dual-bus architecture, providing fast and fl exible design
with an easy migration path from only 6 pins to 80 pins, and from 384 bytes to 128 kbytes of
program memory.
PIC microcontrollers are available with many different specifi cations depending on:
• Memory Type
– Flash
– OTP (One-time-programmable)
– ROM (Read-only-memory)
– ROMless
• Input–Output (I/O) Pin Count
– 4–18 pins
– 20–28 pins
– 32–44 pins
– 45 and above pins
• Memory Size
– 0.5–1 K
– 2–4 K
– 8–16 K
– 24–32 K
– 48–64 K
– 96–128 K
• Special Features
– CAN
– USB
– LCD
– Motor Control
– Radio Frequency
Although there are many models of PIC microcontrollers, the nice thing is that they are
upward compatible with each other and a program developed for one model can very easily, in
many cases with no modifi cations, be run on other models of the family. The basic assembler
instruction set of PIC microcontrollers consists of only 33 instructions and most of the family
members (except the newly developed devices) use the same instruction set. This is why a
program developed for one model can run on another model with similar architecture without
any changes.
All PIC microcontrollers offer the following features:
• RISC instruction set with only a handful of instructions to learn
• Digital I/O ports
• On-chip timer with 8-bit prescaler
• Power-on reset
• Watchdog timer
• Power-saving SLEEP mode
• High source and sink current
• Direct, indirect, and relative addressing modes
• External clock interface
• RAM data memory
• EPROM or Flash program memory
Some devices offer the following additional features:
• Analog input channels
• Analog comparators
• Additional timer circuits
• EEPROM data memory
• External and internal interrupts
• Internal oscillator

• Pulse-width modulated (PWM) output
• USART serial interface
Some even more complex devices in the family offer the following additional features:
• CAN bus interface
• I2C bus interface
• SPI bus interface
• Direct LCD interface
• USB interface
• Motor control
Although there are several hundred models of PIC microcontrollers, choosing a microcontroller
for an application is not a diffi cult task and requires taking into account these factors:
• Number of I/O pins required
• Required peripherals (e.g., USART, USB)
• The minimum size of program memory
• The minimum size of RAM
• Whether or not EEPROM nonvolatile data memory is required
• Speed
• Physical size
• Cost
The important point to remember is that there could be many models that satisfy all of
these requirements. You should always try to fi nd the model that satisfi es your minimum
requirements and the one that does not offer more than you may need. For example, if you
require a microcontroller with only 8 I/O pins and if there are two identical microcontrollers,
one with 8 and the other one with 16 I/O pins, you should select the one with 8 I/O pins.
Although there are several hundred models of PIC microcontrollers, the family can be broken
down into three main groups, which are:

• 12-bit instruction word (e.g., 12C5XX, 16C5X) (also referred to in this book as the 12
Series and the 16C5X Series)
• 14-bit instruction word (e.g., 16F8X, 16F87X) (also referred to in this book as the
16 Series)
• 16-bit instruction word (e.g., 17C7XX, 18C2XX) (also referred to in this book as the
17 Series and the 18 Series).

All three groups share the same RISC architecture and the same instruction set, with a few
additional instructions available for the 14-bit models, and many more instructions available
for the 16-bit models. Instructions occupy only one word in memory, thus increasing the code
effi ciency and reducing the required program memory. Instructions and data are transferred on
separate buses, so the overall system performance is increased.



Tuesday, June 7, 2011

CISC and RISC

 
 This term is often found in computer literature, and it needs to be explained here in more detail. Harvard architecture is a newer concept than von-Neumann's. It rose out of the need to speed up the work of a microcontroller. In Harvard architecture, data bus and address bus are separate. Thus a greater flow of data is possible through the central processing unit, and of course, a greater speed of work. Separating a program from data memory makes it further possible for instructions not to have to be 8-bit words. PIC16F84 uses 14 bits for instructions which allows for all instructions to be one word instructions. It is also typical for Harvard architecture to have fewer instructions than von-Neumann's, and to have instructions usually executed in one cycle. Microcontrollers with Harvard architecture are also called "RISC microcontrollers". RISC stands for Reduced Instruction Set Computer. Microcontrollers with von-Neumann's architecture are called 'CISC microcontrollers'. Title CISC stands for Complex Instruction Set Computer. Foe an example  PIC16F84 is a RISC microcontroller, that means that it has a reduced set of instructions, more precisely 35 instructions . (ex. Intel's and Motorola's microcontrollers have over hundred instructions) All of these instructions are executed in one cycle except for jump and branch instructions.

A review of memory technologies

Introduction
In order to examine the memory capabilities of the 16F84A, and to work with embedded systems in general,
it is important to have some knowledge of the characteristics of the memory technologies in use. A detailed
survey can be found in Chapter 4 of Ref. 1.1. The following section gives just a brief overview of the
different memory technologies currently used by Microchip.
 An ideal memory reads and writes in negligible time, retains its stored value indefinitely, occupies negligible
space and consumes negligible power. In practice no memory technology meets all these happy ideals!
In general, different technologies are strong in one or more of these characteristics and weaker in others.
There is not one best memory technology, and different technologies are therefore applied for different
applications, according to the need.
Any memory is made up of an array of memory cells, where each cell holds one bit of data. The characteristics
of the single cell reflect the characteristics of the overall array; therefore, each technology is described
here simply in terms of its cell design.

Static RAM (SRAM)
Here each memory cell is designed as a simple flip-flop, using two back-to-back transistor pairs. Two further
transistors allow the cell to connect into the main array. Data is held only as long as power is supplied.
Hence the SRAM technology is volatile. With each cell taking six transistors, SRAM is not dense. However,
if made from CMOS (Complementary Metal Oxide Semiconductor) it can be made to consume very little
power and can retain its data down to a low voltage (around 2 V). It has thus been a popular technology in
battery-powered systems. SRAM is mainly used for data memory (RAM) in a microcontroller.

EPROM (Erasable Programmable Read-Only Memory)
In this technology each memory cell is made of a single MOS transistor – but with a difference. Within the
transistor there is embedded a ‘floating gate’. Using a technique known as hot electron injection (HEI), the
floating gate can be charged. When it is not charged, the transistor behaves normally and the cell output takes
one logic state when activated. When it is charged, the transistor no longer works properly and it no longer
responds when it is activated. The charge placed on the floating gate is totally trapped by the surrounding
insulator. Hence EPROM technology is non-volatile. EPROM can, however, be erased by exposing it to
intense ultraviolet light. This gives the trapped electrons the energy to leave the floating gate.

A special version of EPROM is ‘OTP’ – One Time Programmable. Here the EPROM is packaged in plastic,
without a window. Therefore, OTP can be programmed only once and never erased.
With a single transistor for a cell, EPROM is very high density and robust. Its requirement for a quartz
window and ceramic packaging, to enable erasing, raises its price and reduces its flexibility. EPROM used
to be integrated onto many microcontrollers for program memory, forcing the whole microcontroller to be
ceramic-packaged, with a quartz window (as seen in Figure 1.10). As a technology, EPROM is now rapidly
giving way to Flash, which follows shortly.

EEPROM (Electrically Erasable ProgrammableRead-Only Memory)
EEPROM also uses floating gate technology. Its dimensions are finer, so that it can exploit another means
of charging its floating gate. This is known as Nordheim Fowler tunnelling (NFT). With NFT, it is possible
to electrically erase the memory cell, as well as write to it. To allow this to happen, a number of switching
transistors need to be included around the memory element itself, so the high density of EPROM is lost.
Generally, EEPROM can be written to and erased on a byte-by-byte basis. This makes it especially useful
for storing single items of data, like television settings or mobile phone numbers. Both writing and erasing
take finite time, up to several milliseconds, although a read can be accomplished at normal semiconductor
memory access times, i.e. within microseconds or less. Again, like EPROM, because the charge on the
floating gate is totally trapped by the surrounding insulator, EEPROM is non-volatile. Because the EEPROM
structure is now so fine, it suffers from certain wear-out mechanisms. Manufacturers usually therefore define
a guaranteed minimum number of erase/write cycles that their memory can successfully undergo.

Flash
Flash represents a further evolution of floating gate technology. With a single transistor per memory cell, it
uses both HEI and NFT to allow electrical writing and erase. It does not include the extra switch transistors
 that EEPROM has, so can only erase in blocks. It therefore returns to the exceptionally high density of
EPROM. Like EEPROM, it has wear-out mechanisms, so cannot be written and erased indefinitely.
Apart from its inability to erase byte by byte, Flash is an incredibly powerful technology. It is now a central
feature of a huge range of products, including digital cameras, ‘memory sticks’, laptop computers and
microcontroller program memory.

Monday, June 6, 2011

Internal Structure

Memory unit

Memory is part of the microcontroller whose function is to store data. The easiest way to explain it is to describe it as one big closet with lots of drawers. If we suppose that we marked the drawers in such a way that they can not be confused, any of their contents will then be easily accessible. It is enough to know the designation of the drawer and so its contents will be known to us for sure.


Microchip and the PIC microcontroller

Background
The PIC was originally a design of the company General Instruments. It was intended for simple control
applications, hence the name – Peripheral Interface Controller. In the late 1970s General Instruments produced

Thursday, June 2, 2011

Introduction

History
It was year 1969, and a team of Japanese engineers from the BUSICOM company arrived to
United States with a request that a few integrated circuits for calculators be made using their
projects. The proposition was set to INTEL, and Marcian Hoff was responsible for the project.