How to Get a 0.1-µs Unit Timestamp with FX3 – KBA220034

Version: **

 

Question:

How to get 0.1-µs unit timestamp with FX3?

 

Answer:

 FX3 has a complex GPIO timer. To read the current timer value, use the CyU3PGpioComplexSampleNow API. As a result, it is possible to get 0.1-µs unit timestamp with the GPIO timer properly configured.

Assume the value of SYS_CLK_PLL is 403.2 MHz, a 0.1-µs unit timestamp needs the timer running at around 10 MHz frequency

1. Configure Fast GPIO Clock at approximately 10 MHz. Fast GPIO Clock is derived from SYS_CLK_PLL/4 with divider set as 10, so the frequency of Fast GPIO Clock is 10.08 MHz. 
          CyU3PGpioClock_t gpioClock;
         /* Initialize the GPIO module */
         gpioClock.fastClkDiv = 10; 
          gpioClock.slowClkDiv = 0;
          gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2;
          gpioClock.clkSrc = CY_U3P_SYS_CLK_BY_4;
CY_U3P_SYS_CLK_BY_4;           gpioClock.halfDiv = 0; 

          return CyU3PGpioInit(&gpioClock, NULL);

2. Configure DUMMY_COMPLEX_GPIO to be in static output mode. 
         /* Configure DUMMY_COMPLEX_GPIO as static mode output*/ 
        gpioComplexConfig.outValue = CyFalse; 
        gpioComplexConfig.inputEn = CyFalse; 
        gpioComplexConfig.driveLowEn = CyTrue;
        gpioComplexConfig.driveHighEn = CyTrue;
        gpioComplexConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;
        gpioComplexConfig.intrMode = CY_U3P_GPIO_INTR_TIMER_ZERO;
        gpioComplexConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ; 
        gpioComplexConfig.timer = 0; 
        gpioComplexConfig.period = 0xffffffff;
        gpioComplexConfig.threshold = 0xffffffff;
        status = CyU3PGpioSetComplexConfig(DUMMY_COMPLEX_GPIO, &gpioComplexConfig); 
        if (status != CY_U3P_SUCCESS
        {
           CyU3PDebugPrint (4, "CyU3PGpioSetComplexConfig failed, error code= %d\n" ,status);
           CyCx3UvcAppErrorHandler(status); 
        }

3. Use the CyU3PGpioComplexSampleNow API to get the timestamp. 
     CyU3PGpioComplexSampleNow(DUMMY_COMPLEX_GPIO, ×tamp);