LL TIM Macros

LL TIM Macros

group TIM_LL_Exported_Macros

Defines

LL_TIM_GETFLAG_UIFCPY ( cnt ) (STM32_READ_BIT((cnt), TIM_CNT_UIFCPY) >> TIM_CNT_UIFCPY_Pos)

HELPER macro retrieving the UIFCPY flag from the counter value.

Note

e.g. LL_TIM_GETFLAG_UIFCPY ( LL_TIM_GetCounter ());

Note

Relevant only if UIF flag remapping has been enabled (UIF status bit is copied to TIMx_CNT register bit 31)

Parameters :
  • cnt – Counter value

Return values :

UIF – status bit

LL_TIM_CALC_DEADTIME ( tim_clk , clk_div , dt ) ( (((uint64_t)((dt)*1000U)) < (( LL_TIM_DT_DELAY_1 +1U) * LL_TIM_TIM_CALC_DTS

((tim_clk), (clk_div)))) ? \

(uint8_t)(((uint64_t)((dt)*1000U) /

LL_TIM_TIM_CALC_DTS ((tim_clk), (clk_div))) & LL_TIM_DT_DELAY_1

) : \

(((uint64_t)((dt)*1000U)) < ((64U + (

LL_TIM_DT_DELAY_2 +1U)) * 2U * LL_TIM_TIM_CALC_DTS

((tim_clk), (clk_div)))) ? \

(uint8_t)(

LL_TIM_DT_RANGE_2 | ((uint8_t)((uint8_t)((((uint64_t)((dt)*1000U))/ LL_TIM_TIM_CALC_DTS

((tim_clk), \

(clk_div))) >> 1U) - (uint8_t) 64) &

LL_TIM_DT_DELAY_2

)) :\

(((uint64_t)((dt)*1000U)) < ((32U + (

LL_TIM_DT_DELAY_3 +1U)) * 8U * LL_TIM_TIM_CALC_DTS

((tim_clk), (clk_div)))) ? \

(uint8_t)(

LL_TIM_DT_RANGE_3 | ((uint8_t)((uint8_t)(((((uint64_t)(dt)*1000U))/ LL_TIM_TIM_CALC_DTS

((tim_clk), \

(clk_div))) >> 3U) - (uint8_t) 32) &

LL_TIM_DT_DELAY_3

)) :\

(((uint64_t)((dt)*1000U)) < ((32U + (

LL_TIM_DT_DELAY_4 +1U)) * 16U * LL_TIM_TIM_CALC_DTS

((tim_clk), (clk_div)))) ? \

(uint8_t)(

LL_TIM_DT_RANGE_4 | ((uint8_t)((uint8_t)(((((uint64_t)(dt)*1000U))/ LL_TIM_TIM_CALC_DTS

((tim_clk), \

(clk_div))) >> 4U) - (uint8_t) 32) &

LL_TIM_DT_DELAY_4

)) :\

0U)


HELPER macro calculating DTG[0:7] in the TIMx_BDTR register to achieve the requested dead time duration.

Note

e.g. LL_TIM_CALC_DEADTIME(80000000, LL_TIM_GetClockDivision() , 120);

Parameters :
Return values :

DTG[0:7]

LL_TIM_CALC_PSC ( tim_clk , cnt_clk ) (((tim_clk) >= (cnt_clk)) ? (uint32_t)((((tim_clk) + (cnt_clk)/2U)/(cnt_clk)) - 1U) : 0U)

HELPER macro calculating the prescaler value to achieve the required counter clock frequency.

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • cnt_clk – counter clock frequency (in Hz)

Return values :

Prescaler – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_ARR ( tim_clk , psc , freq ) ((((tim_clk)/((psc) + 1U)) >= (freq)) ? (((tim_clk)/((freq) * ((psc) + 1U))) - 1U) : 0U)

HELPER macro calculating the auto-reload value to achieve the required output signal frequency.

Note

e.g. LL_TIM_CALC_ARR(1000000, LL_TIM_GetPrescaler() , 10000);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • freq – output signal frequency (in Hz)

Return values :

Auto-reload – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_ARR_DITHER ( tim_clk , psc , freq )

((((tim_clk)/((psc) + 1U)) >= (freq)) ? \

(uint32_t)((((uint64_t)(tim_clk) * 16U/((freq) * ((psc) + 1U))) - 16U)) : 0U)


HELPER macro calculating the auto-reload value, with dithering feature enabled, to achieve the required output signal frequency.

Note

e.g. LL_TIM_CALC_ARR_DITHER(1000000, LL_TIM_GetPrescaler() , 10000);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • freq – output signal frequency (in Hz)

Return values :

Auto-reload – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_DELAY ( tim_clk , psc , delay )

((uint32_t)(((uint64_t)(tim_clk) * (uint64_t)(delay)) \

/ ((uint64_t)1000000U * (uint64_t)((psc) + 1U))))


HELPER macro calculating the compare value required to achieve the required timer output compare active/inactive delay.

Note

e.g. LL_TIM_CALC_DELAY(1000000, LL_TIM_GetPrescaler() , 10);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • delay – timer output compare active/inactive delay (in us)

Return values :

Compare – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_DELAY_DITHER ( tim_clk , psc , delay )

((uint32_t)(((uint64_t)(tim_clk) * (uint64_t)(delay) * 16U) \

/ ((uint64_t)1000000U * (uint64_t)((psc) + 1U))))


HELPER macro calculating the compare value, with dithering feature enabled, to achieve the required timer output compare active/inactive delay.

Note

e.g. LL_TIM_CALC_DELAY_DITHER(1000000, LL_TIM_GetPrescaler() , 10);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • delay – timer output compare active/inactive delay (in us)

Return values :

Compare – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_PULSE ( tim_clk , psc , delay , pulse ) ((uint32_t)( LL_TIM_CALC_DELAY

((tim_clk), (psc), (pulse)) \

+

LL_TIM_CALC_DELAY ((tim_clk), (psc), (delay))))

HELPER macro calculating the auto-reload value to achieve the required pulse duration (when the timer operates in one pulse mode).

Note

e.g. LL_TIM_CALC_PULSE(1000000, LL_TIM_GetPrescaler() , 10, 20);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • delay – timer output compare active/inactive delay (in us)

  • pulse – pulse duration (in us)

Return values :

Auto-reload – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_CALC_PULSE_DITHER ( tim_clk , psc , delay , pulse ) ((uint32_t)( LL_TIM_CALC_DELAY_DITHER

((tim_clk), (psc), (pulse)) \

+

LL_TIM_CALC_DELAY_DITHER ((tim_clk), (psc), (delay))))

HELPER macro calculating the auto-reload value, with dithering feature enabled, to achieve the required pulse duration (when the timer operates in one pulse mode).

Note

e.g. LL_TIM_CALC_PULSE_DITHER(1000000, LL_TIM_GetPrescaler() , 10, 20);

Parameters :
  • tim_clk – timer input clock frequency (in Hz)

  • psc – prescaler

  • delay – timer output compare active/inactive delay (in us)

  • pulse – pulse duration (in us)

Return values :

Auto-reload – value (between Min_Data=0 and Max_Data=65535)

LL_TIM_GET_ICPSC_RATIO ( ic_psc ) ((uint32_t)(0x01U << (((ic_psc) >> 16U) >> TIM_CCMR1_IC1PSC_Pos)))

HELPER macro retrieving the ratio of the input capture prescaler.

Note

e.g. LL_TIM_GET_ICPSC_RATIO( LL_TIM_IC_GetPrescaler() );

Parameters :
Return values :

Input – capture prescaler ratio (1, 2, 4 or 8)

Common Write and read registers Macros

group TIM_LL_EM_WRITE_READ

Defines

LL_TIM_WRITE_REG ( instance , reg , value ) STM32_WRITE_REG((instance)->reg, (value))

Write a value in TIM register.

Parameters :
  • instance – TIM Instance

  • reg – Register to be written

  • value – Value to be written in the register

LL_TIM_READ_REG ( instance , reg ) STM32_READ_REG((instance)->reg)

Read a value in TIM register.

Parameters :
  • instance – TIM Instance

  • reg – Register to be read

Return values :

Register – value