This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Incorrect Instruction Cycle Time F28335



Hi,

I am seeing something strange.  I have my uC configured to run at 150MHz.  PLLCR = 10, DIVSEL = 2, Oscillator = 30MHz, frequency on XCLKOUT Pin = 37.5MHz.

I would expect that one cycle takes 6.67nS, however I am seeing instructions take much longer to execute than I expect.  So I set up a test where I run the following:

for(;;)
	   {
		   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
		   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
		   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
		   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   asm (" NOT AH");
		   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
		   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
	   }

I am measuring the time between the 2nd & 3rd set of "Set & Clear."  I am seeing that this time takes 650ns to execute the 10 assembly instructions which should only take 1 cycle each to execute or 66.7ns.  Not sure why each instruction is taking about 10 times longer to execute.  What might be the problem?

Thanks,

-Alex

  • I enabled clock to show my how many clock cycles have passed and ran the instructions step by step.  This is how long they are taking to execute (shown to the left of the instruction):

    for(;;)
    	   {
    	32	   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
    	16	   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
    	16	   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
    	16	   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
    	1	   asm (" NOT AH");
    	16	   asm (" NOT AH");
    	1	   asm (" NOT AH");
    	16	   asm (" NOT AH");
    	1	   asm (" NOT AH");
    	16	   asm (" NOT AH");
    	1	   asm (" NOT AH");
    	16	   asm (" NOT AH");
    	1	   asm (" NOT AH");
    	16	   asm (" NOT AH");
    	16	   GpioDataRegs.GPBSET.bit.GPIO32 = 1;
    	16	   GpioDataRegs.GPBCLEAR.bit.GPIO32 = 1;
    	   }

    Why do those assembly instructions alternate between 1 & 16?

  • Alejandro,

    Is this executing from Flash or RAM?  The code on Flash has wait states.

    You should look at the disassembly.  You will see that there is not always a one-to-one mapping between C and assembly instructions.  Although that does not explain the clock cycles in the 'asm'  lines, it would explain why the first GPIO line is slower, because it includes the branch instruction for the loop.

    I usually time algorithms with an oscilloscope, because it is usually easier to interpret the results.  Have you tried the function, DSP28x_usDelay?  It has a tight calibrated loop.  If you have code like:

    #define CPU_CLOCK_HZ     150000000UL

    #define wait_usec(us) DSP28x_usDelay((us)*(CPU_CLOCK_HZ/1000000UL/5)-2)

    ...

    for (;;) {

        GpioDataRegs.GPBTOGGLE.bit.GPIO32 = 1;

        wait_usec(1000);

    }

    You should see a quite accurate toggle at 1ms.

    Regards,

    Bill

  • This is executing from Flash.

    I tried running this code however it immediately takes me to:
    interrupt void ILLEGAL_ISR(void)   // Illegal operation TRAP

    Is that bit of code clean?  Also I still do not understand what in the world is going on in those 'ASM 'lines. Anyone?

    Thanks.

  • I tried running from RAM and sure enough the cycle times make more sense, I am seeing those ASM instructions executing in <80nS.  So this leads me to the question, if I need this faster execution time for my project, I cannot program it each time and run it from the debugger,  would I need to get an external memory or something and load the program onto the uC on startup?  Is there another mechanism in the uC which I can utilize?

    Thanks,

    -Alex

  • See this post here:

    http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/222135/786284.aspx

    Basically, at startup your application will copy critical code sections to RAM and run them there.  The slower code stays in FLASH.

    Regards,

    Bill