本文整理汇总了C++中HAL_TIM_IC_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_TIM_IC_Init函数的具体用法?C++ HAL_TIM_IC_Init怎么用?C++ HAL_TIM_IC_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_TIM_IC_Init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MX_TIM3_Init
/* TIM3 init function */
void MX_TIM3_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim3.Instance = TIM3;
htim3.Init.Prescaler = 71;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 0xffff;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim3);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig);
HAL_TIM_IC_Init(&htim3);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_4);
}
示例2: MX_TIM4_Init
/* TIM4 init function */
void MX_TIM4_Init(void)
{
TIM_Encoder_InitTypeDef sConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim4.Instance = TIM4;
htim4.Init.Prescaler = 0;
htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
htim4.Init.Period = 0xFFFF;
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_IC_Init(&htim4);
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = 8;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = 8;
HAL_TIM_Encoder_Init(&htim4, &sConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim4, &sConfigIC, TIM_CHANNEL_3);
}
示例3: MX_TIM5_Init
/* TIM5 init function */
void MX_TIM5_Init(void)
{
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
TIM_OC_InitTypeDef sConfigOC;
htim5.Instance = TIM5;
htim5.Init.Prescaler = 0;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 8400000 * 5; // 500 ms
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_IC_Init(&htim5);
HAL_TIM_PWM_Init(&htim5);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_1);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 840;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2);
HAL_TIM_MspPostInit(&htim5);
}
示例4: GetLSIFrequency
/**
* @brief Configures TIM5 to measure the LSI oscillator frequency.
* @param None
* @retval LSI Frequency
*/
static uint32_t GetLSIFrequency(void)
{
TIM_IC_InitTypeDef TIMInput_Config;
/* Configure the TIM peripheral *********************************************/
/* Set TIMx instance */
Input_Handle.Instance = TIM5;
/* TIM5 configuration: Input Capture mode ---------------------
The LSI oscillator is connected to TIM5 TIM_CHANNEL_4.
The Rising edge is used as active edge.
The TIM5 CCR TIM_CHANNEL_4 is used to compute the frequency value.
------------------------------------------------------------ */
Input_Handle.Init.Prescaler = 0;
Input_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
Input_Handle.Init.Period = 0xFFFF;
Input_Handle.Init.ClockDivision = 0;
if(HAL_TIM_IC_Init(&Input_Handle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Connect internally the TIM5 TIM_CHANNEL_4 Input Capture to the LSI clock output */
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_AFIO_REMAP_TIM5CH4_ENABLE();
/* Configure the Input Capture of TIM_CHANNEL_4 */
TIMInput_Config.ICPolarity = TIM_ICPOLARITY_RISING;
TIMInput_Config.ICSelection = TIM_ICSELECTION_DIRECTTI;
TIMInput_Config.ICPrescaler = TIM_ICPSC_DIV8;
TIMInput_Config.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&Input_Handle, &TIMInput_Config, TIM_CHANNEL_4) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Start the TIM Input Capture measurement in interrupt mode */
if(HAL_TIM_IC_Start_IT(&Input_Handle, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* Wait until the TIM5 get 2 LSI edges */
while(uwCaptureNumber != 2)
{
}
/* Disable TIM5 CC1 Interrupt Request */
HAL_TIM_IC_Stop_IT(&Input_Handle, TIM_CHANNEL_4);
/* Deinitialize the TIM5 peripheral registers to their default reset values */
HAL_TIM_IC_DeInit(&Input_Handle);
return uwLsiFreq;
}
示例5: TIM4_Config
/**
* @brief TIM4 Configuration
* @note TIM4 configuration is based on APB1 frequency
* @note TIM4 Update event occurs each Input Capture Rising Edge
* @param None
* @retval None
*/
void TIM4_Config(void)
{
TIM_IC_InitTypeDef TIMInput_Config;
uint16_t PeriodValue = 0;
TIM_SlaveConfigTypeDef sSlaveConfig;
/*##-1- Configure the TIM peripheral #######################################*/
/* Input Capture configuration */
Input_Handle.Instance = TIM4;
/* Calculate the period value */
PeriodValue = (uint16_t) ((SystemCoreClock) / FREQ);
Input_Handle.Init.Period = PeriodValue;
Input_Handle.Init.Prescaler = 0;
Input_Handle.Init.ClockDivision = 0;
Input_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
Input_Handle.Init.RepetitionCounter = 0;
HAL_TIM_IC_Init(&Input_Handle);
/*##-2- Configure the Input Capture ########################################*/
/* Input Capture configuration of channel 2 */
TIMInput_Config.ICPolarity = TIM_ICPOLARITY_RISING;
TIMInput_Config.ICSelection = TIM_ICSELECTION_DIRECTTI;
TIMInput_Config.ICPrescaler = TIM_ICPSC_DIV1;
TIMInput_Config.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&Input_Handle, &TIMInput_Config, TIM_CHANNEL_2) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-3- Configure the Trigger Input ########################################*/
/* TIM4 Input Trigger selection */
sSlaveConfig.InputTrigger = TIM_TS_ITR2;
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_TRIGGER;
HAL_TIM_SlaveConfigSynchronization(&Input_Handle, &sSlaveConfig);
/* Reset the flags */
Input_Handle.Instance->SR = 0;
/*##-4- Enable TIM peripheral counter ######################################*/
/* Start the TIM Input Capture measurement in interrupt mode */
if(HAL_TIM_IC_Start_IT(&Input_Handle, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
}
示例6: DHT22_Init
DHT22_RESULT DHT22_Init(DHT22_HandleTypeDef* handle) {
handle->timHandle.Init.Period = 0xFFFF;
handle->timHandle.Init.Prescaler = 0;
handle->timHandle.Init.ClockDivision = 0;
handle->timHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if (HAL_TIM_IC_Init(&handle->timHandle) != HAL_OK) {
return DHT22_ERROR;
}
handle->timICHandle.ICPolarity = TIM_ICPOLARITY_FALLING;
handle->timICHandle.ICSelection = TIM_ICSELECTION_DIRECTTI;
handle->timICHandle.ICPrescaler = TIM_ICPSC_DIV1;
handle->timICHandle.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&handle->timHandle, &handle->timICHandle,
handle->timChannel) != HAL_OK) {
return DHT22_ERROR;
}
return DHT22_OK;
}
示例7: TIM_Config
/**
* @brief Configures TIM2 channel 4 in input capture mode
* @param None
* @retval None
*/
static void TIM_Config(void)
{
/*##-1- Configure the TIM peripheral #######################################*/
/* Set TIMx instance */
TimHandle.Instance = TIMx;
/* Initialize TIMx peripheral as follow:
+ Period = 0xFFFF
+ Prescaler = 0
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 0xFFFF;
TimHandle.Init.Prescaler = 0;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_IC_Init(&TimHandle) != HAL_OK)
{
/* Error */
ErrorHandler();
}
HAL_TIMEx_RemapConfig(&TimHandle, TIM2_TI4_COMP1);
/*##-2- Configure the Input Capture channel ################################*/
/* Configure the Input Capture of channel 4 */
sICConfig.ICPolarity = TIM_ICPOLARITY_BOTHEDGE;
sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
sICConfig.ICPrescaler = TIM_ICPSC_DIV1;
sICConfig.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIM_CHANNEL_4) != HAL_OK)
{
/* Configuration Error */
ErrorHandler();
}
/*##-3- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_4) != HAL_OK)
{
/* Starting Error */
ErrorHandler();
}
}
示例8: MX_TIM1_Init
/* TIM1 init function */
void MX_TIM1_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim1.Instance = TIM1;
htim1.Init.Prescaler = 167;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 0xFFFF;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(&htim1);
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig);
HAL_TIM_IC_Init(&htim1);
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
sSlaveConfig.InputTrigger = TIM_TS_TI1F_ED;
sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sSlaveConfig.TriggerFilter = 0;
HAL_TIM_SlaveConfigSynchronization(&htim1, &sSlaveConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_1);
HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_2);
HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_3);
HAL_TIM_ConfigTI1Input(&htim1, TIM_TI1SELECTION_XORCOMBINATION);
}
示例9: TIM_Init
void TIM_Init(TIM_HandleTypeDef *timh)
{
TIM_IC_InitTypeDef sConfig;
timh->Init.Period = 0xFFFF;
timh->Init.Prescaler = 0;
timh->Init.Prescaler = ((SystemCoreClock) / 1000000) - 1; // 1Mhz
timh->Init.ClockDivision = 0;
timh->Init.CounterMode = TIM_COUNTERMODE_UP;
HAL_TIM_IC_Init(timh);
// Common configuration
sConfig.ICPrescaler = TIM_ICPSC_DIV1;
sConfig.ICFilter = 0;
// Configure the Input Capture of channel 1
sConfig.ICPolarity = TIM_ICPOLARITY_RISING;
sConfig.ICSelection = TIM_ICSELECTION_INDIRECTTI;
HAL_TIM_IC_ConfigChannel(timh, &sConfig, TIM_CHANNEL_1);
// Configure the Input Capture of channel 2
sConfig.ICPolarity = TIM_ICPOLARITY_FALLING;
sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
HAL_TIM_IC_ConfigChannel(timh, &sConfig, TIM_CHANNEL_2);
// Configure the Input Capture of channel 3
sConfig.ICPolarity = TIM_ICPOLARITY_RISING;
sConfig.ICSelection = TIM_ICSELECTION_INDIRECTTI;
HAL_TIM_IC_ConfigChannel(timh, &sConfig, TIM_CHANNEL_3);
// Configure the Input Capture of channel 4
sConfig.ICPolarity = TIM_ICPOLARITY_FALLING;
sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
HAL_TIM_IC_ConfigChannel(timh, &sConfig, TIM_CHANNEL_4);
HAL_TIM_IC_Start_IT(timh, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(timh, TIM_CHANNEL_2);
HAL_TIM_IC_Start_IT(timh, TIM_CHANNEL_3);
HAL_TIM_IC_Start_IT(timh, TIM_CHANNEL_4);
}
示例10: MX_TIM5_Init
/* TIM5 init function */
void MX_TIM5_Init(void)
{
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim5.Instance = TIM5;
htim5.Init.Prescaler = 0;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 0xFFFFFFFF;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_IC_Init(&htim5) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_BOTHEDGE;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 15;
if (HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_3) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_4) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
示例11: MX_TIM5_Init
/* TIM5 init function */
void MX_TIM5_Init(void)
{
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim5.Instance = TIM5;
htim5.Init.Prescaler = 49;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 0xFFFF;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim5);
HAL_TIM_IC_Init(&htim5);
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
sSlaveConfig.InputTrigger = TIM_TS_TI2FP2;
sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sSlaveConfig.TriggerFilter = 0;
HAL_TIM_SlaveConfigSynchronization(&htim5, &sSlaveConfig);
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_1);
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_2);
}
示例12: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Systick timer is configured by default as source of time base, but user
can eventually implement his proper time base source (a general purpose
timer for example or other time source), keeping in mind that Time base
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
handled in milliseconds basis.
- Set NVIC Group Priority to 4
- Low Level Initialization: global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 180 MHz */
SystemClock_Config();
/* Configure LED3 */
BSP_LED_Init(LED3);
/*##-1- Configure the TIM peripheral #######################################*/
/* TIM1 configuration: Input Capture mode ---------------------
The external signal is connected to TIM1 CH2 pin (PA.09 - )
The Rising edge is used as active edge,
The TIM1 CCR2 is used to compute the frequency value
------------------------------------------------------------ */
/* Set TIMx instance */
TimHandle.Instance = TIMx;
/* Initialize TIMx peripheral as follows:
+ Period = 0xFFFF
+ Prescaler = 0
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 0xFFFF;
TimHandle.Init.Prescaler = 0;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.RepetitionCounter = 0;
if(HAL_TIM_IC_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the Input Capture channel ################################*/
/* Configure the Input Capture of channel 2 */
sICConfig.ICPolarity = TIM_ICPOLARITY_RISING;
sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
sICConfig.ICPrescaler = TIM_ICPSC_DIV1;
sICConfig.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIM_CHANNEL_2) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/*##-3- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
while (1)
{
}
}
示例13: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch, instruction and Data caches
- Configure the Systick to generate an interrupt each 1 msec
- Set NVIC Group Priority to 4
- Global MSP (MCU Support Package) initialization
*/
HAL_Init();
/* Configure the system clock to 168 MHz */
SystemClock_Config();
/* Configure LED3 */
BSP_LED_Init(LED3);
/*##-1- Configure the TIM peripheral #######################################*/
/* ---------------------------------------------------------------------------
TIM4 configuration: PWM Input mode
In this example TIM4 input clock (TIM4CLK) is set to 2 * APB1 clock (PCLK1),
since APB1 prescaler is different from 1.
TIM4CLK = 2 * PCLK1
PCLK1 = HCLK / 4
=> TIM4CLK = HCLK / 2 = SystemCoreClock /2
External Signal Frequency = TIM4 counter clock / TIM4_CCR2 in Hz.
External Signal DutyCycle = (TIM4_CCR1*100)/(TIM4_CCR2) in %.
--------------------------------------------------------------------------- */
/* Set TIMx instance */
TimHandle.Instance = TIM4;
/* Initialize TIMx peripheral as follow:
+ Period = 0xFFFF
+ Prescaler = 0
+ ClockDivision = 0
+ Counter direction = Up
*/
TimHandle.Init.Period = 0xFFFF;
TimHandle.Init.Prescaler = 0;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if(HAL_TIM_IC_Init(&TimHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the Input Capture channels ###############################*/
/* Common configuration */
sConfig.ICPrescaler = TIM_ICPSC_DIV1;
sConfig.ICFilter = 0;
/* Configure the Input Capture of channel 1 */
sConfig.ICPolarity = TIM_ICPOLARITY_FALLING;
sConfig.ICSelection = TIM_ICSELECTION_INDIRECTTI;
if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_1) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/* Configure the Input Capture of channel 2 */
sConfig.ICPolarity = TIM_ICPOLARITY_RISING;
sConfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
if(HAL_TIM_IC_ConfigChannel(&TimHandle, &sConfig, TIM_CHANNEL_2) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/*##-3- Configure the slave mode ###########################################*/
/* Select the slave Mode: Reset Mode */
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
sSlaveConfig.InputTrigger = TIM_TS_TI2FP2;
if(HAL_TIM_SlaveConfigSynchronization(&TimHandle, &sSlaveConfig) != HAL_OK)
{
/* Configuration Error */
Error_Handler();
}
/*##-4- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_2) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}
/*##-5- Start the Input Capture in interrupt mode ##########################*/
if(HAL_TIM_IC_Start_IT(&TimHandle, TIM_CHANNEL_1) != HAL_OK)
{
/* Starting Error */
Error_Handler();
//.........这里部分代码省略.........
示例14: GetLSIFrequency
/**
* @brief Configures TIM5 to measure the LSI oscillator frequency.
* @param None
* @retval LSI Frequency
*/
static uint32_t GetLSIFrequency(void)
{
uint32_t pclk1 = 0;
TIM_IC_InitTypeDef timinputconfig;
/* Enable the LSI oscillator */
__HAL_RCC_LSI_ENABLE();
/* Wait till LSI is ready */
while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Configure the TIM peripheral */
/* Set TIMx instance */
TimInputCaptureHandle.Instance = TIM5;
/* TIM5 configuration: Input Capture mode ---------------------
The LSI oscillator is connected to TIM5 CH4.
The Rising edge is used as active edge.
The TIM5 CCR4 is used to compute the frequency value.
------------------------------------------------------------ */
TimInputCaptureHandle.Init.Prescaler = 0;
TimInputCaptureHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimInputCaptureHandle.Init.Period = 0xFFFF;
TimInputCaptureHandle.Init.ClockDivision = 0;
TimInputCaptureHandle.Init.RepetitionCounter = 0;
if(HAL_TIM_IC_Init(&TimInputCaptureHandle) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Connect internally the TIM5_CH4 Input Capture to the LSI clock output */
HAL_TIMEx_RemapConfig(&TimInputCaptureHandle, TIM_TIM5_LSI);
/* Configure the Input Capture of channel 4 */
timinputconfig.ICPolarity = TIM_ICPOLARITY_RISING;
timinputconfig.ICSelection = TIM_ICSELECTION_DIRECTTI;
timinputconfig.ICPrescaler = TIM_ICPSC_DIV8;
timinputconfig.ICFilter = 0;
if(HAL_TIM_IC_ConfigChannel(&TimInputCaptureHandle, &timinputconfig, TIM_CHANNEL_4) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/* Reset the flags */
TimInputCaptureHandle.Instance->SR = 0;
/* Start the TIM Input Capture measurement in interrupt mode */
if(HAL_TIM_IC_Start_IT(&TimInputCaptureHandle, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* Wait until the TIM5 get 2 LSI edges (refer to TIM5_IRQHandler() in
stm32f4xx_it.c file) */
while(uwMeasurementDone == 0)
{
}
uwCaptureNumber = 0;
/* Deinitialize the TIM5 peripheral registers to their default reset values */
HAL_TIM_IC_DeInit(&TimInputCaptureHandle);
/* Compute the LSI frequency, depending on TIM5 input clock frequency (PCLK1)*/
/* Get PCLK1 frequency */
pclk1 = HAL_RCC_GetPCLK1Freq();
/* Get PCLK1 prescaler */
if((RCC->CFGR & RCC_CFGR_PPRE1) == 0)
{
/* PCLK1 prescaler equal to 1 => TIMCLK = PCLK1 */
return ((pclk1 / uwPeriodValue) * 8);
}
else
{ /* PCLK1 prescaler different from 1 => TIMCLK = 2 * PCLK1 */
return (((2 * pclk1) / uwPeriodValue) * 8);
}
}
示例15: MX_TIM5_Init
/* TIM5 init function */
void MX_TIM5_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig;
TIM_SlaveConfigTypeDef sSlaveConfig;
TIM_MasterConfigTypeDef sMasterConfig;
TIM_IC_InitTypeDef sConfigIC;
htim5.Instance = TIM5;
htim5.Init.Prescaler = 840;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 65535;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_IC_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
sSlaveConfig.InputTrigger = TIM_TS_TI2FP2;
sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sSlaveConfig.TriggerFilter = 0;
if (HAL_TIM_SlaveConfigSynchronization(&htim5, &sSlaveConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
sConfigIC.ICSelection = TIM_ICSELECTION_INDIRECTTI;
sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
sConfigIC.ICFilter = 0;
if (HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
if (HAL_TIM_IC_ConfigChannel(&htim5, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
}