/** * @brief Initializes the TIMx Channel1 according to the specified * parameters in the TIM_OCInitStruct. * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral. * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure * that contains the configuration information for the specified TIM peripheral. * @retval None */ voidTIM_OC1Init(TIM_TypeDef* TIMx, TIM_OCInitTypeDef* TIM_OCInitStruct)
参数1、TIMx
参数2、TIM_OCInitTypeDef结构体
结构体内容
/** * @brief TIM Output Compare Init structure definition */
typedefstruct { uint16_t TIM_OCMode; /*!< Specifies the TIM mode. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
uint16_t TIM_OutputState; /*!< Specifies the TIM Output Compare state. This parameter can be a value of @ref TIM_Output_Compare_state */
uint16_t TIM_OutputNState; /*!< Specifies the TIM complementary Output Compare state. This parameter can be a value of @ref TIM_Output_Compare_N_state @note This parameter is valid only for TIM1 and TIM8. */
uint16_t TIM_Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. This parameter can be a number between 0x0000 and 0xFFFF */
uint16_t TIM_OCPolarity; /*!< Specifies the output polarity. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
uint16_t TIM_OCNPolarity; /*!< Specifies the complementary output polarity. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity @note This parameter is valid only for TIM1 and TIM8. */
uint16_t TIM_OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state. This parameter can be a value of @ref TIM_Output_Compare_Idle_State @note This parameter is valid only for TIM1 and TIM8. */
uint16_t TIM_OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State @note This parameter is valid only for TIM1 and TIM8. */ } TIM_OCInitTypeDef;
uint16_t TIM_Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. This parameter can be a number between 0x0000 and 0xFFFF */
/** * @brief Sets the TIMx Capture Compare1 Register value * @param TIMx: where x can be 1 to 17 except 6 and 7 to select the TIM peripheral. * @param Compare1: specifies the Capture Compare1 register new value. * @retval None */ voidTIM_SetCompare1(TIM_TypeDef* TIMx, uint16_t Compare1)
参数1、TIMx
参数2、CRR值
例如
TIM_SetCompare1(TIM2, 100);//修改通道1的CCR值
如何修改频率
/** * @brief Configures the TIMx Prescaler. * @param TIMx: where x can be 1 to 17 to select the TIM peripheral. * @param Prescaler: specifies the Prescaler Register value * @param TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode * This parameter can be one of the following values: * @arg TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event. * @arg TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediately. * @retval None */ voidTIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode)
/** * @brief Changes the mapping of the specified pin. * @param GPIO_Remap: selects the pin to remap. * This parameter can be one of the following values: * @arg GPIO_Remap_SPI1 : SPI1 Alternate Function mapping * @arg GPIO_Remap_I2C1 : I2C1 Alternate Function mapping * @arg GPIO_Remap_USART1 : USART1 Alternate Function mapping * @arg GPIO_Remap_USART2 : USART2 Alternate Function mapping * @arg GPIO_PartialRemap_USART3 : USART3 Partial Alternate Function mapping * @arg GPIO_FullRemap_USART3 : USART3 Full Alternate Function mapping * @arg GPIO_PartialRemap_TIM1 : TIM1 Partial Alternate Function mapping * @arg GPIO_FullRemap_TIM1 : TIM1 Full Alternate Function mapping * @arg GPIO_PartialRemap1_TIM2 : TIM2 Partial1 Alternate Function mapping * @arg GPIO_PartialRemap2_TIM2 : TIM2 Partial2 Alternate Function mapping * @arg GPIO_FullRemap_TIM2 : TIM2 Full Alternate Function mapping * @arg GPIO_PartialRemap_TIM3 : TIM3 Partial Alternate Function mapping * @arg GPIO_FullRemap_TIM3 : TIM3 Full Alternate Function mapping * @arg GPIO_Remap_TIM4 : TIM4 Alternate Function mapping * @arg GPIO_Remap1_CAN1 : CAN1 Alternate Function mapping * @arg GPIO_Remap2_CAN1 : CAN1 Alternate Function mapping * @arg GPIO_Remap_PD01 : PD01 Alternate Function mapping * @arg GPIO_Remap_TIM5CH4_LSI : LSI connected to TIM5 Channel4 input capture for calibration * @arg GPIO_Remap_ADC1_ETRGINJ : ADC1 External Trigger Injected Conversion remapping * @arg GPIO_Remap_ADC1_ETRGREG : ADC1 External Trigger Regular Conversion remapping * @arg GPIO_Remap_ADC2_ETRGINJ : ADC2 External Trigger Injected Conversion remapping * @arg GPIO_Remap_ADC2_ETRGREG : ADC2 External Trigger Regular Conversion remapping * @arg GPIO_Remap_ETH : Ethernet remapping (only for Connectivity line devices) * @arg GPIO_Remap_CAN2 : CAN2 remapping (only for Connectivity line devices) * @arg GPIO_Remap_SWJ_NoJTRST : Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST * @arg GPIO_Remap_SWJ_JTAGDisable : JTAG-DP Disabled and SW-DP Enabled * @arg GPIO_Remap_SWJ_Disable : Full SWJ Disabled (JTAG-DP + SW-DP) * @arg GPIO_Remap_SPI3 : SPI3/I2S3 Alternate Function mapping (only for Connectivity line devices) * When the SPI3/I2S3 is remapped using this function, the SWJ is configured * to Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST. * @arg GPIO_Remap_TIM2ITR1_PTP_SOF : Ethernet PTP output or USB OTG SOF (Start of Frame) connected * to TIM2 Internal Trigger 1 for calibration (only for Connectivity line devices) * If the GPIO_Remap_TIM2ITR1_PTP_SOF is enabled the TIM2 ITR1 is connected to * Ethernet PTP output. When Reset TIM2 ITR1 is connected to USB OTG SOF output. * @arg GPIO_Remap_PTP_PPS : Ethernet MAC PPS_PTS output on PB05 (only for Connectivity line devices) * @arg GPIO_Remap_TIM15 : TIM15 Alternate Function mapping (only for Value line devices) * @arg GPIO_Remap_TIM16 : TIM16 Alternate Function mapping (only for Value line devices) * @arg GPIO_Remap_TIM17 : TIM17 Alternate Function mapping (only for Value line devices) * @arg GPIO_Remap_CEC : CEC Alternate Function mapping (only for Value line devices) * @arg GPIO_Remap_TIM1_DMA : TIM1 DMA requests mapping (only for Value line devices) * @arg GPIO_Remap_TIM9 : TIM9 Alternate Function mapping (only for XL-density devices) * @arg GPIO_Remap_TIM10 : TIM10 Alternate Function mapping (only for XL-density devices) * @arg GPIO_Remap_TIM11 : TIM11 Alternate Function mapping (only for XL-density devices) * @arg GPIO_Remap_TIM13 : TIM13 Alternate Function mapping (only for High density Value line and XL-density devices) * @arg GPIO_Remap_TIM14 : TIM14 Alternate Function mapping (only for High density Value line and XL-density devices) * @arg GPIO_Remap_FSMC_NADV : FSMC_NADV Alternate Function mapping (only for High density Value line and XL-density devices) * @arg GPIO_Remap_TIM67_DAC_DMA : TIM6/TIM7 and DAC DMA requests remapping (only for High density Value line devices) * @arg GPIO_Remap_TIM12 : TIM12 Alternate Function mapping (only for High density Value line devices) * @arg GPIO_Remap_MISC : Miscellaneous Remap (DMA2 Channel5 Position and DAC Trigger remapping, * only for High density Value line devices) * @param NewState: new state of the port pin remapping. * This parameter can be: ENABLE or DISABLE. * @retval None */ voidGPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)