Go Down

Topic: How to read TTL sensor every exact time interval? (Read 7243 times) previous topic - next topic

RandallR

WizenedEE,
I hate to disagree with you but I don't see that working.
If we assume that "Do other stuff" takes 6ms and "Setup" required more than 10ms.

First time through 'Loop" you execute.

6ms later you don't.

6ms later you do that's 12 ms after the first.

... and so on.  You won't get 100 per second.

Now if you change
   prevgyrotime = currenttime;
to
   prevgyrotime += 10;

You will get your 100 reading.  Some space 12ms apart and some 6ms apart.

This is all very simplified and hypothetical.  I don't know anything about one of these gyro, I just know a little about programming.

RandallR


I don't know if there was some editing that has occurred, but the code eovnu posted in reply #4 contains no trace of a MissedReading variable.


This missed reading variable is in post #7

nickgammon


I'm not so sure you need to use interrupts at all.

Code: [Select]

  // Do other stuff



It depends what the other stuff is. Interrupts would let you start a reading pretty close to the target time, give or take the time taken to enter the interrupt, and whether another one was running. Testing in a loop means the sample times stretch out a bit. However you are right to make sure that the stretching is not cumulative.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up