Choosing your Oscillator mode

You need a clock for your microcontroller. For this I recommend you to refer your datasheet, PIC 16F84A operates @ 1-20MHz. How Crystals and RC Oscillators Work is explained here.

There are four modes for PIC 16F84A

• LP Low Power Crystal

• XT Crystal/Resonator

• HS High Speed Crystal/Resonator

• RC Resistor/Capacitor

Whatever the PIC microcontroller you use there will be 2 pins labled OSC1 and OSC2 to connect your clock.

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: