Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC clock cycles, instructions, and crystal frequency?

Status
Not open for further replies.

Hank Fletcher

New Member
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.:
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:
**broken link removed**
 
Last edited:
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:
**broken link removed**

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
 
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
 
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?
 
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.
 
Status
Not open for further replies.

Latest threads

Back
Top