Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Undeletable "Variable Never Used" (help please)

Status
Not open for further replies.

Mr. Ohm Smith

Newbie level 4
Newbie level 4
Joined
Mar 5, 2014
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
65
Hi there! I need some help to solve this problem...

I´m using MPLAB 8.87 with CCS Compiler 4.114 to create a software to a PIC16F1829. The program has about 5000 lines and already works perfectly. I was asked to delete an old funcition and create a new one. Ok! Deleted the old one and implemented the new. After deleted the old function, some warnings appeard with the message "variable never used". Well, I deleted them, rebuild, program again and my hardware JUST STOPPED WORKING!

If I restore those variables (with CTRL+Z) the hardware just turn back to work! I also can't change old variables formats like from int16 to char. The same problem happens! I already made a SEARCH to be sure that it is never used. Also tried to close workspace, close project, create a new one and just open the code files but the problem persists!

In 10 years I never saw a problem like this. Now I can't change variables formats and can't make big changes safely.
 

this sounds like a classic case of array overflow or similar problems.
e.g. an array is overflowing into memory allocated to unused variables. You remove the unused variable declarations and the array now overflows into used variables corrupting the contents and the program fails.
A similar problem could occur when you change a variable type from int16 to char
can you get a memory map of the working program? you can then see what arrays are near the unused variables - this should give you a guide to which array or arrays are overflowing.
 
Re: Undeletable "Variable Never Used" (help please)

this sounds like a classic case of array overflow or similar problems.

Thanks Horace! It gives me a good idea about what is happening but I still have some dificulties to solve it. I just declare the variables like this:

unsigned char Ignition_Flags;
unsigned char Ignition_TimeOutCounter;
unsigned int16 Ignition_StartCounter;
unsigned char Sword_Recorded[2];

I don't control the memory position and I'm not sure about how to manipulate the arrays in memory. Could you give me some help?

- - - Updated - - -

I changed the "Sword_Recorded[2]" to two new independent variables. Now the hardware is working again!

But I still can't delete those unused variables without make the hardware get stuck...
 

Re: Undeletable "Variable Never Used" (help please)

you can print out the addresses of the variables to give you some idea of what may be causing the problems, e.g.
Code:
int main(void)
{
    int i=5;
    long int j=10;
	int array[10]={0};
	unsigned long int sys = 0;
    UART2Init();										// Setup the UART
    printf("\n\nPIC24 TEST1\n\r");
	sys=73700000;
	printf("i %d address %d \n",i, &i );
	printf("j %ld address %d \n",j, &j );
	printf("array[0] %d address %d \n", array[0], &array[0] );
	printf("array[1] %d address %d \n", array[1], &array[1] );
	printf("sys %lu address %d \n",sys, &sys );
	array[11]=45;			// over run end of array corrupting memory
	printf("sys %lu address %d \n ",sys, &sys );
	while(1){}
}
prints
Code:
PIC24 TEST1
i 5 address 4924
j 10 address 4926
array[0] 0 address 4930
array[1] 0 address 4932
sys 73700000 address 4950
sys 2986656 address 4950
you can see the write to array[11] (past end of array) corrupts the variable sys

- - - Updated - - -

a problem can also arise if you fail to use function prototypes and call a function with the wrong type, e.g.
Code:
// main program code
int main(void)
{
    int i=5;
    int j=10;
	int k=20;
    UART2Init();										// Setup the UART
    printf("\n\nPIC24 TEST1\n\r");
	printf("i %d address %d \n",i, &i );
	printf("j %d address %d \n",j, &j );
	printf("k %d address %d \n",k, &k );
	test(&j);
	printf("i %d address %d \n",i, &i );
	printf("j %d address %d \n",j, &j );
	printf("k %d address %d \n",k, &k );

	while(1){}
}

void test(long int *z)
{
	*z=55555555;
	printf("z %ld address %d \n",*z, z );
}
test is called with the address of an int but the function is expecting a pointer to a long int, memory in the calling function is corrupted
e.g. a run gave
Code:
i 5 address 4924
j 10 address 4926
k 20 address 4928
z 55555555 address 4926
i 5 address 4924
j -18973 address 4926
k 847 address 4928
after the call to test not only does j have the incorrect value but k has been corrupted
 
Last edited:

The problem might be either caused by a hidden problem in your code, e.g. writing out of bounds as discussed by horace1 or a compiler bug. CCS C V4.114 is 3 1/2 years old. There's no complete bug index maintained for CCS C so it's impossible to find out easily if a bug related to the observed behaviour has been detected and fixed. But more likely the problem is in your code anyway.

Personally I would try to catch the problem with the MPLAB debugger, trace the code til the point where code execution fails and find out why.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top