中级会员
- 积分
- 240
- 金钱
- 240
- 注册时间
- 2018-4-21
- 在线时间
- 105 小时
|
1金钱
现在用的TM4的芯片 PWM正常 电调是一直在用的好盈30A 油门航程和初始化都在我stm32的芯片上做过的
但在TM4上电调初始化如果加上给油门程序的话就会嘀嘀嘀响 不加初始化也会嘀嘀嘀 但是先烧初始化程序再烧给油门程序电机才转 程序放在一起烧的话就嘀嘀嘀响了
在以前32的芯片上不这样了 现在要求在TM4板子上弄就不行了
放一段TM4的代码
void motor_init(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5);
GPIOPinConfigure(GPIO_PB6_M0PWM0);
GPIOPinConfigure(GPIO_PB7_M0PWM1);
GPIOPinConfigure(GPIO_PB4_M0PWM2);
GPIOPinConfigure(GPIO_PB5_M0PWM3);
PWMGenConfigure(PWM0_BASE,PWM_GEN_1,PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);
PWMGenConfigure(PWM0_BASE,PWM_GEN_0,PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 2500);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 2500);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 0);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 0);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 0);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 0);
PWMOutputState(PWM0_BASE, (PWM_OUT_0_BIT |PWM_OUT_1_BIT), true);
PWMOutputState(PWM0_BASE, (PWM_OUT_2_BIT |PWM_OUT_3_BIT), true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
PWMGenEnable(PWM0_BASE, PWM_GEN_1);
motor_out(1000,1000,1000,1000);
SysCtlDelay(10*SysCtlClockGet()/3);
}
void motor_out(uint32_t motor1, uint32_t motor2, uint32_t motor3, uint32_t motor4)
{
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,motor1);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,motor2);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,motor3);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,motor4);
}
int main()
{
motor_init();
while(1)
{
motor_out(1500,1500,1500,1500);
}
}
|
|