i dont know why once i add the GPIO_setHigh(gpioHandle, GPIO_Number_1); and GPIO_setLow(gpioHandle, GPIO_Number_1);, my motor could not run smoothly, current increased. I want LED 4 to light up when speed is positive and off when speed is negative.
int Count_Pulse ( HAL_Handle handle)
{
static int CurrentState = 0;
int x;
x = HAL_GPIO_getData(handle);
if(x != CurrentState)
{
if(x==1)
{
if ( gMotorVars.SpeedRef_krpm ==_IQ(0.09999996462))
{
GPIO_setLow(gpioHandle, GPIO_Number_1);
gcount1++;
CurrentState=x;
gcount=gcount1;
}
else if ( gMotorVars.SpeedRef_krpm ==_IQ(-0.09999996462))
{
GPIO_setHigh(gpioHandle, GPIO_Number_1);
gcount1--;
CurrentState=x;
gcount=gcount1;
}
}
else
{
gcount2++;
CurrentState=x;
}
}
return gcount;
}
void Shaft_Position ( HAL_Handle handle)
{
if( gcount>=163) {
gMotorVars.SpeedRef_krpm =_IQ(-0.09999996462); //reverse direction
}
else if( gcount <=30) {
gMotorVars.SpeedRef_krpm =_IQ(0.09999996462);
}
}