📄 stm32f10x_tim.c
字号:
* It can be one of the following values:
* - TIM_ExtTRGPolarity_Inverted
* - TIM_ExtTRGPolarity_NonInverted
* - ExtTRGFilter: External Trigger Filter.
* This parameter must be a value between 0x00 and 0x0F
* Output : None
* Return : None
*******************************************************************************/
void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler,
u16 TIM_ExtTRGPolarity, u16 ExtTRGFilter)
{
/* Configure the ETR Clock source */
ETR_Config(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
/* Enable the External clock mode2 */
TIMx->SMCR |= SMCR_ECE_Set;
}
/*******************************************************************************
* Function Name : TIM_SelectInputTrigger
* Description : Select the Input Trigger source
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpsmcr = 0;
tmpsmcr = TIMx->SMCR;
/* Select the Tgigger Source */
tmpsmcr &= SMCR_TS_Mask;
tmpsmcr |= TIM_InputTriggerSource;
TIMx->SMCR = tmpsmcr;
}
/*******************************************************************************
* Function Name : TIM_PrescalerConfig
* Description : Configures the TIM Prescaler.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - Prescaler: specifies the Prescaler Register value
* - TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
* This parameter can be one of the following values:
* - TIM_PSCReloadMode_Update: The Prescaler is loaded at
* the update event.
* - TIM_PSCReloadMode_Immediate: The Prescaler is loaded
* immediatly.
* Output : None
* Return : None
*******************************************************************************/
void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode)
{
/* Set the Prescaler value */
TIMx->PSC = Prescaler;
/* Set or reset the UG Bit */
if (TIM_PSCReloadMode == TIM_PSCReloadMode_Immediate)
{
TIMx->EGR |= TIM_EventSource_Update;
}
else
{
TIMx->EGR &= TIM_EventSource_Update;
}
}
/*******************************************************************************
* Function Name : TIM_CounterModeConfig
* Description : Specifies the Counter Mode to be used.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_CounterMode: specifies the Counter Mode to be used
* This parameter can be one of the following values:
* - TIM_CounterMode_Up: TIM Up Counting Mode
* - TIM_CounterMode_Down: TIM Down Counting Mode
* - TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
* - TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
* - TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
* Output : None
* Return : None
*******************************************************************************/
void TIM_CounterModeConfig(TIM_TypeDef* TIMx, u16 TIM_CounterMode)
{
u32 tmpcr1 = 0;
tmpcr1 = TIMx->CR1;
/* Reset the CMS and DIR Bits */
tmpcr1 &= CR1_CounterMode_Mask;
/* Set the Counter Mode */
tmpcr1 |= TIM_CounterMode;
TIMx->CR1 = tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC1Config
* Description : Forces the TIM output waveform to active or inactive level.
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpccmr1 = 0;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCM Bits */
tmpccmr1 &= CCMR_OCM13_Mask;
/* Configure The Forced output Mode */
tmpccmr1 |= TIM_ForcedAction;
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC2Config
* Description : Forces the TIM output waveform to active or inactive level.
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpccmr1 = 0;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCM Bits */
tmpccmr1 &= CCMR_OCM24_Mask;
/* Configure The Forced output Mode */
tmpccmr1 |= TIM_ForcedAction << 8;
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC3Config
* Description : Forces the TIM output waveform to active or inactive level.
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpccmr2 = 0;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCM Bits */
tmpccmr2 &= CCMR_OCM13_Mask;
/* Configure The Forced output Mode */
tmpccmr2 |= TIM_ForcedAction;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_ForcedOC4Config
* Description : Forces the TIM output waveform to active or inactive level.
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpccmr2 = 0;
tmpccmr2 = TIMx->CCMR2;
/* Reset the OCM Bits */
tmpccmr2 &= CCMR_OCM24_Mask;
/* Configure The Forced output Mode */
tmpccmr2 |= TIM_ForcedAction << 8;
TIMx->CCMR2 = tmpccmr2;
}
/*******************************************************************************
* Function Name : TIM_ARRPreloadConfig
* Description : Enables or disables TIM peripheral Preload register on ARR.
* 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_ARRPreloadConfig(TIM_TypeDef* TIMx, FunctionalState Newstate)
{
u32 tmpcr1 = 0;
tmpcr1 = TIMx->CR1;
if (Newstate != DISABLE)
{
/* Set the ARR Preload Bit */
tmpcr1 |= CR1_ARPE_Set;
}
else
{
/* Reset the ARR Preload Bit */
tmpcr1 &= CR1_ARPE_Reset;
}
TIMx->CR1 = tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_SelectCCDMA
* Description : Selects the TIM peripheral Capture Compare DMA source.
* Input : - TIMx: where x can be 2, 3 or 4 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)
{
u32 tmpcr2 = 0;
tmpcr2 = TIMx->CR2;
if (Newstate != DISABLE)
{
/* Set the CCDS Bit */
tmpcr2 |= CR2_CCDS_Set;
}
else
{
/* Reset the CCDS Bit */
tmpcr2 &= CR2_CCDS_Reset;
}
TIMx->CR2 = tmpcr2;
}
/*******************************************************************************
* Function Name : TIM_OC1PreloadConfig
* Description : Enables or disables TIM 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;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCPE Bit */
tmpccmr1 &= CCMR_OC13PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr1 |= TIM_OCPreload;
TIMx->CCMR1 = tmpccmr1;
}
/*******************************************************************************
* Function Name : TIM_OC2PreloadConfig
* Description : Enables or disables TIM 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;
tmpccmr1 = TIMx->CCMR1;
/* Reset the OCPE Bit */
tmpccmr1 &= CCMR_OC24PE_Mask;
/* Enable or Disable the Output Compare Preload feature */
tmpccmr1 |= TIM_OCPreload << 8;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -