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.

determining what frequency of crystal to use?

Status
Not open for further replies.

bigfarmerdave

New Member
Ok, I'm still learning this micro controller stuff. You all have pointed me in the direction of some very informative reading (which I really appreciate) but I still have a few fuzzy areas that I need cleared up.

In reviewing options, I see that there are a number of solutions to use as a timing circuit for a micro controller. I'm using a PIC16F876 and am wondering what to use as my timing circuit. It looks like a quartz crystal would be a stable solution and appears that it is connected across pins 9 and 10, OSC1 and OSC2 respectively, obviously with some supportive circuitry (caps) as well. My question is, how do you determine what frequency of crystal to use? This particular PIC is rated at 20MHz so I'm assuming I would want to use a 20MHz crystal. What advantage is there to using a lower frequency crystal?

I've read through the PIC data sheets and am trying to get a handle on TIMER0, TIMER1, and TIMER2 as well. It looks like TIMER0 & TIMER1 are software selectable internal or external and that it can be set to Timer Mode or Counter Mode. Timer Mode is incremented with every instruction cycle and Counter Mode is incremented on ever rising or falling edge of the T0CK1 pin. What would be the benefits of each of these modes? I assume that every instruction begins exactly 200 ns after the last one when using a 20MHz crystal?
 
Last edited:
bigfarmerdave said:
I'm using a PIC16F876 and am wondering what to use as my timing circuit. It looks like a quartz crystal would be a stable solution and appears that it is connected across pins 9 and 10, OSC1 and OSC2 respectively, obviously with some supportive circuitry (caps) as well. My question is, how do you determine what frequency of crystal to use? This particular PIC is rated at 20MHz so I'm assuming I would want to use a 20MHz crystal. What advantage is there to using a lower frequency crystal?

You need to use a lower frequency crystal if the operating voltage is lower.

The power consumption is approximately proportional to frequency so a lower frequency will reduce the power.

If you need particular timing, for instance for baud rate generation, frequencies that are a power of 2 multiple of the baud rate can make the frequency division easier. E.g. 38,400 baud * 256 * 2 = 19.6608 MHz

An oscillator can be connected directly to the OSC1 pin and no other components are needed.

bigfarmerdave said:
I've read through the PIC data sheets and am trying to get a handle on TIMER0, TIMER1, and TIMER2 as well. It looks like TIMER0 & TIMER1 are software selectable internal or external and that it can be set to Timer Mode or Counter Mode. Timer Mode is incremented with every instruction cycle and Counter Mode is incremented on ever rising or falling edge of the T0CK1 pin. What would be the benefits of each of these modes?

It is just whether you want to count time from the internal clock or external pulses. The external pulses might represent something other than time or it might be more accurate than the PIC clock. For timing, if the PIC clock is accurate enough for your purposes, use it.

bigfarmerdave said:
I assume that every instruction begins exactly 200 ns after the last one when using a 20MHz crystal?

Yes, except for 2 cycle instuctions like GOTO, CAll etc
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top