Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 7th June 2008, 06:34 PM   (permalink)
Default PIC clock cycles, instructions, and crystal frequency?

I'm trying to educate myself more on the nitty-gritty of PIC assembly programming. First, I gather there is some kind of 1:4 relationship between PIC clock cycles and the PIC's crystal frequency. Is that right, and would anyone care to expand on that?

Second, if I'm trying to be careful about the timing in my program, how can I know how many cycles any given instruction will require (sorry if that's in the datasheet - if it is, can you point me to it?). Has anybody made an easy table illustrating assembly commands (or are they called instructions?) and their respective clock cycle requirements, e.g.:
Quote:
movlw = 1 clock cycle
movwf = ... etc
I don't know if that's right, but it seems to say that here, although some of the info regarding crystal frequencies and clock cylces is a little confusing:
Tutorial 4

Last edited by Hank Fletcher; 7th June 2008 at 06:36 PM.
Hank Fletcher is offline   Reply With Quote
Old 7th June 2008, 07:16 PM   (permalink)
Default

Quote:
Originally Posted by Hank Fletcher View Post
I'm trying to educate myself more on the nitty-gritty of PIC assembly programming. First, I gather there is some kind of 1:4 relationship between PIC clock cycles and the PIC's crystal frequency. Is that right, and would anyone care to expand on that?

Second, if I'm trying to be careful about the timing in my program, how can I know how many cycles any given instruction will require (sorry if that's in the datasheet - if it is, can you point me to it?). Has anybody made an easy table illustrating assembly commands (or are they called instructions?) and their respective clock cycle requirements, e.g.:

I don't know if that's right, but it seems to say that here, although some of the info regarding crystal frequencies and clock cylces is a little confusing:
Tutorial 4
A bunch of information is pic specific. Look under the Instruction Set Summary in the Data Sheet for info on how many cycles an instruction takes
AtomSoft is offline   Reply With Quote
Old 7th June 2008, 07:24 PM   (permalink)
Default

Hello,

It takes four oscillator cycles to complete one instruction cycle. Look at the section of the data sheet about the instruction set. It will have detailed info about each instruction. It will also break down what the processor is doing during the individual oscillator cycles. Take ADDLW for example: It takes one instruction cycle to complete, 4 oscillator cycles.

1.) Decode instruction
2.) Read the literal
3.) Process Data
4.) Write result to W

So if you run a 4MHz crystal, that means your period for one osc cycle is (1/4MHz) = 250 nS. Four of these makes one instruction cycle, 250 nS * 4 = 1000 nS = 1 uS.

Read, read, and re-read the instruction set summary chapter of the datasheet until it makes more sense how the processor executes instructions.
-Jacob
jacob.zurasky is offline   Reply With Quote
Old 7th June 2008, 07:55 PM   (permalink)
Default

Thanks, both! I have a follow-up question:

On the higher-end PICs, the product comparison charts list the individual PIC ICs speed in MIPs as oppose to oscillator frequency. Does that mean "millions of instruction cycles per second," then, which might not necessarily translate to "millions of instructions per second," since certain instructions might take more than one instruction cycle to complete?

Also, there doesn't seem to be any way to deduce the actual oscillator frequencies for those high-end PICs from the product comparison charts. If it's rated 40 MIPS, what frequency external oscillator would I have to get? 160MHz?
Hank Fletcher is offline   Reply With Quote
Old 7th June 2008, 08:06 PM   (permalink)
Default

I think the higher end PICs have a built in PLL clock multiplier. You'd have to check the PDF for the actual maximum oscillator frequency.
__________________
"Because I be what I be. I would tell you what you want to know if I
could, mum, but I be a cat, and no cat anywhere ever gave anyone a
straight answer, har har."
Sceadwian is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
89c52 crystal frequency gondu Micro Controllers 2 9th January 2008 06:39 PM
Crystal frequency redart Datasheet/Parts Requests 4 10th May 2006 07:25 AM
HELP: Connecting 4MHz crystal clock to PIC mr. mister Micro Controllers 3 21st April 2005 12:26 PM
Help with Crystal frequency generator 7404 quad2 input Electronic Projects Design/Ideas/Reviews 2 10th December 2004 04:19 PM
Can I use a 24mhz or 19.968 mhz crystal clock oscillator ? xpembedded Micro Controllers 1 9th June 2004 09:48 PM



All times are GMT. The time now is 06:59 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.