Embedded Artists


We are the leading providers of products and services around prototyping, evaluation and OEM platforms using NXP's ARM-based microcontrollers.

LPC4088DM Using GPIO to Measure Time

When trying to get the most out of the hardware and to get the best possible performance for your program it is important to know what is executing in the system. There are many ways to do this. One way that has minimal impact on the system performance is to use some of the unused pins to signal start/end of the interesting tasks.

Using an external tool, for example LabTool, to sample the level of those pins with a high enough sample rate it is possible to see what happens.

The image below comes from an attempt to profile a time consuming part of a graphical program: /media/uploads/embeddedartists/labtool_example.png

Without going into details it is possible to see that the MEAS7 and MEAS3 signals are high for a longer time than e.g. MEAS8.

Measuring

Most of the needed work is already done in the meas.h file in the DMSupport library.

Start by enabling the measuring pins in the dm_board_config.h file:

#define DM_BOARD_ENABLE_MEASSURING_PINS


The init() function in DMBoard will then set all used pins to GPIO outputs and LOW.

When enabled, the following pins are used:

GPIOPlace on display moduleMACROS
GPIO1[24]Connector J-10, pin 7SET_MEAS_PIN_1()
CLR_MEAS_PIN_1()
GPIO1[23]Connector J-10, pin 8SET_MEAS_PIN_2()
CLR_MEAS_PIN_2()
GPIO1[20]Connector J-10, pin 9SET_MEAS_PIN_3()
CLR_MEAS_PIN_3()
GPIO1[19]Connector J-10, pin 10SET_MEAS_PIN_4()
CLR_MEAS_PIN_4()

Hook up your logic analyzer to the pins above.

To measure the time something takes in your code:

void foo() {
  SET_MEAS_PIN_1();

  // interesting stuff here..

  CLR_MEAS_PIN_1();
}


Detecting Running Thread

There is an example in the Using RTOS wiki page showing how to detect which thread is running and it uses the measurement pins described here.


All wikipages