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

PIC oscillator tutorial

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



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PIC oscillator tutorial
PostPosted: Fri Apr 19, 2013 6:16 am     Reply with quote

Hi friends
I definitely am lost with all these different oscillator modes
Do you know where to find a clear and precise tutorial on it

For example, when I use a 20 MHz resonnator and #fuse HS what frequency my clock is ?
and HSPLL : 2 times ?

Which value have I to specify in #use delay : 20000000 oor 40000000

And in these cases, how the PIC knows to produce a USB 48MHz and not a 24MHz ?

You can derstand that I am lost, and because I am afraid not to be alone in this situation, please somebody give us a CLEAR and understable TUTORIAL

Good WE
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 19, 2013 7:59 am     Reply with quote

#use delay should always be the ULTIMATE frequency , including any PLL multiplication.


so 10mhz xtal with PLLx4 would be 40mhz
and so on
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 19, 2013 8:19 am     Reply with quote

Do #FUSES HS,PLL5 have sense ? or //#FUSES HSPLL,PLL5 is correct ?

And in this case the freq. is 20MHz or more (with a 20M resonator).
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 19, 2013 8:28 am     Reply with quote

#fuses mirror the datasheet features of the actual PIC

different oscillator PLL settings depend on individual pic models

let the DATASheet for your model pic be your guide
( you never specified what PIC you are working with )


PLL X4 is the MOST common


if in doubt - set a timing loop with timer0, at a precise divisor and then
toggle a pin at a given rate , then measure the pin toggle frequency.

simple experiment you can do to know what result you are really getting
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 19, 2013 8:38 am     Reply with quote

I use a PIC18F2550 with a resonator 20MHz

With #FUSES HS and #use delay(clock=20000000) -> Time3 div_by_1 == 5,48ms

With #FUSES HS,PLL2 and #use delay(clock=20000000) -> Time3 div_by_1 == 5,48ms

With #FUSES HSPLL,PLL2 and #use delay(clock=20000000) -> it doesn't work

With #FUSES HSPLL,PLL2 and #use delay(clock=40000000) -> it doesn't work

And what configuration have I to use if I want a reliable USB ?

Thanks for all
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Apr 19, 2013 10:43 am     Reply with quote

Quote:

reliable USB ?


USB1.1 ?? or USB2.x ???


and still you don't say WHAT PIC ???????
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Apr 19, 2013 11:02 am     Reply with quote

Well, the issue with usb is that usb has its own dictate of a 24Mhz clock.
(usb 2.0 D+ D- wires) The pic internal usb clock or the pic code clock can be different. Now since the pic clock and the usb clock are derived from the same external frequency the external frequency is constrained to some multiple of a common divisor.
EX 18F2455 16mhz xtal common divisors are 2 ,4 , 8 ,16
We must choose 4 since only with PLL4 in the fuses can we get 16mhz down to 4 mhz ready for multiplication to the pic internal usb clock ( a fixed multiple of 24mhz) the 18F2455 data sheet says the internal usb has a fixed 24 x PLL and needs 96 mhz for the internal usb part. So 16 mhz is prescaled to 4hz by PLL4 and in the pic usb circuit rescaled once more to 96Mhz via an internal clock multiplied of 24x
Now suppose we want our pic code to run at 32 mhz but we now know the internal is at 96Mhz
#use delay(clock=32000000) then we need CPUDIV2 which is a bit confusing since it is really divide by three to get 32Mhz.
A recap the external 16Mhz clock was manipulated to 96Mhz for the pic internal usb needs and then the 96mhz was then reduced to 32Mhz for our pic code needs.
Perhaps this is not a good explanation and maybe others have a better way of explaining it. The constraint is the usb part of the pic has a chip data sheet dictated osc freq. The user frequency is then constrained by this and the avialable divisors specified in the fuses statement.

An aside
Je crois qu'une explanation en francais va etre aussi complique. Par hazard Jean votre anglais est formidable.
Ttelmah



Joined: 11 Mar 2010
Posts: 19378

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 11:20 am     Reply with quote

Jean FOUGERON wrote:
I use a PIC18F2550 with a resonator 20MHz

With #FUSES HS and #use delay(clock=20000000) -> Time3 div_by_1 == 5,48ms

With #FUSES HS,PLL2 and #use delay(clock=20000000) -> Time3 div_by_1 == 5,48ms

With #FUSES HSPLL,PLL2 and #use delay(clock=20000000) -> it doesn't work

With #FUSES HSPLL,PLL2 and #use delay(clock=40000000) -> it doesn't work

And what configuration have I to use if I want a reliable USB ?

Thanks for all


With this chip, the PLL, _must_ be fed with 4MHz.

So PLL5, is the only legal PLL divisor with a 20MHz clock. With 20MHz, this is _required_ to give the 96MHz USB clock.

Then understand that the PLL always runs. HS means 'feed the CPU clock off the master oscillator without the PLL', while HSPLL means 'feed the CPU clock off the USB PLL output'. The PLL stays running in both cases.

Since the PLL output is 96MHz, you cannot get 20MHz using HSPLL. You need to select HS instead. Then with CPUDIV1, your CPU will be running at 20MHz.

Now if you look at the data sheet, you have four dividers (called by CCS CPUDIV1, CPUDIV2, CPUDI3, and CPUDIV4). If using 'HS', these specify the division to be used from the master clock to feed the CPU.
So if you specify CPUDIV2, your CPU runs at 10MHz, etc..

However when you specify HSPLL, the division starts from the 96MHz clock, and the division ratios change.
CPUDIV1 gives /2
CPUDIV2 gives /3
CPUDIV3 gives /4
CPUDIV4 gives /6

So possible clocks are 48MHz, 32, 24, and 16MHz. These are always the _only_ clocks possible when HSPLL is selected (since the PLL always gives 96MHz).

Best Wishes
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 22, 2013 2:26 am     Reply with quote

asmboy wrote:

reliable USB ?

USB1.1 ?? or USB2.x ??? USB2


and still you don't say WHAT PIC ???????


Quote:
I use a PIC18F2550 with a resonator 20MHz
Jean FOUGERON



Joined: 30 Nov 2012
Posts: 110
Location: France

View user's profile Send private message Visit poster's website

PostPosted: Mon Apr 22, 2013 2:30 am     Reply with quote

Douglas Kennedy wrote:


An aside
Je crois qu'une explanation en francais va etre aussi complique. Par hazard Jean votre anglais est formidable.


Thanks so much Douglas, it is kind of you.
Yes these chock manipulations are a bit confusing, I would like to fiind a clear table sheet with all the #FUSES well explained. Maybe I am not the only one in this case ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19378

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 3:57 am     Reply with quote

The translation between CCS fuses and 'what they actually are', is in the document 'fuses.txt' that comes with the compiler. This is an 'often missed resource'.
Then the reference from this, is the data sheet.
Some are really annoying like the CPUDIV ones. Problem here is that (for instance) the pattern 01, means /2, when used with the crystal as an input yet /3 from the PLL. CCS in their 'wisdom' elected to call this fuse CPUDIV2, and give the description '/2 postscaler', but this is simply wrong from the PLL....
Personally I wish they had been a little less 'spoon-feeding' in their thinking, and on fuses like this, used the binary patterns, so you'd have CPUDIV00 CPUVIV01 CPUDIV10 & CPUDIV11, with the numbers corresponding to the binary values put into the CPUDIV bits, then a simple look in the data sheet would give the actual dividers without any confusion....

Best Wishes
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