Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
TiSh_1496096
Level 1
Level 1

Simple question I've looked at several different ways.  Can someone look over the code below and help me understand what I'm doing wrong?  I'm recieving the warning below and the Array is not functional.  It has to be something simple I'm not seeing.  Any help would be greatly appreciated.

   

"M0121: variable 'Input_Array' set but not used [-Wunused-but-set-variable]

   

int main()

   

{

   

int16 x;

   

uint8 Input_ADC;

   

uint8 ADC_Result =0;

   

uint8 Input_Array[16];

   

uint8 Input_Channel =0;

   

CyGlobalIntEnable; /* Enable global interrupts. */

   

ADC_SAR_1_Start();

   

ADC_SAR_1_IRQ_Enable();

   

M_4_Write(1); // enable external analog mux

   

while (x<3000) // delay before using

   

x++; //

   

x=0;

   

for(;;)

   

{

   

Control_Reg_1_Write (Input_Channel);  // set channel external mux

   

while (x<3000) // Delay Before Conversion

   

x++;

   

x=0;

   

while (Input_Channel<16) // scan routine

   

{

   

ADC_SAR_1_StartConvert(); // Start Conversion

   

if(ADC_SAR_1_IsEndConversion(ADC_SAR_1_WAIT_FOR_RESULT));

   

{

   

ADC_Result = ADC_SAR_1_GetResult8();

   

Input_Array[Input_Channel] = ADC_Result;

   

Input_Channel++;

   

Control_Reg_1_Write (Input_Channel);

   

while (x<3000) // Delay Before Conversion

   

x++; //

   

x=0;

   

}

   

}

   

}// end for

   

}// end main

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the Forum, Tim.

   

The warning is quite reasonable: You assign a value to Input_Array[] which is not a global variable (local to the function main) and you never use that value again. When not compiling with a strong optimization there will be no effect, just a warning. When compiling with optimization set to "Size" or "Speed" the assignment may be optimized-out.

   

Another pitfall: your delay-loop is quite undetermined. Better use CyDelay() or CyDelayus(), both documented in the "System Reference guide" (from Creator "Help"-menu.

   

 

   

Happy coding

   

Bob

View solution in original post

0 Likes
1 Reply
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the Forum, Tim.

   

The warning is quite reasonable: You assign a value to Input_Array[] which is not a global variable (local to the function main) and you never use that value again. When not compiling with a strong optimization there will be no effect, just a warning. When compiling with optimization set to "Size" or "Speed" the assignment may be optimized-out.

   

Another pitfall: your delay-loop is quite undetermined. Better use CyDelay() or CyDelayus(), both documented in the "System Reference guide" (from Creator "Help"-menu.

   

 

   

Happy coding

   

Bob

0 Likes