instruction cycles verification

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi all!
Attached is my template and code...
In the previous posting i was asking about how to read the instruction
cycles...
you will find in the attachement 3 modules: Binary to BCD Module (Bin_2_bcd), BCD to 7 Segment Module (Bcd_2_7seg), BCD to binary Module (bcd_2_binary)

im using MPLAB v7 and simulating the whole thing with PIC16F684 (no implementation on real processor)...

i managed to read the code size for each module, i read 28, 15, 11 words for Bin_2_bcd, Bcd_2_7seg and bcd_2_binary respectively!
please check it out if im right?

my main concern is to read the instruction cycles (best and worst case) for each module ! and my understanding is that for best (worst) case i'll have to test each module with "0" ("99"), am i right??

In the previous posting u guyz gave me some useful informations that really opened my mind...I would like you, for checking purposes, to provide the instruction cycles for each module (best and worst cases) and explain the method used!

Also, please lemme know if u find anything that does not make sense in the code or comment!!!

As for the bcd_2_binary module, can u explain the algorithm used?

Everything that i need clarification with has been highlighted in red!!!

Notice that i have highlighted in red "_congig...." in the header file section coz it was giving me an error while building it so i was putting a semi colon so it can ignore it!

To check each module stuff, i was putting other module codes and...as comments

NOTE: this exercise had for purposes to get familiar with MPLAB IDE and its functionalities, PIC instruction set!

i have downloaded lots of documentations regarding PIC microcontrollers and MPLAB and im learning them...

my goal is to really master it as i like it

regards,
 

Attachments

Markd77

Joined Sep 7, 2009
2,806
Depending on the algorithm, it might not be sufficient to test only 2 values. However in your cases (unless I missed something) I think they will take the same time for all values.
This part for example always takes the same time because btfsc takes 2 instruction cycles if it causes a skip, but only one cycle if there is no skip.

btfsc temp,7 ; skip next instruction if bit7 in temp is clear
addlw 0x30 ; value is added to value in the W register
movwf bcdUnits ; result is stored into bcdUnits
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@ Markd77: ok ! I was thinking of testing each module with smallest (0) and largest (99) value for binary to bcd module...I'm not sure but I think they will have the same number of instr.cycles anyway how many do u think each module has? (Best & worst case)

Thx for ur reply
 

Markd77

Joined Sep 7, 2009
2,806
You can run it in the simulator with the stopwatch, it's easier than counting by hand.
A useful thing for testing is to bring up the file registers window, then you can change the value of a register without recompiling.
 

debjit625

Joined Apr 17, 2010
790
If you want to count the instruction cycles by hand, then in your device datasheet you will find a section named "INSTRUCTION SET SUMMARY" their you will find a table where all the instruction and their cycle are given.

Instead of posting your codes in a *.doc file, post it using code tags. Like this
Rich (BB code):
Rich (BB code):
Rich (BB code):
btfsc temp,7 ; skip next instruction if bit7 in temp is clear
addlw 0x30 ; value is added to value in the W register
movwf bcdUnits ; result is stored into bcdUnits

In PIC16F627A the above instructions will take 1 instruction cycle for each instruction
that makes total 3 instruction cycles, now if the system clock source is 4MHz then each instruction will take about 1 micro second that gives us total 3 micro seconds.
In your earlier post I have already shown you how to calculate the timing...

Good Luck
 
Top