📄 stm32f10x_tim1.c
字号:
TIM1_ICInitStruct->TIM1_ICFilter);
/* Set the Input Capture Prescaler value */
TIM1_SetIC4Prescaler(TIM1_ICInitStruct->TIM1_ICPrescaler);
}
}
/*******************************************************************************
* Function Name : TIM1_PWMIConfig
* Description : Configures the TIM1 peripheral in PWM Input Mode according
* to the specified parameters in the TIM1_ICInitStruct.
* Input : - TIM1_ICInitStruct: pointer to a TIM1_ICInitTypeDef structure
* that contains the configuration information for the specified
* TIM1 peripheral.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_PWMIConfig(TIM1_ICInitTypeDef* TIM1_ICInitStruct)
{
u8 ICPolarity = TIM1_ICPolarity_Rising;
u8 ICSelection = TIM1_ICSelection_DirectTI;
/* Check the parameters */
assert_param(IS_TIM1_PWMI_CHANNEL(TIM1_ICInitStruct->TIM1_Channel));
assert_param(IS_TIM1_IC_POLARITY(TIM1_ICInitStruct->TIM1_ICPolarity));
assert_param(IS_TIM1_IC_SELECTION(TIM1_ICInitStruct->TIM1_ICSelection));
assert_param(IS_TIM1_IC_PRESCALER(TIM1_ICInitStruct->TIM1_ICPrescaler));
/* Select the Opposite Input Polarity */
if (TIM1_ICInitStruct->TIM1_ICPolarity == TIM1_ICPolarity_Rising)
{
ICPolarity = TIM1_ICPolarity_Falling;
}
else
{
ICPolarity = TIM1_ICPolarity_Rising;
}
/* Select the Opposite Input */
if (TIM1_ICInitStruct->TIM1_ICSelection == TIM1_ICSelection_DirectTI)
{
ICSelection = TIM1_ICSelection_IndirectTI;
}
else
{
ICSelection = TIM1_ICSelection_DirectTI;
}
if (TIM1_ICInitStruct->TIM1_Channel == TIM1_Channel_1)
{
/* TI1 Configuration */
TI1_Config(TIM1_ICInitStruct->TIM1_ICPolarity, TIM1_ICInitStruct->TIM1_ICSelection,
TIM1_ICInitStruct->TIM1_ICFilter);
/* Set the Input Capture Prescaler value */
TIM1_SetIC1Prescaler(TIM1_ICInitStruct->TIM1_ICPrescaler);
/* TI2 Configuration */
TI2_Config(ICPolarity, ICSelection, TIM1_ICInitStruct->TIM1_ICFilter);
/* Set the Input Capture Prescaler value */
TIM1_SetIC2Prescaler(TIM1_ICInitStruct->TIM1_ICPrescaler);
}
else
{
/* TI2 Configuration */
TI2_Config(TIM1_ICInitStruct->TIM1_ICPolarity, TIM1_ICInitStruct->TIM1_ICSelection,
TIM1_ICInitStruct->TIM1_ICFilter);
/* Set the Input Capture Prescaler value */
TIM1_SetIC2Prescaler(TIM1_ICInitStruct->TIM1_ICPrescaler);
/* TI1 Configuration */
TI1_Config(ICPolarity, ICSelection, TIM1_ICInitStruct->TIM1_ICFilter);
/* Set the Input Capture Prescaler value */
TIM1_SetIC1Prescaler(TIM1_ICInitStruct->TIM1_ICPrescaler);
}
}
/*******************************************************************************
* Function Name : TIM1_OCStructInit
* Description : Fills each TIM1_OCInitStruct member with its default value.
* Input : - TIM1_OCInitStruct : pointer to a TIM1_OCInitTypeDef structure
* which will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_OCStructInit(TIM1_OCInitTypeDef* TIM1_OCInitStruct)
{
/* Set the default configuration */
TIM1_OCInitStruct->TIM1_OCMode = TIM1_OCMode_Timing;
TIM1_OCInitStruct->TIM1_OutputState = TIM1_OutputState_Disable;
TIM1_OCInitStruct->TIM1_OutputNState = TIM1_OutputNState_Disable;
TIM1_OCInitStruct->TIM1_Pulse = TIM1_Pulse_Reset_Mask;
TIM1_OCInitStruct->TIM1_OCPolarity = TIM1_OCPolarity_High;
TIM1_OCInitStruct->TIM1_OCNPolarity = TIM1_OCPolarity_High;
TIM1_OCInitStruct->TIM1_OCIdleState = TIM1_OCIdleState_Reset;
TIM1_OCInitStruct->TIM1_OCNIdleState = TIM1_OCNIdleState_Reset;
}
/*******************************************************************************
* Function Name : TIM1_ICStructInit
* Description : Fills each TIM1_ICInitStruct member with its default value.
* Input : - TIM1_ICInitStruct : pointer to a TIM1_ICInitTypeDef structure
* which will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_ICStructInit(TIM1_ICInitTypeDef* TIM1_ICInitStruct)
{
/* Set the default configuration */
TIM1_ICInitStruct->TIM1_Channel = TIM1_Channel_1;
TIM1_ICInitStruct->TIM1_ICSelection = TIM1_ICSelection_DirectTI;
TIM1_ICInitStruct->TIM1_ICPolarity = TIM1_ICPolarity_Rising;
TIM1_ICInitStruct->TIM1_ICPrescaler = TIM1_ICPSC_DIV1;
TIM1_ICInitStruct->TIM1_ICFilter = TIM1_ICFilter_Mask;
}
/*******************************************************************************
* Function Name : TIM1_TimeBaseStructInit
* Description : Fills each TIM1_TimeBaseInitStruct member with its default value.
* Input : - TIM1_TimeBaseInitStruct : pointer to a TIM1_TimeBaseInitTypeDef
* structure which will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_TimeBaseStructInit(TIM1_TimeBaseInitTypeDef* TIM1_TimeBaseInitStruct)
{
/* Set the default configuration */
TIM1_TimeBaseInitStruct->TIM1_Period = TIM1_Period_Reset_Mask;
TIM1_TimeBaseInitStruct->TIM1_Prescaler = TIM1_Prescaler_Reset_Mask;
TIM1_TimeBaseInitStruct->TIM1_ClockDivision = TIM1_CKD_DIV1;
TIM1_TimeBaseInitStruct->TIM1_CounterMode = TIM1_CounterMode_Up;
TIM1_TimeBaseInitStruct->TIM1_RepetitionCounter = TIM1_RepetitionCounter_Reset_Mask;
}
/*******************************************************************************
* Function Name : TIM1_BDTRStructInit
* Description : Fills each TIM1_BDTRInitStruct member with its default value.
* Input : - TIM1_BDTRInitStruct : pointer to a TIM1_BDTRInitTypeDef
* structure which will be initialized.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_BDTRStructInit(TIM1_BDTRInitTypeDef* TIM1_BDTRInitStruct)
{
/* Set the default configuration */
TIM1_BDTRInitStruct->TIM1_OSSRState = TIM1_OSSRState_Disable;
TIM1_BDTRInitStruct->TIM1_OSSIState = TIM1_OSSIState_Disable;
TIM1_BDTRInitStruct->TIM1_LOCKLevel = TIM1_LOCKLevel_OFF;
TIM1_BDTRInitStruct->TIM1_DeadTime = TIM1_DeadTime_Reset_Mask;
TIM1_BDTRInitStruct->TIM1_Break = TIM1_Break_Disable;
TIM1_BDTRInitStruct->TIM1_BreakPolarity = TIM1_BreakPolarity_Low;
TIM1_BDTRInitStruct->TIM1_AutomaticOutput = TIM1_AutomaticOutput_Disable;
}
/*******************************************************************************
* Function Name : TIM1_Cmd
* Description : Enables or disables the TIM1 peripheral.
* Input : - Newstate: new state of the TIM1 peripheral.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_Cmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* set or Reset the CEN Bit */
*(vu32 *) CR1_CEN_BB = (u16)NewState;
}
/*******************************************************************************
* Function Name : TIM1_CtrlPWMOutputs
* Description : Enables or disables the TIM1 peripheral Main Outputs.
* Input : - Newstate: new state of the TIM1 peripheral Main Outputs.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_CtrlPWMOutputs(FunctionalState Newstate)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(Newstate));
/* Set or Reset the MOE Bit */
*(vu32 *) BDTR_MOE_BB = (u16)Newstate;
}
/*******************************************************************************
* Function Name : TIM1_ITConfig
* Description : Enables or disables the specified TIM1 interrupts.
* Input : - TIM1_IT: specifies the TIM1 interrupts sources to be enabled
* or disabled.
* This parameter can be any combination of the following values:
* - TIM1_IT_Update: TIM1 update Interrupt source
* - TIM1_IT_CC1: TIM1 Capture Compare 1 Interrupt source
* - TIM1_IT_CC2: TIM1 Capture Compare 2 Interrupt source
* - TIM1_IT_CC3: TIM1 Capture Compare 3 Interrupt source
* - TIM1_IT_CC4: TIM1 Capture Compare 4 Interrupt source
* - TIM1_IT_CCUpdate: TIM1 Capture Compare Update Interrupt
* source
* - TIM1_IT_Trigger: TIM1 Trigger Interrupt source
* - TIM1_IT_Break: TIM1 Break Interrupt source
* - Newstate: new state of the TIM1 interrupts.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_ITConfig(u16 TIM1_IT, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_TIM1_IT(TIM1_IT));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState == ENABLE)
{
/* Enable the Interrupt sources */
TIM1->DIER |= TIM1_IT;
}
else
{
/* Disable the Interrupt sources */
TIM1->DIER &= (u16)~TIM1_IT;
}
}
/*******************************************************************************
* Function Name : TIM1_DMAConfig
* Description : Configures the TIM1抯 DMA interface.
* Input : - TIM1_DMABase: DMA Base address.
* This parameter can be one of the following values:
* - TIM1_DMABase_CR1, TIM1_DMABase_CR2, TIM1_DMABase_SMCR,
* TIM1_DMABase_DIER, TIM1_DMABase_SR, TIM1_DMABase_EGR,
* TIM1_DMABase_CCMR1, TIM1_DMABase_CCMR2, TIM1_DMABase_CCER,
* TIM1_DMABase_CNT, TIM1_DMABase_PSC, TIM1_DMABase_ARR,
* TIM1_DMABase_RCR, TIM1_DMABase_CCR1, TIM1_DMABase_CCR2,
* TIM1_DMABase_CCR3, TIM1_DMABase_CCR4, TIM1_DMABase_BDTR,
* TIM1_DMABase_DCR.
* - TIM1_DMABurstLength: DMA Burst length.
* This parameter can be one value between:
* TIM1_DMABurstLength_1Byte and TIM1_DMABurstLength_18Bytes.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_DMAConfig(u16 TIM1_DMABase, u16 TIM1_DMABurstLength)
{
u32 tmpdcr = 0;
/* Check the parameters */
assert_param(IS_TIM1_DMA_BASE(TIM1_DMABase));
assert_param(IS_TIM1_DMA_LENGTH(TIM1_DMABurstLength));
tmpdcr = TIM1->DCR;
/* Reset the DBA and the DBL Bits */
tmpdcr &= DCR_DMA_Mask;
/* Set the DMA Base and the DMA Burst Length */
tmpdcr |= TIM1_DMABase | TIM1_DMABurstLength;
TIM1->DCR = (u16)tmpdcr;
}
/*******************************************************************************
* Function Name : TIM1_DMACmd
* Description : Enables or disables the TIM1抯 DMA Requests.
* Input : - TIM1_DMASources: specifies the DMA Request sources.
* This parameter can be any combination of the following values:
* - TIM1_DMA_Update: TIM1 update Interrupt source
* - TIM1_DMA_CC1: TIM1 Capture Compare 1 DMA source
* - TIM1_DMA_CC2: TIM1 Capture Compare 2 DMA source
* - TIM1_DMA_CC3: TIM1 Capture Compare 3 DMA source
* - TIM1_DMA_CC4: TIM1 Capture Compare 4 DMA source
* - TIM1_DMA_COM: TIM1 Capture Compare Update DMA
* source
* - TIM1_DMA_Trigger: TIM1 Trigger DMA source
* - Newstate: new state of the DMA Request sources.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM1_DMACmd(u16 TIM1_DMASource, FunctionalState Newstate)
{
u32 tmpdier = 0;
/* Check the parameters */
assert_param(IS_TIM1_DMA_SOURCE(TIM1_DMASource));
assert_param(IS_FUNCTIONAL_STATE(Newstate));
tmpdier = TIM1->DIER;
if (Newstate == ENABLE)
{
/* Enable the DMA sources */
tmpdier |= TIM1_DMASource;
}
else
{
/* Disable the DMA sources */
tmpdier &= (u16)~TIM1_DMASource;
}
TIM1->DIER = (u16)tmpdier;
}
/*******************************************************************************
* Function Name : TIM1_InternalClockConfig
* Description : Configures the TIM1 interrnal Clock
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM1_InternalClockConfig(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -