高中生
最后登录1970-1-1
在线时间 小时
注册时间2014-4-19
|
- /* 初始化上层控制电机两个IO口 B0 B1 */
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE); //使能时钟
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 复用推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- /* 上层电机 B0 B1 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- /* 下层电机 C6 C7 */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- /* 初始化TIM模块 */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //使能TIM3时钟
-
- TIM_TimeBaseStructure.TIM_Prescaler=0;//预分频为0
- TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上计数
- TIM_TimeBaseStructure.TIM_Period=10285;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时钟分频系数为0
- TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //TIM3初始化
-
-
- TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//模式1
- TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//正向通道输出使能
- TIM_OCInitStructure.TIM_Pulse = 2400;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //正向通道输出极性
- TIM_OC1Init(TIM3, &TIM_OCInitStructure);//使能通道1
- TIM_OC2Init(TIM3, &TIM_OCInitStructure);//使能通道2
- TIM_OC3Init(TIM3, &TIM_OCInitStructure);//使能通道3
- TIM_OC4Init(TIM3, &TIM_OCInitStructure);//使能通道4
- TIM_Cmd(TIM3, ENABLE);
复制代码 通道1、2一直是低电平,3、4正常输出 请问是怎么回事TIM_SetCompare1(TIM3,6000);
TIM_SetCompare2(TIM3,0);
|
|