2. 库函数配置
1) ①PWM输出库函数
void TIM_OCxInit(TIM_TypeDef* TIM_OCInitTypeDef* TIM_OCInitStruct);
typedef struct
{
uint16_t TIM_OCMode;//PWM模式1或者模式2
uint16_t TIM_OutputState;//比较输出使能
uint16_t TIM_Pulse;// 设置CCRx的值
uint16_t TIM_OCPolarity;//比较输出极性
}TIM_OCInitTypeDef;
TIM_OCInitStructure. TIM_OCMode=TIM_OCMode_PWM2; //PWM2模式
TIM_OCInitStructure. TIM_OutputState=TIM_OutputState_Enable;//比较输出使能
TIM_OCInitStructure. TIM_Pulse=100;
TIM_OCInitStructure. TIM_OCPolarity;=OCPolarity_High;//输出极性,TIM输出比较极性高
TIM_OC2Init(TIM3,&TIM_OCInitStructure);//根据指定参数初始化外设TIM3 OC2
|