📄 stm32f10x_tim.c
字号:
/* Write to TIMx CR1 register */
TIMx->CR1 = tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_SelectInputTrigger
* Description : Selects the Input Trigger source
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - TIM_InputTriggerSource: The Input Trigger source.
* This parameter can be one of the following values:
* - TIM_TS_ITR0: Internal Trigger 0
* - TIM_TS_ITR1: Internal Trigger 1
* - TIM_TS_ITR2: Internal Trigger 2
* - TIM_TS_ITR3: Internal Trigger 3
* - TIM_TS_TI1F_ED: TI1 Edge Detector
* - TIM_TS_TI1FP1: Filtered Timer Input 1
* - TIM_TS_TI2FP2: Filtered Timer Input 2
* - TIM_TS_ETRF: External Trigger input
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
{
u16 tmpsmcr = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));
/* Get the TIMx SMCR register value */
tmpsmcr = TIMx->SMCR;
/* Reset the TS Bits */
tmpsmcr &= SMCR_TS_Mask;
/* Set the Input Trigger source */
tmpsmcr |= TIM_InputTriggerSource;
/* Write to TIMx SMCR */
TIMx->SMCR = tmpsmcr;
}
/*******************************************************************************
* Function Name : TIM_EncoderInterfaceConfig
* Description : Configures the TIMx Encoder Interface.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 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: IC Falling edge.
* - TIM_ICPolarity_Rising: IC Rising edge.
* - TIM_IC2Polarity: specifies the IC2 Polarity
* This parmeter can be one of the following values:
* - TIM_ICPolarity_Falling: IC Falling edge.
* - TIM_ICPolarity_Rising: IC Rising edge.
* Output : None
* Return : None
*******************************************************************************/
void TIM_EncoderInterfaceConfig(TIM_TypeDef* TIMx, u16 TIM_EncoderMode,
u16 TIM_IC1Polarity, u16 TIM_IC2Polarity)
{
u16 tmpsmcr = 0;
u16 tmpccmr1 = 0;
u16 tmpccer = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity));
/* Get the TIMx SMCR register value */
tmpsmcr = TIMx->SMCR;
/* Get the TIMx CCMR1 register value */
tmpccmr1 = TIMx->CCMR1;
/* Get the TIMx CCER register value */
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_Reset & CCER_CC2P_Reset;
tmpccer |= (TIM_IC1Polarity | (u16)(TIM_IC2Polarity << 4));
/* Write to TIMx SMCR */
TIMx->SMCR = tmpsmcr;
/* Write to TIMx CCMR1 */
TIMx->CCMR1 = tmpccmr1;
/* Write to TIMx CCER */
TIMx->CCER = tmpccer;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC1Config
* Description : Forces the TIMx output 1 waveform to active or inactive level.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - TIM_ForcedAction: specifies the forced Action to be set to
* the output waveform.
* This parameter can be one of the following values:
* - TIM_ForcedAction_Active: Force active level on OC1REF
* - TIM_ForcedAction_InActive: Force inactive level on
* OC1REF.
* Output : None
* Return : None
*******************************************************************************/
void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
{
u16 tmpccmr1 = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OC1M Bits */
tmpccmr1 &= CCMR_OC13M_Mask;
/* Configure The Forced output Mode */
tmpccmr1 |= TIM_ForcedAction;
/* Write to TIMx CCMR1 register */
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC2Config
* Description : Forces the TIMx output 2 waveform to active or inactive level.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - TIM_ForcedAction: specifies the forced Action to be set to
* the output waveform.
* This parameter can be one of the following values:
* - TIM_ForcedAction_Active: Force active level on OC2REF
* - TIM_ForcedAction_InActive: Force inactive level on
* OC2REF.
* Output : None
* Return : None
*******************************************************************************/
void TIM_ForcedOC2Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
{
u16 tmpccmr1 = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
tmpccmr1 = TIMx->CCMR1;
/* Reset the OC2M Bits */
tmpccmr1 &= CCMR_OC24M_Mask;
/* Configure The Forced output Mode */
tmpccmr1 |= (u16)(TIM_ForcedAction << 8);
/* Write to TIMx CCMR1 register */
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC3Config
* Description : Forces the TIMx output 3 waveform to active or inactive level.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - TIM_ForcedAction: specifies the forced Action to be set to
* the output waveform.
* This parameter can be one of the following values:
* - TIM_ForcedAction_Active: Force active level on OC3REF
* - TIM_ForcedAction_InActive: Force inactive level on
* OC3REF.
* Output : None
* Return : None
*******************************************************************************/
void TIM_ForcedOC3Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
{
u16 tmpccmr2 = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OC1M Bits */
tmpccmr2 &= CCMR_OC13M_Mask;
/* Configure The Forced output Mode */
tmpccmr2 |= TIM_ForcedAction;
/* Write to TIMx CCMR2 register */
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC4Config
* Description : Forces the TIMx output 4 waveform to active or inactive level.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - TIM_ForcedAction: specifies the forced Action to be set to
* the output waveform.
* This parameter can be one of the following values:
* - TIM_ForcedAction_Active: Force active level on OC4REF
* - TIM_ForcedAction_InActive: Force inactive level on
* OC4REF.
* Output : None
* Return : None
*******************************************************************************/
void TIM_ForcedOC4Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
{
u16 tmpccmr2 = 0;
/* Check the parameters */
assert_param(IS_TIM_123458_PERIPH(TIMx));
assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OC2M Bits */
tmpccmr2 &= CCMR_OC24M_Mask;
/* Configure The Forced output Mode */
tmpccmr2 |= (u16)(TIM_ForcedAction << 8);
/* Write to TIMx CCMR2 register */
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_ARRPreloadConfig
* Description : Enables or disables TIMx peripheral Preload register on ARR.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 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_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_TIM_ALL_PERIPH(TIMx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Set the ARR Preload Bit */
TIMx->CR1 |= CR1_ARPE_Set;
}
else
{
/* Reset the ARR Preload Bit */
TIMx->CR1 &= CR1_ARPE_Reset;
}
}
/*******************************************************************************
* Function Name : TIM_SelectCOM
* Description : Selects the TIM peripheral Commutation event.
* Input :- TIMx: where x can be 1 or 8 to select the TIMx peripheral
* - NewState: new state of the Commutation event.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectCOM(TIM_TypeDef* TIMx, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_TIM_18_PERIPH(TIMx));
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Set the COM Bit */
TIMx->CR2 |= CR2_CCUS_Set;
}
else
{
/* Reset the COM Bit */
TIMx->CR2 &= CR2_CCUS_Reset;
}
}
/*******************************************************************************
* Function Name : TIM_SelectCCDMA
* Description : Selects the TIMx peripheral Capture Compare DMA source.
* Input : - TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM
* peripheral.
* - NewState: new state of the Capture Compare DMA source
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectCCDMA(TIM_TypeDef* TIMx, FunctionalState NewState)
{
/* Check the parameters */
assert_pa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -