中级会员
- 积分
- 240
- 金钱
- 240
- 注册时间
- 2018-4-21
- 在线时间
- 105 小时
|
1金钱
本帖最后由 c627933142 于 2018-5-7 18:47 编辑
先是PWM程序
void PWM(int16_t duty1,int16_t duty2,int16_t duty3,int16_t duty4)
{
TIM_SetCompare1(TIM1,duty1);
TIM_SetCompare2(TIM1,duty2);
TIM_SetCompare3(TIM1,duty3);
TIM_SetCompare4(TIM1,duty4);
}
void motor_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=1999;
TIM_TimeBaseStructure.TIM_Prescaler=516;
TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);
TIM_Cmd(TIM1,ENABLE);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OC1Init(TIM1,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC4Init(TIM1,&TIM_OCInitStructure);
TIM_OC4PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM1,ENABLE);
}
然后是主函数
int main(void)
{
delay_init(72);
motor_init();
PWM(1999,1999,1999,1999);
delay_ms(1000);
PWM(0,0,0,0);
delay_ms(1800);
while(1)
{
PWM(999,999,999,999);
}
}用示波器看根本没有波出来 单片机用的是stm32f407 电调是新西达30A 初始化从没成功过 哪位大神能帮忙纠正一下 或者提供个能用的初始化程序
|
最佳答案
查看完整内容[请看2#楼]
复制别人的程序改的时候看仔细点啊。。。你时钟使能的是GPIOA,初始化的时候又初始化GPIOB 有输出就怪了
|