Timer not counting

Hello everybody,

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:

My code in the void loop is as follows:

void loop(){
  
  
   
    for (teller == 1; teller <= 1000; teller++){
  //      rTime = millis();
        I2C_READ_ACC(0x00);
        Serial.print(teller); 
        Serial.print(";");
        Serial.print(axeXnow); 
        Serial.print(";");
        Serial.print(axeYnow); 
        Serial.print(";");
        Serial.print(axeZnow); 
        Serial.println(";");
        delayMicroseconds(250);  
   //     Serial.println("Run Time =" + rTime);
    }

I so get the 1000 data points so no fault there.

Thanks in advance.

    for (teller == 1; teller <= 1000; teller++)

Did you deliberately write the for loop like this ?

Your incomplete code doesn't say what rate the serial line is running at.

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.

Dear PerryBebbington,

How would I be measuring this with an osciloscope when it takes several seconds to finish the loop?

Dear UKHeliBob,

Yes what is wrong with the loop?
I'm a little new to Arduino so i'll take all the info I can take! :slight_smile:

for (teller == 1;

Now do you see what's wrong?

How would I be measuring this with an osciloscope when it takes several seconds to finish the loop?

With a very slow sample rate.

How would I be measuring this with an oscilloscope when it takes several seconds to finish the loop?

By setting the timebase at an appropriately low speed.

PerryBebbington

Thank you very much!!

For people who might find this usefull:

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!

Thank you very much for your input everybody and especially PerryBebbington!

You're welcome!