Serial.write command execution time variations
hi, i'm writing a module spatial orientation using arduino uno. came across weird behaviour of serial.write lately (i send pretty big amount of data through serial , need send fast, that's why serial.print useless). worked fine until today, when checked sampling time of sketch (micros() before first , after last command @ loop() section) , found out execution time of serial.write varies 1600 15000us! can't understand did come from, when checked previouselly (before writing libraries project, week before) sampling times stable (about 30 variation). need program execution time constant , possibly shortest use numeric integration acions in computations. send 60 bytes of data through serial in every loop realisation. may cause execution time variations? why did parameter change? how can fix this?
below attach simplified sketch of program.
regards
gr4jp3r
below attach simplified sketch of program.
regards
gr4jp3r
code: [select]
#include <wire.h>
#include <math.h>
#include <compasshmc6352.h>
#include <itg3200gyroscope.h>
#define tp_micros 12000
#define tp_seconds 0.012
unsigned int starttime = 0;
unsigned int stoptime = 0;
byte frame[60];
byte frameincrement = 0;
\\...\\
void setup()
{
serial.begin(57600);
wire.begin();
\\...\\
}
void loop()
{
starttime = micros();
kompas.leavesleepmode();
gyro.updatevelocities();
gyro.updateangles();
kompas.downloadangle();
bmareadaccel();
anglefusion(zeta,w0,fusionroll,bmaaccroll,gyro.getprevvelocity(0));
anglefusion(zeta,w0,fusionpitch,bmaaccpitch,gyro.getprevvelocity(1));
anglefusion(zeta,w0,fusionyaw,kompas.getangle(),gyro.getprevvelocity(2));
setframeready();
unsigned int t9 = micros();
serial.write(frame, frameincrement);
stoptime = micros();
delaymicroseconds(tp_micros-(stoptime-starttime));
// serial.println(stoptime-t9); //this varies 1.6ms 15ms!
}
inline void convertinttobyte(unsigned int inttoconvert, byte *tempbyte)
{
tempbyte[0] = (byte)inttoconvert;
tempbyte[1] = (byte)(inttoconvert>>8);
}
void setframeready(void)
{
frameincrement = 0;
byte tempbytearray[2];
convertinttobyte(11111,tempbytearray);
frame[frameincrement++] = tempbytearray[0];
frame[frameincrement++] = tempbytearray[1];
\\...\\
convertinttobyte(kompas.getangle()*100 +5000,tempbytearray);
frame[frameincrement++] = tempbytearray[0];
frame[frameincrement++] = tempbytearray[1];
\\...\\
}
the first thing we'd need know version of ide using.
Arduino Forum > Using Arduino > Programming Questions > Serial.write command execution time variations
arduino
Comments
Post a Comment