In CX3 can we read a time 10us using GPIO timer?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
SaKu_1902391
Level 1
Level 1
Welcome! First question asked First reply posted

Hi all,

I am trying to read the PWM pulse where ON time ranges to 10us and OFF time ranges to 80us. In CX3 , using the simple GPIO interrupt as both edges and complex gpio for reading the GPIO timer. During ON time read the GPIO timer using the CyU3PGpioComplexSampleNow and do the same during the OFF interrupt. By subtracting the OFF time with ON time am not getting the expected ON time value. My doubt is using the GPIO timer can we read the PWM pulse where ON time is 10us?? If the ON time is 40us above we can able to read the time correctly. Below is the simple GPIO and complex GPIO configuration. The SYS_CLK_PLL is 403.2 MHz.

  //Clock configuration

   gpioClock.fastClkDiv = 10;

    gpioClock.slowClkDiv = 10;

    gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2;

    gpioClock.clkSrc = CY_U3P_SYS_CLK_BY_4;

    gpioClock.halfDiv = 0;

      status = CyU3PGpioInit(&gpioClock, EsGpioInputIntrCb);

      if( status != CY_U3P_SUCCESS)

      {

      CyU3PDebugPrint (4, "\n\rSee3CAM_CU30 AppInit:GPIOInit Err = 0x%x",status);

    // CyCx3AppErrorHandler(status);

      }

//Complex GPIO

   status = CyU3PDeviceGpioOverride(25, CyFalse);

    if (status != 0)

    {

    /* Error Handling */

    CyU3PDebugPrint(4, "PAN_GPIO override failed, error code = %d\n", status);

    }

        /* Configure DUMMY_COMPLEX_GPIO as static mode output*/

    complex_gpioConfig.outValue = CyFalse;

    complex_gpioConfig.inputEn = CyFalse;

    complex_gpioConfig.driveLowEn = CyTrue;

    complex_gpioConfig.driveHighEn = CyTrue;

    complex_gpioConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

    complex_gpioConfig.intrMode = CY_U3P_GPIO_INTR_TIMER_ZERO;

    complex_gpioConfig.timerMode = CY_U3P_GPIO_TIMER_LOW_FREQ;

    complex_gpioConfig.timer = 0;

    complex_gpioConfig.period = 0x7fffffff;

    complex_gpioConfig.threshold = 0x7fffffff;

    status = CyU3PGpioSetComplexConfig(25, &complex_gpioConfig);

    if (status != CY_U3P_SUCCESS)

    {

       CyU3PDebugPrint (4, "CyU3PGpioSetComplexConfig failed, error code= %d\n" ,status);

    }

//Simple GPIO

/* GPIO 17 as interrupt enabled for both edge */

status = CyU3PDeviceGpioOverride (17, CyTrue);

if (status != CY_U3P_SUCCESS)

CyU3PDebugPrint(4, "\n\resUVCGpioInit DeviceGpioOverride failed, error code = %d", status);

gpioConfig.outValue = CyTrue;

gpioConfig.driveLowEn = CyFalse;

gpioConfig.driveHighEn = CyFalse;

gpioConfig.inputEn = CyTrue;

gpioConfig.intrMode = CY_U3P_GPIO_INTR_BOTH_EDGE;

status = CyU3PGpioSetSimpleConfig(17, &gpioConfig);

if (status != CY_U3P_SUCCESS)

CyU3PDebugPrint(4, "\n\resUVCGpioInit SetSimpleConfig failed, error code = %d", status);

// GPIO Interrupt

//High Event

glreadHsyncONStop=0;

CyU3PGpioComplexSampleNow(25,&glreadHsyncONStop);

glontime=glreadHsyncONStop;

glcurrentvalue1=glontime-glofftime;

glreadBuffer1[glHsyncCount]=glcurrentvalue1;

glHsyncCount++;

//Low Event

glreadHsyncONStop=0;

CyU3PGpioComplexSampleNow(25,&glreadHsyncONStop);

glofftime=glreadHsyncONStop;

glcurrentvalue=glofftime-glontime;

glreadBuffer[glHsyncCount1]=glcurrentvalue;

glHsyncCount1++;

Will print the timer value once the glHsyncCount1 reaches 50 in another thread.

0 Likes
1 Solution

Hello Sathish,

I missed out somethings on the gpio clock configuration

Clock source in your GPIO clock configuration is CY_U3P_SYS_CLK_BY_4 i.e. (403.2/4 ~100 MHz)

GPIO Fast clock = Clock source / divider value   (Fast clock (100/10 = 10 MHz)

GPIO Slow clock = GPIO fast clock /  slow clock divider value (Slow clock (10/10) =  1 MHz)

Simple GPIO  clock =  GPIO fast clock / simplediv value ( Simple GPIO sampling clock (10/2) = 5 MHz)

Simple GPIOs use the FX3 GPIO Simple Clock to sample the pins. In your case the clock frequency is  5 MHz.With this frequency the sampling will be done at 0.2 us interval which seems to be fine. If possible you can try increasing the Simple GPIO sampling clock so that sampling time can be reduced further. The maximum value of simple GPIO clock can be around 100 MHz with setSysClk400 = true.

The CyU3PGpioGetValue API in the callback might cause some overhead. GPIO register can be used directly to read the input value to the GPIO. You can refer to FX3 TRM for more details on GPIO registers.

CY_U3P_LPP_GPIO_SIMPLE_ADDRESS(n) = (uvint32_t*)(0xe0001100 + ((n)*(0x0004)))

#define IN_VALUE 0x02 /* The 0th bit is the value that is input on the pins */

uvint32_t *gpio_n_reg = CY_U3P_LPP_GPIO_SIMPLE_ADDRESS;

******in callback************

val = (*gpio_43_reg & 0x2) ;

if (val = 0x2) // if GPIO is high

{

........

}

Test 1: Please try keeping the slow clock and the simple GPIO clock same

Test 2: Try using CY_U3P_GPIO_TIMER_HIGH_FREQ instead of CY_U3P_GPIO_TIMER_SLOW_FREQ

complex_gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

Also, let me know how do you convert the timestamp into the actual time.

Please let me know how much value do you get for the ON time for both fast and slow clock (with simple GPIO clock same as slow clock)

If you just want measure either the GPIO high time or low time you can try to configure the input GPIO as complex GPIO instead of simple GPIO and use complex mode as CY_U3P_GPIO_MODE_MEASURE_HIGH/ CY_U3P_GPIO_MODE_MEASURE_LOW

Please let me know if any queries on this

Regards,

Rashi

Regards,
Rashi

View solution in original post

0 Likes
3 Replies
lock attach
Attachments are accessible only for community members.
Rashi_Vatsa
Moderator
Moderator
Moderator
5 likes given 500 solutions authored 1000 replies posted

Hello,

From the description and the code snippet that you have shared it seems that you have referred to this KBA How to Get a 0.1-µs Unit Timestamp with FX3 – KBA220034  but there is a difference that you are using a slow clock instead of the fast clock.

Please refer to the firmware attached with this thread Re: CX3: How to set tick rate to 1 microsecond

I have modified the same firmware to use the slow clock as done in the GPIO configuration shared by you.

Please let me know if this works at your end. You can make the necessary changes to firmware according to your application.

Please let me know if any query on this

Regards,

Rashi

Regards,
Rashi
0 Likes

Hi Rashi,

Thanks for sharing the source code.

In that source code also, am getting the same behavior which I said earlier.  In this code also, am not able to get the correct time for the signal if the ON time & OFF time is below 50us.  The thing I need to know whether CX3 can able to read the time of the PWM signal where ON time is 12 us. Is there any limitation in GPIO?

0 Likes

Hello Sathish,

I missed out somethings on the gpio clock configuration

Clock source in your GPIO clock configuration is CY_U3P_SYS_CLK_BY_4 i.e. (403.2/4 ~100 MHz)

GPIO Fast clock = Clock source / divider value   (Fast clock (100/10 = 10 MHz)

GPIO Slow clock = GPIO fast clock /  slow clock divider value (Slow clock (10/10) =  1 MHz)

Simple GPIO  clock =  GPIO fast clock / simplediv value ( Simple GPIO sampling clock (10/2) = 5 MHz)

Simple GPIOs use the FX3 GPIO Simple Clock to sample the pins. In your case the clock frequency is  5 MHz.With this frequency the sampling will be done at 0.2 us interval which seems to be fine. If possible you can try increasing the Simple GPIO sampling clock so that sampling time can be reduced further. The maximum value of simple GPIO clock can be around 100 MHz with setSysClk400 = true.

The CyU3PGpioGetValue API in the callback might cause some overhead. GPIO register can be used directly to read the input value to the GPIO. You can refer to FX3 TRM for more details on GPIO registers.

CY_U3P_LPP_GPIO_SIMPLE_ADDRESS(n) = (uvint32_t*)(0xe0001100 + ((n)*(0x0004)))

#define IN_VALUE 0x02 /* The 0th bit is the value that is input on the pins */

uvint32_t *gpio_n_reg = CY_U3P_LPP_GPIO_SIMPLE_ADDRESS;

******in callback************

val = (*gpio_43_reg & 0x2) ;

if (val = 0x2) // if GPIO is high

{

........

}

Test 1: Please try keeping the slow clock and the simple GPIO clock same

Test 2: Try using CY_U3P_GPIO_TIMER_HIGH_FREQ instead of CY_U3P_GPIO_TIMER_SLOW_FREQ

complex_gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

Also, let me know how do you convert the timestamp into the actual time.

Please let me know how much value do you get for the ON time for both fast and slow clock (with simple GPIO clock same as slow clock)

If you just want measure either the GPIO high time or low time you can try to configure the input GPIO as complex GPIO instead of simple GPIO and use complex mode as CY_U3P_GPIO_MODE_MEASURE_HIGH/ CY_U3P_GPIO_MODE_MEASURE_LOW

Please let me know if any queries on this

Regards,

Rashi

Regards,
Rashi
0 Likes