Keywords: number, XPS, timer
How can I measure the number of clock cycles needed to execute a piece of my code?
You can use the PLB Timer Peripheral to measure the processor execution cycles. The PLB Timer is a free-running counter that can be controlled through software. In the software code running on MicroBlaze, you can use functions to initialize, set, reset, start, and stop the timer as follows:
1. Initialize the timer functions:
XTmrCtr_Initialize(&XPS_Timer, XPAR_XPS_TIMER_1_DEVICE_ID);
2. Set the timer reset value:
XTmrCtr_SetResetValue(&XPS_Timer, 0, 0x00000000);
3. Start the XPS Timer to measure the cycles needed to copy the buffer:
a. Reset the timer using the function:
XTmrCtr_Reset(&XPS_Timer, 0);
b. Start the timer to count the processor clock cycles:
XTmrCtr_Start(&XPS_Timer, 0);
4. Run the desired routines.
5. Stop the timer:
XTmrCtr_Stop(&XPS_Timer, 0);
6. Measure the consumed clock cycles:
cycles = XTmrCtr_GetValue(&XPS_Timer, 0);