电机一直控制不了,想确认两件事:
1.这电机有三根线,分别是 红、黑、黄,是不是分别对应着12v+,12v-,和pwm信号线
2.我的控制代码如下,pwm波用示波器查看是正确的
int main()
{
led_init();
delay_init();
/* pwm初始化,50Hz */
pwm_init();
/* 1.5ms */
TIM_SetCompare1(TIM3, 1500);
TIM_SetCompare2(TIM3, 1500);
TIM_SetCompare3(TIM3, 1500);
TIM_SetCompare4(TIM3, 1500);
delay_ms(1000);
delay_ms(1000);
/* 2ms */
TIM_SetCompare1(TIM3, 2000);
TIM_SetCompare2(TIM3, 2000);
TIM_SetCompare3(TIM3, 2000);
TIM_SetCompare4(TIM3, 2000);
delay_ms(1000);
/* 1.5ms */
TIM_SetCompare1(TIM3, 1500);
TIM_SetCompare2(TIM3, 1500);
TIM_SetCompare3(TIM3, 1500);
TIM_SetCompare4(TIM3, 1500);
while (1)
{
TIM_SetCompare1(TIM3, 1200);
TIM_SetCompare2(TIM3, 1200);
TIM_SetCompare3(TIM3, 1200);
TIM_SetCompare4(TIM3, 1200);
delay_ms(1000);
delay_ms(1000);
TIM_SetCompare1(TIM3, 1800);
TIM_SetCompare2(TIM3, 1800);
TIM_SetCompare3(TIM3, 1800);
TIM_SetCompare4(TIM3, 1800);
delay_ms(1000);
delay_ms(1000);
}
}