I am writing a dead reckoning program using the latest Webbotlib Project Designer on the Axon II microcontroller. The program compiles fine using AVR studio 4.19. When I go to upload the hex file to the Axon, the bar goes to max then I get an error message saying that the file failed to flash. I removed bits of code and uploaded it again and again until I found the culprit.

It is during the "reverse" cycle of driving. The forward version of the same code works fine.

if (leftticks > rampdownticks){int difference = 180 - (leftticks - rampdownticks);leftspeed = interpolate(difference, 0, 180, 40, DRIVE_SPEED_MAX);}Im sure there is something going on that Im not aware of, or my logic failed somewhere along the way, but I would like another set of eyes on this.

Any code errors would come up at compile time or run time and definitely not at flash time. The only reason I can think of is that Your HEX file is too big, hence does not fit flash memory in microcontroller. Do You use code optimisation?

Logged

"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

39.4k. If everything that can be compiled can be uploaded no problem, there is definitely something fishy going on. I've had the same issue with a simple "cout << variable" line that it wouldn't upload unless I deleted that line.

The standard C++ library for I/O is basically unusable in embedded microcontrollers. It includes facets and support for locales and time and other things which use way too much resources to work in a tiny amount of program space and RAM.

"I am already looking at the C++ stuff - and have been for a year or two. The avr-g++ compiler does have some issues and hence I abandoned a pure C++ version of the library - but I may start by wrapping the C code with a thin C++ layer (like Arduino and others do). This would allow existing user code to continue to function in C only mode as well as allowing C++ notation."

Im assuming this is what Webbot did, and what is being uploaded to the Axon is a hex file compiled from C "wraped in a thin C++ layer" for ease of use.

Oddly enough, making a minor change eliminated that problems, and neatened up my code abit.

This does exactly the same thing, but it uploads fine. I went to mirror the code for the right wheel, and ran into the same problem, with the identical line of code. It doesnt matter what I put in the if statement, it fails to upload. Anything from declaring a variable, making leftspeed a specific number, anything at all and the program wont load.

I was going to do this all by hand as a coding exercise, and then was going to implement PID as I believe that would be a better solution in the long run anyway.

Programmers like AVRISP and McUber etc are exactly that -they copy a file on your computer to the flash memory of your computer. They have no idea about the content of the file - other than that it conforms to the hex format which is incredibly basic. It would be quite easy to take a jpeg photograph and write it out in hex format and a programmer would upload it - of course it would be jibberish but the programmer doesn't know that.ie if it compiles to a hex then it is uploadable (else blame the programmer software), if it compiles but doesn't run as expected then it is most likely your code but could also be the optimizer in the compiler (compilers are never 100% bug free and errors will change with the compiler version number, whether you are using C or C++, optimization command line settings etc) in which case try again with optimization turned off (see the codegen dialog box in Project Designer).