Post Go back to editing

Timer Config ADUCM3029

Hello. I have a simple code below that generate PWM with GP2 Timer2 Config and uses the GPIO33 pin of the ADUCM3029. Well, can you help me to configure the code that instead of usingTimer2 it will use the Timer1 (GPIO27 pin of the IC). I'm bit confused on how the pinmux map on physical IO pins with the GP Timers. Any help would be very appreciated. Thanks

 

#include <common.h>
#include <drivers/pwr/adi_pwr.h>
#include <drivers/tmr/adi_tmr.h>

#define GP2_LOAD_VALUE_FOR_60HZ 27084 // 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;

  common_Init();

  adi_pwr_Init();
  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);

  while(1){

  }

}

  • Hi,

    Not sure if you already figured it out, but if you are using the Cross Core IDE the pin muxing is located in the system.svc file at the bottom of your project. If you are trying to do it manually I think this is what the code should look like:

    #include <common.h>
    #include <drivers/pwr/adi_pwr.h>
    #include <drivers/tmr/adi_tmr.h>
    
    #define GP1_LOAD_VALUE_FOR_60HZ 27084 // load value: (16.667ms / (1/26MHz * 16))
    
    #define TIMER1_TIMER1_OUT_PORTP1_MUX  ((uint32_t) ((uint32_t) 2<<22))
    
    void GP1CallbackFunction(void *pCBParam, uint32_t Event, void  * pArg)
    {
    }
    
    int main()
    {
    
      ADI_TMR_CONFIG        tmrConfig;
      ADI_TMR_RESULT        eResult;
      ADI_TMR_PWM_CONFIG   	pwmConfig;
    
      common_Init();
    
      adi_pwr_Init();
      adi_pwr_SetClockDivider(ADI_CLOCK_HCLK, 1u);
      adi_pwr_SetClockDivider(ADI_CLOCK_PCLK, 1u);
    
      *((volatile uint32_t *)REG_GPIO1_CFG) = TIMER1_TIMER1_OUT_PORTP1_MUX;
    
      adi_tmr_Init(ADI_TMR_DEVICE_GP1, GP1CallbackFunction, 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        = GP1_LOAD_VALUE_FOR_60HZ;
      tmrConfig.nAsyncLoad   = GP1_LOAD_VALUE_FOR_60HZ;
      tmrConfig.bReloading   = true;
      tmrConfig.bSyncBypass  = false;
    
      eResult = adi_tmr_ConfigTimer(ADI_TMR_DEVICE_GP1, &tmrConfig);
      DEBUG_RESULT("Error configuring GP1 PWM.", eResult, ADI_TMR_SUCCESS);
    
      /* timer PWM configuration */
      /* Configure GP1 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) (GP1_LOAD_VALUE_FOR_60HZ / 2);
      eResult = adi_tmr_ConfigPwm(ADI_TMR_DEVICE_GP1, &pwmConfig);
      DEBUG_RESULT("Error configuring GP1 PWM.", eResult, ADI_TMR_SUCCESS);
    
      /* GP timer enable */
      eResult = adi_tmr_Enable(ADI_TMR_DEVICE_GP1, true);
      DEBUG_RESULT("Error configuring GP1 PWM.", eResult, ADI_TMR_SUCCESS);
    
      while(1){
    
      }
    
    }

    Hope it works,

    Aleks

  • Oh I see. I didn't notice it. Anyway thank you so much.

    By the way, I have an additional question regarding how to implement the time delay. I want my waveform to have a 180 degrees phase angle.