I am trying to add a timer for my accelerometer.
It has to get 1000 values in 1250 ms, because the data rate of the sensor is 800Hz.
The data has to be analyzed afterwards in Matlab so I have to be sure the 1000 values are measured in 1250ms for the data to be correct.
Right now I think the loop is too slow to measure in 1250ms and I’m trying to add a timer to see how much time it takes to get all the data.
When I add the timer I only get weird signs like in the picture below:
Hello Svekke1,
Welcome to the forum. ++Karma for posting your code correctly.
When I wan to measure how long a loop or a piece of code takes I set an output pin high at the point I want to start measuring and low at the end, then measure the time delay on an oscilloscope.
You code contains a lot of prints plus a delay, all these things are slow. If you want fast code they need to go. Take your measurements, dump them to RAM and then output them when they are all completed.
I added a LED to my void loop and attached this to the scope.
I then timed like Perry said and changed my loop to store my values in an array.
At last I added a microseconds delay to make sure I had 1250ms.
Thank you very much for your input everybody and especially PerryBebbington!