Why do I get inconsistent clock rate for PRU 28-bit shift input mode?

Hello everybody,

So I am trying to make a PRU program that reads Input to BBB in 28-bit shift mode. The following is my current code:

`

START:
//INITIALIZATION
// Enable the OCP master port – allows transfer of data to Linux userspace
LBCO r0, C4, 4, 4 // * load SYSCFG reg into r0 (use c4 const addr)
CLR r0, r0, 4 // * clear bit 4 (STANDBY_INIT)
SBCO r0, C4, 4, 4 // * store the modified r0 back at the load addr

//SETUP GPI FOR BIT-SHIFT INPUT
LBCO r0, C4, 8, 4 // * load SYSCFG reg into r0 (use c4 const addr)
LDI r0.b0, 0xAA // 0-1: 0x2 (01), 2: 0x0 (0), 3-7: 0x15 (10101)
LDI r0.b1, 0x2 // 8-12: 0x2 (01)
SBCO r0, C4, 8, 4 // * store the modified r0 back to the CFG register

MOV r1, 0x00010000 // r1: Shared RAM Address
MOV r2, 1 // r2: High Value
MOV r4, 0 // r4: Low Value
MOV r3, 0 // r3: input value

SBBO r4, r1, 0 , 2

//WAIT UNTIL START BIT IS SET
WBS r31.t29

READDATA:
QBBC READDATA,r31.t28
CALL TOGGLEFLAG
SBBO r31.w0, r1, 1, 2
LBCO r0, C4, 8, 4 // * load SYSCFG reg into r0 (use c4 const addr)
SET r0.t13
SBCO r0, C4, 8, 4
QBA READDATA

END:
MOV r31.b0, PRU0_R31_VEC_VALID | PRU_EVTOUT_0
HALT // End of program – below are the “procedures”

TOGGLEFLAG:
QBBC SETT2, r30.t2
CLR r30.t2
RET

SETT2:
SET r30.t2
RET

`

The idea behind this:

  • READDATA is the main loop

  • The program will wait until Cnt_16 flag is set and 16 bits are sampled

  • write the read value to RAM and toggle flag (for debugging)

  • Set Start Bit flag in GPCFG register to clear shift register
    However, when I checked in oscilloscope, I found some weird behavior, that is every 4th iteration of this loop, the duration this program takes to toggle r30.t2 is different (e.q. 1.8626 microseconds, 1.8755 microseconds, 1.8705 microseconds, 1.9818 microseconds). Is this normal or is there any problem in my implementation?

Moreover, if you have any suggestion about best practice in implementing what I intended to do (or coding PRU program overall), please let me know. I am very new to PRU programming and there is nobody in my lab that has prior knowledge about this subject.

Thank you for your kind attention. Looking forward to hear from you all.

Regards,
Yogi Salomo