View Single Post
Old 06-16-2008, 07:49 PM   #15 (permalink)
awillard69
EcoModding Apprentice
 
awillard69's Avatar
 
Join Date: Feb 2008
Location: Streamwood, IL
Posts: 105

Dakota - '00 Dodge Dakota Club Cab, Sport
90 day: 18.57 mpg (US)

Jeep - '01 Jeep Wrangler TJ Sport
90 day: 18.46 mpg (US)
Thanks: 0
Thanked 1 Time in 1 Post
Red face I tried...

It appears the the memoryTest() function is the culprit - on 2 different Duinos. I've commented it out completely, and it works; I've commented out the while loop and it works. Something in the allocation routine is amiss, like maybe the processor is getting trounced - at the moment it needs memory, the program has it allocated, so it resets.

I've modified it as follows, what do you get on the serial? I changed it to an unsigned long to match the data type in the calling function, but no luck. I even added the check before the final deallocation.

Code:
// this function will return the number of bytes currently free in RAM    
unsigned long memoryTest() {    
  unsigned long byteCounter = 0; // initialize a counter    
  byte *byteArray = NULL; // create a pointer to a byte array    

  while ( (byteArray = (byte*) malloc ((int)byteCounter * sizeof(byte))) != NULL ) 
  {    
//    byteCounter++; // if allocation was successful, then up the count for the next try    
    byteCounter += 10; // if allocation was successful, then up the count for the next try    
    free(byteArray); // free memory after allocating it    
    #ifdef debuguino
    Serial.print("Memory: ");Serial.print(byteCounter);Serial.print("\n");
    #endif
  }
  if( byteArray != NULL ) free(byteArray); // also free memory after the function finishes    
  return byteCounter; // send back the highest number of bytes successfully allocated    
}
On count by 1 (ie byteCounter++), I get:
Code:
...snip
Memory: 840
Memory: 841
Memory: 842
Memory: 843
JMemory: 844KMemory: L845Memory:M846MemoryN847MemorO848MemoP849MemQ850MeR851MS852T85385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291317367953914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979instant: 0,133444,54,166
current: 0,133444,54,166

...snip
For += 10, I get:
Code:
...snip
Memory: 910
Memory: 920
Memory: 930
M¢940
M¢950
M¢960
M¢970
M¢980
M¢990
M¢1000

...snip
Any help?
__________________

  Reply With Quote