Which PIC to use?

Fonte: Wikibooks

Long time ago General Instruments produced a chip called the PIC1650, described as a Programmable Intelligent Computer. This chip is the mother of all PIC chips, functionally close to the current 16C54. It was intended as a peripheral for their CP1600 microprocessor. Maybe that is why most people think PIC stands for Peripheral Interface Controller. Microchip has never used PIC as an abbreviation, just as PIC. And recently Microchip has started calling its PICs microcontrollers PICmicro MCU's. Manufactured by Microchip, the PIC ("Programmable Intelligent Computer" or "Peripheral Interface Controller" ) microcontroller is popular among engineers and hobbyists alike. PIC microcontrollers come in a variety of "flavors", each with different components and capabilities.

Many types of electronic projects can be constructed easily with the PIC family of microprocessors, among them clocks, very simple video games, robots, servo controllers, and many more. The PIC is a very general purpose microcontroller that can come with many different options, for very reasonable prices.

Other microprocessors in this family include the Parallax SX, the Holtek HT48FxxE Series, and some "PIC-on-a-FPGA" implementations.

Contents



Which PIC to Use

There are nearly 2000 different models of PIC microcontrollers, although an embedded systems engineer doesn't need to sort through every single model. This section will talk about how to find the PIC that is right for you.

Rule Number 1: only pick a microprocessor you can actually obtain. PICs are all similar, and therefore you don't need to be too picky about which model to use.

If there is only 1 kind of PIC available in your school storeroom, use it. If you order from a company such as http://www.Newark.com/ or http://Digikey.com/ , ignore any part that is "out of stock" -- only order parts that are "in stock". This will save you lots of time in creating your project.

At one time, the PIC16F84 was far and away the best PIC for hobbyists. But Microchip, Parallax, and Holtek are now manufacturing many chips that are even better.


(Summarizing PICList Beginners checklist for PIC Microcontrollers, PIC Elmer 160: Appendix "A": "Other PICs" 2003, and Wouter van Ooijen :)

PIC: Select a chip and buy one.

Many people recommend the following PICs as a good choice for the "first PIC" for a hobbyist:

  • PIC18F4620 -- Wouter van Ooijen recommends that hobbyists use the largest and most capable chip available[1], and this is it (as of 2006-01).
  • PIC16F877A (the largest chip of the 16F87x family) -- Wouter's #2 choice; AmQRP; PICList.
  • PIC16F88 -- AmQRP
  • PIC16F628 -- (better and cheaper than the PIC16F84A, but like it, has no analog inputs) -- Wouter's #3 choice; AmQRP


There several different "families":

  • The "F" Suffix implies that the chip has reprogrammable Flash memory.
 PIC10F -- in super-tiny 6 pin packages
PIC12F -- in tiny 8-pin packages
PIC14F
PIC16F
PIC18F
dsPIC30F


  • The "C" suffix implies that the chip uses EPROM memory. A few of these chips can be erased with an Ultra-Violet eraser. But with most of these chips, once you write it, you can't change it -- it's OTP (one-time programmable).
 PIC12C
PIC16C
PIC17C
PIC18C

Each family has one "full" member with all the goodies, and bunch of variant members that lack one thing or another. For prototyping, we generally use the "full" version to make sure we can get the prototype working at all. During prototyping we want to tweak code, reprogram, and test, over and over until it works. So we use one of the above "Flash" families, not the "OTP" families.

Each member of each family generally comes in several different packages. Hobbyists generally use the plastic dual inline package (often called DIP or PDIP) because it's the easiest to stick in a solderless breadboard and tinker with. (The "wide-DIP" works just as well). They avoid using ceramic dual inline package (CDIP), not because ceramic is bad (it's just as easy to plug into a solderless breadboard), but because the plastic parts work just as well and are much cheaper.

(Later, for mass production, we may figure out which is the cheapest cut-down version that just barely has enough goodies to work, and comes in the cheapest package that has just barely enough pins for this particular application ... perhaps even a OTP chip).

And then each different package, for each member of each family, comes in both a "commercial temperature range" and a "industrial temperature range".

PIC 16x

The PIC 16 family is considered to be a good, general purpose family of PICs. PIC 16s generally have 3 output ports to work with. Here are some models in this family that were once common:

  1. PIC 16C54 - The original PIC model, the 'C54 is available in an 18 pin DIP, with 12 I/O pins.
  2. PIC 16C55 - available in a 28-pin DIP package, with 20 available I/O pins
  3. PIC 16C56 - Same form-factor as the 'C54, but more features
  4. PIC 16C57 - same form-factor as the 'C55, but more features
  5. PIC 16C71 - has 4 available ADC, which are mapped to the same pins as Port A (dual-use pins).
  6. PIC 16C84 - has the ability to erase and reprogram in-circuit EEPROMs

Many programs written for the PIC16x family are available for free on the Internet.

Flash-based chips such as the PIC16F88 are far more convenient to develop on, and can run code written for the above chips with little or no changes.

Is there anything these chips can do that the PIC16F88 can't do better and faster?

PIC 12x

The PIC 12 series are all very small chips, with 8 pins, and 4 available I/O pins. These are used only when space is a huge factor, and the PIC doesn't have many responsibilities

PIC 18x

The PIC 18x series are available in a 28 and 40-pin DIP package. They have more ports, more ADC, etc... PIC 18s are generally considered to be very high-end microcontrollers, and are even sometimes called full-fledged CPUs.

Microchip is currently (as of 2007) producing 6 Flash microcontrollers with a USB interface. All are in the PIC18Fx family. (The 28 pin PIC18F2450, PIC18F2455, PIC18F2550; and the 40/44 pin PIC18F4450, PIC18F4455, PIC18F4550 ).

The PIC Stack

The PIC stack is a dedicated bank of registers (separate from programmer-accessible registers) that can only be used to store return addresses during a function call (or interrupt).

  • 12 bit: A PIC microcontroller with a 12 bit core (the first generation of PIC microcontrollers) ( including most PIC10, some PIC12, a few PIC16 ) only has 2 registers in its hardware stack. Subroutines in a 12-bit PIC program may only be nested 2 deep, before the stack overflows, and data is lost. People who program 12 bit PICs spend a lot of effort working around this limitation. (These people are forced to rely heavily on techniques that avoid using the hardware stack. For example, macros, state machines, and software stacks).
  • 14 bit: A PIC microcontroller with a 14 bit core (most PIC16) has 8 registers in the hardware stack. This makes function calls much easier to use, even though people who program them should be aware of some remaining gotchas [2].
  • 16 bit: A PIC microcontroller with a 16 bit core (all PIC18) has a "31-level deep" hardware stack depth. This is more than deep enough for most programs people write.

Many algorithms involving pushing data to, then later pulling data from, some sort of stack. People who program such algorithms on the PIC must use a separate software stack for data (reminiscent of Forth). (People who use other microprocessors often share a single stack for both subroutine return addresses and this "stack data").

Call-tree analysis can be used to find the deepest possible subroutine nesting used by a program. (Unless the program uses w:recursion). As long as the deepest possible nesting of the "main" program, plus the deepest possible nesting of the interrupt routines, give a total sum less than the size of the stack of the microcontroller it runs on, then everything works fine. Some compilers automatically do such call-tree analysis, and if the hardware stack is insufficient, the compiler automatically switches over to using a "software stack". Assembly-language programmers are forced to do such analysis by hand.

What else do you need

Compilers, Assemblers

Versions of BASIC, C, Forth, and a few other programming languages are available for PICmicros. See Embedded Systems/PIC Programming.

Programmers

You need a device called a "programmer" to transfer compiled programs from your PC and burn them into the microcontroller. (Unfortunately "programming" has 2 meanings. Sometimes "programming" means the overall process of a person writing software on a PC, going through many edit-compile-download-burn-test cycles. Other times "programming" means the specific step of the "programmer" device burning the compiled code into the chip. Please help us make this book less confusing.)

There are 2 styles of programmers. If you have your PIC in your system and you want to change the software,

  • with a "IC programmer" style device, you must pull out the PIC, plug it into the "IC programmer", reprogram, then put the PIC back in your system.
  • with a "in circuit programmer" style device (ICSP), you don't touch the PIC itself -- you plug a cable from the programmer directly into a header that you have (hopefully) placed next to the PIC, reprogram, then unplug the cable.

An (incomplete) list of programmers includes:

Many people prefer to use a "bootloader" for programming whenever possible. Bootloaders are covered in detail in chapter Bootloaders and Bootsectors .

Power Supply

The most important part of any electronic circuit is the power supply. The PIC programmer requires a +5 volt and a +13 volt regulated power supply. The need for two power supplies is due to the different programming algorithms:

  • High Power Programming Mode - In this mode, we enter the programming mode of the PIC by driving the RB7(Data) and RB6(CLOCK) pins of the PIC low while driving the MCLR pin from 0 to VCC(+13v).
  • Low Power Programming Mode - This alogrithm requires only +5v for the programming operation. In this algorithm, we drive RB3(PGM) from VDD to GND to enter the progamming mode and then set MCLR to VDD(+5v).

The circuit can be explained as follows:

  • The Bridge Rectifier converts AC input voltage to full-wave DC voltage. Since we want to keep the heat dissipation to minimum, it is better to keep the input voltage as close to our output voltage, i.e. 13V. Hence the restriction of 15V - 16V on the input.
  • The 7805 voltage regulator maintains a steady +5V which is used as VDD, and provides the VREF for the 7808 voltage reguator.
  • We derive the +13V output by applying +5V as VREF for the 7808 and taking the input from the rectifier. the output is then regulated at 8V + 5V = 13V.

Simple isn't it?

Here is the part list:

  • C1 1 1000uF/25V
  • R1,R4 2 470r
  • C2,C3 2 47uF
  • R2,R3 2 4K7
  • D1 1 7.5V
  • U1 1 7805
  • U2 1 7808
  • D2,D3 2 LED
  • BR1 1 W04

Pin Diagrams

Oscillator Circuits

The PIC microcontrollers all have built-in RC oscillator circuits available, although they are slow, and have high granularity. External oscillator circuits may be applied as well, up to a maximum frequency of 20MHz. PIC instructions require 4 clock cycles for each machine instruction cycle, and therefore can run at a maximum effective rate of 5MHz. However, certain PICs have a PLL (phase locked loop) multiplier built in. The user can enable the Times 4 multiplier, thus yielding a virtual oscillator frequency of 4 X External Oscillator. For example, with a maximum allowable oscillator of 16MHz, the virtual oscillator runs at 64MHz. Thus, the PIC will perform 64 / 4 = 16 MIPS (million instructions per second).

programming

Continue with Embedded Systems/PIC Programming.

Further reading

  • [ht tp://www.geo cities.com/nozomsite Free and Explained PIC microController Projects]

There is a lot of information about using PIC microcontrollers (and electronics design in general) in the PICList archives. If you are really stumped, you might consider subscribing to the PICList, asking your question ... and answering someone else's question in return. The PICList archives are hosted at http://massmind.org/techref/microchip/