cancel
Showing results for 
Search instead for 
Did you mean: 

Can't update HRTIM Compare Reg using HAL when running

sasha
Associate III
Posted on October 18, 2016 at 05:46

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

}

#hrtim
3 REPLIES 3
slimen
Senior
Posted on October 18, 2016 at 17:39

Hello marks.sasha,

You can follow the HRTIM example under STM32CubeF3 to identify what is going wrong in your case:  STM32Cube_FW_F3_V1.6.0\Projects\STM32F3348-Discovery\Examples\HRTIM

You can compare your generated code with this provided application and check your needed functions with regarding passed parameters.

Regards

sasha
Associate III
Posted on October 20, 2016 at 06:46

Thanks for your reply, but I could not find any examples using the SimplePWM HAL methods.  I think the problem is that using SimplePWM methods, the register pre-load is enabled - how do I force the preload register to be copied across to the active register?  I can't find any info on this in the HAL manual.

Walid FTITI_O
Senior II
Posted on October 26, 2016 at 14:39

Hi marks.sasha, 

I recommend to get help to develop your HRTIM application from the following sources:

- Application note 

http://www.st.com/content/ccc/resource/technical/document/application_note/13/d6/48/9d/11/11/4c/08/DM00121475.pdf/files/DM00121475.pdf/jcr:content/translations/en.DM00121475.pdf

- Application note 

http://www.st.com/content/ccc/resource/technical/document/application_note/ec/9c/b0/81/b5/12/4e/21/DM00108726.pdf/files/DM00108726.pdf/jcr:content/translations/en.DM00108726.pdf

- Ready-to-use examples ''HRTIM_BuckBoost'' and ''HRTIM_BuckBoost_AN4449'' ''HRTIM_snippet'' you find at the STM32CubeF3 at this path: STM32Cube_FW_F3_V1.6.0\Projects\STM32F3348-Discovery\Examples\HRTIM

-> You check the STM32F3xx_it.c file where the IRQ Handlers are called

-Hannibal-