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

cross mob
ArSa_3842301
Level 3
Level 3
25 sign-ins 10 replies posted 10 questions asked

I want to configure some GPIO as pwm signals, but a don't know how to do it. For this reason, i have the following questions:

-first of all, I have seen that  GPIOs have two different configurations: simple and complex. But, all GPIOs are able to work with both configurations?

-Secondly how are the functions to configure a GPIO as pwm output signal?. In order to set the duty cycle or frequency.

Thanks for the support.

0 Likes
1 Solution

Hello,

Please make the following modifications to the code:

1. In the IO_Matrix part:

    io_cfg.isDQ32Bit = CyFalse;

    io_cfg.useUart   = CyTrue;

    io_cfg.useI2C    = CyTrue;

    io_cfg.useI2S    = CyFalse;

    io_cfg.useSpi    = CyTrue;

    io_cfg.lppMode   = CY_U3P_IO_MATRIX_LPP_DEFAULT;

    /* GPIOs 50,51 and 52 enabled. */

    io_cfg.gpioSimpleEn[0]  = 0;

    io_cfg.gpioSimpleEn[1]  = 0;

    io_cfg.gpioComplexEn[0] = 0;

    io_cfg.gpioComplexEn[1] = 0x001C0000;

    status = CyU3PDeviceConfigureIOMatrix (&io_cfg);

    if (status != CY_U3P_SUCCESS)

    {

        goto handle_fatal_error;

    }

2. You need not call CyU3PGpioInit() as it is called internally by the API CyU3PMipicsiInitializeGPIO().

3. You need not override GPIO50 as it is already configured as a complex in the IO_Matrix.

4. For configuring complex GPIO 50 as PWM, use the following lines of code after the API CyU3PMipicsiInitializeGPIO() is called:

    /* Configure GPIO 50 as PWM output */

        gpioConfig.outValue = CyFalse;

        gpioConfig.inputEn = CyFalse;

        gpioConfig.driveLowEn = CyTrue;

        gpioConfig.driveHighEn = CyTrue;

        gpioConfig.pinMode = CY_U3P_GPIO_MODE_PWM;

        gpioConfig.intrMode = CY_U3P_GPIO_NO_INTR;

        gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;

        gpioConfig.timer = 0;

        gpioConfig.period = CY_FX_PWM_PERIOD;

        gpioConfig.threshold = CY_FX_PWM_25P_THRESHOLD;

        status = CyU3PGpioSetComplexConfig(50, &gpioConfig);

        if (status != CY_U3P_SUCCESS)

        {

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

            status);

        }

where CY_FX_PWM_PERIOD = (201600 - 1)

and     CY_FX_PWM_25P_THRESHOLD = (50400  - 1)

You can use your own period and threshold.

Please let me know if you still face any error after making the modifications mentioned above.

Best Regards,

Jayakrishna

Best Regards,
Jayakrishna

View solution in original post

0 Likes
7 Replies