📄 stm32f10x_tim.c
字号:
TIMx->CCMR1 = (u16)tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_ClearOC3Ref
* Description : Clears or safeguards the OCREF3 signal on an external event
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCClear: new state of the Output Compare Clear Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCClear_Enable
* - TIM_OCClear_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_ClearOC3Ref(TIM_TypeDef* TIMx, u16 TIM_OCClear)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC13CE_Mask;
/* Enable or Disable the Output Compare Clear Bit */
tmpccmr2 |= (u16)(TIM_OCClear);
TIMx->CCMR2 = (u16)tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_ClearOC4Ref
* Description : Clears or safeguards the OCREF4 signal on an external event
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCClear: new state of the Output Compare Clear Enable Bit.
* This parameter can be one of the following values:
* - TIM_OCClear_Enable
* - TIM_OCClear_Disable
* Output : None
* Return : None
*******************************************************************************/
void TIM_ClearOC4Ref(TIM_TypeDef* TIMx, u16 TIM_OCClear)
{
u32 tmpccmr2 = 0;
/* Check the parameters */
assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear));
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC24CE_Mask;
/* Enable or Disable the Output Compare Clear Bit */
tmpccmr2 |= (u16)(TIM_OCClear << 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_param(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_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode));
assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity));
assert_param(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.
* This parameter can be one or more of the following values:
* - TIM_EventSource_Update: Timer update Event source
* - TIM_EventSource_CC1: Timer Capture Compare 1 Event source
* - TIM_EventSource_CC2: Timer Capture Compare 2 Event source
* - TIM_EventSource_CC3: Timer Capture Compare 3 Event source
* - TIM_EventSource_CC4: Timer Capture Compare 4 Event source
* - TIM_EventSource_Trigger: Timer Trigger Event source
* Output : None
* Return : None
*******************************************************************************/
void TIM_GenerateEvent(TIM_TypeDef* TIMx, u16 TIM_EventSource)
{
/* Check the parameters */
assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource));
/* Set the event sources */
TIMx->EGR |= TIM_EventSource;
}
/*******************************************************************************
* Function Name : TIM_OC1PolarityConfig
* Description : Configures the TIMx channel 1 polarity.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPolarity: specifies the OC1 Polarity
* This parmeter can be one of the following values:
* - TIM_OCPolarity_High: Output Compare active high
* - TIM_OCPolarity_Low: Output Compare active low
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC1PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
{
u32 tmpccer = 0;
/* Check the parameters */
assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
tmpccer = TIMx->CCER;
/* Set or Reset the CC1P Bit */
tmpccer &= CCER_CC1P_Mask;
tmpccer |= TIM_OCPolarity;
TIMx->CCER = (u16)tmpccer;
}
/*******************************************************************************
* Function Name : TIM_OC2PolarityConfig
* Description : Configures the TIMx channel 2 polarity.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPolarity: specifies the OC2 Polarity
* This parmeter can be one of the following values:
* - TIM_OCPolarity_High: Output Compare active high
* - TIM_OCPolarity_Low: Output Compare active low
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC2PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
{
u32 tmpccer = 0;
/* Check the parameters */
assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
tmpccer = TIMx->CCER;
/* Set or Reset the CC2P Bit */
tmpccer &= CCER_CC2P_Mask;
tmpccer |= (u16)((u16)TIM_OCPolarity << 4);
TIMx->CCER = (u16)tmpccer;
}
/*******************************************************************************
* Function Name : TIM_OC3PolarityConfig
* Description : Configures the TIMx channel 3 polarity.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPolarity: specifies the OC3 Polarity
* This parmeter can be one of the following values:
* - TIM_OCPolarity_High: Output Compare active high
* - TIM_OCPolarity_Low: Output Compare active low
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC3PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
{
u32 tmpccer = 0;
/* Check the parameters */
assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
tmpccer = TIMx->CCER;
/* Set or Reset the CC3P Bit */
tmpccer &= CCER_CC3P_Mask;
tmpccer |= (u16)((u16)TIM_OCPolarity << 8);
TIMx->CCER = (u16)tmpccer;
}
/*******************************************************************************
* Function Name : TIM_OC4PolarityConfig
* Description : Configures the TIMx channel 4 polarity.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OCPolarity: specifies the OC4 Polarity
* This parmeter can be one of the following values:
* - TIM_OCPolarity_High: Output Compare active high
* - TIM_OCPolarity_Low: Output Compare active low
* Output : None
* Return : None
*******************************************************************************/
void TIM_OC4PolarityConfig(TIM_TypeDef* TIMx, u16 TIM_OCPolarity)
{
u32 tmpccer = 0;
/* Check the parameters */
assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity));
tmpccer = TIMx->CCER;
/* Set or Reset the CC4P Bit */
tmpccer &= CCER_CC4P_Mask;
tmpccer |= (u16)((u16)TIM_OCPolarity << 12);
TIMx->CCER = (u16)tmpccer;
}
/*******************************************************************************
* Function Name : TIM_UpdateRequestConfig
* Description : Configures the TIMx Update Request Interrupt source.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_UpdateSource: specifies the Update source.
* This parameter can be one of the following values:
* - TIM_UpdateSource_Regular
* - TIM_UpdateSource_Global
* Output : None
* Return : None
*******************************************************************************/
void TIM_UpdateRequestConfig(TIM_TypeDef* TIMx, u16 TIM_UpdateSource)
{
u32 tmpcr1 = 0;
/* Check the parameters */
assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource));
tmpcr1 = TIMx->CR1;
if (TIM_UpdateSource == TIM_UpdateSource_Regular)
{
/* Set the URS Bit */
tmpcr1 |= CR1_URS_Set;
}
else
{
/* Reset the URS Bit */
tmpcr1 &= CR1_URS_Reset;
}
TIMx->CR1 = (u16)tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_SelectHallSensor
* Description : Enables or disables the TIMx抯 Hall sensor interface.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - Newstate: new state of the TIMx Hall sensor interface.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Re
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -