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 support@ccsinfo.com

Oscillator config / 18F4550

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



Joined: 25 Apr 2011
Posts: 11
Location: Belgium

View user's profile Send private message

Oscillator config / 18F4550
PostPosted: Sun Feb 12, 2012 3:25 pm     Reply with quote

Hi there,

I wish to configure a 12MHz crystal to be applied as USB clock source and to CPU.

I'm misunderstanding how to procede and I would be very pleased to get some help.

According Figure 2-1 from the datasheet, page 24, 12MHz comes from OSC1-2, then through PLL /3 to get 4MHz.

These 4MHz are converted to 96MHz PLL and divided by 2 to get 48MHz applied to USB.

On the other way, I wonder how to configure the clock system to get 96MHz/2, 48MHz, to CPU using HSPLL.

I'm working on a automation application where treatment speed is critical.

Here are my fuses and use-delay instruction

Code:
#FUSES PLL3                     //Divide By 3(12MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#use delay(clock=12000000)


I tried to erase "setup_oscillator" line but nothing happened ; So I undeleted it.

What does that line really do? According to CCS manual, it's used to work with RC internal oscillator ... which I want to cut off.

Code:
setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_PLL_ON);


Could you please give me more information on the way to procede? And/Or a bit of source code to help me?

Thanks so much
_________________
- Be the change you want to see in the world (Gandhi) -
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 12, 2012 4:33 pm     Reply with quote

Quote:
I wish to configure a 12MHz crystal.
I wonder how to configure the clock system to get 96MHz/2, 48MHz, to CPU using HSPLL.

See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=31879&start=2
padbol



Joined: 25 Apr 2011
Posts: 11
Location: Belgium

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 3:22 pm     Reply with quote

Except the "Use Delay" instruction, I don't really see a difference between what I did and what you suggest.

Here is the complete list of the fuses I configured.

Code:
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL                    //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES LVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#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 NOMCLR                   //Master Clear pin used for I/O
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL3                     //Divide By 3(12MHz oscillator input)
#FUSES CPUDIV1                  //No System Clock Postscaler
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled
#FUSES ICPRT                    //ICPRT enabled

#use delay(clock=12000000)



What about "setup_oscillator" instruction?



I can plug an oscilloscope to an output pin with
Code:

while (1) {
   output_high(PIN_XX);
   output_low(PIN_XX);
}

But what frequency should I measure?
_________________
- Be the change you want to see in the world (Gandhi) -
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 3:27 pm     Reply with quote

Don't measure frequency like that. Use the LED blinking example in the
link that I posted. It's much easier.

With the code you posted, it's necessary to look at the .LST file and
count instructions, with normal instructions counting as 1 cycle, and
jump instructions as 2 cycles (if they take the jump). Then you have
to know that the instruction cycle frequency is the oscillator freq/ 4.
Use the example code I posted. It's much easier.
padbol



Joined: 25 Apr 2011
Posts: 11
Location: Belgium

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 3:46 pm     Reply with quote

Great! That seems to works fine!

I also measured delays with oscilloscope : 1000ms is a "real" second on the scope.

Thank you Smile
_________________
- Be the change you want to see in the world (Gandhi) -
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