EZ-USB FX3 Technical Reference Manual, Document Number: 001-76074 Rev. *F 196
Low Performance Peripherals (LPP)
8.9.4.3 Configure GPIO[50] to Generate PWM Output
The I/O matrix needs to be configured to use simple and complex GPIOs. I/Os that are not configured for peripheral
interfaces can be used as GPIOs. This selection must be explicitly made. Otherwise, these lines will be configured per their
default function. This selection is made via four 32-bit bit masks, where each I/O is represented by (1 << IO number). In this
case, GPIO[50] is used as an input pin and is selected during the I/O matrix configuration.
io_cfg.gpioSimpleEn[0] = 0;
io_cfg.gpioSimpleEn[1] = 0;
/* GPIO[50] is used as complex GPIO. */
io_cfg.gpioComplexEn[0] = 0;
io_cfg.gpioComplexEn[1] = 0x00040000;
CyU3PDeviceConfigureIOMatrix (&io_cfg);
Initialize the GPIO module. The GPIO block runs with a fast clock at SYS_CLK / 2, and a slow clock is not used. In this case,
the SYS_CLK runs at 403 MHz
gpioClock.fastClkDiv = 2;
gpioClock.slowClkDiv = 0;
gpioClock.simpleDiv = CY_U3P_GPIO_SIMPLE_DIV_BY_2;
gpioClock.clkSrc = CY_U3P_SYS_CLK;
gpioClock.halfDiv = 0;
CyU3PGpioInit(&gpioClock, NULL);
CyU3PGpioSetComplexConfig configures a complex GPIO. The code for configuring GPIO[50] as a PWM output with a 25
percnet duty cycle is as follows.
/* 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; /* (201600 - 1) */
gpioConfig.threshold = CY_FX_PWM_25P_THRESHOLD; /* (50400 - 1) */
apiRetStatus = CyU3PGpioSetComplexConfig(50, &gpioConfig);
The following code changes the PWM duty cycle to 75 percent.
/* Change the PWM duty cycle to 75%. */
CyU3PGpioComplexUpdate (50, CY_FX_PWM_75P_THRESHOLD, CY_FX_PWM_PERIOD); /* CY_FX_PWM_75P_-
THRESHOLD = (151200 - 1) */