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.

TMS320F28069F: InstaSpin behaves differently When running from FLASH vs. Debugger

Part Number: TMS320F28069F


Hi Folks,
Designing an electric dental handpiece (drill).
There are essentially 2 modes - 1 for cavity prep, which is usually run at high speed, and doesn't require much torque;
the other is called Endo mode, which is used for endodontic procedures (mostly root canal).
I'm running into a problem with the Endo Mode.
There are 3 Endo features, all of them dependent on a parameter called Torque Limit, or Torque Threshold.
1. Auto Stop - which stops the motor when the Torque threshold is exceeded.
2. Auto Reverse - which backs the bur (how we refer to the drill bit) out of whatever it's in, again when the Torque Limit is breached.
3. Auto Reverse/Forward - which puts the motor in reverse for 3 seconds, when the Torque Limit is exceeded; then runs forward again.
The torque threshold goes from a minimum of 0.3 Ncm up to a max of 3.0 Ncm (Newton-Centimeters).
The speed can be set anywhere from 100 rpm to 40,000 rpm.
All three of these features work reasonably well when the debugger is hooked up, and I'm running the program from Code Composer.
When the program is run from FLASH, however, as a stand-alone device, it behaves quite differently.

When I select AUTO STOP:
When the debugger is running, the minimum speed that reacts to a 0.3 Ncm torque is 500 rpm. The motor won't stop in response to an applied
load, until the speed is 500 rpm or greater. In other words, the motor is not capable of exceeding the 0.3 Nm threshold, unless it's going
500 rpm, or faster. This is not ideal, but it's just a limitation of the motor. I can live with that.

When code is being executed from FLASH, and 0.3 Ncm is selected as the torque threshold, every speed reacts not only to an applied load,
but stops in response to just the load supplied by the handpiece itself. The thing just doesn't move, unless I change the torque
limit to 0.7 Ncm, or greater.

I can understand some differences in how the system reacts when run from the Debugger vs. stand-alone, but this is kind of extreme.
I feel like I must be doing something wrong, or the A to D is providing quite different values, depending only on whether the code
is being deployed in debug or from FLASH.

There is another anomaly in addition the one described above.
We can't have the drill running backward on start-up, when it's told to go forward (and vice-versa). Didn't want to go through the
rigamarole of implementing high frequency injection (I don't think I understand it anyway).
So, we opted for a controlled stop, so that the motor always ends up at or near the zero position. That way, the controls know where it is
on start-up, and it can zip right up to speed, going in the proper direction.
This works really well when the debugger is hooked up and running the show. When I power the system up as a stand-alone device, I get that
back and forth dance when the motor starts up.

Can you help me?
Thanks,
Dave

  • To generalize - what I'm asking is how could the FLASH version of code differ programmatically from the Debug version? They are identical textually; how come they're different behaviorally? The alternative is that they are receiving different data from the A to D, which also does not make sense (and also probably does not apply to the 2nd anomaly presented above (going the wrong direction at start-up)).

  • Hi Dave,

    It's not so uncommon to see different programmatic behavior when JTAG is removed from the debug simpulator, executes code much slower than in real time CPU speed. What you are describing sounds like one or several subroutines are executing a bit too fast or perhaps an ISR has higher priority over others. That you will have to determine via optimizations using #pragma statements to control functions you may suspect as being problematic. The C2000 compiler can actually be told to change the speed of one or more functions via #pragma statements added just above suspect functions. To rapidly zoom in on issues try reducing project optimization levels & speeds.

    0247.TI-C2000 Optimizing C,C++ Compilers spru514y.pdf

  • Hi Genatco,

    Thanks for the advice. Makes sense that execution speed is different when the debugger is out of the picture.

    I tried fiddling with the Optimization levels in a general way from Project Properties by varying the optimization level and the speed vs. size tradeoffs. This had no discernible effect.

    How does one go about changing the speed of a subroutine using #pragma statements?

    Thanks,

    Dave

  • Hi Dave,

    The syntax is located in the compiler guide PDF posted above. Simply add the statement above suspect function/s then clean/compile the project. The same guide might also be included in the documents folder under the compiler version. BTW is your project compiled as eabi or legacy Coff can also have some unintended aspects, there are different set of compiler linker switches for each method.

  • Hi Genatco,

    I'm using the Coff abi.

    Any #pragma statement? Or is there a particular one that is used for slowing down a function? If there is, it's not obvious in the '...Optimizing C...' document you sent me.

    Thanks,

    Dave

  • Hi Dave,

    It's inside FUNCTION_OPTIONS (See Section 6.9.14)

    #pragma FUNCTION_OPTIONS (MyFunctionName, "--opt_level=1 --opt_for_speed=2")

  • Ahhh - I see it now.

    Thanks Genatco!

  • Turns out it was something else entirely. Two different algorithms were fighting over Flag_Run_Identify. The scheme for stooping the motor and holding it at a "home" position needs Flag_Run_Identify always enabled. but another function for stopping the motor after the foot-pedal is released was setting it to false. Not sure why this resulted in different behavior for standalone vs. debug, but hey, at least it's fixed. Thanks for your help.

    Dave