Dangerous Prototypes

Other projects => Open Bench Logic Sniffer => Topic started by: rsdio on April 29, 2010, 01:24:49 am

Title: Review: 20 MHz crystal with 27 pF caps?
Post by: rsdio on April 29, 2010, 01:24:49 am
I've done some design with the PIC18, and I'm pretty sure it doesn't like a 20 MHz crystal. The data sheet for the PIC18F24J50 indicates that you can only use 4, 8, 12, or 16 MHz. You should probably change this part in the schematic and parts list (but don't worry, the internal instruction clock can still go to 48 MHz with any of the supported crystals).

The 27 pF capacitor is recommended for a 4 MHz crystal, but the Microchip table suggests 22 pF for 8 MHz and 18 pF for 16 MHz.

P.S. Some of the engineers that I asked recommended an 8 MHz crystal since that matches the default internal clock, so that's what I've always used.  Others recommended that a 4 MHz crystal would produce less noise on the circuit board.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: robots on April 29, 2010, 09:28:21 am
Datasheet http://ww1.microchip.com/downloads/en/D ... 39931c.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/39931c.pdf) Page number 506 (External clock timing requirements) states

Fosc = DC to 48Mhz. With a note:
In order to use the PLL, the external clock frequency must be either 4, 8, 12, 16, 20, 24, 40 or 48 MHz.

Don't worry about the capacitors :) I have nowhere in the world seen exact capacity calculation, as this strongly depends on the layout of the board, etc.

I have used the OLS quite a lot, and no glitch so far.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: ian on April 29, 2010, 10:32:24 am
Thanks for the feedback, I appreciate you taking a look at the design.

20MHz is used on most 18F (USB) dev boards from Microchip, and it's the default in most (all?) of their USB stack demo code that I use. I picked a 20MHz crystal for my first USB design, and I've just stuck with it. I'm not sure it's the best choice for the 18f24j50, but it should be an allowable choice within spec and able to create a 48MHz internal clock with the PLL.

I think with the lower speeds (and higher PLL values) that the accuracy of the crystal starts to have a bigger role. I'm not 100% sure on this though.

You're probably 100% correct about the caps, I play pretty loose with the values on parts like that. I'd be happy to test a correction and see that it gets into the next batch produced.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: rsdio on April 29, 2010, 03:52:46 pm
[quote author="robots"]
Datasheet http://ww1.microchip.com/downloads/en/D ... 39931c.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/39931c.pdf) Page number 506 (External clock timing requirements) states

Fosc = DC to 48Mhz. With a note:
In order to use the PLL, the external clock frequency must be either 4, 8, 12, 16, 20, 24, 40 or 48 MHz.
[/quote]
Read the very next line:
Fosc = 4 to 16 MHz. HS and HSPLL Oscillator mode
Note 2: In order to use the PLL, the crystal/resonator must produce a frequency of either 4, 8, 12, or 16 MHz.

Also pay attention to Note 4 after the 16 MHz Max: This is the maximum crystal/resonator driver frequency. The internal Fosc frequency when running from the PLL can be up to 48 MHz.

There are different specs for an external clock, like the 50 MHz clock feeding the FPGA, versus an external crystal, like is feeding the PIC. The line you're reading is EC (External Clock) Oscillator Mode, and that's not the mode used for a crystal.

Quote
Don't worry about the capacitors :) I have nowhere in the world seen exact capacity calculation, as this strongly depends on the layout of the board, etc.
That's a very good point. Even Microchip points out that their calculations were very dependent upon the specifics of the manufacturers they tested.

However, my point is that if you're going to start with a completely untested value, you might as well start with the one that Microchip found to be best-suited for the crystal you've selected, rather than going to the opposite end of the range.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: rsdio on April 29, 2010, 04:11:34 pm
[quote author="ian"]20MHz is used on most 18F (USB) dev boards from Microchip, and it's the default in most (all?) of their USB stack demo code that I use. I picked a 20MHz crystal for my first USB design, and I've just stuck with it. I'm not sure it's the best choice for the 18f24j50, but it should be an allowable choice within spec and able to create a 48MHz internal clock with the PLL.[/quote]
It's certainly not within spec. See the exact data sheet quoted above.

What you're probably seeing here is that the transistors in the crystal oscillator circuit just happen to work at 20 MHz, even though that's out of spec, because it's close enough to 16 MHz, which is in spec.  But with variations from chip to chip, you might find some that don't work, and I'm sure you want to avoid customers returning even a small fraction of OLS products that are overclocked. I imagine that, like any circuit, the amplitude at 20 MHz is not full scale, since it's near their 3 dB cutoff, and the exact range will vary with chip fabrication yields. Microchip only guarantees that a 4 MHz to 16 MHz crystal will work, and it's pretty clear that they're leaving 20, 24, 40, and 48 off the list, even though an External Clock at those speeds would work just fine.

Be careful about assuming that all PICs are alike. I've designed with a couple, and each has different abilities.

Don't worry, though, you can still create the 48 MHz internal clock for the PLL from any crystal on that list. If you look at the clock diagram on page 30, you'll see that every supported clock input is divided down to 4 MHz first before feeding the PLL. So there's not really anything gained by overclocking the crystal oscillator circuit.

Quote
I think with the lower speeds (and higher PLL values) that the accuracy of the crystal starts to have a bigger role. I'm not 100% sure on this though.
On this question, I'd say go with your feeling. If you think higher speed is better, then go with the 16 MHz crystal.

You could be right, too. I was recently trying to figure out whether the percent accuracy of a crystal was multiplied and divided when fed through a multiplier/divider circuit. I didn't do enough research to find an answer, so I'm certainly not going to disagree with your hunch.

I worried about this a bit too much when settling on 8 MHz, and then when someone subsequently suggested that 4 MHz would be better, I just decided that it wasn't that important to go back and change a working design that was within spec. I also looked at price, and that didn't help the decision because all crystals from a given manufacturer in a given package seem to cost the same regardless of speed.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: ian on April 29, 2010, 04:14:51 pm
I think you're right, the oscillator is out of spec. I went by table 2-5 on page 35, but you're absolutely correct that the crystal specified in 29-10 is <16MHz.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: rsdio on April 29, 2010, 04:22:35 pm
Clarification: <=16MHz

No worries, mate!  I got burned by this on my first PIC board. I went for full speed and bought a 48 MHz crystal. That sucker never worked, and never even had half a chance.  I think the Microchip forum is where I learned about the finer details hidden in these over-500-page data sheets.

I swear, I don't know which is better: Microchip puts every detail about each chip in a single document, but you have to read over 500 pages to know everything.  Texas Instruments breaks out the common subsystems into separate documents, so you usually have less to read if you use multiple chips.  But in the latter case, even they have a hard time tracking the exact list of documents which are needed for a specific chip.  The TMS320VC5506 master documents have pointers to detail documents, but those detail documents list five other DSP chips, leaving the C5506 out.  It's really confusing to know for sure whether you're reading the right data sheet when they don't update the list with each new chip that is released.  Anyway, that's enough data sheet griping from me...
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: alm on April 29, 2010, 04:42:19 pm
[quote author="robots"]
Don't worry about the capacitors :) I have nowhere in the world seen exact capacity calculation, as this strongly depends on the layout of the board, etc.
[/quote]
Actually the crystal datasheet usually does state a precise load capacitance (and can make them with various load capacitances). This load capacitance does consist of the parallel capacitors and any parasitic capacitance from both the PCB and the PIC. Microchip appnote AN826a and Atmel appnotes AVR186 and AVR042 talk about this. A small change usually doesn't have much effect, the frequency will shift slightly, but as long as it's close enough, the crystal will usually start reliably. I'm not claiming that it's something to worry about, but it's not like everybody just chooses some random value either.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: ian on April 29, 2010, 04:46:46 pm
Microchips datasheets are a bit of a maze. 21.7 USB OSC refers to 2.3 settings for USB, which lists the same info as the 18F2550 datasheet (I remember cross checking them when I had such a hard time with the bootloader firmware). Sure enough the final spec at the end says no more than 16MHz. I need to contact seeed and see if this is causing self-test verification problems and start testing a 16mhz version for the next batch.
Title: Re: Review: 20 MHz crystal with 27 pF caps?
Post by: ian on April 29, 2010, 06:09:22 pm
Here's an updated bootloader and firmware for PICs running 16MHz crystal. I'm testing this now. We also wrote to Seeed to see how many OLS might have failed the self-test because of an out-of-spec crystal (we didn't hear anything about frequent failures, but you never know).

http://gadgetfactory.net/gf/project/but ... tal-PIC%2F (http://gadgetfactory.net/gf/project/butterflylogic/scmsvn/?action=browse&path=%2Ftrunk%2F16MHz-crystal-PIC%2F)

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01112075120session_write_close ( )...(null):0
20.01152206696ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01152207472Database_MySQL->query( ).../DatabaseHandler.php:119
40.05822346184Database_MySQL->error( ).../Db-mysql.class.php:273