|
|
View previous topic :: View next topic |
Author |
Message |
Hamzeh Soboh
Joined: 20 Jul 2012 Posts: 2
|
Using 40MHz clock with PIC 18f4550 |
Posted: Fri Jul 20, 2012 4:53 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Jul 20, 2012 5:42 am |
|
|
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
|
|
Posted: Fri Jul 20, 2012 5:52 am |
|
|
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
|
|
Posted: Wed Sep 12, 2012 8:47 am |
|
|
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: 19537
|
|
Posted: Wed Sep 12, 2012 9:26 am |
|
|
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
|
|
Posted: Wed Sep 12, 2012 10:57 am |
|
|
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. |
|
|
|
|
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
|