Post Go back to editing

Configure PWM EVAL-ADICUP3029


Is there any example projects setup for the EVAL-ADICUP3029 on how to generate/configure PWM? 

If none, can you at least write a simple code to configure PWM. Thanks

  • Hi,

    There is an example available on CCES (tmr_example_gp) for EVAL-ADICUP3029 to perform basic timer operation but it does not cover PWM configuration. For the PWM configuration, consider the code below. This generate PWM 50% duty cycle on pin IO33 of the board. 


    #include <common.h>
    #include <drivers/pwr/adi_pwr.h>
    #include <drivers/tmr/adi_tmr.h>
    #define GP2_LOAD_VALUE_FOR_60HZ 27082 // load value: (16.667ms / (1/26MHz * 16))
    #define TIMER2_TIMER2_OUT_PORTP2_MUX  ((uint16_t) ((uint16_t) 2<<2))
    void GP2CallbackFunction(void *pCBParam, uint32_t Event, void  * pArg)
    int main()
      ADI_TMR_CONFIG        tmrConfig;
      ADI_TMR_RESULT        eResult;
      ADI_TMR_PWM_CONFIG   	pwmConfig;
      adi_pwr_SetClockDivider(ADI_CLOCK_HCLK, 1u);
      adi_pwr_SetClockDivider(ADI_CLOCK_PCLK, 1u);
      *((volatile uint32_t *)REG_GPIO2_CFG) = TIMER2_TIMER2_OUT_PORTP2_MUX;
      adi_tmr_Init(ADI_TMR_DEVICE_GP2, GP2CallbackFunction, NULL, true);
      /* GP timer configuration */
      tmrConfig.bCountingUp  = false;
      tmrConfig.bPeriodic    = true;
      tmrConfig.ePrescaler   = ADI_TMR_PRESCALER_16;
      tmrConfig.eClockSource = ADI_TMR_CLOCK_HFOSC;
      tmrConfig.nLoad        = GP2_LOAD_VALUE_FOR_60HZ;
      tmrConfig.nAsyncLoad   = GP2_LOAD_VALUE_FOR_60HZ;
      tmrConfig.bReloading   = true;
      tmrConfig.bSyncBypass  = false;
      eResult = adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP2, &tmrConfig);
      DEBUG_RESULT("Error configuring GP2 PWM.", eResult, ADI_TMR_SUCCESS);
      /* timer PWM configuration */
      /* Configure GP2 PWM0 to have a PWM duty cycle of 50% */
      pwmConfig.eOutput      = ADI_TMR_PWM_OUTPUT_0;
      pwmConfig.bMatch       = true;
      pwmConfig.bIdleHigh    = false;
      pwmConfig.nMatchValue  = (uint16_t) (GP2_LOAD_VALUE_FOR_60HZ / 2);
      eResult = adi_tmr_ConfigPwm(ADI_TMR_DEVICE_GP2, &pwmConfig);
      DEBUG_RESULT("Error configuring GP2 PWM.", eResult, ADI_TMR_SUCCESS);
      /* GP timer enable */
      eResult = adi_tmr_Enable(ADI_TMR_DEVICE_GP2, true);
      DEBUG_RESULT("Error configuring GP2 PWM.", eResult, ADI_TMR_SUCCESS);