Due not going as fast as it should??


i have project requires microprocessor fast possible. have set of calculations need done repeatedly. end goal send signals stepper motor drivers follow trajectories. purchased arduino due (upgrading mega) because theoretically faster.

however after got , have been doing benchmarking on actual speeds of 2 coming due not being fast should.

from clock speeds alone expect due 5.25 faster mega (84mhz/16mhz). not taking account 32 bit processor on 8 bit one. don't know details of have read big upgrade.

i have run identical code in both processors. calculations take ~968us on due, , ~2832us on mega... according due not 3x faster mega. below code.


code: [select]

float a0, a1, a2, a3, a4, a5, a6;     //polynomial coefficients
float thv = 360;            //middle angle
float ths = 0;             //initial theta
float thf = 0;            //final theta
float tf = 2;               //movement duration
float t=1.5;
float angle;
float start, stop, elapsed;
void setup()
{
  serial.begin(9600);
}

void loop()
{
  start=micros();
  a0 = ths;
  a1 = 0;
  a2 = 0;
  a3 = (2 / pow(tf, 3)) * (32 * (thv - ths) - 11 * (thf - ths));
  a4 = -1 * (3 / pow(tf, 4)) * (64 * (thv - ths) - 27 * (thf - ths));
  a5 = (3 / pow(tf, 5)) * (64 * (thv - ths) - 30 * (thf - ths));
  a6 = -1 * (32 / pow(tf, 6)) * (2 * (thv - ths) - (thf - ths));
  angle = pow(t, 6) * a6 + pow(t, 5) * a5 + pow(t, 4) * a4 + pow(t, 3) * a3 + a0;   //calculate desired position
  stop=micros();
  elapsed=stop-start;
  serial.println(elapsed);
  //takes ~968us on due
  //takes ~2832us on mega
}


am missing something?

probably of calculation.

i doubt mega carry out bunch of floating-point-arithmetics in 2832µs.

pow (1.234, 5.678) avr2 9293 avr4 5047

http://www.atmel.com/webdoc/avrlibcreferencemanual/benchmarks_1bench_libm.html


Arduino Forum > Using Arduino > Programming Questions > Due not going as fast as it should??


arduino

Comments