EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Calculating PIC instruction speed

Started by Nelson Viegas April 28, 2008
Hello group!

Although I'm able to do some stuff using PIC microcontrollers, I still
don't know to calculate how long does a PIC instruction takes to
execute! God knows I've been up and down the PIC16F628A datasheet and
maybe it's because I'm kinda of a noob, but I was unable to figure it
out.

Can anybody shed some light on this?

Thanks!

Best regards,
Nelson

----- Original Message -----
From: "Nelson Viegas"
To:
Sent: Thursday, April 17, 2008 12:40 PM
Subject: [piclist] Calculating PIC instruction speed
> Hello group!
>
> Although I'm able to do some stuff using PIC microcontrollers, I still
> don't know to calculate how long does a PIC instruction takes to
> execute! God knows I've been up and down the PIC16F628A datasheet and
> maybe it's because I'm kinda of a noob, but I was unable to figure it
> out.
>
> Can anybody shed some light on this?
>

Actually, it is pretty simple. Each instruction takes 4 clock cycles, so if
your clock is 4 MHz, each instruction takes 1 microsecond. However, any
instruction that poisons the pipeline takes an extra instruction time. So a
call will take 2 microseconds. A conditional branch will take 1 microsecond
if the branch is not taken, two if it is. Any time the next instruction is
not the next instruction in memory, then it takes an extra instruction time.
Also, modifying the program counter causes an extra instruction time, even
if the next instruction is the next in line.

But wait, there's an easier way. In the MPLAB simulator, there is a
stopwatch. Simply set breakpoints around the code you want to time, and
zero the stopwatch at the first breakpoint.

72/73 de WB8RCR http://www.qsl.net/wb8rcr
didileydadidah QRP-L #1446 Code Warriors #35

The 2024 Embedded Online Conference