Different execution speed between simulator and chip (LDRB, STRB instructions).
2005-09-26 by conhalk
Hello,
I am using the lpc2138, and I have wrote a program which includes
reading port0.16-24 pins at a 10 Mhz sampling rate:
// R6 contains port.26-24 address
LDRB R7,[R6,#0x00000002] // R5 contains the memory address
STRB R7,[R5,#0x00000000]! // to store the input(auto-increments)
NOP // R7 is temporary storage
LDRB R7,[R6,#0x00000002]
STRB R7,[R5,#0x00000001]!
NOP
LDRB R7,[R6,#0x00000002]
STRB R7,[R5,#0x00000001]!
NOP
......
......} X 128 total
......
LDRB R7,[R6,#0x00000002]
STRB R7,[R5,#0x00000001]!
NOP
LDRB R7,[R6,#0x00000002]
STRB R7,[R5,#0x00000001]!
NOP
As you can see, it doesn't branch anywhere. The problem is:
ON THE KEIL ARM SIMULATOR (60 MHZ) THE ROUTINE SAMPLES AT 10 Mhz.
ON THE REAL CHIP (60 MHZ) THE ROUTINE SAMPLES AT 5,5 Mhz ! ( I
specify the function to be copied to ram)
Meanwhile, I use an output compare timer on a pin, and it works at
10 Mhz both on the simulator and the chip (checked on a scope)!
The simulator shows the lDRB, STRB need 2,3 and the nop 1 cycle,
hence rate = 60 / (3+2+1) = 10Mhz
I guess LDRB, STRB actually take double time. If it is so, does
anybody know why? Is there any way around this?
I tried using four temporary registers in a chain sequence in case
of a pipeline issue from sequentially accessing the same register,
and stoped using write back. The result was the same. When I took
the NOP's out, speed was increased by approx. 1/10th.
Unfortunately I must use the 2138, and it has no external bus. Is it
possible to achieve 10 Mhz sampling with this chip?
Thank you.