View previous topic :: View next topic |
Author |
Message |
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
Oscillator config / 18F4550 |
Posted: Sun Feb 12, 2012 3:25 pm |
|
|
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) - |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
|
Posted: Mon Feb 13, 2012 3:22 pm |
|
|
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) - |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 13, 2012 3:27 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
|
Posted: Mon Feb 13, 2012 3:46 pm |
|
|
Great! That seems to works fine!
I also measured delays with oscilloscope : 1000ms is a "real" second on the scope.
Thank you ![Smile](images/smiles/icon_smile.gif) _________________ - Be the change you want to see in the world (Gandhi) - |
|
![](templates/subSilver/images/spacer.gif) |
|