As yet there are only a few questions, fewer answers, and no structure, And a lot of [parts in brackets] that need elaboration. But everything needs a start.
This text is copyrighted by me. Unaltered reproduction in any form is allowed, but I prefer that you don't reproduce it on your website, please use a link instead. Use it at your own risk; I do not accept responsibility for it.
You can contribute by emailing Q&A's to me. If you post them on the PICLIST I might pick them up too.
Wouter van Ooijen wouter@voti.nl
todo: crystal connections, MCLR circuit, ICSP isolation, LVP/HVP
1. What is the meaning of a PIC type number?
2. What is a PIC?
3. What is the best PIC to start with?
4. Is the PIC 16F628 a better choice than the 16F84?
5. What's the difference between the * and *A (for *=16F84, 16F628, 16F877 etc)?
6. Why do I need ICD?
7. Why do I need ICSP?
8. What's a simulator, vs. an emulator?
9. What is the best PCB layout program?
10. What is the best PIC programmer?
11. What is the minimum I need to get started?
12. Do I need a logic analyzer?
13. Do I need an oscilloscope?
14. Where are good places to get PCBs fabricated?
15. How can I fabricate my own PCB?
16. Can I do SMT without a bunch of $$?
17. Should I use assembler, a compiler, or an interpreter?
18. Which compiler is recommended?
19. Do I really need decoupling caps?
20. Where can I get a GCC for PICs?
21. Where can I get a 40 MHz crystal or resonator to run my 18F chip at full speed
22. What are the differences between the 16F628 and the 16F628A/16F648A?
1. What is the meaning of a PIC type number?
The main type number of a PIC consist of PIC or dsPIC followed a two-digit number, some letters,
and then a two or three digit number (example: PIC16F628).
The PIC/dsPIC prefix is often left out.
Next there can be a letter (A, B etc) indicating a revision,
an/or a letter T indicating that the chips are on a tape (SMD only).
This can be followed by a dash followed by a two-digit number and/or
a letter that indicates the temperature range.
Finally there can be a slash followed by a packaging indication.
The first number can be 12, 16, 17, 18 or 30.
30 is for the 24-bit core dsPIC's.
18 is for PICs with a 16-bit core, 17 for PICs with different 16-bit core,
12 is for other PICs with 8 pins, and 16 is for all the rest.
The 12 and 16 prefixes are used for both PICs with 12-bit and 14-bit cores.
The letter can be C or F, with some additions.
C is for OTP (One Time Programmable) PICs, the F is
for Flash (electrically reprogrammable) types.
The 16C84 is an exception: it is EEPROM based,
which is in practice the same as Flash based, yet it has a C in its typenumber.
CR (instead of just C) indicates a ROM (factory programmed) chip.
CE indicates a C-type chip with a separate EEPROM chip in the same package.
An L can be added to idicate a low-voltage chip.
Such chip can operate on lower voltages than their normal brothers,
but often (always?) have a lower maximum clock frequency.
To summarise the letter code:
If there is any structure in the last number I have not grasped it yet.
There are some oddbal chips that do not fit the above structure,
like the PIC14000 (called a mixed-signal PIC because it has some analog functions)
and the PIC16HV540 (which has a build-in voltage regulator).
If you think this numbering scheme so far is totally weird I am with you.
The last parts are somewhat better.
The above number is followed by a dash and a frequency and/or temperature
range indication, but only when this is relevant (that is, when
the PIC is available in different maximum clock frequencies or
in different temperature ranges). The frequency is indicated by a two-digit
number expressed in megahertz (I have only seen 04 and 20), the temperature
range by the letter I (industrical) or E (Extended).
When a chip is available in [add packaging info].
2. What is a PIC?
(from http://www.voti.nl/swp)
PIC is also the abbreviation of Peripheral Interrupt Controller - but that's
an entirey different story.
3. What is the best PIC to start with?
That (of course) depends on your objectives.
The 16C84 was the first PIC that could be re-programmed electrically.
It is no longer made, but its direct successors (16F84 and 16F84A) are.
There are countless webpages and other documents about starting with the 16C84/16F84/16F84A
(collectively desigated as 16x84), which can make it a good choice to start with.
In that case take a 16F84A, it is the latest and cheapest version of this group.
When you are after a cheap PIC that can be used for small projects the 16F630 should be
your pick. It has only 14 pins (the 16x84 has 18), but it can be used with its internal
oscillator and internal reset, bringing the number of useable pins to 12 (13 on the 16x84).
For a realy small project you could consider the 12F629 or one of the newer 8 or even 6 pin chips.
Note that both chips have a slightly higher priced version that includes A/D.
Technically the 16F628 is the successor of the 16x84, and untill the arrival of the
16F877, the 16F630 and the smaller 18F's it was the logical choice as first PIC.
It is still the first choice if you want to port a 16x84 project to a modern (cheaper) PIC.
Untill the arrival of the 18F's the 16F877 and its smaller derivates were the best choice
for a PIC to do development work (lots of pins, large code space, lots of RAM).
I would still recommend to start with one of these when your final aim is
one of the other (smaller) 16F PICs. Note that there are now never versions of
these chips with an A suffix. These are improved and cheaper, but use
a different programming algorithm, so check whether your programmer and/or PC software
supports them.
If you want to get into PICs with the least hassle
(especially when you want to use assembler) I would recommend to start
with an 18F. These chips use a newer CPU core, run faster, have more memory, peripherals, etc
than the 16F's and are priced only slightly higher. The 18F4520 would be a good
starting point. Like the 16F877 it has a range of smaller cousins which
you could consider for your project when it is finalised.
Some say that this line of reasoning (start with a big chip so you won't be
tied down by lack of CPU power, memory, pins, peripherals, etc) should be taken
to the extreme, so you should start with one of the dsPIC30F chips. Personally
I disagree: the dsPICs are not closely related to the other PICs
(so experience with them is not much help when you wnat to use other PICs lateron),
and when you need that kind of chip (in terms of CPU power, memory, etc) you should
seriously consider another familiy of microcontrollers. My suggestion would be ARM,
for instance one of the Philips LPC chips.
4. Is the PIC 16F628 a better choice than the 16F84?
If it is your first PIC, refer to "What is the best PIC to start with?".
If not, you should by now be able to be your own judge :).
5. What's the difference between the * and *A (for *=16F84, 16F628, 16F877 etc)?
The *A is the newer version of the *.
For some chips there might even be a *B version.
In most cases you will be able to use the *A chip instead of the *, but
you'd better check the document that describes the differences.
Go to the page on Microchips website that describes the newer chip,
and get the 'migration' document.
Watch out: the 16F87*A chips use a programming algorithm that
is very different from the 16F87* chips, so unless your programmer / PC software
explcitly supports the 16F87*A chips you will probably not be able to program them.
6. Why do I need ICD?
ICD = In Circuit Debugger
Maybe you don't. Personally I seldom use an ICD. But I am the type that does
not us a debugger for a PC program either.
But an In Circuit Debugger can be very handy when you want to run a program
up to some breakpoint and then check the values of various memory locations.
You can of course use a simulator (for instance the one build into MPLAB), but
that has its limitations (not all peripherals are simulated, timing is different,
and it is unlikely that the non-PIC part of your design is simulated).
Microchip sells the ICD and the ICD2, and there are various clones of these two
on the web, both commercial and do-it-yourself. These ICDs do have some quircks,
but they are supported by MPLAB, the firmware can be updated, and Microchip
keeps adding support for new chips.
7. Why do I need ICSP?
ICSP = In Circuit Serial Programming (sometimes: ICP = In Circuit Programming)
The Serial part is not so important, except that it puts less constraints on
your target circuit than the alternative (parallel). The important point
is In-Circuit.
Because you will quickly be tired of getting your PIC out of the target circuit,
into the programmer, do the programming, back into the target circuit, and resetting it.
And you will probably break some pins of your precious PICs. Or do you have ZIF sockets
in both your programmer *and* your target circuit?
The only reasons I found for using ex-circuit programming are series production of
programmed PICs, and the devlopment of software that targets lots of different chips
(like when you are developing your own programmer).
8. What's a simulator, vs. an emulator?
A simulator is a program that runs on your PC which contains a
model of the PIC (or another simulated controller) in the PC's software.
The behaviour of the chip is simulated from clock cycle to clock cycle
according to the intended functioning of the chip.
An emulator is a small circuit board which contains one or more components
which electrically mimic the chip, while built-in sensors allow you to peek
into its internal workings.
This circuit board is often supplied with a PIC-shaped plug on the end of a
ribbon cable, which you can actually plug into the intended circuit.
The advantage of simulators is that they're cheap to produce (a copy of a program),
and that you can see everything hapenning inside the logical model of the chip,
as all its working features are contained in the simulator's structure.
Finding out the content of a register at any cycle is not much more
complicated than a printf() statement.
on the downside, simulators don't tell you anything about the electrical
interaction between the chip and the circuit it sits in.
Emulators are great for giving you a good idead (not perfect, mind you)
of how the chip will behave inside the circuit, with all those bits of
unexpected non-ideal behaviour that make electronics interesting.
On the down side they're much more expensive to make, may require
special interface hardware, and it's harder to get the information
about what's happening inside the chip out to the PC.
9. What is the best PCB layout program?
A question that contains 'best' is suspect, especially when no constraints are given.
There are many layout programs available.
From heresay it seems that *all* have a steep learning curve, so don't expect
to get a good picture after a few hours of trial.
[Eagle]
10. What is the best PIC programmer?
That depends on you, especially on your time/money balance.
To start with the cheapest: check the $ic-prog and $pony-prog programs.
They support many types of cheap hardware that you can build yourself.
In most cases it will even work.
[Wisp628]
[Warp-13]
[PicAll]
[PS+]
11. What is the minimum I need to get started?
Picstart Plus is good in that it will usually be the first programmer
to support new devices. Not the cheapest but wil probably save you
hassle in the long term.
Actually I suspect this will be overtaken by the ICD2 in being the first to
support new devices. See the recent discussion on the new menu selections in
MPLAB6.30 for flash updating the PS+ which you cannot yet do until a new
hardware attachment is made available. Also the ICD2 allows in circuit
debugging, for about the same cost as a PS+, and will run off a USB port,
which may be important for folk with new machines without built in serial
ports.
12. Do I need a logic analyzer? [needs an answer...]
13. Do I need an oscilloscope?
I developed a compiler for PICs without even using a multimeter, but I am crazy.
If you can afford to buy a scope do get one, even if it is only an old 1 MHz valve model.
In most cases two (or more!) channels is much more important than a higher
bandwidth.
14. Where are good places to get PCBs fabricated?
[Olimex]
15. How can I fabricate my own PCB?
Yes (see www.electricstuff.co.uk/pcbs.html)
There is no 'best' - there are many choices depending on your needs,
preferences and budget.
But point them at Eagle and any other easy to use low cost ones.
16. Can I do SMT without a bunch of $$?
Yes. Opinions vary on what you need. My choice would be a good bright light,
a magnifier and a small tipped iron,
plus a pair of tweezers, preferably the "normally closed" type, and some
very fine (26awg) solder.
Some others prefer a broder blade-type solder to drag components to their place.
If you are short-sighted you might want to take your glasses of for visual inspection :)
17. Should I use assembler, a compiler, or an interpreter?
All three alternatives are in widespread use, so don't expect a simple answer.
An assembler programmer can, given sufficient time,
always make his program smaller, faster, etc. than a programmer that uses C
or another high level language.
An HLL (High Level Language) programmer can, given a fixed amount of time, realise
much more functionality than an assembler programmer will be able to do.
A programmer that uses an interpreter that offers intrinsic functions that match the
task at hand will probably outperform a programmer that uses a compiled language.
The above can be influenced a lot by existing experience or the availability of re-useable code.
My personal opinion is that when you are either new to programming and want to start with
embedded programming, or you want to finish a specific project in the shortest time your best
choice is an interpreter or a HLL, but only when the tool provides a suitable (for your
project) set of intrinsic functions or libraries.
When you choose this option you are not realy programming the PIC but rather programming
the abstraction presented to you by the programming envrironment
When you are a more experienced in programming, want to do more than one project, and/or
value the learning experience, you should use a compiler. The available libraries are now
less important because you will develop your own set, and probably will enjoy doing so.
Even when you don't want to learn the PIC assembly language you will still have to learn
the nitty gritty details of your chip (timers, A/D, UART, I2C, PWM, etc) to make the most of it.
For some time-critical things you might have to use in-line assembly.
And knowing the PICs instruction set can help you even when you use a HLL,
for instance to write more efficient code or to hunt a bug that turns out to be a compiler bug!
When you are more familiar with assembler than with a HLL, or you want to
things with a PIC that other people though realy impossible the assembler will be your tool.
But if you fall into this category you are unlikely to need my advice anyway.
In any case, don't let anyone frighten you away from at least trying all options.
And take a look at a typical datasheet (16F877A): it is some 300 pages in all,
of which the assembler instructions take only 10 pages! OK, some
aspects of the CPU are described elsewhere (for instance indirection), but
PIC assembler is realy quite simple. But that is not the same as simple to use.
18. Which compiler is recommended?
[Jal]
19. Do I really need decoupling caps?
Probably (let's say 9 out of 10 times) no.
Do you need to look right and left to survive crossing a quiet street?
Probably not. Is that sufficient reason not to?
For those who don't get the point I also give the management summary: YES.
If your chip has multiple power and/or ground pins be sure to connect them all.
If the manufacturer pairs these pins it is much recommended to put a decoupling capacitor
on each such pair. And a decoupling capacitor should always be as close to the pins as possible.
On a solderless breadbord this might not look pretty, but if aesthetics are important
to you PICs might not be an appropriate hobby anyway.
The most common value for a decoupling capacitor these days is 100 nF for the capacitors
close to a chip, and a 10 .. 1000 uF elco somewhere on each PCB
(let's no further than 10cm from each chip).
The value of this elco depends on the lower-frequency variations of the current
your board draws. For most microcontroller applications 22uF will be fine.
20. Where can I get a GCC for PICs?
(from http://www.voti.nl/swp)
21. Where can I get a 40 MHz crystal or resonator to run my 18F chip at full speed
There are two ways to run an 18F at full speed, but neither involves a 40 MHz crystal or resonator.
The first way is to use an external 40 MHz oscillator,
feed the oscillator output to the OSC1 pin, and configure the chip for EC or ECIO mode.
The second way is to use a 10 MHz crystal or resonator with the internal multiply-by-four PLL
(HS4 mode).
22. What are the differences between the 16F628 and the 16F628A/16F648A?
[Maarten Hofman on the PICLIST]
The differences that I have noticed are:
Note that most of these differences are either advantages or are really obscure. If your
programmer can support it, using the 'A' part is the wiser choice,
and the 16F648A price is about the same as the 16F628 price, which is
slightly higher than the 16F628A price.
A long, long time ago (when computer chips died when a cat came near on a dry day)
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.
As far as I know Microchip has never used PIC as an abbreviation, just as PIC.
And recently Microchip has started calling its PICs microcontrollers PICmicro MCU's.
Maybe they heard that PIC sounds like the Dutch word for dick and wanted to spare me
the frowns from Dutch readers.
There is no GCC port for PICs,
and it is not likely that one will ever exist. The assumptions made
by GCC about the target CPU architecture are reasonable for almost all CPU's
that can be found in the world (including AVR, 8051 and 68HC microcontrollers),
but definitely not for PICs.
There is at least one attempt to create a free C compiler for PICs (based on SDCC),
but at this moment (2002) no useable product is available.
1) there are programmers (like the El Cheapo) that can program the
16F628, but not the 16F628A/16F648A, even with modern software.
2) Some revisions of the 16F628A/16F648A suffer from a bug that
requires you to basically halt your program while writing to the
EEPROM memory. This is rarely an issue, as most of the time you'll be
waiting for it to finish anyway.
3) The 16F628A is cheaper and can be interchanged for the 16F648A with
very little effort (the 16F648A is about the same price as the 16F628,
and therefore a good deal, unless your design states you don't need
the additional 2KWord).
4) Some mode bits have changed (ER -> RC, BOD -> BOR, PWRT can be
controlled separately, INTRC is called INTOSC, only one CP bit).
5) The Timer1 oscillator has been limited to 32.768 kHz, instead of
anything up to 200 kHz.
6) The dual speed oscillator no longer works in ER mode.
7) The 16F628A/16F648A consumes a lot less power.
8) All versions of the 16F628A/16F648A can handle 20 MHz. With the
16F628 there are different versions for different frequencies.
>BR>9) The 16F648A also has more data memory (256 instead of 224) and
more EEPROM memory (256 bytes instead of 128 bytes). However, these
are still not significant changes from the 16F628A, so my list of
changes should still work fine.