使用的是stm32f407的板子,用pwm驱动直流电机,板子的引脚高低电平有输出,PA4和PA5。。一个3.3V,一个0V。pwm波有输出。但经过电机驱动模块后的输出为0
电机驱动模块经测试可用,用f1的板子写的程序电机能转。。。
以下是我的程序:
pwm.c
void PWM_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource9,GPIO_AF_TIM3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(GPIOA,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period= 500 - 1;
TIM_TimeBaseStructure.TIM_Prescaler= 84-1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC4Init(TIM3, &TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_Cmd(TIM3, ENABLE);
}
pwm.h
#define D_IN1_H GPIO_SetBits(GPIOA,GPIO_Pin_4)
#define D_IN1_L GPIO_ResetBits(GPIOA,GPIO_Pin_4)
#define D_IN2_H GPIO_SetBits(GPIOA,GPIO_Pin_5)
#define D_IN2_L GPIO_ResetBits(GPIOA,GPIO_Pin_5)
void PWM_Configuration(void);
int main(void)
{
SystemInit();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
PWM_Configuration();
while(1)
{
delay_ms(10);
D_IN1_H ;
D_IN2_L ;
TIM->CC4=300;
//TIM_SetCompare4(TIM3, 300);
delay_ms(10);
}
}
不知道哪里出了问题。。哪位大佬来帮帮忙。。 |