AnsweredAssumed Answered

Can't update HRTIM Compare Reg using HAL when running

Question asked by marks.sasha on Oct 18, 2016
Latest reply on Oct 26, 2016 by FTITI.Walid
Hi,

I'm trying to use the HRTIM for a high resolution simple PWM signal, using HAL.  If I set the pulse length in the HRTIM initialise routine, then call SimplePWMStart() then I get the correct PWM output.  However, the __HAL_HRTIM_SETCOMPARE macro does not change the output period.  Is there some trick to using this macro?

I'm using the STM32F334R8Tx Nucleo board.

<code>

int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();
/* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_HRTIM1_Init();

  HAL_HRTIM_SimplePWMStart(&hhrtim1,HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1); // this does start the PWM running

__HAL_HRTIM_SETCOMPARE(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, 0x1000); // DOES NOTHING!!!


/* HRTIM1 init function */
void MX_HRTIM1_Init(void)
{
  HRTIM_TimeBaseCfgTypeDef pTimeBaseCfg;
  HRTIM_SimplePWMChannelCfgTypeDef pSimplePWMChannelCfg;

  hhrtim1.Instance = HRTIM1;
  hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
  hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
  if (HAL_HRTIM_Init(&hhrtim1) != HAL_OK)
  {
    Error_Handler();
  }

  if (HAL_HRTIM_DLLCalibrationStart(&hhrtim1, HRTIM_CALIBRATIONRATE_14) != HAL_OK)
  {
    Error_Handler();
  }

  if (HAL_HRTIM_PollForDLLCalibration(&hhrtim1, 10) != HAL_OK)
  {
    Error_Handler();
  }

  pTimeBaseCfg.Period = 0xFFF7;
  pTimeBaseCfg.RepetitionCounter = 0x00;
  pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL8;
  pTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS;
  if (HAL_HRTIM_TimeBaseConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, &pTimeBaseCfg) != HAL_OK)
  {
    Error_Handler();
  }

  pSimplePWMChannelCfg.Pulse = 0xFFDF;
  pSimplePWMChannelCfg.Polarity = HRTIM_OUTPUTPOLARITY_HIGH;
  pSimplePWMChannelCfg.IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
  if (HAL_HRTIM_SimplePWMChannelConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &pSimplePWMChannelCfg) != HAL_OK)
  {
    Error_Handler();
  }

  HAL_HRTIM_MspPostInit(&hhrtim1);

}


Outcomes