Quote Originally Posted by ngeronikolos View Post
Taylor,

Thanks for your interested.
So, you said that the following code running in 20mhz take 2μsec:
----------------------------
START:
If PORTA.1 = 1 THEN
GO TO SOMEWHERE1
ENDIF
If PORTA.2 = 1 THEN
GO TO SOMEWHERE2
ENDIF

GOTO START
--------------------------

I need to check all the ports of A&B in a loop.
1 LOOP SHOULD TAKE MAXIM 500μsec.

Please advice
Nikos
MPLab has a fine, working simulator in it that will count cycles/time for whatever you want. You just have to set breakpoints at the correct places and keep track of the count in the window. And you can check your .lst file to actually count the number of instruction words used by a particular statement.

At any rate,

Clk = 20mhz = 5mhz instruction rate = .2us per instruction

START: = 0 cycles

If PORTA.1 = 1 THEN
GO TO SOMEWHERE1
ENDIF

is roughly equivalent to a BTFSS instruction, 2 cycles

depending on the PIC and options used, checking all bits in Port A and B is 16 checks. Total of 32 cycles just for the checking. Add in 2 cycles for the jump back to the start, 34 cycles.
So, this loop, not including the GOTO SOMEWHEREs, takes about 34 cycles.

But, we haven't including any PBP interrupt checking or CLRWDTs yet. So, assume that you have an ON INTERRUPT statement somewhere, add in another 8 cycles (I think, I'll check when I get home) for each interrupt check, which happens before each PBP statement. Same thing for a CLRWDT.

Total so far = 34 + ( 17 * 8, interrupt check) + ( 17 x 1, CLRWDT ) = 187 cycles. .2us per cycle * 187 cycles = 37.4us per loop not including any goto's. 26738hz loop rate.

Again, if you have any doubts, check your .LST file generated by the assembler and manually count the number of instructions between the start and end of the loop.