大学生
最后登录1970-1-1
在线时间 小时
注册时间2020-10-5
|
发表于 2020-11-12 21:04:31
|
显示全部楼层
你好,可以请教一下大佬吗,为什么我用的和他的一样的硬件,而我输出的PWM波智能通过TB6612FNG控制一个轮转动呢。软件仿真显示是有两路PWM输出的。- /*INT1~INT4和PWMA,PWMB GPIO初始化*/
- void Motor_Direction_GPIO_Config(void )
- {
- /*INT1~INT4*/
- GPIO_InitTypeDef GPIO_InitStruct;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
-
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; //端口配置
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //50MHZ
- GPIO_Init(GPIOB, &GPIO_InitStruct); //根据设定参数初始化GPIOB
- /*PWMA,PWMB*/
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Pin =GPIO_Pin_11| GPIO_Pin_8;
- GPIO_Init(GPIOA,&GPIO_InitStruct);
-
- }
复制代码
- void Motor_Forward(void)
- {
- /*IN1->GPIO_Pin_12
- IN2->GPIO_Pin_13
- IN3->GPIO_Pin_14
- IN4->GPIO_Pin_15*/
- /*右轮正转,超声波方向*/
- GPIO_SetBits(GPIOB,GPIO_Pin_12);//1
- GPIO_ResetBits(GPIOB,GPIO_Pin_13);//0
- /*B轮*/
- GPIO_SetBits(GPIOB,GPIO_Pin_14);//1
- GPIO_ResetBits(GPIOB,GPIO_Pin_15);//0
- }
复制代码
- void Motor_Pwm_Tim(void)
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
- TIM_OCInitTypeDef TIM_OCInitStruct;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);/*开启TIM1时钟*/
-
- /*定时器基本配置*/
- TIM_TimeBaseInitStruct.TIM_ClockDivision = 0;/*时钟分频*/
- TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;/*向上计数*/
- TIM_TimeBaseInitStruct.TIM_Period = 1000;//计数器周期arr
- TIM_TimeBaseInitStruct.TIM_Prescaler = 7200-1;//分频系数psc
- TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStruct);
-
- /*输出比较寄存器配置*/
- TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;//输出模式
- TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;//比较输出极性
- TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;//比较输出使能
- TIM_OCInitStruct.TIM_Pulse = 1000;//脉冲宽度
-
- //使能通道1和通道4
- TIM_OC1Init(TIM1,&TIM_OCInitStruct);
- TIM_OC4Init(TIM1,&TIM_OCInitStruct);
-
- TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
- TIM_OC4PreloadConfig(TIM1,TIM_OCPreload_Enable);
-
- /*使能TIM1在ARR上的预装载值*/
- TIM_ARRPreloadConfig(TIM1,ENABLE);
-
- TIM_CtrlPWMOutputs(TIM1,ENABLE);
- /*使能定时器1*/
- TIM_Cmd(TIM1,ENABLE);
- }
复制代码 |
|