This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DRV8301-69M-KIT: Restructuring a loop from InstaSPIN labs - advice needed



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.

  • Dear Jakub Klein,

    Based on your questions and my developed projects with InstaSPIN, I share my ideas to response your questions as following:

    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?

    Answer: Yes, you can do this. Or you can use this flag to run background task if it is enabled, for example:

        // Run background task if the enable system flag is true
        if(gMotorVars.Flag_enableSys)
        {
          <<RUN BACKGROUND TASKS>>
        }

    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.

    Answer: Yes, you can. If you don't want to use PI Speed Controller and replace it by Spin-TAC controllers, you need to disable this flag at the initialization stage.

    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?

    Answer: I did this such as above suggestion. You can verify by seeing the screen shot below:

    Best regards,