📄 stm32f10x_tim.c
字号:
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC3PreloadConfig
* Description : Enables or disables TIM 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;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCPE Bit */
tmpccmr2 &= CCMR_OC13PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr2 |= TIM_OCPreload;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC4PreloadConfig
* Description : Enables or disables TIM 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;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCPE Bit */
tmpccmr2 &= CCMR_OC24PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr2 |= TIM_OCPreload << 8;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC1FastConfig
* Description : Configures the Capture Compare 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;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCFE Bit */
tmpccmr1 &= CCMR_OC13FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr1 |= TIM_OCFast;
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC2FastConfig
* Description : Configures the Capture Compare 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;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCFE Bit */
tmpccmr1 &= CCMR_OC24FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr1 |= TIM_OCFast << 8;
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC3FastConfig
* Description : Configures the Capture Compare 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;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC13FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr2 |= TIM_OCFast;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_OC4FastConfig
* Description : Configures the Capture Compare 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;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCFE Bit */
tmpccmr2 &= CCMR_OC24FE_Mask;
/* Enable or Disable the Output Compare Fast Bit */
tmpccmr2 |= TIM_OCFast << 8;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_UpdateDisableConfig
* Description : Enables or Disables the 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;
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 = tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_EncoderInterfaceConfig
* Description : Configures the TIM 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,
u8 TIM_IC1Polarity, u8 TIM_IC2Polarity)
{
u32 tmpsmcr = 0;
u32 tmpccmr1 = 0;
u32 tmpccer = 0;
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 |= (u32)TIM_IC1Polarity | (TIM_IC2Polarity << 4);
TIMx->SMCR = tmpsmcr;
TIMx->CCMR1 = tmpccmr1 ;
TIMx->CCER = 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)
{
/* Set the event sources */
TIMx->EGR |= TIM_EventSource;
}
/*******************************************************************************
* Function Name : TIM_OC1PolarityConfig
* Description : Configures the 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;
tmpccer = TIMx->CCER;
/* Set or Reset the CC1P Bit */
tmpccer &= CCER_CC1P_Mask;
tmpccer |= TIM_OCPolarity;
TIMx->CCER = tmpccer;
}
/*******************************************************************************
* Function Name : TIM_OC2PolarityConfig
* Description : Configures the 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;
tmpccer = TIMx->CCER;
/* Set or Reset the CC2P Bit */
tmpccer &= CCER_CC2P_Mask;
tmpccer |= TIM_OCPolarity << 4;
TIMx->CCER = tmpccer;
}
/*******************************************************************************
* Function Name : TIM_OC3PolarityConfig
* Description : Configures the 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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -