Reply To: Time Scale
Ok. So, if I understand it correctly, it works like this: start iteration –> ask sensors (fix time) -> compute all the stuff -> form a packet (place time value to packet) -> send packet. Correct?
Suppose, that with properly set baud rate for the desired packet size we are out of the problems with transmission delays. It should be like this for the 115200 and 20 bytes for packet and 200 hz.
The next question that arise is that how main loop is organized. I see two cases (on example of 100Hz):
1) Internal timer send a signal -> start a loop -> do all the stuff (read sensors, form packet send packet) -> done -> wait for the next signal from internal timer and so on… And internal timer here generates signal exactly at 100 Hz, meaning that the time between two iterations is 10 ms with an accuracy of internal timer. Since the internal clock is working at 10 MHz this accuracy is good. It should be no more than microseconds.
2) based on the frequency (100 Hz) we get a time interval 10 ms and than starting the loop -> first iteration -> do all the stuff (read sensors, form packet send packet) -> done -> wait 10 ms -> start second iteration -> and so on.
I think I a little bit confused you. In the previous message, I wrote that I get something like that:
1 packet. Time: 00.7 ms.
2 packet. Time: 10.2 ms.
3 packet. Time: 21.2 ms.
4 packet. Time: 30.4 ms.
5 packet. Time: 40.5 ms.
6 packet. Time: 50.2 ms.
However, I meant a little bit different thing. Sorry. Let me clarify it. I get (for 50 Hz):
1 packet. T1: 4804.4799804688 s => T1 – T0 = 20.5078 ms (T0 is not shown)
2 packet. T2: 4804.5009765625 s => T2 – T1 = 20.9961 ms
3 packet. T3: 4804.5214843750 s => T3 – T2 = 20.5078 ms
4 packet. T4: 4804.5424804688 s => T4 – T3 = 20.9961 ms
5 packet. T5: 4804.5629882813 s => T5 – T4 = 20.5078 ms
6 packet. T6: 4804.5834960938 s => T6 – T5 = 20.5078 ms
Here, come back to the question how the main loop is organized. Those results show that it works in a second way with a delay of 20 ms between the end of the previous iteration and the beginning of the next one, where the time about 1 ms on average is a time at which a single iteration completes.
In comparison to the first case when the loop operates by the timer signal, yes, there are could be a small time from the beginning of the operation and the moment at which sensors data is coming. But that one will be microseconds and it will be almost consistent over all iterations and results in that the difference between T(i) and T(i-1) on average will be equals to the time at which timer starts next iterations, say 20 ms. So I expect to have in this case:
1 packet. T1: 4804.4799804688 s => T1 – T0 = 20.0 ms (T0 is not shown)
2 packet. T2: 4804.5009765625 s => T2 – T1 = 20.0 ms
3 packet. T3: 4804.5214843750 s => T3 – T2 = 20.0 ms
4 packet. T4: 4804.5424804688 s => T4 – T3 = 20.0 ms
5 packet. T5: 4804.5629882813 s => T5 – T4 = 20.0 ms
6 packet. T6: 4804.5834960938 s => T6 – T5 = 20.0 ms