Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC Oscillator Crystal

Status
Not open for further replies.

hugoender

New Member
I am new to PICs and have seen some tutorials include external crystal oscillators without explaining why or how they chose the frequency.

I would like to know how you decide what oscillator frequency you need and how the oscillator affects your circuit. I know this is a very general question and it depends on what you are trying to make/do but if you guys could provide some examples where you might need an external crystal oscillator, why you need it, and how you decide the oscillator frequency I would greatly appreciate it.

I did a search through the forums and found a post about assembly instructions taking 4 clock cycles. Does that mean that instructions can be carried out faster with a higher oscillator frequency?

For example:
4MHz Oscillator: Period (clock cycle) = 1/4MHz = 250ns; 1 instruction = 4 clock cycles = 1us

20MHz Oscillator: Period (clock cycle) = 1/20MHz= 50ns; 1 instruction = 4 clock cycles = 200ns

Is this correct? I would greatly appreciate any examples where certain frequencies are required or additional information on oscillators and their function in PIC circuits.
 
I am new to PICs and have seen some tutorials include external crystal oscillators without explaining why or how they chose the frequency.

I would like to know how you decide what oscillator frequency you need and how the oscillator affects your circuit. I know this is a very general question and it depends on what you are trying to make/do but if you guys could provide some examples where you might need an external crystal oscillator, why you need it, and how you decide the oscillator frequency I would greatly appreciate it.

I did a search through the forums and found a post about assembly instructions taking 4 clock cycles. Does that mean that instructions can be carried out faster with a higher oscillator frequency?

For example:
4MHz Oscillator: Period (clock cycle) = 1/4MHz = 250ns; 1 instruction = 4 clock cycles = 1us

20MHz Oscillator: Period (clock cycle) = 1/20MHz= 50ns; 1 instruction = 4 clock cycles = 200ns

Is this correct? I would greatly appreciate any examples where certain frequencies are required or additional information on oscillators and their function in PIC circuits.

hi,
The frequency of the crystal osc is divided by 4, this means a 4MHz xtal would give a PIC instruction
execution time of 4MHz/4 = 1uSec.

The usual range of xtal frequencies are 4, 6,8,10MHz.
If you were going to decide to use the PIC as a RTC or Timer, a 3.2768MHz xtal would be a good choice
as its divides nicely down to 1 sec.

The PIC that you use will determine the maximum xtal frequency that can be used.

Some PIC's have an internal PLL which can increase the frequency of the external xtal,
so for example a 10MHz clock could use the PLL to give an internal frequency of say 40MHz.

Does this help.?
 
Last edited:
Also, most of the newer pics have an internal oscillator that runs at 4 or 8MHz that is accurate to 1%. This is normally accurate enough for all things except clock type applications.

Mike.
 
I have a question that might be relavent to this thread.

I'm going to use a PIC (18LF4620) at 3.3V for the first time, what is the max frequancy I can run it at? I had a look at the equation MC give in the datasheet, but it seems I am missing something as I don't get the same answer they do.

Thanks,
 
Last edited:
I have a question that might be relavent to this thread.

I'm going to use a PIC (18LF4620) at 3.3V for the first time, what is the max frequancy I can run it at? I had a look at the equation MC give in the datasheet, but it seems I am missing something as I don't get the same answer they do.

Thanks,

I calculted a maximum frequency of about 25 MHz @ 3.3 V. That should be correct according to Figure 26-3 in the datasheet. What did you get from your calculations?
 
Might as well add this, as no one else has mentioned it:
The relationship of power and frequency is nearly linear; if you are concerned with power consumption, run your mcu at lower frequency.

You know there is a difference between oscillator and crystal, don't you? A canned oscillator usually is in a square or rectangular package with four pins.
 
I thought that was 32.768 killo, isn't it?

hi BeeBop,
The 32KHz would get the job done but the PIC would be a little slow.:)

The 3.2768MHz divided down in TMR0 and a few TMRO interrupt counts, works OK.
 
Last edited:
hi BeeBop,
The 32KHz would get the job done but the PIC would be a little slow.:)

The 3.2768MHz divided down in TMR0 and a few TMRO interrupt counts, works OK.

Thanks Eric!

I like coming here because I learn new ways of doing things.
 
Best way to do accurate timing is to use the internal oscillator and a 32.768K watch crystal on timer1 oscillator. You get best of both worlds, accurate timing and a fast (or slow if you wish) processor.

Mike.
 
Best way to do accurate timing is to use the internal oscillator and a 32.768K watch crystal on timer1 oscillator. You get best of both worlds, accurate timing and a fast (or slow if you wish) processor.

Mike.
hi Mike,
Using a very similar method [32KHz] at the moment on a RTC with a member.:)
Main xtal is a 3.2768MHz
 
Eric,

If you use a 32.768k watch crystal on Timer1 Oscillator, you can use the internal oscillator at any speed you wish. The watch crystals on timer1 appear to keep much better time and Microchip provide example code in the 16F88 data sheet.

Mike.
 
Eric,

If you use a 32.768k watch crystal on Timer1 Oscillator, you can use the internal oscillator at any speed you wish. The watch crystals on timer1 appear to keep much better time and Microchip provide example code in the 16F88 data sheet.

Mike.

hi Mike,
What we are doing is a 'general purpose' RTC clock hardware design that has the option to use external and or internal timing signals.

Its the got the option of DS1307, ext 1Sec, Rugby radio transmission.
The current clock is a HH:MM:SS mux LED with timed ambient tempr display, using a 1sec source.

Its running on my bench on a project board, I am trying to keep the hardware for the design as versatile as possible. When he makes this version of the clock, he can use the same hardware design for other jobs. [tutorial]

The member I am working with isnt yet savvy with programming, the programs are written in Oshonsoft Basic, so as he learns he can try different techniques himself.[tutorial]

We have chosen the 16F876A for the current range of projects, for the last projects we used the 16F628A

Regards
 
Last edited:
No one has answered if my calculations were correct... also, in layman's terms, what is PLL and is it possible to use the internal and external oscillators? If so, how do you calculate the overall frequency (with both the internal and external oscillators in use). I still have not received my PICkit2 nor my PICs so I have not yet been able to get some hands on experience so excuse me if my questions seem a bit dumb.
 
No one has answered if my calculations were correct... also, in layman's terms, what is PLL and is it possible to use the internal and external oscillators? If so, how do you calculate the overall frequency (with both the internal and external oscillators in use).
PLL is a multiplier for clock rates. You can set it (depending on PIC model) at different multipliers like 4x, 8x, 16x, meaning you multiply the internal or external clock by 4, 8 or 16. For instance, the dsPIC 30F4013 has a 7.37MHz internal clock, but you can PLL multiply it by up to 16x, giving you an effective clock rate of 117.92MHz (just a little below the chip's max of 120MHz).
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top