I was alerted to the existence of this in another thread:
http://arduino.cc/forum/index.php/topic,98133I ordered one of the 32-bit chips (Floating Point Co-Processor uM-FPU v3.1) from Sparkfun for $US 19.65.
Manufacturer's page:
http://www.micromegacorp.com/index.htmlIt's an 18 leg DIP chip, with straightforward wiring requirements. For SPI, just MOSI, MISO, SCK, +5V and Gnd. Plus tying a few of the other pins either to +5V or Gnd.
In its default configuration it doesn't need slave select (SS) however you can configure it to do so, if you need to use other SPI devices as well.
The supplied Arduino library and demo sketch worked as advertised, displaying things like a simple graph of a sine wave.
The big questions are: how fast is it? is it easy to use?
The default speed of the processor in the chip is 29.48 MHz, which is almost twice the clock speed of the normal Arduinos.
However offset against that is the need to communicate with the chip, although SPI is pretty fast. You basically send (via SPI) simple "commands" like "load register 1 with literal 10", "add register 1 to register 2", "retrieve register 2".
Test of calculating sines:
#include <SPI.h>
#include <Fpu.h>
#include <FpuSerial.h>
void setup()
{
Serial.begin(115200);
Serial.println("Nick FPU test");
SPI.begin();
Fpu.begin();
if (Fpu.sync() == SYNC_CHAR)
FpuSerial.printVersionln();
else
{
Serial.println("FPU not detected");
while(1) ; // stop if FPU not detected
}
}
unsigned long start1, end1, start2, end2;
volatile float result;
void loop()
{
#define RESULT 1 // uM-FPU register
float rad;
start1 = micros ();
for (rad = 0.0; rad < 3.0; rad += 0.1)
{
Fpu.write(SELECTA, RESULT);
Fpu.write(FWRITE0);
Fpu.writeFloat(rad);
Fpu.write(FSET0, SIN);
}
end1 = micros ();
start2 = micros ();
for (rad = 0.0; rad < 3.0; rad += 0.1)
result = sin (rad);
end2 = micros ();
Serial.print (end1 - start1);
Serial.println (" uS for maths chip.");
Serial.println ();
Serial.print (end2 - start2);
Serial.println (" uS for inbuilt.");
Serial.println ();
Serial.println("Done.");
while(true)
{
}
} // end of loop
Results:
Nick FPU test
uM-FPU V3.1.2
2572 uS for maths chip.
3572 uS for inbuilt.
Done.
In this case the FPU chip gave a reasonable speed increase (72% of the execution time).
Trying division however:
// same setup as above ...
unsigned long start1, end1, start2, end2;
volatile float result;
volatile float foo;
volatile float bar = 424242;
void loop()
{
#define RESULT 1 // uM-FPU register
start1 = micros ();
for (foo = 1.0; foo < 1000.0; foo++)
{
Fpu.write(SELECTA, RESULT);
Fpu.write(FWRITE0);
Fpu.writeFloat(foo);
Fpu.write(FSET0, FWRITE0);
Fpu.writeFloat(bar);
Fpu.write(FDIV0);
}
end1 = micros ();
start2 = micros ();
for (foo = 1.0; foo < 1000.0; foo++)
result = foo / bar;
end2 = micros ();
Serial.print (end1 - start1);
Serial.println (" uS for maths chip.");
Serial.println ();
Serial.print (end2 - start2);
Serial.println (" uS for inbuilt.");
Serial.println ();
Serial.println("Done.");
while(true)
{
}
} // end of loop
Results:
124228 uS for maths chip.
42628 uS for inbuilt.
Exponentiation doesn't seem faster either:
for (foo = 1.0; foo < 1000.0; foo++)
{
Fpu.write(SELECTA, RESULT);
Fpu.write(FWRITE0);
Fpu.writeFloat(foo);
Fpu.write(FSET0, EXP);
}
// ...
for (foo = 1.0; foo < 1000.0; foo++)
result = exp (foo);
85360 uS for maths chip.
36528 uS for inbuilt.
Mind you, 85350 uS for the chip is probably mostly the 1000 lots of SPI sending the command and getting the result. In fact I'm a tiny bit skeptical about the results for the inbuilt maths, they seem a bit fast.
(to be continued)