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

Using 40MHz clock with PIC 18f4550

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



Joined: 20 Jul 2012
Posts: 2

View user's profile Send private message

Using 40MHz clock with PIC 18f4550
PostPosted: Fri Jul 20, 2012 4:53 am     Reply with quote

I have a 40MHz crystal and I have to use it with PIC18f4550

However, I tried a simple blink example that turns on an LED for one second, then turns it off for one second, and so on..

I noticed that it turns it on for longer than one second, about two seconds, and turns it off for two second.

This is my code:

Code:

#include <18f4550.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT
#use delay(clock = 40M)

void main()
{
   set_tris_b(0);
   
   while(1)
   {
      output_b(255);
     
      delay_ms(1000);
     
      output_b(0);
     
      delay_ms(1000);
   }
}


Something wrong with the code?

Thanks.
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 20, 2012 5:42 am     Reply with quote

My understanding of the datasheet is that you can only use a crystal of up to 24MHz, not 40 MHz. You can use an 'external osicillator' up to 48MHz but that's a self contained 'can' that needs +5 to run.
All PICs seem to have a similar primary xtal circuitry on the die good for 20-24 MHz for the past 20 years.

To get '40 MHz' performance you need a slower crystal( say 4 MHz) and then configure the PLL options appropriately. I currently run the 4550 at 48MHz with a 4MHz xtal so I know it does work.

hth
jay
Hamzeh Soboh



Joined: 20 Jul 2012
Posts: 2

View user's profile Send private message

PostPosted: Fri Jul 20, 2012 5:52 am     Reply with quote

temtronic wrote:
My understanding of the datasheet is that you can only use a crystal of up to 24MHz, not 40 MHz. You can use an 'external osicillator' up to 48MHz but that's a self contained 'can' that needs +5 to run.
All PICs seem to have a similar primary xtal circuitry on the die good for 20-24 MHz for the past 20 years.

To get '40 MHz' performance you need a slower crystal( say 4 MHz) and then configure the PLL options appropriately.I currently run the 4550 at 48MHz with a 4MHz xtal so I know it does work.

hth
jay


Thanks very much..
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Sep 12, 2012 8:47 am     Reply with quote

Hey Temtronic,

I'm going through the 18F4620 specs (the 4550 is similar I believe). How can you use a 48MHz clock? Honestly I have't looked at the 4550 specs but the HSPLL specs say that it's a max external crystal of 10MHz, x4 = 40MHz.

Here's my situation.... I have a few variations of crystals but I need to generate a PWM of 128kHz. To do that, I am currently using a crystal of 16.384 MHz. Any multiple of that will work. But I'd like to crank it up to 32.768MHz using the PLL but I don't think it's possible... or is it? I thought the PLL was only x4 with a max input frequency of 10MHz?
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Sep 12, 2012 9:26 am     Reply with quote

The 4620, is very different from the 4550.

On the 4550, the PLL gives *24, with a programmable prescaler offering /2, 3, 4, 5, 6, 10, 12. The output of the divider has to have a frequency close to 4Mhz. You then have /2, /3, /4, & /6 dividers after the PLL.
This is all done, because the chip _requires_ an input frequency of 96MHz to the USB circuitry.
The 4550, works to 48MHz (96MHz/2).

On the 4620, you only have *4, and the chip is specified to 40Mhz max.

There are chips that are later relatives of the 4620, that will clock to 64MHz. 46K20 for example.

Except for the USB PIC's, most don't have the complex divider/multipliers allowing such a wide range of clocks. Realistically your best bet would be to get an 8.192MHz crystal, which will run directly with the *4 PLL to give 32.768MHz.

Best Wishes
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Wed Sep 12, 2012 10:57 am     Reply with quote

Ok, thanks. That's what I had thought - that the 4620 was x4, that's it, and the ideal thing was to use a multiple of what I need that is less than 10MHz.

Thanks.
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