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.

Variable was set but never used warning?



Hi Folks,

I'm trying to get the eCAP functionality to work in my modified Lab10a code. Since there's no Motorware example I have to look at the Controlsuite
and the TI eCAP pdf (SPRUFZ8A May 2009) for help. I've added the below code to my main.c code. The code compiles but the it gives me 2 warnings:

"#552-D variable "capPeriod1" was set but never used". I also can't set a breakpoint here. When I try I get the following message:

"No code associated with line #10".

1
2
3
4
5
6
7
8
9
10
11
12
uint32_t DutyOnTime1 = 0;
uint32_t DutyOffTime1 = 0;
uint32_t DutyOnTime2 = 0;
uint32_t DutyOffTime2 = 0;
uint32_t capPeriod1 = 0;
uint32_t capPeriod2 = 0;
DutyOnTime1 = CAP_getCap2(halHandle->capHandle);
DutyOffTime1 = CAP_getCap3(halHandle->capHandle);
DutyOnTime2 = CAP_getCap4(halHandle->capHandle);
DutyOffTime2 = CAP_getCap1(halHandle->capHandle);
capPeriod1 = DutyOnTime1 + DutyOffTime1;
capPeriod2 = DutyOnTime2 + DutyOffTime2;

Any suggestions on what I need to change?

Thanks again,

Richard

  • Richard,

    Are you using capPeriod1 anywhere else in your code? If not, then it is giving that warning since the variable is set to a value but not being used anywhere else.

    Edit: Forgot to mention that the compiler may think that capPeriod1 is being set to a constant value although the values at the memory address are changing, so in that case setting capPeriod1 to volatile will get rid of the warning. 


    Do you have optimization turned on? This is typically the cause of not being able to set a breakpoint because that line of code has been optimized away.

    Best Regards,
    Chris

  • Chris,

    I completely turned off Optimizations and I can now turn on the breakpoints. Thanks for that tip.

    Just for future reference - is Optimization level 2 (which I believe is the default) a good place to leave it when I build out my code and get closer to a production level?

    Thanks again,

    Richard
  • Richard,

    Excellent!

    The details of what happens at each optimization level can be found in section 3.1 of: www.ti.com/.../spru514h.pdf

    I recommend having optimization off when developing to make debugging easier. Then once your code is in a good known state, start stepping up the optimization levels.

    Best Regards,
    Chris