Embedded Systems/PIC Microcontroller

< Embedded Systems

Manufactured by Microchip, the ("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.

History

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.

Which PIC to Use

How do you find a PIC that is right for you out of nearly 2000 different models of PIC microcontrollers?

The Microchip website has an excellent Product Selector Tool. You simply enter your minimum requirements and optionally desired requirements, and the resulting part numbers are displayed with the basic features listed.

You can buy your PIC processors directly from Microchip Direct, Microchip's online store. Pricing is the same or sometimes better than many distributors.

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 Newark or DigiKey , 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 and often even cheaper, because of the higher level of production.


  1. I'd like a list of the top 4 or so PIC recommendations, and *why* they were recommended, so that when better/cheaper chips become available, it's easy to confirm and add them to the list.


(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, take in count the revision numbers (like the A in 16F628A):

Of the many new parts Microchip has introduced since 2003, are any of them significantly better for hobbyists in some way than these chips ? Todo: Does "Starting out PIC Programming: What would be a good PIC chip to start out with?" have any useful recommendations to add to the above?

There are several different "families":

More selection tips

 PIC10F -- in super-tiny 6 pin packages
 PIC12F -- in tiny 8-pin packages
 PIC14F
 PIC16F 
 PIC18F
 PIC24F
 PIC24E
 PIC24H
 dsPIC30F
 dsPIC33F
 dsPIC33E
 PIC12C
 PIC16C
 PIC17C
 PIC18C

Each family has one "full" member with all the goodies and a subset of variant members that lack one thing or another. For example, on the 16F84 family, the 16F84 was the fully featured PIC, with Flash memory and twice the program space of the 16F83. The family was also composed by the 16C84 and 16C83, one of the few reprogrammable C suffix PICs. 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, unless required. For short production, the C parts are recommended. For very long production lines some PICs with mask-programmed ROMs where used. Now in-factory preprogramming is available from Microchip.

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.

PIC 12x

The PIC12x series is the smallest series with 8 pins and up to 6 available I/O pins. These are used when space and/or cost is a factor.

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).

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.

downloaders

You need a device called a "downloader" to transfer compiled programs from your PC and burn them into the microcontroller. (Unfortunately "programming" has 2 meanings -- see Embedded_Systems/Terminology#programming).)

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

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:

This is already taken care of inside the PIC burner hardware. If you are curious as to how this is done, you might want to look at the various PIC burner hardware schematics online.[1][2]

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). Certain pics also have built-in oscillators, usually 4Mhz for precisely 1MIPS, or a low-power imprecise 48kHz. This frees up to two I/O pins for other purposes. The pins can also be used to produce a frequency if you want to synchronize other hardware to the same clock as one PIC's internal one.

programming

Continue with Embedded Systems/PIC Programming.

Further reading

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 MassMind

  1. "PIC Microcontroller Programmers"
  2. "Choosing a PIC programmer"
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.