8
\$\begingroup\$

I am using the PIC16F690 and I know that the internal oscillator has certain values (20,8,4...).

I would like to put an external 8MHz crystal, but I could find only 8.8MHz or 7.6MHz.

I would like to know if it's possible to put any of these to the PIC, or must it be exactly 8MHz? Also, how should I choose the capacitors for each?

\$\endgroup\$
10
\$\begingroup\$

You can use any crystal so long as it is within the frequency range that the PIC crystal driver is specified for.

The crystal driver of most PICs (I didn't look up your PIC specifically, that's your job) can be set to three different drive levels, usually called LP (low power), XT (crystal), and HS (high speed). The slower ones use less power but also have a lower maximum crystal frequency they can support. HS mode might overdrive and damage sensitive low frequency 32768 Hz crystals, like are used in wrist watches. Together the three crystal drive levels cover the range from a few 10s of kHz to 20 MHz, which is the fastest that PIC can be driven at anyway.

Another point is that you want to use a crystal specified for parallel resonance application. That means its frequency is specified for the way the PIC crystal driver will drive the crystal. These crystals will be specified with a load capacitance. Series resonant crystals will work, but the frequency probably won't be within tolerance.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks a lot . my problem was that internal oscillator gave me 0.47us instruction clock instead of 0.5us - for the 8mhz. so i guess an EXTERNAL oscillator will be more accurate. is that true? another thing, i could not understand how to set the fuses for that f ? \$\endgroup\$ – Curnelious Oct 10 '13 at 14:05
  • 4
    \$\begingroup\$ @Curn: Yes, a external crystal will be more accurate than the internal oscillator. Even cheap crystals are good for 50 ppm, and 20 ppm is usually available for not too much more money. As for the config settings, these are all well described in the datasheet. For a 8 MHz crystal, you will want to use HS mode. \$\endgroup\$ – Olin Lathrop Oct 10 '13 at 14:24
8
\$\begingroup\$

Assuming you don't exceed the clockrate spec in the silicon, programmed fuses, and application code, you can use any crystal you like. The datasheets will explain which capacitors to use.

| improve this answer | |
\$\endgroup\$
  • 3
    \$\begingroup\$ It's worth noting that changing the clock rate will also change the calculations for things like baud rate and interval timers. It seems obvious, but it's easy to forget. \$\endgroup\$ – Scott Winder Oct 10 '13 at 13:05
  • \$\begingroup\$ @Scott: Only if you write irresponsible code with baud rate divisors and the like hard-coded. With proper coding, you change one number that is the oscillator frequency and everything is automatically derived from that at build time, with of course error checking for impossible or out of range cases. You are right in that you do have to remember to change the one number though. \$\endgroup\$ – Olin Lathrop Oct 10 '13 at 18:17
  • 1
    \$\begingroup\$ @OlinLathrop: I agree with you in the case of slight changes in frequency. However, drastic frequency changes may require a modification to the pre- and/or post-scalar of a baud rate generator in order to keep the intermediate frequencies within the recommended range. On the timer side, some switches in clock frequency can result in overflows and any different frequency will give you a different clock resolution, so modifying the timer counts (using a frequency macro) is only part of the solution. The timer clock may also need to be modified to attain the required accuracy and length. \$\endgroup\$ – Scott Winder Oct 10 '13 at 18:41
  • 1
    \$\begingroup\$ @Scott: But that's all stuff that is either calculated at build time or at least checked. If you hard-code something like a prescaler (usually not necessary) and the new instruction frequency doesn't support what you want to do, then the build-time code will throw a error to alert you. If it can handle it, it silently does so. There is no excuse for a frequency change to silently cause a problem. That's just bad coding. \$\endgroup\$ – Olin Lathrop Oct 10 '13 at 18:47
  • \$\begingroup\$ @OlinLathrop: I don't disagree. I'm just pointing out that it's not always as easy as changing a single number, even in the case of good coding. In any case, it's something to watch for when changing the frequency. \$\endgroup\$ – Scott Winder Oct 10 '13 at 18:50
0
\$\begingroup\$

As the datasheet said, you can to use up to 20Mhz oscillator. For capacitor the datasheet can say to you that use of what type of those but for amount of capacitor you should use of your experience.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ While "experience" is always a good thing, but the required load capacitance depends on the crystal and should be specified in the crystals data sheet. This has to do with the parallel resonance frequency. Also, stray capacitance from the uC pins and traces should be taken into account. \$\endgroup\$ – Rev1.0 Oct 11 '13 at 6:40
  • \$\begingroup\$ @Rev1.0 Great and thanks! i voted to you. for example i saw this datasheet:html.alldatasheet.com/html-pdf/236074/CRYSTEKCRYSTAL/CYSDXX/… at the right of it you can see a table(Standard part number). should i use of it for choose the capacitor? for example for 16mhz should i use 20pf capacitor? \$\endgroup\$ – Roh Oct 11 '13 at 7:27
  • 1
    \$\begingroup\$ No, the given load capacitance is the total capacitance required, not the value for the both capacitors. Calculate CX = 2*(CL - Cstray), where CX is the capacitor you need, CL=20pf and Cstray depends on your design (around 2-5pf). \$\endgroup\$ – Rev1.0 Oct 11 '13 at 9:51
  • 1
    \$\begingroup\$ Cstray is the capacitance of the micro controller pins (data sheet) + the parasitic capacitance of the traces on your board (can be approximated knowing length, width and layer of the traces). If this is just for a hobby project assume 5pf and be probably fine. \$\endgroup\$ – Rev1.0 Oct 11 '13 at 10:38
  • 1
    \$\begingroup\$ Read and understand this :). "If Cin and Cout are not specified, then a guess value of 5 pF for each is a good start." \$\endgroup\$ – Rev1.0 Oct 11 '13 at 11:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.