18F4550 MCU oscillator basics

General discussion on mikroC.
Author
Message
User avatar
milan
mikroElektronika team
Posts: 1013
Joined: 04 May 2006 16:36
Contact:

18F4550 MCU oscillator basics

#1 Post by milan » 04 Jul 2007 09:25

We noticed that 18F4550 oscillator are often confusing our users
so we decided to explain them using the examples, get 18F4550 datasheet and we can start:


Image

- 18F4550 datasheet chapter 2.1:

You need to provide:
1) 48 MHz to USB module
2) Clock to CPU


- 18F4550 datasheet chapter 2.2.4 PLL FREQUENCY MULTIPLIER
It is designed to produce a fixed 96 MHz reference clock from a fixed 4 MHz input...


--- Example for 8MHz crystal on your board ---

1) Set _PLL_DIV2_1L.
PLL Prescaler (see Datasheet->Figure 2-1) will then divide 8MHz by 2 and produce 4MHz (needed on 96MHz PLL input).

2) Option 1
If you choose HSPLL oscillator (check _FOSC_HSPLL_HS_1H flag, uncheck _FOSC_INTOSC_HS_1H and _FOSC_HS_1H if checked)

In this case CPU will use 96MHz HSPLL divided by PLL Postscaller, set CPUDIV flags to choose the divider.
_CPUDIV_OSC1_PLL2_1L will divide 96MHz by 2 and CPU will get 48MHz [you need to set Clock field in EditProject to 48MHz]
...
_CPUDIV_OSC4_PLL6_1L will divide 96MHz by 6 and CPU will get 16MHz [you need to set Clock field in EditProject to 16MHz]
Note: PLLx part of the flag is relevant, ignore the OSCx part of the flag

Option 2
If you choose HS oscillator (check _FOSC_HS_1H flag, uncheck _FOSC_HSPLL_HS_1H and _FOSC_INTOSC_HS_1H if checked)

In this case CPU will use 8MHz HS divided by Oscillator Postscaller, set CPUDIV flags to choose the divider.
_CPUDIV_OSC1_PLL2_1L will divide 8MHz by 1 and CPU will get 8MHz [you need to set Clock field in EditProject to 8MHz]
...
_CPUDIV_OSC4_PLL6_1L will divide 8MHz by 4 and CPU will get 2MHz [you need to set Clock field in EditProject to 2MHz]
Note: OSCx part of the flag is relevant, ignore the PLLx part of the flag


--- Example for 20MHz crystal on your board ---

1) Set _PLL_DIV5_1L.
PLL Prescaler (see Datasheet->Figure 2-1) will then divide 20MHz by 5 and produce 4MHz (needed on 96MHz PLL input).

2) Option 1
If you choose HSPLL oscillator (check _FOSC_HSPLL_HS_1H flag, uncheck _FOSC_INTOSC_HS_1H and _FOSC_HS_1H if checked)

In this case CPU will use 96MHz HSPLL divided by PLL Postscaller, set CPUDIV flags to choose the divider.
_CPUDIV_OSC1_PLL2_1L will divide 96MHz by 2 and CPU will get 48MHz [you need to set Clock field in EditProject to 48MHz]
...
_CPUDIV_OSC4_PLL6_1L will divide 96MHz by 6 and CPU will get 16MHz [you need to set Clock field in EditProject to 16MHz]
Note: PLLx part of the flag is relevant, ignore the OSCx part of the flag


Option 2
If you choose HS oscillator (check _FOSC_HS_1H flag, uncheck _FOSC_HSPLL_HS_1H and _FOSC_INTOSC_HS_1H if checked)

In this case CPU will use 20MHz HS divided by Oscillator Postscaller, set CPUDIV flags to choose the divider.
_CPUDIV_OSC1_PLL2_1L will divide 20MHz by 1 and CPU will get 20MHz [you need to set Clock field in EditProject to 20MHz]
...
_CPUDIV_OSC4_PLL6_1L will divide 20MHz by 4 and CPU will get 5MHz [you need to set Clock field in EditProject to 5MHz]
Note: OSCx part of the flag is relevant, ignore the PLLx part of the flag



- Do not forget to check _USBDIV_2_1L to provide clock to USB module via PLL Prescaler and 96MHz PLL, this is not needed in the case
that you have 48MHz crystal so you can provide it directly to USB module.


mikroElektronika Team

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: 18F4550 MCU oscillator basics

#2 Post by tihomir.losic » 18 Feb 2010 15:13

Hello,

In PRO versions of PIC compilers we introduced Schemes for Configuration Bits.
Here is the list of the present schemes:
  • 18F2455_8MHz_to_PLL48MHz.cfg
    18F4520_HSPLL.cfg
    18F4550_8MHz_to_PLL48MHz.cfg
    18F8520_HSPLL.cfg
18F4550_8MHz_to_PLL48MHz.cfg Scheme covers PIC18F4550 as described in this post (most common settings used)
Example for 8MHz crystal on your board --- Option 1 --- Clock field in EditProject to 48MHz

In this way it's much easier to set Configuration Bits for any MCU.

For the next version of our compiler we are planning to expand this list :
  • P16F877A.cfgsch
    P16F887.cfgsch
    P18F242.cfgsch
    P18F242_PLLx4.cfgsch
    P18F2439.cfgsch
    P18F2439_PLLx4.cfgsch
    P18F2455_PLL_8_to_48MHz.cfgsch
    P18F2455_PLL_8_to_8MHz.cfgsch
    P18F2585.cfgsch
    P18F2585_PLLx4.cfgsch
    P18F2620.cfgsch
    P18F2620_PLLx4.cfgsch
    P18F4220.cfgsch
    P18F4220_PLLx4.cfgsch
    P18F4320.cfgsch
    P18F4320_PLLx4.cfgsch
    P18F448.cfgsch
    P18F448_PLLx4.cfgsch
    P18F4520.cfgsch
    P18F4520_PLLx4.cfgsch
    P18F4525.cfgsch
    P18F4525_PLLx4.cfgsch
    P18F4550_PLL_8_to_48MHz.cfgsch
    P18F4550_PLL_8_to_8MHz.cfgsch
    P18F8520.cfgsch
    P18F8520_PLLx4.cfgsch
    P18F8722.cfgsch
    P18F8722_PLLx4.cfgsch
    P18F87J50_PLL_8_to_48MHz.cfgsch
    P18F87J50_PLL_8_to_8MHz.cfgsch
    P18F87J60.cfgsch
    P18F87J60_PLLx4.cfgsch
There are 2 different Schemes for PIC18F4550 so you can choose mode between available options of the PLL output.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

pic_on_me
Posts: 22
Joined: 21 Feb 2010 22:30

Re: 18F4550 MCU oscillator basics

#3 Post by pic_on_me » 21 Feb 2010 22:38

I am using a pic18f4550 kit with a 20MHz oscillator and MikroC version 7.0.0.3. I have tried both options with the clock set to 20MHz and the delay functions do not delay the desired amount of time.

This is the pic kit I am using from sparkfun
http://www.sparkfun.com/commerce/produc ... ts_id=8562

pic_on_me
Posts: 22
Joined: 21 Feb 2010 22:30

Re: 18F4550 MCU oscillator basics

#4 Post by pic_on_me » 22 Feb 2010 06:00

I got the delays to work properly I think. I believe the problem was that I had not followed all of the above steps.

joetraff
Posts: 2
Joined: 13 Aug 2010 15:01

Re: 18F4550 MCU oscillator basics

#5 Post by joetraff » 13 Aug 2010 20:01

pic_on_me wrote:I am using a pic18f4550 kit with a 20MHz oscillator and MikroC version 7.0.0.3. I have tried both options with the clock set to 20MHz and the delay functions do not delay the desired amount of time.

This is the pic kit I am using from sparkfun
http://www.sparkfun.com/commerce/produc ... ts_id=8562
I loved the pic kit.
Keep up the good work of sharing.

sophtware
Posts: 60
Joined: 05 Jun 2008 02:35
Location: Dacula, GA
Contact:

Re: 18F4550 MCU oscillator basics

#6 Post by sophtware » 18 Nov 2010 20:26

Just my two cents:

I think much of the confusion comes from mistaking the 'Frequency' Project Setting for the crystal frequency.

All a user needs to remember is that the Frequency setting is what the CPU is running at *after* all the oscillator settings have been applied to the crystal frequency.
Kind Regards,
Michael Lange

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 18F4550 MCU oscillator basics

#7 Post by janko.kaljevic » 05 Jan 2012 11:21

Hello,

Please can you tell me have you set the config bits for 48MHz?
Please if you can post here your entire project so we can see config bits settings.

Also i strongly suggest to upgrade to latest version of compiler.

Best regards.

lejeff
Posts: 218
Joined: 04 Dec 2011 16:10
Location: France

Re: 18F4550 MCU oscillator basics

#8 Post by lejeff » 19 Jan 2012 12:13

Hi

I try to use the 18F4550 on the microboard
http://www.mikroe.com/eng/downloads/get ... manual.pdf

Do I have to replace the 10MHz crystal with another one because it's not possible to divide 10 by 2.5 to obtain 4 MHz

Thanks

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 18F4550 MCU oscillator basics

#9 Post by janko.kaljevic » 20 Jan 2012 10:22

Hello,

You will have to use another crystal if you want to generate appropriate USB clock.
Since this board has soldered 10MHz crystal, you will have to desolder it and solder new one.

Notice that this hardware modification on mikroboard will void warranty on this product.

Best regards.

sucipto
Posts: 1
Joined: 05 Jan 2012 06:45
Contact:

Re: 18F4550 MCU oscillator basics

#10 Post by sucipto » 17 Feb 2012 17:13

I think much of the confusion comes from mistaking the 'Frequency' Project Setting for the crystal frequency.

All a user needs to remember is that the Frequency setting is what the CPU is running at *after* all the oscillator settings have been applied to the crystal frequency.
Iklan Internet Murah Efektif Berkualitas Indonesia
Last edited by sucipto on 01 Jun 2012 10:43, edited 1 time in total.

salimabdullah
Posts: 4
Joined: 20 Dec 2011 07:53

Re: 18F4550 MCU oscillator basics

#11 Post by salimabdullah » 19 Feb 2012 17:46

Hi, milan.

i compile the code by using MiKroC pro for PIC and i generated the Hex file .when i loaded the hex file into PIC16F887, the circuit did not function as per the code commands!! the code i past it in this link:

http://pastebin.com/2NvQnE0p


for more clear about circuit connection, i have attached my schematic. i hope you help me to verify the exact problem. thanks

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 18F4550 MCU oscillator basics

#12 Post by janko.kaljevic » 20 Feb 2012 13:34

Hello,

Please can you explain in more details the issue that you are experiencing.
Have you set up config bits properly according to your requirements.

Best regards.

thebrij34
Posts: 4
Joined: 31 Jan 2012 11:54

Re: 18F4550 MCU oscillator basics

#13 Post by thebrij34 » 04 Mar 2012 19:00

hey.... i m trying with 16 Mhz external crystal to operate lcd library simple example ..!!
we have tried a lot in MicroC pro ..!!
pls anybody tells me what exectly i have to add in the code for the oscillator setting as mikroC team saying.
pls help to finish my work
thanks in advance ..!!

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 18F4550 MCU oscillator basics

#14 Post by janko.kaljevic » 05 Mar 2012 13:55

Hello,

I assume that you are using PIC18F4550.
If you want to use USB PLL follow instructions from above.

For 48MHz settings choose PLL Prescaler selection to divide by 4,
Oscillator Selection as HS Oscillator, PLL enabled
And set clock field in Edit Project window to 48 MHz.

Best regards.

NadhyneeMF
Posts: 1
Joined: 03 Apr 2012 23:57

Re: 18F4550 MCU oscillator basics

#15 Post by NadhyneeMF » 04 Apr 2012 02:57

Hello, I'm trying ti use a 18F4550 MCU with a 48MHz oscillator. I want to show a message in a LCD (16x2) but it only shows a blinking cursor. I think it's a configuration problem but I'm not sure. Could you tell me, what I should do to fix the problem?

Thank you!!

Post Reply

Return to “mikroC General”