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

cross mob

Pulse on FX3 Complex GPIO – KBA228439

Pulse on FX3 Complex GPIO – KBA228439

ChaitanyaV_61
Employee
Employee
50 questions asked 25 likes received 25 sign-ins

Author: HemanthR_06           Version: **

Translation - Japanese: FX3 Complex GPIOのパルス– KBA228439 - Community Translated (JA)

How do I use the FX3 API functions CyU3PGpioComplexPulseNow () and CyU3PGpioComplexPulse ()?

This article describes how to configure a Complex GPIO so that when either of these API functions  (CyU3PGpioComplexPulseNow () and CyU3PGpioComplexPulse ()) is called, a pulse is generated on the GPIO. See the FX3 API Guide in the FX3 SDK (C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\doc\firmware\ FX3APIGuide.pdf) for details.

CyU3PGpioComplexPulseNow ():

Use the following code snippet:

       /*Complex GPIO Configuration*/

    CyU3PGpioComplexConfig_t gpioConfig;

    gpioConfig.outValue = CyFalse;

    gpioConfig.inputEn = CyFalse;

    gpioConfig.driveLowEn = CyTrue;

    gpioConfig.driveHighEn = CyTrue;

    gpioConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

    gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR;

    gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

    gpioConfig.timer = 0;

    gpioConfig.period = CY_FX_PWM_PERIOD_3MS;

    gpioConfig.threshold = 0;

    apiRetStatus = CyU3PGpioSetComplexConfig(50, &gpioConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

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

                apiRetStatus);

        CyFxAppErrorHandler(apiRetStatus);

    }

       /*Initiate pulse now*/

       CyU3PGpioComplexPulseNow(50, CY_FX_PWM_25P_OF_3MS_THRESHOLD); //25% of 3ms is the threshold set

This snippet configures the Complex GPIO 50 (it is assumed that the corresponding bit in the I/O Matrix is set).

gpioConfig.period configures the period of the pulse to be generated (This example sets the period as 3 ms).

CyU3PGpioComplexPulseNow()is called to generate the pulse. As mentioned in the FX3 API Guide (C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\doc\firmware\FX3APIGuide.pdf), this function is used to drive a pulse out on the specified complex GPIO, starting immediately. The first parameter of this API function is the GPIO ID and the second is the threshold for the pulse.

Because the configured period of the pulse is 3 ms and the threshold is set to 0.25 * 3 ms, the generated pulse would be asserted for 0.75 ms and de-asserted for the rest of the period as shown in the Figure 1. There will not be any pulse on the GPIO until CyU3PGpioComplexPulseNow() is called again.

For reference to the time instance when CyU3PGpioComplexPulseNow() is called in the firmware, a GPIO Ref is set and then CyU3PGpioComplexPulseNow() is called.

pastedImage_0.png

Figure 1

Note that CyU3PGpioComplexPulseNow() will not wait to return until the pulse generation is completed. It will return immediately after the configuration of the threshold.

Note:

Calculation of gpioConfig.period and how it translates to time is as follows:

In the main() of FX3 firmware, CyU3PDeviceInit (&clockConfig) is called to configure the system clock. If DeviceInit call is done with NULL as the parameter, by default, the system clock would be 384 MHz. If it is called with the following configuration, the system clock would be 403.2 MHz.

CyU3PSysClockConfig_t clockConfig;

clockConfig.setSysClk400  = CyTrue; //system clock = 403.2MHz

clockConfig.cpuClkDiv     = 2; //cpu clock    = 201.6MHz

If the 3-ms period is required as in the above example, the number of clocks necessary: (201600000 * 0.003) = 604800

The value to be set in gpioConfig.period    = CY_FX_PWM_PERIOD_3MS = (604800 - 1)

If 25% of the period is to be set as the threshold, the number of clocks necessary: (604800 * 0.25) = 151200

The value of CY_FX_PWM_25P_OF_3MS_THRESHOLD = (151200 - 1)

CyU3PGpioComplexPulse ():

As mentioned in the FX3 API Guide, this API function is used to generate a delayed version of a pulse generated using CyU3PGpioComplexPulseNow(). For achieving this, gpioConfig.timer is used. Once this function is called, the timer of the complex GPIO starts incrementing from the value given in gpioConfig.timer, and when the timer rolls to ‘0’, the start of the pulse output happens.

The Complex GPIO configuration is shown below:

    gpioConfig.outValue = CyFalse;

    gpioConfig.inputEn = CyFalse;

    gpioConfig.driveLowEn = CyTrue;

    gpioConfig.driveHighEn = CyTrue;

    gpioConfig.pinMode = CY_U3P_GPIO_MODE_STATIC;

    gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR;

    gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

    gpioConfig.timer = CY_FX_PWM_PERIOD_1MS;

    gpioConfig.period = CY_FX_PWM_PERIOD_3MS;

    gpioConfig.threshold = 0;

    apiRetStatus = CyU3PGpioSetComplexConfig(50, &gpioConfig);

    if (apiRetStatus != CY_U3P_SUCCESS)

    {

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

                apiRetStatus);

        CyFxAppErrorHandler(apiRetStatus);

    }

    CyU3PGpioComplexPulse(50, CY_FX_PWM_25P_OF_3MS_THRESHOLD);

gpioConfig.period is same as in the example above. The timer is set to 1 ms (The value of gpioConfig.timer = CY_FX_PWM_PERIOD_1MS = (201600 - 1) as described above).

Because the timer value is set to (201600 - 1), the value of the timer becomes ‘0’ after 2 ms because the period is 3 ms.

Therefore, the Complex GPIO will be asserted 2 ms after the function call as shown in Figure 2. Similar to the example above, a simple GPIO named ‘Ref’ in the Figure 2 is asserted before the function call is made (this is to verify the delay given by the function).

pastedImage_6.png

Figure 2

Because the second parameter of CyU3PGpioComplexPulse() is the same as above example, the ON period of the pulse is for 0.75 ms.

As another example, Figure 3 shows the behavior of the GPIO configured with gpioConfig.timer = CY_FX_PWM_PERIOD_2MS = (403200 - 1) maintaining the period of the GPIO timer (3 ms) and the threshold of the pulse the same (0.75 ms).

pastedImage_12.png

Figure 3

Note:

If the timer value is set for the whole period (3 ms as in this example), the delay before the pulse start will be the period value (in this case 3 ms).

0 Likes
930 Views
Contributors