http://en.wikibooks.org/wiki/Embedded_Systems/PIC_MicrocontrollerEmbedded Systems/PIC MicrocontrollerFrom Wikibooks, the open-content textbooks collectionManufactured 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.
[edit] HistoryA 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 [edit] Which PIC to UseHow do you find a PIC that is right for you out of nearly 2000 different models of PIC microcontrollers? 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. [edit] Recommended "first PIC"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.
PIC: Select a chip and buy one. Many people recommend the following PICs as a good choice for the "first PIC" for a hobbyist:
Of the many new parts Microchip has introduced since 2003, are any of them significantly better for hobbyists in some way than these chips ? There are several different "families": [edit] More selection tips
PIC10F -- in super-tiny 6 pin packages PIC12F -- in tiny 8-pin packages PIC14F PIC16F PIC18F dsPIC30F
Each family has one "full" member with all the goodies and a subset
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. 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 And then each different package, for each member of each family, comes in both a "commercial temperature range" and a "industrial temperature range". [edit] PIC 16xThe 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:
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. [edit] PIC 12xThe 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 [edit] PIC 18xThe 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 ). [edit] The PIC StackThe 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. [edit] What else do you need[edit] Compilers, AssemblersVersions of BASIC, C, Forth, and a few other programming languages are available for PICmicros. See Embedded Systems/PIC Programming. [edit] downloadersYou 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 . [edit] Power SupplyThe 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] [edit] Pin Diagrams[edit] Oscillator CircuitsThe 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 syncrhonize other hardware to the same clock as one PIC's internal one. [edit] programmingContinue with Embedded Systems/PIC Programming. [edit] Further reading
|
