Friday, May 8, 2009

WIP: It Good

So much work in the last week...
The motor control library caused issues that made me learn more about Arduino program architecture than I thought I needed to know! My old QA skills narrowed down the offending line of code that caused the whole program to crash before it even ran (!!!) That only took a day or so to figure out and resolve. With the libraries working, I moved on to debugging the i2c command interface which had problems returning data from the slave unit because I was trying to send it one byte at a time since I hadn't read the Wire library commands. Oh the fun of being a novice. Once again there went another day of head grinding.
Then for a brief moment it seemed as if all the clouds might be disappearing, all the pieces were going together: the UI display was getting sorted, the input routines were debugged (a whole day coding manual Latitude and Longitude setting with only 5 buttons), the target and schedule tables were defined, the database routines were almost done, and still 10k of program ROM left.
Oh but the most important part, the solar position calculations was still absent! I had tested the code module long ago, and at that point was just happy to have some code that put out accurate numbers. As I started looking through the header and counting all the floating point variables, I began sensing trouble on the horizon. The SolPos algorithm uses over 1/4 of my total SRAM. Even when I commented out all the unneccessary variables and code, it still caused the 328 to reset during execution due to corruption of memory.
Yesterday I had some breakthroughs with the 128 based Amber board from SOCMachines, but it didn't turn out to be enough. It's an exciting little board with 256k of external memory and built-in ethernet connectivity. Back when I got the board, the first thing I did was the thing they tell you in bold letters not to do, and that was after reading the instructions! The result of that was that I erased the memory so that the demo program didn't run, which took some time in itself before I was able to test because I had to get a usb/serial cable and a special link cable to plug board straight into my laptops ethernet connection. After a couple months of EEPROM burner phobia, I downloaded PonyProg2000, figured out the parallel cable interface, and was soon uploading hex files both to the Amber, and the Arduino. This was cool because I learned how to upload an Arduino bootloader, and upload and run a program without any bootloader.
I was opti-mystic about the Amber being able to run an Arduino program since the new MEGA 128 based Arduino came out, but it turns out the Arduino team chose to support the 1280, and the Amber has the 128 16AU, which has 4k less of SRAM, although identical in almost all other aspects, and after much experimentation and diving into the Arduino core files, I determined that it just wouldn't work (with my level of knowledge at least).
Several more hours were spent investigating the demo program for the Amber, at the end of which I decided that it would just be too much work to port everything I've done over for it.
So the end result was that I decided to byte the bullet and buy a new Arduino Mega board (yeah)! It's still tempting to simply integrate a 3'rd processor (168 or 328) into the design, as a second slave, using the i2c bus and have it perform all the solar calculations, but that would still leave the master unit (a 328) perilously close to capacity, without network functionality added to the code base yet. So now I'll use the 128, like I knew I needed in the beginning, but it was a good learning experience the last couple of months: first with the 168 chips, then the 328 came out and doubled the memory, and now I can step up to the 128 and quadruple the 328's memory!
So bottom line is that the code base is coming along very nicely and the remaining processor issues should be taken care of as well. The new MEGA board is ordered from NKCElectronics and should be here within a week.
Oh yeah, the H1 heliostat prototype has been outside and setup for over a week now, and has endured several thunderstorms with wind gusts up to 30 mph!

No comments:

Post a Comment