Posted by: deSilva Posted on: Today at 21:49:45
I try again:
(1) There is no need for interrupts in your application. In fact I have NEVER seen an issues here brought to the forum, where interrupt was needed, and - if used - had not made the situation even worse..
(2) You might have a THROUGHPUT problem. The bottleneck I see is attitude and control =2ms. Is this "control" really needed at high frequency?
(3) Serial communication for HardwareSerial should not need processor time.. You could avoid the waiting involved in multicharacter sending by sending on a character by character basis with activities in between. This needs some coding of course...
(4) There is also some hidden waiting in the analogRead() routine, which can be re-claimed by direct accessing the ADC..
(5) By detats I mean: Just the differences! So you have 6 values (A,B,C,D,E,F) the old values already sent were (a,b,c,d,e,f)
Now you send this:
if (a-A !=0) "A" (a-A)
if (b-B !=0) "B" (b-B)
if (c-C !=0) "C" (c-C)
if (d-D !=0) "D" (d-D)
if (e-E !=0) "E" (e-E)
if (f-F !=0) "F" (f-F)
Thank you. I will try it. I feel stupid for not thinking of doing it like that

. I will see if the interrupt is really needed
I've actually not timed the control algorithm, just put a extremely worst case scenario, might never occur. A more accurate estimate would be around 500-700 us.
I will give your method a shot, as it doesn't require changing much of the PC program.
Again thank you

.
As deSilva has pointed out, you're spending all that time blocking waiting on sending the data.
The way serial writes work is that the library routines take, say, a string and write it one character at a time, waiting for the serial transmit register to become empty before writing another character.
In this time, the processor does nothing except read and test a UART status register
As soon as the last character is written to the transmit register, the write routine routine returns.
At 115200 bps, each character takes about 87us to transmit, and you're sending (I estimate) about 46 characters.
So, don't send strings, send one character at a time, and use the 86 or so microseconds you gain not waiting for the tx register to become empty to do something more productive.
(PS pretty much the same story for the "analogRead"s)
Can you explain that a bit more?
if i have variable int i=180 and do
Serial.print(i); Serial.print(",");
i am sending 4 characters in total ?I lack a lot of knowledge about Serial Communication...
Thank you.
Problem solved: So i tried something different before i read DeSilva's reply and it worked, no need to change the PC program as well.
here is what i did.
Easier explained in code:
void loop()
{
...
//last lines
Serial.print(DataTelemetry[dataToBeSent]);Serial.print(",");
dataToBeSent++;
if ( dataToBeSent>=5) {
dataToBeSent=0;
Serial.println(dt);
waitToSample=true;
}
}
Thank you guys.
I've yet to give deSilva idea a shot.