初中生
最后登录1970-1-1
在线时间 小时
注册时间2020-11-15
|
- [code]
- //TIM1_单通道输出PWM信号
- #include"bsp_advance.h"
- static void ADVANCE_TIM_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- //输出通道GPIO_PA8
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- }
- static void ADVANCE_TIM_Mode_Config(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
- //配置时基结构体
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
-
- TIM_TimeBaseStructure.TIM_Period=899;
- TIM_TimeBaseStructure.TIM_Prescaler=0;
- TIM_TimeBaseStructure.TIM_ClockDivision=0;
- TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
- TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
-
- TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
-
- //配置输出比较结构体
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse =449;
- TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
-
- TIM_OC1Init(TIM1,&TIM_OCInitStructure);
-
- TIM_CtrlPWMOutputs(TIM1, ENABLE);
-
- TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
-
- TIM_ARRPreloadConfig(TIM1, ENABLE);
-
- TIM_Cmd(TIM1, ENABLE);
- }
-
- void ADVANCE_TIM_Init(void)
- {
- ADVANCE_TIM_GPIO_Config();
- ADVANCE_TIM_Mode_Config();
- }
复制代码
|
-
|