Hi all,
I was wondering if anyone knew of a way to modify/add to your sketch a small compatability tester that would determine the smallest ATmega chip one could use with the sketch. I have a 328 in my Arduino and once I've finished with my project I wanted to see if there was someway to have the software tell me what the smallest ATmega chip (based off memory constraints) that I could use. Any suggestions? Thanks.
After a compile, the IDE displays the Flash used by a Sketch. If the target processor has a bootloader, you'll have to subtract the bootloader size from the available Flash.
The SRAM used has to be determined at run-time. There are functions floating around this forum and the Pololu forum that return "free memory". You need to use the value from the maximum stack depth.
Thanks. I do have a follow up question though based off all the reading I just did. Couldn't I just simply change the starting address of the stack pointer by adding 1024 to simulate the difference between a 328 and 168 chip? The heap pointer should "technically" start at the same address between the two chips and the stack moves down from the end of the RAM on both chips. The difference being the RAMEND address due to different sizes of total memory. Assuming the compiled size on the IDE is less ~15k (168 IC) and the stack pointer starts at the new address it "technically" would simulate it?? maybe??? or I am missing something? Thanks again for all the help...
Wayne
Couldn't I just simply change the starting address of the stack pointer by adding 1024 to simulate the difference between a 328 and 168 chip?
In neither case will that work. The stack grows towards address zero. While running the Sketch on a 328, you could subtract 1024 from the stack pointer to simulate running on a 168.
Note1: In some cases, you cannot safely return from the function that adjusts the stack pointer without putting the stack pointer back the way it was.
Note2: alloca may be a better choice than directly manipulating the stack pointer.
But it isn't worth the effort. Simulating a 168 could easily work minutes, hours, even days before failing. The only way to prove the Sketch is reliable using this method is to let it run indefinately. But if you're going to do that you may as well run it on a an unadulterated 328.