Choosing your Oscillator mode
There are four modes for PIC 16F84A
• LP Low Power Crystal
• XT Crystal/Resonator
• HS High Speed Crystal/Resonator
• RC Resistor/Capacitor
I’ve used Crystals and RC, crystal gives you a very accurate clock speed that will not change up to 5 decimals whereas RC is never constant. The capacitance changes in different temperatures. Only advantage using RC is low cost. The clock speed corresponding to the capacitor and resistor you use are shown in graphs of the datasheet.
For time sensitive applications always use a crystal. For crystals you must use capacitors to remove any stray oscillations. The capacitance you need is mentioned in the datasheet of your microcontroller. For crystals of 4MHz and below 4MHz you use the XT mode. For crystals above 4MHz you use the HS mode.
Using a 4 MHz crystal with two 15-33 pF capasitors is appropiate for many applications since PIC microcontrollers are RISC processors and each instruction is excecuted with 4 clock cycles. 4 MHz is 1/4 µs per clock cycle. So for a instruction it takes 1µs. You will see that this becomes very handy in timing.
LP mode is for frequencies below 200kHz. This is the lowest power consumption mode available.
The default mode in PIC microcontroller just came out from microchip factory is RC. So just putting a Crystal won’t work! To get it working you need to set up the configuration bits of the microcontroller. You can’t access these while programming, you can change these only by the programmer you use or in MPLAB IDE when compiling.
To set the Configuration bits with the programmer check for menu for setting the oscillator mode. This changes by programmer to programmer.
To set the configuration bits with MPLAB IDE, Go to the menu Configure -> Configuration Bits -> Untick Configurations Bits set in Code -> change to XT or HS oscillator.
The resonators do the same thing but there was a difference between crystal and resonator apart from accuracy, how they are built, I can’t remember, find out!.
You can use external clocks too, generated by another circuit (by 555 or something). I haven’t used them yet.