📄 stm32f10x_tim.c
字号:
/*******************************************************************************
* Function Name : TIM_OC1PreloadConfig
* Description : Enables or disables the TIMx peripheral Preload register on CCR1.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPreload: new state of the TIMx peripheral Preload
* register
* This parameter can be one of the following values:
* - TIM_OCPreload_Enable
* - TIM_OCPreload_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC1PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
{
u32 tmpccmr1 = 0;
/* Check the parameters */
assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCPE Bit */
tmpccmr1 &= CCMR_OC13PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr1 |= TIM_OCPreload;
TIMx->CCMR1 = (u16)tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC2PreloadConfig
* Description : Enables or disables the TIMx peripheral Preload register on CCR2.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPreload: new state of the TIMx peripheral Preload
* register
* This parameter can be one of the following values:
* - TIM_OCPreload_Enable
* - TIM_OCPreload_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC2PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
{
u32 tmpccmr1 = 0;
/* Check the parameters */
assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCPE Bit */
tmpccmr1 &= CCMR_OC24PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr1 |= (u16)(TIM_OCPreload << 8);
TIMx->CCMR1 = (u16)tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC3PreloadConfig
* Description : Enables or disables the TIMx peripheral Preload register on CCR3.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPreload: new state of the TIMx peripheral Preload
* register
* This parameter can be one of the following values:
* - TIM_OCPreload_Enable
* - TIM_OCPreload_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC3PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCPE Bit */
tmpccmr2 &= CCMR_OC13PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr2 |= TIM_OCPreload;
TIMx->CCMR2 = (u16)tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC4PreloadConfig
* Description : Enables or disables the TIMx peripheral Preload register on CCR4.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPreload: new state of the TIMx peripheral Preload
* register
* This parameter can be one of the following values:
* - TIM_OCPreload_Enable
* - TIM_OCPreload_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC4PreloadConfig(TIM_TypeDef* TIMx, u16 TIM_OCPreload)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCPE Bit */
tmpccmr2 &= CCMR_OC24PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr2 |= (u16)(TIM_OCPreload << 8);
TIMx->CCMR2 = (u16)tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC1FastConfig
* Description : Configures the TIMx Output Compare 1 Fast feature.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCFast_Enable
* - TIM_OCFast_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC1FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
{
u32 tmpccmr1 = 0;
/* Check the parameters */
assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCFE Bit */
tmpccmr1 &= CCMR_OC13FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr1 |= TIM_OCFast;
TIMx->CCMR1 = (u16)tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC2FastConfig
* Description : Configures the TIMx Output Compare 2 Fast feature.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCFast_Enable
* - TIM_OCFast_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC2FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
{
u32 tmpccmr1 = 0;
/* Check the parameters */
assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCFE Bit */
tmpccmr1 &= CCMR_OC24FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr1 |= (u16)(TIM_OCFast << 8);
TIMx->CCMR1 = (u16)tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC3FastConfig
* Description : Configures the TIMx Output Compare 3 Fast feature.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCFast_Enable
* - TIM_OCFast_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC3FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC13FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr2 |= TIM_OCFast;
TIMx->CCMR2 = (u16)tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC4FastConfig
* Description : Configures the TIMx Output Compare 4 Fast feature.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCFast: new state of the Output Compare Fast Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCFast_Enable
* - TIM_OCFast_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC4FastConfig(TIM_TypeDef* TIMx, u16 TIM_OCFast)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert(IS_TIM_OCFAST_STATE(TIM_OCFast));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC24FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr2 |= (u16)(TIM_OCFast << 8);
TIMx->CCMR2 = (u16)tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_UpdateDisableConfig
* Description : Enables or Disables the TIMx Update event.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - Newstate: new state of the TIMx peripheral Preload register
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM_UpdateDisableConfig(TIM_TypeDef* TIMx, FunctionalState Newstate)
{
u32 tmpcr1 = 0;
/* Check the parameters */
assert(IS_FUNCTIONAL_STATE(Newstate));
tmpcr1 = TIMx->CR1;
if (Newstate != DISABLE)
{
/* Set the Update Disable Bit */
tmpcr1 |= CR1_UDIS_Set;
}
else
{
/* Reset the Update Disable Bit */
tmpcr1 &= CR1_UDIS_Reset;
}
TIMx->CR1 = (u16)tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_EncoderInterfaceConfig
* Description : Configures the TIMx Encoder Interface.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_EncoderMode: specifies the TIMx Encoder Mode.
* This parameter can be one of the following values:
* - TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge
* depending on TI2FP2 level.
* - TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge
* depending on TI1FP1 level.
* - TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and
* TI2FP2 edges depending on the level of the other input.
* - TIM_IC1Polarity: specifies the IC1 Polarity
* This parmeter can be one of the following values:
* - TIM_ICPolarity_Falling
* - TIM_ICPolarity_Rising
* - TIM_IC2Polarity: specifies the IC2 Polarity
* This parmeter can be one of the following values:
* - TIM_ICPolarity_Falling
* - TIM_ICPolarity_Rising
* Output : None
* Return : None
*******************************************************************************/
void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, u16 TIM_EncoderMode,
u16 TIM_IC1Polarity, u16 TIM_IC2Polarity)
{
u32 tmpsmcr = 0;
u32 tmpccmr1 = 0;
u32 tmpccer = 0;
/* Check the parameters */
assert(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
assert(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
assert(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
tmpsmcr = TIMx->SMCR;
tmpccmr1 = TIMx->CCMR1;
tmpccer = TIMx->CCER;
/* Set the encoder Mode */
tmpsmcr &= SMCR_SMS_Mask;
tmpsmcr |= TIM_EncoderMode;
/* Select the Capture Compare 1 and the Capture Compare 2 as input */
tmpccmr1 &= CCMR_CC13S_Mask & CCMR_CC24S_Mask;
tmpccmr1 |= CCMR_TI13Direct_Set | CCMR_TI24Direct_Set;
/* Set the TI1 and the TI2 Polarities */
tmpccer &= CCER_CC1P_Mask & CCER_CC2P_Mask;
tmpccer |= (TIM_IC1Polarity | (u16)((u16)TIM_IC2Polarity << 4));
TIMx->SMCR = (u16)tmpsmcr;
TIMx->CCMR1 = (u16)tmpccmr1;
TIMx->CCER = (u16)tmpccer;
}
/*******************************************************************************
* Function Name : TIM_GenerateEvent
* Description : Configures the TIMx event to be generate by software.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_EventSource: specifies the event source.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -