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

PIC18F4520 clock/osc questions

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







PIC18F4520 clock/osc questions
PostPosted: Mon Feb 05, 2007 4:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 05, 2007 5:51 pm     Reply with quote

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







PostPosted: Mon Feb 05, 2007 5:55 pm     Reply with quote

Yes indeed. The H4 makes all the difference. Thank you.
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Thu Jul 22, 2010 10:13 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jul 22, 2010 10:16 pm     Reply with quote

Are you using an 18F4520 ? And what compiler version ?
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Fri Jul 23, 2010 2:36 am     Reply with quote

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: 19510

View user's profile Send private message

PostPosted: Fri Jul 23, 2010 4:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 24, 2010 3:40 am     Reply with quote

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