55827709 Pic Micro Controller

Post on 29-Oct-2014

156 views 0 download

Tags:

Transcript of 55827709 Pic Micro Controller

BY:- Anil Kumar Pathak, Mayank Tripathi, P. l. Rongmei, Instrumentation & Control Engg. Electrical Engg. Department NITTTR ,Chandigarh

Our world is full of integrated circuits. We can find several of them in

computers. For example, microprocessor. The microprocessor is an integrated

circuit that processes all functions in the computer.

But a microprocessor can not work alone . It requires some external peripherals such as memory(RAM & ROM), Input/Output ports , Timers, etc.

But the addition of external RAM,ROM, Timers and I/O ports makes these systems bulkier and much more expansive.

Which forced to engineers to devolve a special type of chip having CPU (microprocessor) with a fixed amount of memory, I/O ports and Timers.

So we do not need to add any external memory, I/O port and timer to it.

Which reduces system cost and weight.

So we can say that microcontroller is a CPU on a small chip with some amount of fixed memory(RAM and ROM), I/O ports and Timers.

Some microcontroller manufacturers have gone far as integrating an ADC and other peripherals.

The types of micro controller can be classified based on internal bus width, instruction set, memory architecture ,family etc. some of them are given below:-

Intel 8051 (8-bit) PIC (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24) FreeScale 68HC11(8-bit) Atmel AVR(8-bit), AVR32 (32-bit) Toshiba TLCS-870 Hitachi H8, Hitachi SuperH (32-bit), etc.

In 1989, Microchip Corporation introduced an 8-bit microcontroller called PIC microcontroller. (PIC16xxx)

PIC16xxx had :-Small amount of DATA RAM and

PROM.One TimerFew Pins for I/O portsOne ADC

After the introduction of PIC16xxx, they have introduced an array of 8-bit microcontrollers.

They includes the PIC families of :- PIC10xxx PIC12xxx PIC14xxx PIC16xxx PIC18xxx All of above are 8-bit microcontrollers.

Right now PIC18xxx and PIC16xxx families has the highest performance of all the families of 8-bit PIC microcontrollers.

Right now no 8 pinPIC18xxx exists, and this is the main reason to choose other family members(PIC10xxx to PIC16xxx), if our design call for small package.

Interrupt

Control Logic OSC

EEPROM

I/O Ports

Other periphe

ralTimers

CPU

PROMSTACK

PC

RAM

PIC18 Program ROM The maximum size of PROM is 2M The PROM size can vary from 4k to 128k

bytes. PIC18 PROM is available in different

memory types, such as :- UV-EPROM Flash PROM OTP PROM ( All of have different part

numbers)

Masked PROM

UV-EPROM

This UV-EPROM requires a PROM burner to write programs and a UV-EPROM eraser to erase the contents of ROM.

The problem with UV-ROM is that it takes around 20 minutes to erase the chip before it can be programmed again.

At this time Flash ROM is replacing UV-ROM.

Flash PROM

The flash version is ideal for fast development.

Flash memory can be erased in few seconds.

Because flash memory is a EEPROM. It requires a ROM burner to write programs. No need of separate eraser to erase the

programs.

OTP Version of PIC OTP(One-time programmable) version of the

PIC is also available from Microchip.(PIC16C432).

It can not re-programmed again.Masked Version of PIC Microchip corporation provides a service in

which we can send our program to them and they will burn the program in to the PIC chip during the fabrication process of the chip.

RAM is used for store the data. The data size for the PIC18 varies from

256 bytes to 4096 bytes.

Data EEPROM We also have a small amount of

EEPROM to store Critical data, that does not need to be changed very often.

Not all PIC18 comes with Data EEPROM ,because it is optional.

PIC microcontroller can have from 16 to 72 pins dedicated for I/O.

The number of pins for the PIC18 package goes from 18 to 80 at this time.

Other Peripherals ADC (10 bit) Timers(4) USART(universal synchronous

asynchronous receiver/transmitter)-for serial data transfer.

Part Num

PROM DATA RAM

I/O Pins

ADC Timers Pin no & Package

PIC18F1220

4k (Flash)

256 16 10-bit 4 18 DIP

PIC18F2420

16k (Flash)

768 25 10-bit 4 28 DIP

PIC18F2220

4k (Flash)

512 25 10-bit 4 28 DIP

PIC18F452

32k (Flash)

1536 34 10-bit 4 4o DIP

PIC18F4520

32k (Flash)

1536 36 10-bit 4 40 DIP

PIC18F8722

128k (Flash)

3936 72 10-bit 5 80 TQFP

*All Memories(PROM & Data RAM) are in bytes

Features 8051/52

PIC18xxx

PROM (Maximum Space)

64 K 2M

Data RAM (Maximum Space)

256 bytes 4 K

Timers 3 4

I/O Pins 32 33 to 36

Serial Ports 1 1

*All Memories(PROM & Data RAM) are in bytes

Device Pins Instruction Word Size

PIC10XXX 8 8 - bit

PIC12XXX 8 12 - bit

PIC16XXX 18 8 - bit

PIC16XXX 40 14 - bit

PIC17XXX 84 16 – bit

PIC18XXX 80 8-bit

20

1

2

3

4 5

6

7

8VDD

GP5/OSC1/CLKIN

GP4/OSC2

GP3/MCLR/VPP

VSS

GP2/ICSPDAT

GP1/ICSPCLK

GPO/ICSPT0CKI

PIC

12F508/5

09

Sl. Pin. Descriptions01 VDD Power Supply

02 OSC1, Oscillator PinOSC2

03 VPP Programming Voltage Input

04 GP0 to GP5 General Purpose input/output pins (Bidirectional

except GP3)

21

Sl. Pin. Descriptions05 CSPDAT In-circuit Serial

Programming Data pin06 CSPCLK In-circuit Serial

Programming clock pin

07 VSS Ground

08 MCLR Master clear09 CLKIN External Clock input

22

23

Pin No

Pin Name

Buffer Type

Descriptions

01 RA2 TTL Bidirectional i/o port

02 RA3 TTL Bidirectional i/o port

03 RA4/

TOCK1

TTL Can also be selected to be the clock input to the TMRO Timer / Counter. Output is open drain type.

24

25

Pin No

Pin Name

Buffer Type

Descriptions

04 MCLR ST Master Clear (Reset) input/ Programming Voltage input. This pin is an activelow RESET to the device.

05 VSS ------- Ground reference for logic and Input / Output pins

26

Pin No

Pin Name

Buffer Type

Descriptions

06 RBO/INT TTL/ST Bidirectional i/o port. Port B can be software programmed for internal week pull-up on all input.

RB0/INT can also be selected as an external interrupt pin.

27

Pin No

Pin Name

Buffer Type

Descriptions

07 RB1 TTL Bidirectional i/o port.

08 RB2 TTL Bidirectional i/o port.

09 RB3 TTL Bidirectional i/o port.

10 RB4 TTL Interrupt-on-change pin

11 RB5 TTL Interrupt-on-change pin

28

Pin No

Pin Name

Buffer Type

Descriptions

12 RB6 TTL/ST Interrupt-on-change pin

Serial Programming clock

13 RB7 TTL/ST Interrupt-on-change pin Serial Programming data

14 VDD ------- Positive supply for logic and Input / Output pins

29

Pin No

Pin Name

Buffer Type

Descriptions

15 OSC2/

CLKOUT

-------- Oscillator Crystal output , connect to Crystal or Resonator in crystal oscillator mode. In RC mode, OSC2 pin outputs CLKOUT, which has ¼ the frequency of OSC1

TTL = TTL Input; ST = Schmitt

Trigger Input;

30

Pin No

Pin Name

Buffer Type

Descriptions

16 OSC1/

CLKIN

ST/

CMOS

Oscillator Crystal input / External clock source input

17 RA0 TTL Bidirectional input output port

18 RA1 TTL Bidirectional input output port

TTL = TTL Input; ST = Schmitt Trigger

Input;

On power on of the PIC or after a reset, all ports become inputs.

This is done to avoid driving an output pin directly to the VDD or VSS.

31

To define the type of an I/O pin, you use the TRIS register.

There are two TRIS registers, the TRISA and the TRISB

When one bit of this register is set to '1', the corresponding port pin shall become an input.

When it is set to '0', then this port pin shall become an output.

32

PIC16F84 can work with four different configurations of an oscillator.

Microcontroller type with a crystal oscillator (XT), and

A microcontroller with resistor-capacitor pair (RC). This is important because we need to mention the type of oscillator when buying a microcontroller.

33

34

C2=30pF

C2=30pF

XTAL

35

“R” should be between 3K to 100K. Below 2.2K of “R” Oscillator become

unstable. At 1M and above of “R” Oscillator

becomes very sensitive to noise and humidity.

“C” should be select as per the requirement of the clock.

The clock frequency must be divided by 4.36

37

The main oscillator signal is divided by 4 to produce the instruction cycle time.

38

The overall speed of the microcontroller operation is entirely dependent on this clock frequency.

Higher frequency -> Higher Performance and higher power consumption.

39

40

VDD

R

41

The microcontroller pins have multiple functions

42

Peripheral Interface Controller is a family of Micro controller by Microchip Technology.

It Uses Harvard Architecture. Here we have separate Data and Program

memories.

DataMemory

CPUProgramMemory

CPU

ProgramandData

Memory

Harvard von-Neumann

8 kB of FLASH Program Memory. 256 bytes of EEPROM Data Memory. 33 input or output pins. 20 MHz operating speed(200 ns instruction

cycle) High performance RISC CPU.

PIC 16F877 44

Only 35 simple word instructions. Power on Reset (POR). Power-Up Timer (PWRT) and oscillator start-up

timer. Wide operating voltage range (2.0 – 5.56)volts. Low power consumption .

46 PIC 16F877

A PIC CPU consists of several sub units such as instruction decoder, ALU, control unit, etc.

It normally supports Reduced Instruction Set Computer (RISC) architecture. RISC Architecture has only 35 instructions. The execution time is very less 5 MIPS(Million Instructions per second)

As like normal microcontrollers, the PIC chip also has certain amount of RAM, ROM, EEPROM, other flash memory, etc.

8 KB of FLASH Program Memory. 256 bytes of EEPROM Data Memory.

ALU normally performs all the arithmetic operations. One of the operand is normally in W-Register and second operand can be in any other register.

Address Bus- 13 Bit Data Bus- 8 Bit

When the power supply drops below a certain voltage(4 v in case of PIC),it causes PIC to reset.

The Reset function will set the Program counter to the starting address.

A special timer that delay the start of program execution after the PIC has been reset on power. This time delay allows VDD to rise to the required level.

A watch dog timer is a simple timer circuit that performs a specific operation after a certain period of time if something goes wrong.

Suppose we have written a program which is compiled successfully and when we simulate it every time seems to work fine.

Then we program the PIC. However after a long period of time the program

gets stuck somewhere . What needs it this case is some kind of reset if

the program is gets stuck.54

This is a purpose of a watchdog timer circuit. When the WDT is enable, a counter starts at 00 and

increment by 1 unit until it reaches FF. When it goes from FF to 00 the PIC will be reset,

irrespective of what it is doing. The only way we can stop the WDT, from resetting

the WDT back to 00 throughout the program which is done by the processor.

Which indicates that the processor functioning is going on.

Watchdog timer is thus increases the system reliability.

PIC 16F877 55

It is similar to Accumulator in 8051. It is an 8 bit register. It is only used for ALU operation.

Status register is an eight bit register that contains the arithmetic status of the arithmetic logic unit (ALU), the reset status and the bank select bits for the data memory. The detailed explanation of status register is given below.

Carry bit(C) When two 8-bit operands are added ,a 9 bits result

occurs,Because the result of addition may exceeds 256(FFH).

The 9th bit is copied in the Carry bit.

57 PIC 16F877

Bit 0 (C): Carry/borrow bit (ADDWF, ADDLW, SUBLW, SUBWF instructions)

1 = A carry-out from the Most Significant bit of the result occurred

0 = No carry-out from the Most Significant bit of the result occurred.

Digit Carry This bit indicates a Carry from the lower 4

bits.During 8 bit addition. If set,it means there is a carry from the 3rd bit to 4th

bit position. (1 = A carry-out from the 4th low order bit of the

result occurred 0 = No carry-out from the 4th low order bit

PIC 16F877 58

Many arithmetic and logic instructions affect the zero flag.

if result is zero, Zbit is set, otherwise cleared. Bit 2, (Z): Zero bit

1 = the result of an arithmetic or logic operation is zero

0 = the result of an arithmetic or logic operation is not zero.)

PIC 16F877 59

Used along with the SLEEP mode of PIC.During the sleep mode the microcontroller save lots of power. After coming out of this mode, the CPU can check these two status bits to determine which kind of event is responsible to bring it out of the SLEEP modeBit 4, (TO): this is a time-out bit used for timing and counting, sleep and reset functions. 1 = after power-up, CLRWDT instruction 0 = A WDT time-out occurredBit 3, (PD): Power-down bit1 = after power-up or by the CLRWDT instruction0 = by execution of the SLEEP instruction

There are four memory banks ,each of 128 bytes in size.

For bank selection 2 bits are needed, making the effective address 9-bit wide.

Microchip has provided only direct addressing mode for the register file with 7-bits address plus remaining 8th and 9th bits frozen in the STATUS REGISTER bits RP1:RP0.

11 = Bank 3 (180h-1FFh) 10 = Bank 2 (100h-17Fh) 01 = Bank 1 (80h-FFh) 00 = Bank 0 (00h-7Fh)

62 PIC 16F877

63 PIC 16F877

IRP bit is used for indirect addressing. The IRP bit allows selecting either 1= Bank 2 & bank 3 0= Bank 0 & bank 1 The IPR bit and FSR decide the effective 9 bit

address.

64 PIC 16F877

65 PIC 16F877

FSR is the pointer used for indirect memory addressing in the whole register file.

In PIC every instruction that can be used for direct addressing may also be used in a different way for indirect addressing.

The only difference in indirect addressing mode is that one has to write the address byte in FSR .

66 PIC 16F877

Different from the program counter. Any write to PCL will cause the contents of

PCLATH to be transferred to the 13 bit PC higher locations.

67 PIC 16F877

PIC 16F877 series normally has five input/output ports.

They are used for the input/output interfacing with other devices/circuits.

Most of these port pins are multiplexed for handling alternate function for peripheral features on the devices.

The PIC 16F877 chip basically has 5 input/output ports.

PORT A PORT B PORT C PORT D PORT E 68

A PIC microcontroller is an amazingly powerful fully featured processor with internal RAM, EEPROM FLASH memory and peripherals.

We can use it to control our projects (or build projects around it).  So it saves us from building a circuit that has separate external RAM, ROM and peripheral chips.

In fact PIC has an amazing number of internal peripherals. These are divided in several categories:

Communication peripherals:• RS232/RS485• SPI• USB• Radio Frequency• TCP/IP• Ethernet• CAN( Controller Area Network)• LIN( Local Interconnect Network)

Control and Timing Peripherals:Capture/ComparePulse Width ModulatorsCounters/TimersWatchdog Timers

Display Peripherals:LED driversLCD drivers

Analog Peripherals:Up to 12 bit A-D convertersComparators and Op-AmpsBrown-Out DetectorsLow voltage DetectorsTemperature sensorsOscillatorsVoltage referencesD-A ConvertersVoltage Regulators

Mainly 3 Interrupt Sources : External Interrupt–Due to external source.

Edge Sensitive RB0/INT causes this interrupt.This interrupt wakes up processor from SLEEP.This must be set before going into SLEEP mode.

Timer 0–Timer 0 overflow. FF to 00 overflow. Port B Change Interrupt–A change from high

to low or low to high on port B pins RB4 to RB7 causes this interrupt. This interrupt can wake device from SLEEP.

TIMER 0 8 Bit wide with an 8 bit prescaler. Clocked internally by system clock which

is Fosc/4 or by external clock on RA4/TOCKI.

It generates an interrupt on overflow when the count goes from 255 to zero.

Timer 0 always synchronizes the input clock (when using external clock).

We can read and write timer 0 but can not read the prescaler.

The prescaler changes its effect depending on whether it is a timer prescaler or a watch dog prescaler - so the same prescaler setting may prescale by 2 or by 1 depending on its use.

TIMER 1 This is a 16 bit timer that generates an

overflow interrupt when it goes from 65535 to zero.

It has an 8 bit programmable prescaler and you can  drive it from the internal clock (Fosc/4) or an external pin.  

This timer can be used in sleep mode and will generate a wakeup interrupt on overflow.  

Timer 1 is also read by the CCP module to capture an event time.

Using this timer in sleep mode will use more current.

TIMER 2 This is an 8 bit timer with an 8 bit

prescaler and an 8 bit postscaler. It takes its input only from the internal

oscillator (Fosc/4). This timer is used for the timebase of a

PWM when PWM is active. It also has a period register that allows

easy control of the period When timer 2 reaches the PR2 register

value then it resets. This saves having to check the timer

value in software and then reset the timer and since it is done in hardware the operation is much faster.

In Circuit Serial Programming:It allows microcontroller to be programmed after being placed on a circuit board, offering tremendous flexibility, reduced development time, increasing manufacturing efficiency and reducing cost.

Self Programming:Self programming enables remote upgrades to the Flash memory. It allows for easy code revisions in the end user applications.

One Time Programming:These are manufactured in high volumes without specific software and provided immediately for custom programming.

12, 14 and 16 bit wide instructions are upward compatible and provided to maximize efficiency and boost the performance.

Instruction and Data are transferred on separate buses avoiding, processing bottlenecks and increasing overall system performance.

Two stage pipelining enables one instruction to be executed while the next instruction is fetched.

Single wide word instructions increase software code efficiency and reduce required programming memory

With only 33 – 79 instructions, Programming and Debugging tasks are easy to learn and perform.

Devices with self write options have the ability to remotely program and upgrade the MCU application in the field ( Flexible Flash program Memory).

Low power capability. Extremely Rich Peripheral set. Optimal Cost to performance Ratio. Data EEPROM is also available for those

applications which require secure, non volatile memory for data that changes frequently.

PIC microcontroller is very popular. It is used in variety of applications at each level.

Consumer level Motion detectors Remote controls Rice cookers Battery management Smoke detectors Toys

In Communication Telephone handset Microphone control UART Replacements

Industrial applications Utility metering Portable instruments Data acquisition Motor control: Stepper, Fan,

Brushless DC, AC inductance, Switched reluctance

Automotive applications Light Dimmers Intelligent sensors Proximity detectors Keyless entry Tire pressure monitors Dash Controllers Seat Controllers In Appliances Refrigerator control units Smart relay Delay Timers Temperature Sensors

THANKS