PIN_FREQUENCY

The PIN_FREQUENCY function returns the frequency in Hz of an XJLink2 pin. Pins can be referenced by their name if they are a PIO pin, by their JTAG function if they are a JTAG pin (i.e. TDI/TDO/TCK/TMS, etc) or else by their number.

PIN_FREQUENCY was added in XJTAG v2.3 and is not recognised in versions prior to that.

Note that the clock generators in the XJLink2 require some time to settle so if the PIN_FREQUENCY function is called immediately at the start of running tests a small additional delay may occur before the measurement is taken to ensure that the measurement is accurate.

Syntax

PIN_FREQUENCY( PIO.pioName { , INT timePeriod })
PIN_FREQUENCY( jtagPin { , INT timePeriod })
PIN_FREQUENCY( INT pinNumber { , INT timePeriod })

Parameters

pioName

The name of a PIO pin. A compile error will be produced if this PIO pin does not exist in the Pin Mapping.

jtagPin

Any one of the possible JTAG pins: TDI, TDI2 to TDI8, TDO, TDO2 to TDO8, TCK, TCK2 to TCK8, TMS, TMS2 to TMS8, RTCK.

In versions of XJTAG prior to v4.0, the pins TCKb, TCKc and TCKd, and TMSb, TMSc and TMSd were used in place of the numbered TCK and TMS pins. These forms are still supported for backwards compatibility, but will be removed in a future version of XJTAG.

pinNumber

The pin number on the XJLink2 JTAG connector and between 1 and 20. If 0 or greater than 20, a runtime error will occur. Referencing pins by number is only supported on an XJLink2; if an XJLink-PF20 or XJLink-PF40 is being used, then an error occurs.

timePeriod

An optional period of time in milliseconds over which the frequency measurement will be made. If this argument is missing, the frequency will be measured over 1000 ms (1 second). Valid values are 1, 10, 50, 100, 500, 1000 (1 second), 5000 (5 seconds) and 10000 (10 seconds). If timePeriod is not one of these values then it is rounded up to the next one. If it is greater than 10000 it is rounded down to 10000.

Return value

An INT value containing the measured frequency in Hz.

Errors

An error can occur in the following circumstances:

  • The specified pinNumber is zero or greater than 20 (compile-time or run-time).
  • The specified PIO pin is not defined in the pin mapping (compile-time).

Example

// Function to check a PIO pin frequency is within 0.01% of the expected value.
// Assumes there is a PIO pin called TRST.
//
GLOBAL TestPioFrequency()(INT result)
  INT expectedFrequency := 10000000; // expect 10 MHz
  INT actualFrequency;

  result := RESULT_PASS;
  SLEEP(5000); // allow settle
  actualFrequency := PIN_FREQUENCY(PIO.TRST);
  PRINT("Frequency read: ", actualFrequency, " Hz\n");

  IF actualFrequency > expectedFrequency + (expectedFrequency / 10000) THEN
    result := RESULT_FAIL;
  END;
  IF actualFrequency < expectedFrequency - (expectedFrequency / 10000) THEN
    result := RESULT_FAIL;
  END;
END;

See Also