CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F2550 & PIC18F2550 crystal settings

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PIC18F2550 & PIC18F2550 crystal settings
PostPosted: Tue Jul 10, 2007 8:58 pm     Reply with quote

Hi there,
I had a good search through the net and through datasheets and I have not found one simple explaination on how to set the crystal settings on the 2/4550.

Here is my attempt to try and puts some information together and hopefully with help we can create a table that everyone can understand.
Code:

input    pll division   clock mode     mcu clock divison      MCU frequency
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48Mhz   n/a             EC,ECIO         none                        48Mhz
                                                   /2                            24Mhz
                                                   /3                            16Mhz
                                                   /4                            12Mhz
48Mhz   /12             EC,ECIO         none                        48Mhz
                                                   /2                            24Mhz
                                                   /3                            16Mhz
                                                   /4                            12Mhz
                            ECPLL,ECPIO    /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
40Mhz    /10          EC,ECIO           none                        40Mhz
                                                   /2                            20Mhz
                                                   /3                            13.33Mhz
                                                   /4                            10Mhz
                            ECPLL,ECPIO   /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
24Mhz    /6            HS,EC,ECIO     none                        24Mhz
                                                   /2                            12Mhz
                                                   /3                            8Mhz
                                                   /4                            6Mhz
                    HSPLL,ECPLL,ECPIO  /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
20Mhz   /5           HS,EC,ECIO       none                        20Mhz
                                                   /2                            10Mhz
                                                   /3                            6.67Mhz
                                                   /4                            5Mhz
                HSPLL,ECPLL,ECPIO      /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
16Mhz     /4        HS,EC,ECIO        none                        16Mhz
                                                   /2                            8Mhz
                                                   /3                            5.33Mhz
                                                   /4                            4Mhz
                  HSPLL,ECPLL,ECPIO    /2                        48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
12Mhz   /3     HS,EC,ECIO             none                        12Mhz
                                                   /2                            6Mhz
                                                   /3                            4Mhz
                                                   /4                            3Mhz
                 HSPLL,ECPLL,ECPIO     /2                            48Mhz
                                                   /3                            24Mhz
                                                   /6                            16Mhz
8Mhz    /2        HS,EC,ECIO           none                        8Mhz
                                                   /2                            4Mhz
                                                   /3                            2.67Mhz
                                                   /4                            2Mhz
               HSPLL,ECPLL,ECPIO       /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz
4Mhz    /1      XT,HS,EC,ECIO        none                        4Mhz
                                                   /2                            2Mhz
                                                   /3                            1.33Mhz
                                                   /4                            1Mhz
           HSPLL,ECPLL,XTPLL,ECPIO  /2                            48Mhz
                                                   /3                            32Mhz
                                                   /4                            24Mhz
                                                   /6                            16Mhz

This is taken from the 2/4550 datasheet, how do the clock mode settings corrospond to the CCS fuses? I reconnise XT,HS, HSPLL but the others I am not familiar with.

I am going to write a program for working out the crystal settings once enougth information is gathered, then people new to this can have it a little easier.
Ttelmah
Guest







PostPosted: Wed Jul 11, 2007 2:34 am     Reply with quote

In a sense, you are starting at the wrong 'end' with this. Start with a key question. Do you want to use USB?.
If the answer here is 'no', then you can progress to the normal fuse settings, using XT, HS, EC, or ECIO.
If however the answer is'yes', then a second question arises. Fast, or standard mode?. If standard mode, then you are basically stuck with a 24MHz clock.

For Fast mode, you now get the big requirement, that the USB 'section', needs to receive a clock at exactly 4MHz. There is an internal prescaler (selected by PLLx fuses, with 'x' as 1,2,3,4,5,6,10 or 12), so your external clock is limited to 4,8,12,16,20,24 or 48MHz.
Now you must use the external clock for USB (internal oscillator is not accurate enough), so you have the choices for oscillator types at this point, of:
Code:

* EC (4MHz only)
* EC_IO
  ECPIO  (Allows I/O on RA6)
  ECPLL
* XT
  XTPLL (4MHz only)
* HS
  HSPLL
! INTXT (4MHz only - internal oscillator used for CPU)
! INTHS

With the required external clock source or crystal for each one, selected from the above 'possible' rates. With this, you then add the required PLL fuse, to give 4MHz for the USB.
At this point, the 4MHz, goes through an internal PLL, to generate 96Mhz for the USB system.

Now you have the question of how fast you want to run the CPU?. You have three key choices at this point. You can elect to run the CPU from the internal RC oscillator, while running the USB off the external oscillator. This is the 'INTHS', and 'INTXT' fuse settings above (marked with !). The second choice is to feed the CPU's divider, directly from the master clock. This is automatically done, when you omit the phrase 'PLL' (or 'P' for the ones allowing IO) from the clock source. So if you select 'HS', the PLL is still enabled, and running for the USB, and the USB dividers still apply for this, but the CPU clock is now fed from the master external clock, and not from the USB PLL output. These are the options marked with '*' above.
The CPU, then has a divider, offering /1, /2, /3 or /4. These are the CPUDIV1, CPUDIV2, CPUDIV3, and CPUDIV4 fuses.
The third choice is to feed the CPU from the output of the USB PLL (all the options with a 'P' in them). With this selected, the 96MHz clock is divided by 2, and then fed to the CPUDIV divider. This leads to the confusing behaviour, that 'CPUDIV1', selects the USB clock /2. However if you just redraw the Microchip oscillator schematic, so the source of the CPU clock in this setting, is after the /2 stage, then it all makes logical sense (this is presumably what is actually being done in the chip...).
You also have one other option here. If running 'standard' rate USB, and using a 24MHz clock, you can add the 'NOUSBDIV' fuse to select the USB is fed directly from the master clock, and not the PLL.

Now with the 'INTXT', and 'INTHS' selections, you can then set the CPU oscillator to the eight available rates from 31K, to 8MHz, using the 'setup_oscillator' function.

There are actually over 1000 'possible' oscillator configurations available with these chips, so no table is ever going to be complete, which is why you need instead to use a 'tree' decision approach, starting from what yr use requirements are.

Best Wishes
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Wed Jul 11, 2007 5:00 am     Reply with quote

Thanks for your reply, it does make things a little cleared.

Am I understanding correctly; Fast USB needs 96Mhz internally so you need to provide 4Mhz by PLL and/or Division, while Standard USB requires 24Mhz internally? this is why you can have a 24Mhz master clock directly using the 'NOUSBDIV' fuse?

When considering oscillator types; I got these from the CCS wizard.
Code:
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES XTPLL                    //Crystal/Resonator with PLL enabled
#FUSES EC_IO                    //External clock
#FUSES EC                       //External clock with CLKOUT
#FUSES ECPIO                    //External Clock with PLL enabled, I/O on RA6
#FUSES ECPLL                    //External Clock with PLL enabled and Fosc/4 on RA6
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES INTRC                    //Internal RC Osc
#FUSES INTXT                    //Internal Oscillator, XT used by USB
#FUSES INTHS                    //Internal Oscillator, HS used by USB
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES HSPLL                    //High Speed Crystal/Resonator with PLL enabled

Does external clock refere to oscillators such as those 4 leg silver modules? and crystal/resonators refere to the 2 legged and 3 legged variaty?

Thanks again
Peter
Ttelmah
Guest







PostPosted: Wed Jul 11, 2007 6:13 am     Reply with quote

You can get oscillators with just three legs... Smile
Generally though four pins is more normal.
Key I'd say, is whether the module needs power. This implies it has an internal amplifier, and is then almost certainly an oscillator.
The PIC itself provides the required amplification stage, with all the modes containing 'HS', or 'XT', and can then be used with a resonator/crystal that does not oscillate "on it's own".
Generally, avoid resonators for USB. Unfortunately, they are used in a hell of a lot of cheaper USB kit (mainly because they of the price), which then gives problems when the temperature range goes outside normal 'office' tolerances. Typically resonators have tolerances about 500* 'worse' than standard crystals, and will rarely meet the USB specification, over more than about a 20 degree range, 'at best'...

Best Wishes
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Thu Jul 12, 2007 12:39 pm     Reply with quote

I finally got the Serial-USB demo going last night on my breadboard, I had to fiddle with the crystal but its finally working, many thanks for the help with crystal settings.

Do you know if the 470nF cap from the pic's Vusb pin to ground is critical? my demo seems to work with it in or out.
Ttelmah
Guest







PostPosted: Thu Jul 12, 2007 12:56 pm     Reply with quote

Depends on the chip, and how the system is powered (USB or local supply). On some chips a larger capacitor seems essential toevenget them to work...

Best Wishes
aaaaamartin



Joined: 17 Apr 2005
Posts: 39
Location: Germany Stuttgart

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 2:00 pm     Reply with quote

look here

http://www.sprut.de/electronic/pic/8bit/18f/programm/usbbootloader/usbboot.htm

for a graphic and explanation (in german) on how to setup the xtal.

Best wishes Martin
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group