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.
I've been trying to add a few test lines of C code to an existing project in CCSv6 without success. Here's a snippet of the code
_iq20 MotorPosn;
_iq20 MotorPosn2;
I am unable to reproduce those diagnostics. Please submit a test case, preprocessed like this, along with the compiler version and the exact build options you use.
Thanks and regards,
-George
George,
Thanks for the offer of looking at the code. I thought I'd check a few other things with you before that, just to make sure I'm not doing anything fundamentally wrong.
My first question is, does the active project in the Project Explorer window (or anywhere else for that matter) have to be specifically set up for debug ? At the moment it's set to "Active - Release" in the Project Explorer.
If this doesn't matter then I've still got problems, different to the one I indicated before.
Below is the code where the problems lie, and this is a function called by the main ISR in a modded version of the motorware Lab13b :-
static inline void HAL_readAdcData(HAL_Handle handle,HAL_AdcData_t *pAdcData)
{
HAL_Obj *obj = (HAL_Obj *)handle;
_iq value;
_iq current_sf = HAL_getCurrentScaleFactor(handle);
_iq voltage_sf = HAL_getVoltageScaleFactor(handle);
//_iq20 MotorPosn, MotorPosn2;
// convert current A
// sample the first sample twice due to errata sprz342f, ignore the first sample
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_1);
value = _IQ12mpy(value,current_sf) - obj->adcBias.I.value[0]; // divide by 2^numAdcBits = 2^12
pAdcData->I.value[0] = value;
// convert current B
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_2);
value = _IQ12mpy(value,current_sf) - obj->adcBias.I.value[1]; // divide by 2^numAdcBits = 2^12
pAdcData->I.value[1] = value;
// convert current C
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_3);
value = _IQ12mpy(value,current_sf) - obj->adcBias.I.value[2]; // divide by 2^numAdcBits = 2^12
pAdcData->I.value[2] = value;
// convert voltage A
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_4);
value = _IQ12mpy(value,voltage_sf) - obj->adcBias.V.value[0]; // divide by 2^numAdcBits = 2^12
pAdcData->V.value[0] = value;
// convert voltage B
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_5);
value = _IQ12mpy(value,voltage_sf) - obj->adcBias.V.value[1]; // divide by 2^numAdcBits = 2^12
pAdcData->V.value[1] = value;
// convert voltage C
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_6);
value = _IQ12mpy(value,voltage_sf) - obj->adcBias.V.value[2]; // divide by 2^numAdcBits = 2^12
pAdcData->V.value[2] = value;
// read the dcBus voltage value
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_7); // divide by 2^numAdcBits = 2^12
value = _IQ12mpy(value,voltage_sf);
pAdcData->dcBus = value;
// convert encoder sine
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_8);
value = _IQ12mpy(value,_IQ24(2.0)); // This scales the IQ12 adc value to be from 0 to 2 in IQ24
value = value - _IQ24(1.0); // This will offset the value to be from -1 to 1 in IQ24
pAdcData->SinValue = value;
value = (_iq)ADC_readResult(obj->adcHandle,ADC_ResultNumber_9);
value = _IQ12mpy(value,_IQ24(2.0)); // This scales the IQ12 adc value to be from 0 to 2 in IQ24
value = value - _IQ24(1.0); // This will offset the value to be from -1 to 1 in IQ24
pAdcData->CosValue = value;
pAdcData->AtanValue = _IQ24atan2PU(pAdcData->SinValue, pAdcData->CosValue);
pAdcData->MotorPosn = _IQ20(2000.1234);
pAdcData->MotorPosn2 = _IQdiv64(pAdcData->MotorPosn);
pAdcData->MotorPosn2 = _IQdiv2(pAdcData->MotorPosn2);
value = pAdcData->MotorPosn2;
pAdcData->MotorPosn2 = value;
return;
What I've found is that if I declare "_iq20 MotorPosn, MotorPosn2; " in the code, then in debug these variables aren't recognised, so I then tried adding the variables into the gAdcData which seems to work, in that these variables are recognised. However, if I try to put breakpoints on the last five lines before "return;" only the first 3 will accept breakpoints fully, the last two show greyed out ones. If I try to enable them, there's a message saying there's no code associated with these lines, hence the greying out. Someone suggested that lines which used a local variable may be optimised out by the compiler if the local variable wasn't subsequently used by the function, but that wouldn't explain the last two lines, would it ?
Single stepping gets me nowhere either as the program just seems to jump out of this function back into the main program loop.
Do hope there's a simple answer to this as I don't feel like I have enough years left to live to ever complete this project at the current rate of progress !
Thanks,
Geoff
GEOFF JACKSON said:My first question is, does the active project in the Project Explorer window (or anywhere else for that matter) have to be specifically set up for debug ? At the moment it's set to "Active - Release" in the Project Explorer.
You are referring to the build configuration for the project. The difference between two build configurations is the compiler options. I presume you are using a compiler of version 6.2.x. If so, then building with the debug options is not required. However, your level of optimization could make a difference.
Try lowering your optimization level and see if that helps. You can either change the level in the current build configuration, or change to the debug build configuration.
More information about this tradeoff between debug and optimization is in this wiki article.
Thanks and regards,
-George
George,
Thanks for the advice, looks like my debug problems were caused by optimization being set at level 2. I've created a debug configuration now with optimization initially turned off.
One other question, is there an option anywhere to automatically save modded files when the 'debug' button is pressed, before the build commences ? It's very easy to do a mod, forget to save the file, then end up compiling the version before the most recent mod.
Thanks,
Geoff
GEOFF JACKSON said:One other question, is there an option anywhere to automatically save modded files when the 'debug' button is pressed, before the build commences ?
Modified source files in the project should be saved automatically before build. Are you not seeing this happen? Do you consistently find that modified files are not saved prior to build?
Yes I do.
Just tried it to make sure, by modifying "hal.h" then hitting the Debug button. The hal.h tab remains marked with a * to indicate it's been modified and the star only goes away when I manually save the file.
Ok, so a header file needs to be explicitly saved, you are correct. For all C source files though, you will be prompted asking if you want to save the file, and there is also a checkbox for always saving before launching.
Is there any reason for not automatically saving a header file, or is it that there shouldn't be C code in a header file ?
In "hal.c", which TI wrote not me, there's a function to read the ADC that I need to modify.
GEOFF JACKSON said:Is there any reason for not automatically saving a header file,
If the header file is physically not in the project folder then the tools unfortunately do not have a good way of determining if that file affects the project or not.
In your last response, you mention "hal.c". If "hal.c" is part of the project, then that should prompt for auto-saving before build, however if it is "hal.h" that you are modifying and if hal.h is in a folder outside the project folder, then it will not prompt to auto-save and you would need to explicitly save it.
Sorry for confusing the issue, I meant "hal.h" not "hal.c" as I wrote; it's the .h file where the function is that I'm modifying.
Just to be clear on this, are you saying that ANY file that I modify which is visible in the project, in Project Explorer, will be prompted for saving after modification, not just a .c file ?
I don't think hal.h is in the project folder so that would explain it not being save prompted.
GEOFF JACKSON said:Just to be clear on this, are you saying that ANY file that I modify which is visible in the project, in Project Explorer, will be prompted for saving after modification, not just a .c file ?
That is correct. Any file that is part of the project (and visible in the Project Explorer) will be prompted for saving.