Posted:   2020-08-21 
Status:   
Completed 
 
Previous:   
         
         STM32底层LL库ADC使用DMA多通道采集LL篇6
         
      
Next:   
         
         STM32底层LL库高级定时器PWM输出LL篇8
         
      
LL库1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
  * @brief  TIM Time Base configuration structure definition.
  */
typedef struct
{
  uint16_t Prescaler;         /*!< Specifies the prescaler value used to divide the TIM clock.
                                   This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
                                   This feature can be modified afterwards using unitary function @ref LL_TIM_SetPrescaler().*/
  uint32_t CounterMode;       /*!< Specifies the counter mode.
                                   This parameter can be a value of @ref TIM_LL_EC_COUNTERMODE.
                                   This feature can be modified afterwards using unitary function @ref LL_TIM_SetCounterMode().*/
  uint32_t Autoreload;        /*!< Specifies the auto reload value to be loaded into the active
                                   Auto-Reload Register at the next update event.
                                   This parameter must be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
                                   Some timer instances may support 32 bits counters. In that case this parameter must be a number between 0x0000 and 0xFFFFFFFF.
                                   This feature can be modified afterwards using unitary function @ref LL_TIM_SetAutoReload().*/
  uint32_t ClockDivision;     /*!< Specifies the clock division.
                                   This parameter can be a value of @ref TIM_LL_EC_CLOCKDIVISION.
                                   This feature can be modified afterwards using unitary function @ref LL_TIM_SetClockDivision().*/
  uint8_t RepetitionCounter;  /*!< Specifies the repetition counter value. Each time the RCR downcounter
                                   reaches zero, an update event is generated and counting restarts
                                   from the RCR value (N).
                                   This means in PWM mode that (N+1) corresponds to:
                                      - the number of PWM periods in edge-aligned mode
                                      - the number of half PWM period in center-aligned mode
                                   This parameter must be a number between 0x00 and 0xFF.
                                   This feature can be modified afterwards using unitary function @ref LL_TIM_SetRepetitionCounter().*/
} LL_TIM_InitTypeDef;
PrescalerCounterMode1
2
3
4
5
6
7
8
/** @defgroup TIM_LL_EC_COUNTERMODE Counter Mode
  * @{
  */
#define LL_TIM_COUNTERMODE_UP                  0x00000000U          /*!<Counter used as upcounter */
#define LL_TIM_COUNTERMODE_DOWN                TIM_CR1_DIR          /*!< Counter used as downcounter */
#define LL_TIM_COUNTERMODE_CENTER_UP           TIM_CR1_CMS_0        /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels  are set only when the counter is counting down. */
#define LL_TIM_COUNTERMODE_CENTER_DOWN         TIM_CR1_CMS_1        /*!<The counter counts up and down alternatively. Output compare interrupt flags of output channels  are set only when the counter is counting up */
#define LL_TIM_COUNTERMODE_CENTER_UP_DOWN      TIM_CR1_CMS          /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels  are set only when the counter is counting up or down. */
AutoreloadClockDivision1
2
3
4
5
6
/** @defgroup TIM_LL_EC_CLOCKDIVISION Clock Division
  * @{
  */
#define LL_TIM_CLOCKDIVISION_DIV1              0x00000000U          /*!< tDTS=tCK_INT */
#define LL_TIM_CLOCKDIVISION_DIV2              TIM_CR1_CKD_0        /*!< tDTS=2*tCK_INT */
#define LL_TIM_CLOCKDIVISION_DIV4              TIM_CR1_CKD_1        /*!< tDTS=4*tCK_INT */
RepetitionCounter__LL_TIM_CALC_PSC(__TIMCLK__, __CNTCLK__)__LL_TIM_CALC_ARR(__TIMCLK__, __PSC__, __FREQ__)__LL_TIM_CALC_DELAY(__TIMCLK__, __PSC__, __DELAY__)void LL_TIM_EnableCounter(TIM_TypeDef *TIMx)void LL_TIM_EnableARRPreload(TIM_TypeDef *TIMx)void LL_TIM_SetCounter(TIM_TypeDef *TIMx, uint32_t Counter)uint32_t LL_TIM_GetCounter(TIM_TypeDef *TIMx)uint32_t LL_TIM_GetPrescaler(TIM_TypeDef *TIMx)void LL_TIM_SetAutoReload(TIM_TypeDef *TIMx, uint32_t AutoReload)void LL_TIM_CC_EnableChannel(TIM_TypeDef *TIMx, uint32_t Channels)void LL_TIM_OC_EnablePreload(TIM_TypeDef *TIMx, uint32_t Channel)void LL_TIM_OC_SetCompareCH1(TIM_TypeDef *TIMx, uint32_t CompareValue)void LL_TIM_OC_SetCompareCH2(TIM_TypeDef *TIMx, uint32_t CompareValue)void LL_TIM_OC_SetCompareCH3(TIM_TypeDef *TIMx, uint32_t CompareValue)void LL_TIM_OC_SetCompareCH4(TIM_TypeDef *TIMx, uint32_t CompareValue)void LL_TIM_IC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPolarity)uint32_t LL_TIM_IC_GetCaptureCH1(TIM_TypeDef *TIMx)uint32_t LL_TIM_IC_GetCaptureCH2(TIM_TypeDef *TIMx)uint32_t LL_TIM_IC_GetCaptureCH3(TIM_TypeDef *TIMx)uint32_t LL_TIM_IC_GetCaptureCH4(TIM_TypeDef *TIMx)void LL_TIM_EnableAllOutputs(TIM_TypeDef *TIMx)void LL_TIM_ClearFlag_UPDATE(TIM_TypeDef *TIMx)uint32_t LL_TIM_IsActiveFlag_UPDATE(TIM_TypeDef *TIMx)void LL_TIM_ClearFlag_CC1(TIM_TypeDef *TIMx)uint32_t LL_TIM_IsActiveFlag_CC1(TIM_TypeDef *TIMx)void LL_TIM_ClearFlag_CC2(TIM_TypeDef *TIMx)uint32_t LL_TIM_IsActiveFlag_CC2(TIM_TypeDef *TIMx)void LL_TIM_ClearFlag_CC3(TIM_TypeDef *TIMx)uint32_t LL_TIM_IsActiveFlag_CC3(TIM_TypeDef *TIMx)void LL_TIM_ClearFlag_CC4(TIM_TypeDef *TIMx)uint32_t LL_TIM_IsActiveFlag_CC4(TIM_TypeDef *TIMx)void LL_TIM_EnableIT_UPDATE(TIM_TypeDef *TIMx)void LL_TIM_EnableIT_CC1(TIM_TypeDef *TIMx)void LL_TIM_EnableIT_CC2(TIM_TypeDef *TIMx)void LL_TIM_EnableIT_CC3(TIM_TypeDef *TIMx)void LL_TIM_EnableIT_CC4(TIM_TypeDef *TIMx)stm32f10x_it.c文件添加外部变量1
extern __IO uint32_t time;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
  * @brief This function handles TIM6 global interrupt.
  */
void TIM6_IRQHandler(void)
{
    /* USER CODE BEGIN TIM6_IRQn 0 */
    if(LL_TIM_IsActiveFlag_UPDATE(TIM6))
    {
        LL_TIM_ClearFlag_UPDATE(TIM6);
        time++;
    }
    /* USER CODE END TIM6_IRQn 0 */
    /* USER CODE BEGIN TIM6_IRQn 1 */
    /* USER CODE END TIM6_IRQn 1 */
}
main.c文件添加变量1
__IO uint32_t time;
1
2
    LL_TIM_EnableCounter(TIM6);//使能定时器
    LL_TIM_EnableIT_UPDATE(TIM6);//使能更新中断
1
2
3
4
5
6
7
8
9
        if(time>=1000)
        {
            time=0;
            LED1_TOGGLE;
            LED2_TOGGLE;
            printf( "\r\n The IC current tem= %.2fC\r\n", temp);
            printf( "\r\n The IC current VDDA= %.2fV\r\n", VREF);
            printf( "\r\n The IC current ADC= %.2fV\r\n", adcValue);
        }