CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Bad Code Causes Reset

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Bad Code Causes Reset
PostPosted: Thu Nov 10, 2005 4:40 pm     Reply with quote

Hello All,

I've been chasing my tail for hours. I've narrowed down my problem to a #defined value that is causing problems. I won't include the code at this point because it's quite spaghetti'ish...

But I do know that the end result of my problem is a reset. My question is: What are the errors in code that could cause a reset? I don't have WDT enabled. I'm not doing any memory manipulation. The only thing I am doing that I can imagine causing the problem is working with an array that I remove a value from and repack.

Suggestions?

Thanks,

John
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 10, 2005 4:45 pm     Reply with quote

Quote:
My question is: What are the errors in code that could cause a reset?

1. You could be writing beyond the limits of the array, and
trashing other variables that are used by the compiler.

2. If you're using #separate directive, the compiler won't automatically
limit you to the 8 stack locations of the 16F series PICs, and you
could be using 9 or more locations. This will cause a crash.
Ttelmah
Guest







PostPosted: Thu Nov 10, 2005 4:51 pm     Reply with quote

Stack overflow.
An array index that is too large, on a constant array in a 12/16 chip (on these, constant arrays are accessed by adding the value to the program counter, and jumping to a 'RETLW' instruction). Jumping too far, could result in a jump anywhere...
'Repacking' an array, implies a RAM array, and using either the indirect register, or table read/write. Obviously this has the potential to damage other RAM memory entries if the values are incorrect, which could then lead to unexpected code flows.
An interrupt, without protection on the table registers (using #int_global or #fast), resulting in the array pointer becoming corrupted.
There are some "erratas" that apply to table read accesses on specific chips.
Remember also that #define can result in 'unexpected' results, if the value is included in arithmetic. Bracketing round the value, ensures that the macro expansion should be what is expected.
I'd start by checking the erratas for your chip, and adding tests for the values used to access the array.

Best Wishes
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Thu Nov 10, 2005 6:39 pm     Reply with quote

Well,

I found one problem:

Code:
array_index = rand() - 1;


I brain-farted and forgot that rand() can return 0.

Still, after that, I couldn't track down the offending code. Will try something else for now.

Thanks for those pointers. That was exactly what I was looking for.

John


EDIT:

No arrays, no problems! The KISS method works again.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Fri Nov 11, 2005 11:24 am     Reply with quote

I thought I had it fixed....

It must be a stack problem. As I increase a value past a point the problem appears.

Is there a way in software to monitor what's happening on the stack in software? i.e. can I read the memory locations and print them out to see if that is really the problem?

Thanks,

John
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Fri Nov 11, 2005 1:51 pm     Reply with quote

Aaaaarrrrrrrrrgggggghhhhhhhhh!

I SHOULD HAVE KNOWN!

The code I was worried about was used to control some LED controllers. As the number of LEDs being illuminated got too high, when I enabled them it caused a droop in Vcc.... And when would that cause a reset?

I had BOR28 on a 3.3V chip....

Only 2 days wasted on that one!

Thanks again for the pointers.

John
Ttelmah
Guest







PostPosted: Fri Nov 11, 2005 3:33 pm     Reply with quote

Not exactly a 'code' error, but a bit of a 'classic'. The phrase 'Aaargh'!, seems to cover it... :-)

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group