Thanks for taking a look at my code. Below is code for a motor controller. Everything looks just fine to me. It works for one cycle, and then will NOT return to the neutral state and I have no idea why. Anyone see something I am missing?
flash_param[] array is previously entered data from usb by user. This works great and the values entered are correctly stored in flash. When starting the program, only M1_Forward_onFlag is set, so the program always starts with this. Next neutral will always come, then reverse. Next I am SUPPOSED to go back to neutral but I do not make it back to neutral.
Thanks much.
(in case you are wondering, all counters increment every 100ms)
Code:
void motor1_stateControl(void)
{
if(M1_Forward_onFlag == SET)
{
M1_Forward_Counter++;
GPIO_SetBits(GPIOG, GPIO_Pin_2);
if(M1_Forward_Counter >= flash_param[2])
{
M1_Forward_Counter = 0;
M1_Forward_onFlag = RESET;
Neutral_Flag = SET;
Back_or_ForwardNext = BACKWARD;
}
}
if(Neutral_Flag == SET)
{
GPIO_ResetBits(GPIOG, GPIO_Pin_2);
GPIO_ResetBits(GPIOG, GPIO_Pin_3);
M1_Neutral_Counter++;
if(M1_Neutral_Counter >= flash_param[7])
{
M1_Neutral_Counter = 0;
Neutral_Flag = RESET;
if(Back_or_ForwardNext == FORWARD)
M1_Forward_onFlag = SET;
if(Back_or_ForwardNext == BACKWARD)
M1_Backward_onFlag = SET;
}
}
if(M1_Backward_onFlag == SET)
{
M1_Backward_Counter++;
GPIO_SetBits(GPIOG, GPIO_Pin_3);
if(M1_Backward_Counter >= flash_param[3])
{
M1_Forward_Counter = 0;
M1_Forward_onFlag = RESET;
Neutral_Flag = SET;
Back_or_ForwardNext = FORWARD;
}
}
return;
}