想用三个按键执行电机的正反转,程序如下:
void key_control(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
//CTRL_setSpd_ref_krpm(ctrlHandle,_IQ(0.8));
gMotorVars.SpeedRef_krpm=_IQ24(1.8);
CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
{
HAL_Obj *obj = (HAL_Obj *)handle;
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
//CTRL_setSpd_ref_krpm(ctrlHandle,_IQ(0.8));
gMotorVars.SpeedRef_krpm=_IQ24(1.8);
CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
for(;;)
{
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
for(;;)
{
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(1.8)); // set the speed reference
usDelay(500);
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
usDelay(5);
}
}
}
}
usDelay(500);
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
usDelay(5);
}
}
}
}
为什么按键始终没有反应?
比较急,麻烦各位帮帮忙!
Susan Yang:请问您是否有进行在线调试?在按键的中断服务程序内打断点,按下按键的话是否可以正常进入中断?
另外您现在使用的是什么芯片呢?
想用三个按键执行电机的正反转,程序如下:
void key_control(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
//CTRL_setSpd_ref_krpm(ctrlHandle,_IQ(0.8));
gMotorVars.SpeedRef_krpm=_IQ24(1.8);
CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
{
HAL_Obj *obj = (HAL_Obj *)handle;
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_12)==LOW)
{
//CTRL_setSpd_ref_krpm(ctrlHandle,_IQ(0.8));
gMotorVars.SpeedRef_krpm=_IQ24(1.8);
CTRL_setSpd_ref_krpm(ctrlHandle,gMotorVars.SpeedRef_krpm);
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_13)==LOW)
{
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
}
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
for(;;)
{
}
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
usDelay(500);
if(GPIO_read(obj->gpioHandle,GPIO_Number_22)==LOW)
{
for(;;)
{
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(1.8)); // set the speed reference
usDelay(500);
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
usDelay(5);
}
}
}
}
usDelay(500);
CTRL_setSpd_ref_krpm(ctrlHandle,_IQ24(-1.8));
usDelay(5);
}
}
}
}
为什么按键始终没有反应?
比较急,麻烦各位帮帮忙!
user6024771:
回复 Susan Yang:
在CCS的监视窗口输入转速,可以实现电机的转动。
在按键的中断服务程序内打断点,按下按键的话是否可以正常进入中断?
因为我是程序小白,所以断点调试还是不太会。如果断点调试时,按下按键无法进入中断,什么原因呢?
芯片是28069mlab11e
还想问个问题,就是运行lab11e时,加载lab11e.js监视窗口的基准速度是给定的,我们要在程序的哪里把他设置成0(因为打开电源,希望电机的转速为0,通过后续再给不同的速度)