Hello,
I'm planning to incorporate my own program into the code provided by instaSPIN labs. I want to change the main loop structure a bit for better integration and I need an advice to make sure it will not cause any unpredicted behavior.
Let's take a look at general code structure as in lab 6a:
void main(void)
{
<<INITIALIZE ALL MODULES>>
while(1)
{
// Waiting for enable system flag to be set
while(!(gMotorVars.Flag_enableSys));
// Dis-able the Library internal PI. Iq has no reference now
CTRL_setFlag_enableSpeedCtrl(ctrlHandle, false);
// loop while the enable system flag is true
while(gMotorVars.Flag_enableSys)
{
<<RUN INSTASPIN FUNCTIONS>>
}
// disable the PWM
HAL_disablePwm(halHandle);
// set the default controller parameters (Reset the control to re-identify the motor)
CTRL_setParams(ctrlHandle,&gUserParams);
gMotorVars.Flag_Run_Identify = false;
// setup the SpinTAC Components
ST_setupVelCtl(stHandle);
ST_setupVelMove(stHandle);
} // end of while(1) loop
} // end of main() function
The changes I'd like to do are:
1) Delete the very first "while(!(gMotorVars.Flag_enableSys));" that blocks the code from moving on after the Flag_enableSys is cleared - I guess it's there only to prevent the code from running idle through setup instructions at the bottom of the while(1) loop?
2) Move the "CTRL_setFlag_enableSpeedCtrl(ctrlHandle, false);" before the loop (to the initialization phase) - I'm planning to use Spin-TAC controller so don't need to re-enable this one
3) Change the "while(gMotorVars.Flag_enableSys)" loop to an "if" statement, and place everything outside the loop to an "else" part - it shouldn't make the difference (after doing point 1), unless there are some hidden 'break' statements?
Thank you for any help.
