PIC frequency

Thread Starter

dhruv1128

Joined Jun 28, 2014
6
Hello all,

I am using pic18f4550 and i am interfacing a crystal of 20Mhz. I want to know the execution time of 1 instruction cycle. I am having a great confusion. Please help me.

Also, suggest me the method to do so please.

Thanking you in advance
 

atferrari

Joined Jan 6, 2004
5,011
In case of doubt, using the simulator, MPLAB Sim, just by stepping through a simple series of NOPs, you could see how much time is spent in each instruction cycle.

Look for the "stopwatch" function.
 

Sensacell

Joined Jun 19, 2012
3,784
Very common problem, there are so many clocking options to consider.
I usually test the clock frequency like this:

loop:
btg LATX,X ;toggle IO pin state
bra loop

Measure the frequency of the output to confirm the clock speed.
This saves much confusion about what is really going on, it's easy to get confused and set the clock bits wrong, then drive yourself insane trying to set a UART Baud rate.
 

ErnieM

Joined Apr 24, 2011
8,415
Very common problem, there are so many clocking options to consider.
I usually test the clock frequency like this:

loop:
btg LATX,X ;toggle IO pin state
bra loop

Measure the frequency of the output to confirm the clock speed.
This saves much confusion about what is really going on, it's easy to get confused and set the clock bits wrong, then drive yourself insane trying to set a UART Baud rate.
But how long is a bra? I go a another step when pounding this out:

loop:
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bfs LATX,X ;toggle IO pin state
bcs LATX,X ;toggle IO pin state
bra loop

Then I look with a scope, and it is right there in my face what the instruction rate is.
 
Top