DIY Logging Volt/Ampmeter
tim.c File Reference

This file provides code for the configuration of the TIM instances. More...

#include "tim.h"

Go to the source code of this file.

Functions

void MX_TIM2_Init (void)
 
void MX_TIM3_Init (void)
 

Detailed Description

This file provides code for the configuration of the TIM instances.

Attention

© Copyright (c) 2021 STMicroelectronics. All rights reserved.

This software component is licensed by ST under BSD 3-Clause license, the "License"; You may not use this file except in compliance with the License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause

Definition in file tim.c.

Function Documentation

◆ MX_TIM2_Init()

void MX_TIM2_Init ( void  )

Definition at line 28 of file tim.c.

29 {
30  LL_TIM_InitTypeDef TIM_InitStruct = {0};
31 
32  /* Peripheral clock enable */
33  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
34 
35  /* TIM2 interrupt Init */
38 
39  TIM_InitStruct.Prescaler = 800;
40  TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
41  TIM_InitStruct.Autoreload = 10000;
42  TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
43  LL_TIM_Init(TIM2, &TIM_InitStruct);
44  LL_TIM_DisableARRPreload(TIM2);
45  LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
46  LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
47  LL_TIM_DisableMasterSlaveMode(TIM2);
48 
49 }

◆ MX_TIM3_Init()

void MX_TIM3_Init ( void  )

TIM3 GPIO Configuration PA6 ---—> TIM3_CH1 PA7 ---—> TIM3_CH2

Definition at line 51 of file tim.c.

52 {
53  LL_TIM_InitTypeDef TIM_InitStruct = {0};
54 
55  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
56 
57  /* Peripheral clock enable */
58  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
59 
60  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
61  /**TIM3 GPIO Configuration
62  PA6 ------> TIM3_CH1
63  PA7 ------> TIM3_CH2
64  */
65  GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
66  GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
67  GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
68  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
69 
70  LL_TIM_SetEncoderMode(TIM3, LL_TIM_ENCODERMODE_X4_TI12);
71  LL_TIM_IC_SetActiveInput(TIM3, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI);
72  LL_TIM_IC_SetPrescaler(TIM3, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1);
73  LL_TIM_IC_SetFilter(TIM3, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1);
74  LL_TIM_IC_SetPolarity(TIM3, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING);
75  LL_TIM_IC_SetActiveInput(TIM3, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI);
76  LL_TIM_IC_SetPrescaler(TIM3, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
77  LL_TIM_IC_SetFilter(TIM3, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
78  LL_TIM_IC_SetPolarity(TIM3, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
79  TIM_InitStruct.Prescaler = 0;
80  TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
81  TIM_InitStruct.Autoreload = 65535;
82  TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
83  LL_TIM_Init(TIM3, &TIM_InitStruct);
84  LL_TIM_EnableARRPreload(TIM3);
85  LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
86  LL_TIM_DisableMasterSlaveMode(TIM3);
87 
88 }
NVIC_GetPriorityGrouping
#define NVIC_GetPriorityGrouping
Definition: core_armv8mbl.h:1189
NVIC_EncodePriority
__STATIC_INLINE uint32_t NVIC_EncodePriority(uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
Encode Priority.
Definition: core_armv8mbl.h:1496
TIM3
#define TIM3
Definition: stm32f103xb.h:649
GPIOA
#define GPIOA
Definition: stm32f103xb.h:665
TIM2
#define TIM2
Definition: stm32f103xb.h:648
TIM2_IRQn
@ TIM2_IRQn
Definition: stm32f103xb.h:111
NVIC_SetPriority
#define NVIC_SetPriority
Definition: core_armv8mbl.h:1197
NVIC_EnableIRQ
#define NVIC_EnableIRQ
Definition: core_armv8mbl.h:1190