View previous topic :: View next topic |
Author |
Message |
Frosty Guest
|
PIC18F4520 clock/osc questions |
Posted: Mon Feb 05, 2007 4:06 pm |
|
|
Hello all!
Just getting into PICs and using the CCS compiler suite (3.234).
I'm trying to get my system using a 10Mhz osc with PLL, and I cannot get it there! Not sure whats what!
Here is my code that WORKS using the internal 8mhz clock with PLL
Code: |
#include <18F4520.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#fuses INTRC_IO // internal 8mhz osc
#use delay(clock=32000000)
#byte OSCTUNE = 0xF9B
#bit PLLEN = OSCTUNE.6
void main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_PLL_ON);
PLLEN=1;
output_low(PIN_B0);
while(1)
{
delay_ms(1000);
output_toggle(PIN_B0);
}
}
|
Now the v3.234 compiler has an error where is does not put in the PLLEN setting, hence the manual setting.
I have an external 10Mhz osc all connected, and I wish to use that plus PLL...
This is my new program that shows the 10Mhz working
Code: |
#include <18F4520.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
//#fuses INTRC_IO // internal 8mhz osc
//#use delay(clock=32000000)
//#FUSES HS //High speed Osc (> 4mhz)
//#use delay(clock=20000000)
#FUSES HS //High speed Osc (> 4mhz)
#use delay(clock=10000000)
#byte OSCTUNE = 0xF9B
#bit PLLEN = OSCTUNE.6
void main()
{
// setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_PLL_ON);
// PLLEN=1;
output_low(PIN_B0);
while(1)
{
delay_ms(1000);
output_toggle(PIN_B0);
}
}
|
Okay, now I want to make it into 40Mhz...
change to
Code: |
#FUSES HS //High speed Osc (> 4mhz)
#use delay(clock=40000000)
|
I'm not sure what to chage in the setup_osc setting. There is not 10Mhz choice...
Code: |
void main()
{
// What goes here???
// setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_PLL_ON);
// PLLEN=1;
output_low(PIN_B0);
while(1)
{
delay_ms(1000);
output_toggle(PIN_B0);
}
}
|
Thanks in advance! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 05, 2007 5:51 pm |
|
|
I don't have an 18F4520 to test, but I believe the following fuse
settings will put it into 4x PLL mode with an external 10 MHz
crystal or oscillator.
Code: |
#include <18F4520.h>
#fuses H4, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=40000000)
//====================================
void main()
{
while(1);
} |
|
|
|
Frosty Guest
|
|
Posted: Mon Feb 05, 2007 5:55 pm |
|
|
Yes indeed. The H4 makes all the difference. Thank you. |
|
|
neverlog
Joined: 02 May 2010 Posts: 36
|
|
Posted: Thu Jul 22, 2010 10:13 pm |
|
|
Frosty wrote: | Yes indeed. The H4 makes all the difference. Thank you. |
I have tested with 10Mhz Crystal + H4, Delay Clock =40Mhz, but seems like the same speed like 20Mhz crystal alone(Delay Clock =20Mhz).
I wonder someone did test it out. For me no different at all.
Feel free to comments |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 22, 2010 10:16 pm |
|
|
Are you using an 18F4520 ? And what compiler version ? |
|
|
neverlog
Joined: 02 May 2010 Posts: 36
|
|
Posted: Fri Jul 23, 2010 2:36 am |
|
|
PCM programmer wrote: | Are you using an 18F4520 ? And what compiler version ? |
Yes. I am using 18F4520, my compiler is 4.104.
I am testing the for loop with fix loop value let say 2048 round.
I found that the time the PIC need to finish the loop is same for (H4, 10Mhz) and (20Mhz alone).
Not much different. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Fri Jul 23, 2010 4:13 am |
|
|
You do realise, that if your loop contains a delay (*as shown in your example), the delay _will_ remain the same length, with each different oscillator setting?. The whole 'point' of the clock statement, is that that the compiler then knows how to adjust the internal loops used, to give the same time.
Best Wishes |
|
|
neverlog
Joined: 02 May 2010 Posts: 36
|
|
Posted: Sat Jul 24, 2010 3:40 am |
|
|
Ttelmah wrote: | You do realise, that if your loop contains a delay (*as shown in your example), the delay _will_ remain the same length, with each different oscillator setting?. The whole 'point' of the clock statement, is that that the compiler then knows how to adjust the internal loops used, to give the same time.
Best Wishes |
Hi Ttelmah, that is not my example code.
I didn't post my code. It's just as simple code with loop for comparing 2048 records in the 24LC256 memory module.
Perhaps reading and compare data from 24LC256 already has limit itself. |
|
|
|