Author Topic: Choosing a crystal for PIC USB project  (Read 3913 times)

0 Members and 1 Guest are viewing this topic.

Offline BytesGuyTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: gb
Choosing a crystal for PIC USB project
« on: August 27, 2015, 07:46:49 pm »
Hi everyone,

This may seem like a bit of a simple question, but with the PIC18F4550 which frequency should be chosen for the crystal?

I have been reading the datasheet and understand that the USB module needs to be running at 48MHz, but the rest of it was a bit confusing. It seemed like you could use pretty much any frequency crystal (4MHz, 10Mhz, 20Mhz etc), so what is the advantage of using a higher one when you could just chose 4MHz for example.

Perhaps I have the wrong end of the stick here :palm: This is quite ambitious for my first PIC project, but I am determined to learn :) I have used things such as Arduino, Picaxe, FPGAs etc, but they have always been with pre-built boards.

Thanks!
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Choosing a crystal for PIC USB project
« Reply #1 on: August 27, 2015, 08:13:31 pm »
Quote
any frequency crystal (4MHz, 10Mhz, 20Mhz etc),
You need a 48MHz clock for USB FS or 6MHz for USB LS so not any.
 

Offline BytesGuyTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: gb
Re: Choosing a crystal for PIC USB project
« Reply #2 on: August 27, 2015, 08:25:18 pm »
Quote
any frequency crystal (4MHz, 10Mhz, 20Mhz etc),
You need a 48MHz clock for USB FS or 6MHz for USB LS so not any.

Yeah I realise it needs 48MHz, but the datasheet was talking about being able to derive 48MHz from various crystal frequencies - this the bit that is confusing me.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: Choosing a crystal for PIC USB project
« Reply #3 on: August 27, 2015, 08:47:39 pm »
The crystal needs to be an exact multiple of 4MHz for the PLL and divider chains to be able to generate the USB clock.  10MHz is *NOT* suitable.   The maximum crystal frequency for USB operation is 24MHz, but a higher external clock can be used up to 48MHz.  See datasheet fig. 2-1 and oscillator CONFIG settings from table 2-3
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2542
  • Country: us
Re: Choosing a crystal for PIC USB project
« Reply #4 on: August 27, 2015, 11:40:23 pm »
The key thing to remember here is that you're not only picking a frequency for USB support; but you're selecting the processor frequency.  The clock for the USB Peripheral and the CPU clock are from the same source.  So pick the CPU clock frequency you want that will still support the USB operation.

See FIGURE 2-1: PIC18F2455/2550/4455/4550 CLOCK DIAGRAM and
TABLE 2-3: OSCILLATOR CONFIGURATION OPTIONS FOR USB OPERATION.
 

Offline marshallh

  • Supporter
  • ****
  • Posts: 1462
  • Country: us
    • retroactive
Re: Choosing a crystal for PIC USB project
« Reply #5 on: August 28, 2015, 04:59:19 am »
Some crystals may be harder to find in some form factors than others. I.e. a tiny SMD one versus HC49.
Verilog tips
BGA soldering intro

11:37 <@ktemkin> c4757p: marshall has transcended communications media
11:37 <@ktemkin> He speaks protocols directly.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1637
  • Country: nl
Re: Choosing a crystal for PIC USB project
« Reply #6 on: August 28, 2015, 07:55:43 am »
See page 26 of the datasheet.

The PIC contains a 4 to 96MHz PLL. This multiplies the frequency basically. The frequency is divided by 2 which makes the USB clock of 48MHz.
The CPU clock can be chosen quite flexible, with it's own post-divider. So you could run the CPU at 48MHz too.

If you look at the diagram, there is a divider before the PLL to get your 4MHz input frequency. Think backwards to get the crystal frequency; 4MHz x prescaler. That means this PIC supports USB from 4, 8, 12, 16, 20, 24, 40 and 48MHz clock sources. In theory you could pick any, but I would stick to 12MHz as it's a very common frequency for USB applications. (likely to match 12Mbit/s USB speed)

This particular PIC has no way to clock the USB from the internal FRC crystal. Some newer PIC18's can from the K-series I believe, and also some decent PIC24's have accurate enough oscillators for basic USB operation.
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Choosing a crystal for PIC USB project
« Reply #7 on: August 28, 2015, 10:18:53 am »
So now when you know a 10MHz won't do, one more thing worth noting is that if you plan to use XC8 compiler then in a crippled mode the USB stack eats up half of the memory.
 

Offline BytesGuyTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: gb
Re: Choosing a crystal for PIC USB project
« Reply #8 on: August 28, 2015, 12:26:13 pm »
Thank you all for your input, I really appreciate it!  :-+

I think I will chose a 12MHz crystal then, I have a bunch lying around somewhere. The frequency for the processor doesn't need to be anything more than that, I'm not going to be doing anything taxing or dependent on speed.

Brutte, interesting to hear that about the compiler... I guess they want you to pay for the upgraded version  :-- Any suggestions for alternatives?
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Choosing a crystal for PIC USB project
« Reply #9 on: August 28, 2015, 07:36:18 pm »
Any suggestions for alternatives?
I would suggest a Nucleo-STM32L152 or STM32L152C-Discovery These run similar 32MHz Cortex-M3 chips. Start with uVision (32k limit?) and run through all blinky examples provided by STM and Keil. Once you learn how to blink with uVision, you can move to gcc-arm-embedded toolchain which is not as cutting edge but free (as in freedom).
« Last Edit: August 29, 2015, 07:15:38 am by Brutte »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf