View previous topic :: View next topic |
Author |
Message |
theteaman
Joined: 04 Aug 2006 Posts: 98
|
PIC speed fundamentals |
Posted: Tue Aug 15, 2006 11:24 pm |
|
|
Hello
In this forum I see a lot of references to usecs (I assume microseconds) and clocks and oscillators etc
What I want to be able to do is calculate how long, say, an SPI operation will take. I want to know the significance of 'usecs' and the relation with a 20MHz crystal oscillator etc.. Yes I know these things are probably in the datasheet but I don't even know where to begin looking. I think this is fundamental knowledge that I'm missing. Can someone explain it to me, or point me to a web reference? Thanks |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Aug 16, 2006 12:42 am |
|
|
The speed at which the PIC runs (executes instructions) is always the crystal speed (except in case of PLL) divided by 4. For those PICs with PLLs, if they are enabled, the execution speed will be the crystal speed since the PLL is x4.
So if your PIC's crystal is 20 MHz, the PIC actually runs at 5 MHz. This turns out to be one instruction every 200 ns (nanoseconds).
Most PIC instructions take one clock cycle to execute, but some can take 2 or more. The data sheet should help to clear this up for you.
When you see something like delay_us(2); in some code, the number of instruction cycles this delay will consume depends on the clock speed of the PIC. That's why each CCS program requires a #use delay statement - to let the compiler know how quickly the processor is running. |
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Wed Aug 16, 2006 1:00 am |
|
|
thanks newguy
another question.. is the PIC little or big endian?
EDIT:
also, why does 10MHz = 10Mbps in SPI mode? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Aug 16, 2006 8:23 am |
|
|
Newguy, I think you have that backwards.. or I misinterpreted
This is a quote from the 18F452 spec.
Quote: | A Phase Locked Loop circuit is provided as a programmable
option for users that want to multiply the frequency
of the incoming crystal oscillator signal by 4.
For an input clock frequency of 10 MHz, the internal
clock frequency will be multiplied to 40 MHz. |
|
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Aug 16, 2006 8:43 am |
|
|
theteaman wrote: | thanks newguy
another question.. is the PIC little or big endian?
EDIT:
also, why does 10MHz = 10Mbps in SPI mode? |
Since for the smaller parts, the native word size is 8-bits (may be for the 24's and 30's too, really haven't looked) the endian-ness isn't an intrinsic function of the chip. You can look at a LST file to see how 16-bit numbers are handled. Functions like make8() imply that it is handling multi-byte values as little endian.
In the native 8-bit word (and control registers) the LS bit is typically the lowest order bit, i.e. bit 0. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 16, 2006 9:30 am |
|
|
theteaman wrote: | also, why does 10MHz = 10Mbps in SPI mode? | Don't mix up Fcy and Fosc.
Fosc is the oscillator frequency (Max 40 MHz).
Fcy is the instruction cycle frequency = 1/4 Fosc (Max. 10MHz)
The SPI maximum bitrate = Fcy = 10Mbps. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Wed Aug 16, 2006 11:44 am |
|
|
treitmey wrote: | Newguy, I think you have that backwards.. or I misinterpreted
This is a quote from the 18F452 spec.
Quote: | A Phase Locked Loop circuit is provided as a programmable
option for users that want to multiply the frequency
of the incoming crystal oscillator signal by 4.
For an input clock frequency of 10 MHz, the internal
clock frequency will be multiplied to 40 MHz. |
|
You're right, that wasn't the clearest thing I've ever said.
The PLL exists so that you can use a relatively slow crystal to minimize EMI. The datasheet is correct in that the PLL multiplies the external xtal frequency by 4 internal to the PIC, but the internal system (instruction) clock is this multiplied frequency divided by 4. So, in a convoluted way, when you use the PLL the PIC's internal clock runs at the same speed as your xtal. |
|
|
theteaman
Joined: 04 Aug 2006 Posts: 98
|
|
Posted: Wed Aug 16, 2006 5:12 pm |
|
|
Thank you everyone |
|
|
|