AnsweredAssumed Answered

[S] TIM2 - PWM Mode 1 - minimal duty cycle at 5kHz

Question asked by life_augmented.st on Jun 23, 2016
Latest reply on Jun 27, 2016 by life_augmented.st

Hi Guys,

I am currently working on a PWM signal of f = 5kHz (T = 200us) with the 32-bit general purposte timer 2. While testing my implementation I am observing a strange behaviour. At the moment I am not sure if I pushed the boundaries of timer 2 to much or it is an implementation problem. 

The issue is that the high signal becomes a low signal if I make my duty cycle to small, in this my, when I go below 1us or 1/200 of T. 

My code looks as follows:

TIM2_TE_ERR TIM2_Init(void){
   
  //=== local vars ==============================================================
  GPIO_InitTypeDef GPIO_InitStruct = {0};
   
  /*** power supply timer configuration {SIG_T2CH4_VLTG_LVL_TO} == ***/
  SYSC_ClockEnable(CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_PORT);
  GPIO_InitStruct.Pin   = CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_PIN;
  GPIO_InitStruct.Mode  = GPIO_MODE_AF_PP;              /* set to output */
  GPIO_InitStruct.Pull  = GPIO_GetPull(CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_LOGIC, CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_DEFLVL);
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  GPIO_InitStruct.Alternate = CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_AF;
  (void)GPIO_InitPin(CNFG_GPIO_SIG_T2CH4_VLTG_LVL_TO_PORT, &GPIO_InitStruct, GPIO_TYPE_TIM, TRUE /*force*/);
 
  /* === code === */
    /*** initialize module control structure                                 ***/
  if (TRUE == _this.bIsInitialized) {
     
    _DeInit();
  } /* </ (TRUE == _this.bIsInitialized) > */
 
    /* === configuration of the PWM-timer === */
  
  /* enable clock of PWM timer */
  TIM2_TIMER_FORCE_RESET;
  TIM2_TIMER_RELEASE_RESET;
  TIM2_TIMER_CLK_ENABLE;
   
  /* Set TIMx instance */
  _this.hTimer.Instance      = _TIM;
 
  /* Master configuration: TIM3  */
  _this.hTimer.Init.Prescaler         = 0;
  _this.hTimer.Init.Period            = 16800 - 1;    /* refresh rate ~5kHz */
  _this.hTimer.Init.ClockDivision     = 0;
  _this.hTimer.Init.RepetitionCounter = 0;
  _this.hTimer.Init.CounterMode       = TIM_COUNTERMODE_UP;
 
  /* Initialize timer */
  if (HAL_TIM_PWM_Init(&_this.hTimer) != HAL_OK){
 
     /* error - initialization failed */
    _DeInit();
 
    /* set error status */
    _this.Error = _TE_ERR_FAILURE;
    return _this.Error;
  } else {
    /* no error - nothing to do */
  }/* </ if (HAL_TIM_PWM_Init() != HAL_OK) > */
 
  /* Configure the PWM_channel_1  */
  _this.sConfig.OCMode        = TIM_OCMODE_PWM1;
  _this.sConfig.OCPolarity    = TIM_OCPOLARITY_HIGH;
  _this.sConfig.OCNPolarity   = TIM_OCNPOLARITY_LOW;
  _this.sConfig.OCFastMode    = TIM_OCFAST_ENABLE;
  _this.sConfig.OCIdleState   = TIM_OCIDLESTATE_SET;
  _this.sConfig.OCNIdleState  = TIM_OCNIDLESTATE_RESET;
 
  /* set the pulse value for channel 4 */
  _this.sConfig.Pulse         = (16800/100);     /* 1% PWM default */
   
  if (HAL_TIM_PWM_ConfigChannel(&_this.hTimer, &_this.sConfig, _OUT_CHANNEL) != HAL_OK){
      
    /* set error status */
    _this.Error = _TE_ERR_FAILURE;
    return _this.Error;
  } else {
    /* no error - nothing to do */
  } /* </ if (HAL_TIM_PWM_ConfigChannel() != HAL_OK) > */
 
  /* set  state to initialized */
  _this.State = _TE_STATE_INIT;
 
  /* finalize initialization */
  _this.bIsInitialized = TRUE;
   
  /* successful - set error status */
  _this.Error = _TE_ERR_NONE;
  return _this.Error;
}

What gets me totally confused is the fact that a configuration of 50kHz on the 16-bit timer 11 is working with a much smaller high time.

Has anybody a idea? Is this a hardware restiction?

Thank you

Outcomes