0% found this document useful (0 votes)
61 views61 pages

PIC Microcontroller: and Its Applications

Internal Oscillator · Peripheral Features:  10-bit ADC  Comparator  USART  SPI  I2C  PWM  Capture/Compare/PWM functions  Watchdog Timer  Low Voltage Programming · Low Power Modes: Sleep, Idle, Deep Sleep · Brown-out Reset (BOR) · In-Circuit Serial ProgrammingTM (ICSPTM) via Two Pins

Uploaded by

Arun Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views61 pages

PIC Microcontroller: and Its Applications

Internal Oscillator · Peripheral Features:  10-bit ADC  Comparator  USART  SPI  I2C  PWM  Capture/Compare/PWM functions  Watchdog Timer  Low Voltage Programming · Low Power Modes: Sleep, Idle, Deep Sleep · Brown-out Reset (BOR) · In-Circuit Serial ProgrammingTM (ICSPTM) via Two Pins

Uploaded by

Arun Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

NC PU CHD

PIC Microcontroller
And its Applications
Neeru Chaudhary
Assistant Professor
Physics Dept.
P U Chd

1
These devices were originally designed for use in applications
with
• 16-bit microprocessors and computer peripherals,
• remote control transmitters,
• domestic products and
• automotive systems.

2 NC PU CHD
• A simple microcontroller consists of the
following modules:
• An Arithmetic Logic Unit (ALU)
• One or more working registers (called accumulators in the past)
for temporary storage during computations. A register is a small
block of memory, often the size of a byte, where data is stored.
• Program memory (ROM) and data memory (RAM).
• A program counter.
• An instruction register with instruction decoder.
• The control unit.
• A stack.

3 NC PU CHD
NC PU CHD

Introduction
• The PIC microcontroller was developed by General
Instruments in 1975
• PIC stands for Peripheral Interface Controller. The General
Instruments used the acronyms Programmable Interface
Controller and Programmable Intelligent Computer for the
initial PICs (PIC1640 and PIC1650).
• In 1993, Microchip Technology launched the 8-bit
PIC16C84 with EEPROM which could be programmed using
serial programming method. The improved version of
PIC16C84 with flash memory (PIC18F84 and PIC18F84A) hit
the market in 1998.
 

4
NC PU CHD

Classification
The 8-bit PIC microcontroller is divided into
following four categories on the basis of
internal architecture:
• Base Line PIC
• Mid-Range PIC
• Enhanced Mid-Range PIC

• PIC18

5
NC PU CHD

Base line PIC


• Base Line PICs are the least complex PIC
microcontrollers.
• These microcontrollers work on 12-bit instruction
architecture which means that the word size of
instruction sets are of 12 bits for these controllers.
• These are smallest and cheapest PICs, available
with 6 to 40 pin packaging.
•  The small size and low cost of Base Line PIC
replaced the traditional ICs like 555, logic gates etc.
in industries.

6
NC PU CHD

Mid-Range PIC
• Mid-Range PICs are based on 14-bit instruction
architecture and are able to work up to 20 MHz
speed.
• These controllers are available with 8 to 64 pin
packaging.
• These microcontrollers are available with different
peripherals like ADC, PWM, Op-Amps and different
communication protocols like USART, SPI, I2C (TWI),
etc. which make them widely usable microcontrollers
not only for industry but for hobbyists as well.
 

7
NC PU CHD

Enhanced Mid-Range PIC


• These controllers are enhanced version of Mid-
Range core.
•This range of controllers provides additional
performance, greater flash memory and high
speed at very low power consumption.
• This range of PIC also includes multiple
peripherals and supports protocols like USART,
SPI, I2C and so on.
 

8
NC PU CHD

PIC18

• PIC18 range is based on 16-bit instruction


architecture incorporating advanced RISC
architecture which makes it highest performer
among the all 8-bit PIC families.
• The PIC18 range is integrated with new age
communication protocols like USB, CAN, LIN,
Ethernet (TCP/IP protocol) to communicate with
local and/or internet based networks.
• This range also supports the connectivity of
Human Interface Devices like touch panels etc.

9
NC PU CHD

PIC17 high end core devices

•a memory mapped accumulator


• read access to code memory (table reads)

• direct register to register moves (prior cores needed


to move registers through the accumulator)
• an external program memory interface to expand
the code space
• an 8-bit × 8-bit hardware multiplier

• a second indirect register pair

• auto-increment/decrement addressing controlled


by control bits in a status register

10
NC PU CHD
PIC18 high end core devices

• much deeper call stack (31 levels deep)


• the call stack may be read and written

• conditional branch instructions

• indexed addressing mode


• extending the FSR registers to 12 bits, allowing
them to linearly address the entire data
address space
• the addition of another FSR register (bringing
the number up to 3)

11
NC PU CHD
PIC24 and dsPIC 16-bit microcontrollers

• they feature a set of 16 working registers (W0-


W15)
• they fully support a stack in RAM

• bank switching is not required to access RAM or


special function registers
• data stored in program memory can be accessed
directly using a feature called Program Space
Visibility
• interrupt sources may be assigned to distinct
handlers using an interrupt vector table

12
NC PU CHD
PIC32 32-bit microcontrollers

• The highest execution speed 80 MIPS Dhrystone


MIPS @ 80 MHz)
• The largest flash memory: 512 kByte

• One instruction per clock cycle execution

• The first cached processor

• Allows execution from RAM

• Full Speed Host/Dual Role and OTG USB


capabilities
• Full JTAG and 2 wire programming and debugging

13
Following table compares the above four categories: 

  Base Line Mid-Range Enhanced Mid- PIC18


Range
No. of Pins 6-40 8-64 8-64 18-100
Program Up to 3 KB Up to 14 KB Up to 28 KB Up to 128 KB
Memory
Data Memory Up to 134 Bytes Up to 368 Bytes Up to 1.5 KB Up to 4 KB
Instruction 12-bit 14-bit 14-bit 16-bit
Length
No. of 33 35 49 83
instruction set
Speed   5 MIPS 8 MIPS Up to 16 MIPS
 
5 MIPS*
Feature • Comparator In addition of In addition of Mid- In addition of
• 8-bit ADC baseline range Enhanced Mid-
• Data Memory ·   SPI ·   High range
•Internal Oscillator ·   I2C Performance • CAN
·   UART ·   Multiple • LIN
·   PWM communication • USB
·   10-bit ADC peripherals • Ethernet
·   OP-Amps   • 12-bit ADC
Families PIC10,PIC12, PIC12, PIC16 PIC12F1XXX, PIC18
PIC16 PIC16F1XXX

14
NC PU CHD
15 NC PU CHD
NC PU CHD

PIC18 Harvard Architecture 

• PIC microcontroller contains an 8-bit ALU (Arithmetic Logic


Unit) and an 8-bit Working Register (Accumulator).
• There are different GPRs (General Purpose Registers) and
SFRs (Special Function Registers) in a PIC microcontroller.
• The overall system performs 8-bit arithmetic and logic
functions. These functions usually need one or two
operands. One of the operands is stored in WREG
(Accumulator) and the other one is stored in GPR/SFR.
• The two data is processed by ALU and stored in WREG or
other registers.
•  In PIC microcontroller, a single machine cycle consists of 4
oscillation periods

16
Pipelining:
Early processors and controllers could fetch or execute a single instruction in a unit of
time. The PIC microcontrollers are able to fetch and execute the instructions in the same
unit of time thus increasing their instruction throughput. This technique is known as
instruction pipelining where the processing of instructions is split into a number of
independent steps.
 
 

17 NC PU CHD
Features:
· C Compiler Optimized Architecture with Optional
Extended Instruction Set
·         100,000 Erase/Write Cycle Enhanced Flash
·         Program Memory Typical
·         1,000,000 Erase/Write Cycle Data EEPROM Memory
Typical
·         Flexible oscillator option
    Four Crystal modes, including High-Precision PLL for
USB
     Two External Clock modes, Up to 48 MHz
     Internal Oscillator: 8 user-selectable
frequencies, from 31 kHz to 8 MHz
     Dual Oscillator Options allow Microcontroller and
USB module to Run at different Clock Speeds

18 NC PU CHD
Memory: 
1.      Flash Memory: Flash memory is used to store the program
downloaded by a user on to the microcontroller. Flash memory is
non-volatile, i.e., it retains the program even after the power is
cut-off. PIC18F4550 has 32KB of Flash Memory.
 
2.      EEPROM: This is also a nonvolatile memory which is used to
store data like values of certain variables. PIC18F4550 has 256
Bytes of EEPROM.
 
3.      SRAM: Static Random Access Memory is the volatile memory
of the microcontroller, i.e., it loses its data as soon as the power is
cut off. PIC18F4550 is equipped with 2 KB of internal SRAM.

19 NC PU CHD
   Oscillator: The PIC18F series has flexible clock options.
An external clock of up to 48 MHz can be applied to this
series. These controllers also consist of an internal oscillator
which provides eight selectable frequency options varying
from 31 KHz to 8 MHz.
 
  8x8 Multiplier: The PIC18F4550 includes an 8 x 8
multiplier hardware. This hardware performs the
multiplications in single machine cycle. This gives higher
computational throughput and reduces operation cycle &
code length.

20 NC PU CHD
·         ADC Interface: PIC18F4550 is equipped with 13 ADC (Analog to
Digital Converter) channels of 10-bits resolution. ADC reads the analog
input, for example, a sensor input and converts it into digital value that
can be understood by the microcontroller.
 
·         Timers/Counters: PIC18F4550 has four timer/counters. There is
one 8-bit timer and the remaining timers have option to select 8 or 16
bit mode. Timers are useful for generating precision actions, for
example, creating precise time delays between two operations.
 
·         Interrupts: PIC18F4550 consists of three external interrupts
sources. There are 20 internal interrupts which are associated with
different peripherals like USART, ADC, Timers, and so on.

21 NC PU CHD
·         EUSART: Enhanced USART (Universal Synchronous and
Asynchronous Serial Receiver and Transmitter) module is full-duplex
asynchronous system. It can also be configured as half-duplex
synchronous system. The Enhanced USART has the feature for
automatic baud rate detection and calibration, automatic wake-up
on Sync Break reception and 12-bit Break character transmit. These
features make it ideally suited for use in Local Interconnect Network
bus (LIN bus) systems.
 
·         ICSP and ICD: PIC18F series controllers have In Circuit Serial
Programming facility to program the Flash Memory which can be
programmed without removing the IC from the circuit. ICD (In Circuit
Debugger) allows for hardware debugging of the controller while it is
in the application circuit.

22 NC PU CHD
·        
SPI: PIC18F supports 3-wire SPI communication
between two devices on a common clock source. The data
rate of SPI is more than that of USART.
 
·         I2C: PIC18F supports Two Wire Interface (TWI) or I2C
communication between two devices. It can work as both
Master and Slave device.
 
·         USB: PIC18F supports full-speed USB with different
clock options

23 NC PU CHD
NC PU CHD

Instruction set
• Mov instructions - they copy a value from/to a file
register or literal to/from register W
• Logic and arithmetic instructions with a file
register and register W as operands
• Logic and arithmetic instructions with a literal and 
register W as operands
• One operand Logic and Arithmetic instructions

• Branch, Skip, Call and Return instructions

• Useful macros for conditional branches, logic and


arithmetic operations

24
NC PU CHD

• AN EXAMPLE OF PIC

25
RA0 To RA4 RA is a bidirectional port.

RB0 To RB7 RB is a second bidirectional port

VSS And VDD These are the power supply pins

MCLR This pin is used to erase the memory locations


inside the PIC

INT This is an input pin which can be monitored. If the


pin goes high, we can cause the program to
restart, stop or any other single function we desire.
We won't be using this one much.

26 NC PU CHD
NC PU CHD

BLOCK DIAGRAM

27
NC PU CHD

FEATURES
• The PIC architecture is based on a configuration
known as a Harvard machine structure where
• In the PIC16F84, the program bus is 14 bits
wide, whereas the data bus is 8 bits wide.
• In addition, the PIC family is based on a
Reduced Instruction Set Computer (RISC)
• PIC16XXX devices have only 35 instructions

28
• The PIC family are fully static devices, meaning that they
preserve the contents of their registers when the clock
frequency is reduced to zero.

• In PIC microcontrollers, each instruction takes four clock periods


to execute. If a 1MHz clock frequency is used, the
corresponding clock period is 1μsec, so each instruction will
take 4μsec–this time is called the instruction cycle time

• The fastest devices in the PIC family can operate at clock


frequencies up to 33MHz, with corresponding instruction cycle
times of 121nsec.

29 NC PU CHD
• A watchdog timer is an internal timer running independently of
the system clock. It resets the device in the event of a program
or circuit malfunction or if an unknown logical state is
encountered.

• For example, if the program hangs, the watchdog timer will time
out and reset the processor. The PIC16F84 has a watchdog timer
with a timeout period of approximately 18msec, with no
prescaler, determined by a separate internal RC oscillator.

30 NC PU CHD
NC PU CHD

Program memory

31
• The program counter (PC) is a 13 bit wide register which will
enable 8K (8 × 1024) program address locations to be
addressed.

• Each program instruction is 14 bits wide, so the PC can address


8K × 14 bits of memory space. However, only 1K of this program
memory is physically implemented.

32 NC PU CHD
• DATA MEMORY

The data memory is separated into two areas, one for the special
function registers and one for the general purpose registers.
• The memory area is further partitioned into two banks which
require bank switching in the program to correctly access
registers.
• For example, access to register PORTA requires Bank0 to be
selected, whereas Bank1 must be selected to access register
TRISB.
• Certain special function registers such as STATUS can be
accessed from either of the two banks.

33 NC PU CHD
NC PU CHD

DATA MEMORY

34
• The special function registers are
TMR0, OPTION, PCL, STATUS, FSR, PORTA, PORTB, TRISA, TRISB,
EEDATA, EECON1, EEADR, EECON2, PCLATH and INTCON
• PORTA is associated with five input/output pins, RA0 to RA4 and
their I/O status is controlled by setting or clearing bits in the
TRISA register.
• Similarly, PORTB is an eight bit wide port and its I/O status is
controlled by the TRISB register

35 NC PU CHD
• STATUS SFR

• The first three bits (STATUS<0> to STATUS<2>) are the carry (C),
digit carry (DC) and zero (Z) flags of the ALU respectively.

• Bits 3 and 4 are the power down PD and watchdog timer


timeout TO bits respectively

• Bits 5 and 6 (RP0 and RP1) are the bank selection bits.

36 NC PU CHD
• OPTION register allows the programmer to select timer settings
and other parameters.

• INTCON register is used to configure the interrupt control logic


circuitry

37 NC PU CHD
• Clock source options
• There are five possible source options for the instruction cycle clock oscillator. Choosing
an option is done when the PIC program is loaded into ROM.
There are three crystal oscillator options - low power, LP, medium speed, XT and high
speed, HS.
The low power option is intended for use with crystals with frequencies up to 200kHz; the
XT
option for crystals up to 4MHz and the HS option for crystals operating up to 10MHz. The
values of the oscillation capacitors in each case is given in the data sheet [3] for the PIC
device.

• It is also possible to run the PIC using an external clock source from a square wave signal
generator on all but the RC option. The external signal is fed directly into pin 16 (OSC1)
and
must have a peak to peak voltage of 0 to 5V. Ensure that there is no voltage offset on the
signal
before applying it to the oscillator pins.

39 NC PU CHD
NC PU CHD

PIC18F – MPU and Memory

40
• Microprocessor Unit
• Includes Arithmetic Logic Unit (ALU), Registers,
and Control Unit
• Arithmetic Logic Unit (ALU)
• Instruction decoder
• 16-bit instructions
• Status register that stores flags
• 5-bits

• WREG – working register


• 8-bit accumulator

41 330_02
• Microprocessor Unit
• Registers
• Program Counter (PC)
• 21-bit register that holds the Program Memory address
• Bank Select Register (BSR)
• 4-bit register used in direct addressing the Data Memory
• File Select Registers (FSRs)
• 12-bit registers used as memory pointers in indirect addressing
Data Memory
• Control unit
• Provides timing and control signals
• Read and Write operations

42 330_02
• PIC18F - Address Buses
• Address bus
• 21-bit address bus for Program Memory
• Addressing capacity: 2 MB
• 12-bit address bus for Data Memory
• Addressing capacity: 4 KB

43 330_02
• Data Bus and Control Signals
• Data bus
• 16-bit instruction/data bus for Program Memory
• 8-bit data bus for Data Memory

• Control signals
• Read and Write

44 330_02
• PIC18F452/4520 Memory
• Program Memory: 32 K
• Address range: 000000 to 007FFFH
• Data Memory: 4 K
• Address range: 000 to FFFH
• Data EEPROM
• Not part of the data memory space
• Addressed through special function registers

45 330_02
• PIC18F452/4520 Memory

• Program Memory • Data Memory

46 330_02
• Data Memory with Access Bank

47 330_02
• PIC18F452 I/O Ports
• Five I/O ports
• PORT A through PORT E
• Most I/O pins are multiplexed
• Generally have eight I/O pins
• Addresses already assigned to these ports
• Each port is identified by its assigned SFR

48 330_02
• I/O Ports A and B

49 330_02
• Data Transfer

50 330_02
• MCU Support Devices
• Timers
• Capture, Compare and PWM (CCP Modules)
• Serial Communications
• Master Synchronous Serial Port (MSSP)
• Addressable USART

• A/D converter
• Parallel Slave Port (PSP)

• Data EEPROM

51 330_02
• MCU Support Devices

52
• PIC18F Special Features
• Sleep mode
• Watchdog timer (WDT)
• Code protection

• In-circuit serial programming

• In-circuit debugger

53 330_02
NC PU CHD

Advantages

• Small instruction set to learn


• RISC architecture

• Built in oscillator with selectable speeds

• Easy entry level, in circuit programming plus in


circuit debugging
• Inexpensive microcontrollers

• Wide range of interfaces including I²C, SPI, USB,


USART, A/D, programmable comparators, PWM,
LIN, CAN, PSP, and Ethernet

54
NC PU CHD
Limitations

• One accumulator
• Register-bank switching is required to access the entire RAM of
many devices
• Operations and registers are not orthogonal; some instructions
can address RAM and/or immediate constants, while others can
only use the accumulator
• The following stack limitations have been addressed in the PIC18
series, but still apply to earlier cores:
The hardware call stack is not addressable, so preemptive task
switching cannot be implemented
Software-implemented stacks are not efficient, so it is difficult to
generate reentrant code and support local variables

55
NC PU CHD

COMPILERS
• Microchip released their own C compilers, C18
and C30, for the line of 18F 24F and 30/33F
processors.
• MPLAB software available free of charge from
Microchip Technology

56
NC PU CHD

57
NC PU CHD

• Today PIC microcontroller is very popular.It is used in


many applications especially in modern consumer
products such as
• Vacuuming Robot

• Mobile phone

• Rice cooker

• Remote control, TV, VCD/DVD player

• MP3/MP4 player

• Toys

• Motor controller even in auto etc.

58
http://www.hobbyprojects.com/pic_tutorials/tutorial1.html

59 NC PU CHD
60 NC PU CHD
NC PU CHD

61
NC PU CHD

Useful websites

1. http://www.eg3.com
2. http://www.ARM.MCU.com
3. http://www.mcjournal.com
4. http://www.iar.com
5. http://http://www.embedded.com
6. http://www.powersoftsystems.com

62

You might also like