Attiny refuses to Multiply (highlowtech.org core)

Guys, im having the weirdest problem ever...

I programming a attiny using this core http://highlowtech.org/?p=1695 (so i can use SoftwareSerial) and using a Arduino 1.0.5 IDE I set the board to Attiny85 (internal 8mhz) The problem is with this line

colourArray[i] = (colourArray[i] - blackArray[i])/ (greyDiff * 255)

Here are the variable declarations

float colourArray[] = {0,0,0};
float whiteArray[] = {0,0,0};
float blackArray[] = {0,0,0};
float greyDiff = whiteArray[i] - blackArray[i];

The problem is exactly with the * 255, if i remove it, it works (in fact if i change 255 to 5 it still gives me the erros, but if i change to 1 or 2, it works)

here is the error:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)

btw.. it works fine on arduino nano or uno. so ive got to be something with the attiny!

well, just some headsup, i did try a few changes but still the same, now i dosent dive temp2 / temp if the * 255 is there

float temp = 255 * greyDiff;
     float temp2 = colourArray[i] - blackArray[i];
     colourArray[i] = temp2 / temp

Tkz for the help guys! and keep the community alive :)

The problem is exactly with the * 255, if i remove it, it works (in fact if i change 255 to 5 it still gives me the erros, but if i change to 1 or 2, it works)

Your post title is wrong. Your assumption about the source of the error is wrong. That is NOT a compiler error, and has NOTHING to do with the tiny's ability to multiply or its willingness to multiply.

Something that happens as a result of the code that is generated causes the linker issues.

Try breaking that complex statement up into individual statements. Since you are dealing with floats, don't mix modes. Multiply by 255.0.

PaulS, thanks for the reply!

Look what i've done and still have the error:

float greyDiff = whiteArray[i] - blackArray[i]; 
float temp =  greyDiff * 255.0;
float temp2 = colourArray[i] - blackArray[i];
colourArray[i] = temp2 / temp;

Cant break the code simpler than that! if i comment the last line "colourArray = temp2 / temp;" it compiles fine!

even if i set a float variable for the 255, still gives the same error. Im blaming attiny because it works fine on Uno or NANO. (if i change the board, works fine!!) I am no genius, i might be doing something wrong but i cant figure out! Thanks again!

What happens if greyDiff is zero? Shouldn't you be handling that?

PaulS,

the greyDiff wont get 0 or below, because of the values that are read from the analog port...

anyway, i found a solution....

my sketch size was 5.404 bytes (max on attiny is 8.192)

And i noticed that all started when i changed the core to highlowtech.org to use software serial (only need tx)

So, i tried to change from SoftwareSerial to TinyDebugSerial using arduino-tiny library from code.google

Now im running my old code line the one that started the error

colourArray[i] = (colourArray[i] - blackArray[i]) / (greyDiff *255) ;

The result is that, all works fine now and the sketch size is 3.874 bytes.

I still believe the problem is within the core of attinys highlowtech.org implementation, and i also opened a issue there https://github.com/damellis/attiny/issues/46

the greyDiff wont get 0 or below, because of the values that are read from the analog port...

It would be nice to be able to believe that. Personally, I don't. Defensive programming is a better choice. But, it's not my app.

You are right, i might add something to just dont do nothing if that occurs :)

Thanks

tessomc: ~~~ /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn85.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o) ~~~

http://www.lmgtfy.com/?q=site%3Aforum.arduino.cc+R_AVR_13_PCREL+Attiny85

Thank you dear Moderator,

Found exactly the problem at http://forum.arduino.cc/index.php?topic=116674.0#msg881917

didn't try the fix yet, but yes it only happens on macs, just compiled the sketch on a Linux box and works fine...

So the problem is in the arduino for mac itself?

http://forum.arduino.cc/index.php?topic=60649.msg437771#msg437771

Yep,

found out that the damn ld file is inside tools-universal.zip inside https://github.com/arduino/Arduino/blob/master/build/macosx/dist/

Im gonna try build it from the source and see if that version works (i doubt it '3 years ago Updating to avrdude 5.11 on Mac OS X.')

if dosen't work then im gonna fork the damn thing and apply the ld file inside the zip and build it... might try to submit a patch then... or just use my forked one.. i don't intend to use 1.5 while still beta..

tessomc: i don't intend to use 1.5 while still beta..

1.5 ships (or will ship) with a much newer toolset that very likely does not have the problem.