📄 stm32f10x_tim.c
字号:
* 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(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(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(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(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(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(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
* Return : None
*******************************************************************************/
void TIM_SelectHallSensor(TIM_TypeDef* TIMx, FunctionalState Newstate)
{
/* Check the parameters */
assert(IS_FUNCTIONAL_STATE(Newstate));
if (Newstate != DISABLE)
{
/* Set the TI1S Bit */
TIMx->CR2 |= CR2_TI1S_Set;
}
else
{
/* Reset the TI1S Bit */
TIMx->CR2 &= CR2_TI1S_Reset;
}
}
/*******************************************************************************
* Function Name : TIM_SelectOnePulseMode
* Description : Selects the TIMx抯 One Pulse Mode.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_OPMode: specifies the OPM Mode to be used.
* This parameter can be one of the following values:
* - TIM_OPMode_Single
* - TIM_OPMode_Repetitive
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectOnePulseMode(TIM_TypeDef* TIMx, u16 TIM_OPMode)
{
u32 tmpcr1 = 0;
/* Check the parameters */
assert(IS_TIM_OPM_MODE(TIM_OPMode));
tmpcr1 = TIMx->CR1;
/* Reset the OPM Bit */
tmpcr1 &= CR1_OPM_Mask;
/* Configure the OPM Mode */
tmpcr1 |= TIM_OPMode;
TIMx->CR1 = (u16)tmpcr1;
}
/*******************************************************************************
* Function Name : TIM_SelectOutputTrigger
* Description : Selects the TIMx Trigger Output Mode.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_TRGOSource: specifies the Trigger Output source.
* This paramter can be one of the following values:
* - TIM_TRGOSource_Reset
* - TIM_TRGOSource_Enable
* - TIM_TRGOSource_Update
* - TIM_TRGOSource_OC1
* - TIM_TRGOSource_OC1Ref
* - TIM_TRGOSource_OC2Ref
* - TIM_TRGOSource_OC3Ref
* - TIM_TRGOSource_OC4Ref
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, u16 TIM_TRGOSource)
{
u32 tmpcr2 = 0;
/* Check the parameters */
assert(IS_TIM_TRGO_SOURCE(TIM_TRGOSource));
tmpcr2 = TIMx->CR2;
/* Reset the MMS Bits */
tmpcr2 &= CR2_MMS_Mask;
/* Select the TRGO source */
tmpcr2 |= TIM_TRGOSource;
TIMx->CR2 = (u16)tmpcr2;
}
/*******************************************************************************
* Function Name : TIM_SelectSlaveMode
* Description : Selects the TIMx Slave Mode.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_SlaveMode: specifies the Timer Slave Mode.
* This paramter can be one of the following values:
* - TIM_SlaveMode_Reset
* - TIM_SlaveMode_Gated
* - TIM_SlaveMode_Trigger
* - TIM_SlaveMode_External1
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, u16 TIM_SlaveMode)
{
u32 tmpsmcr = 0;
/* Check the parameters */
assert(IS_TIM_SLAVE_MODE(TIM_SlaveMode));
tmpsmcr = TIMx->SMCR;
/* Reset the SMS Bits */
tmpsmcr &= SMCR_SMS_Mask;
/* Select the Slave Mode */
tmpsmcr |= TIM_SlaveMode;
TIMx->SMCR = (u16)tmpsmcr;
}
/*******************************************************************************
* Function Name : TIM_SelectMasterSlaveMode
* Description : Sets or Resets the TIMx Master/Slave Mode.
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.
* This paramter can be one of the following values:
* - TIM_MasterSlaveMode_Enable: synchronization between the
* current timer and its slaves (through TRGO).
* - TIM_MasterSlaveMode_Disable: No action
* Output : None
* Return : None
*******************************************************************************/
void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, u16 TIM_MasterSlaveMode)
{
u32 tmpsmcr = 0;
/* Check the parameters */
assert(IS_TIM_MSM_STATE(TIM_MasterSlaveMode));
tmpsmcr = TIMx->SMCR;
/* Set or Reset the MSM Bit */
tmpsmcr &= SMCR_MSM_Mask;
tmpsmcr |= TIM_MasterSlaveMode;
TIMx->SMCR = (u16)tmpsmcr;
}
/*******************************************************************************
* Function Name : TIM_SetAutoreload
* Description : Sets the TIMx Autoreload Register value
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - Autoreload: specifies the Autoreload register new value.
* Output : None
* Return : None
*******************************************************************************/
void TIM_SetAutoreload(TIM_TypeDef* TIMx, u16 Autoreload)
{
/* Set the Autoreload Register value */
TIMx->ARR = Autoreload;
}
/*******************************************************************************
* Function Name : TIM_SetCompare1
* Description : Sets the TIMx Capture Compare1 Register value
* Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
* - Compare1: specifies the Capture Compare1 register new value.
* Output : None
* Return : None
*******************************************************************************/
void TIM_SetCompare1(TIM_TypeDef* T
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -