Calculating PWM Period and Duty Cycle in FX3 – KBA226759

Version 5

    Author: SrinathS_16          Version: **


    Translation - Japanese: FX3のPWM周期とデューティーサイクルを計算する - KBA226759 - Community Translated (JA)



    How can the PWM period and duty cycle with the required values be set in FX3?



    The gpioConfig.period and gpioConfig.threshold parameters define the PWM period and the PWM threshold value in terms of the timer ticks. In the GpioComplexApp example that comes with the FX3 SDK, these parameters are computed for a SYS_CLK frequency of 403.2 MHz. Also, the complex GPIO clock is configured to run from the GPIO fast clock, which is set to SYS_CLK/2. The gpioConfig.period and the gpioConfig.threshold parameters can be adjusted to set the PWM period and the duty cycle to the appropriate value


    The following code snippet calculates the value:


    gpioClock.clkSrc = CY_U3P_SYS_CLK; // GPIO clock is derived from the SYS_CLK

    gpioClock.fastClkDiv = 2;          // GPIO fast clock is configured for SYS_CLK/2 

    gpioConfig.timerMode = CY_U3P_GPIO_TIMER_HIGH_FREQ;     // Use the GPIO fast clock for generating

    // the PWM

    gpioConfig.period = 20160;                       // Set the period to 20160 timer ticks

    gpioConfig.threshold = 10080;        // Set the threshold appropriate to the duty cycle. This is set


    // to 50% in this example  



    §  SYS_CLK frequency = 403.2 MHz

    §  GPIO fast clock frequency = (SYS_CLK frequency)/2 = 201.6 MHz

    §  One clock period = 1/(GPIO fast clock frequency) = (1/201.6) µs

    §  gpioConfig.period = (Desired PWM waveform period/One clock period)