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.

Where do I put code running in a continuous loop, outside main ISR in Lab13b

Other Parts Discussed in Thread: MOTORWARE

I want to put some non time-critical code in Motorware Lab13b, running in a forever loop outside of the main ISR in Lab13b. I thought the obvious place was in the for(;;) loop in the main() function, but everything in that loop only seems to run once.

I tried putting a breakpoint at the end of the main isr to see where it returned to, but all that does is return to an ITRAP0 instruction at location 0x3F9458.

Is there any code running outside of ISR's once the motor is running under position control, where I can put my code ?

Geoff

  • Hello Geoff,

     You can put your code under

    while(!(gMotorVars.Flag_enableSys));

    // put your code here

        or inside this loop (depend on your application)
    // loop while the enable system flag is true
    while(gMotorVars.Flag_enableSys)
    {

    // put your code here

    }

     

    Best regards,

    Maria

  • GEOFF JACKSON said:
    Is there any code running outside of ISR's once the motor is running under position control, where I can put my code ?

    If you mean that only when your motor runs you want to do something, then you can put your code while the control is in online state:

    else if(ctrlState == CTRL_State_OnLine)
                      {
    // put your code here

    }

     

     

    Best regards,

    Maria

  • Hi Maria,

    Thanks for the suggestions, but I don't think any of those loops are executing once the motor has been initialised and is running.

    I tried putting breakpoints in the code at the start of each of these loops with the motor running, and they are never triggered.

    I can't see anywhere in the for(;;) loop that's executing anything but one off tasks, and there doesn't seem to be any 'forever' loop executing while the motor is running, but maybe I'm missing something.

    Geoff

  • Hello Geoff,

    I am not sure about your breakpoints why they behave like that when the motor is running but I am sure about the forever loop because I have put my custom code inside the loop (SCI, SPI, etc) and the code works fine.

    Best regards,

    Maria

  • Hi Maria,

    I have found the cause of breakpoints not working in the forever loop but I don't know why it happens.

    The problem is caused by the optimization level chosen when building the project. I created a build with minimum optimization for debugging, because I've found that with opt. level 2, single-stepping through a program doesn't work very well. The cursor doesn't move as it should through the code but seems to jump around, including backwards sometimes. Selecting minimum optimization fixes this problem.

    Although the single-stepping problem is fixed with minimum optimization, another problem is created, that in some places, the forever loop being an example, breakpoints never trigger. As soon as I switch back to the opt. level 2 build, the breakpoints work, and as you said, additional code can be added within this loop that works with the motor running.

    I do remember seeing other odd behaviour in the past with program operation when minimum optimization was selected. I wonder if anyone has an explanation for this ?

    Regards,

    Geoff