I haven't been able to do timing in C/C++ very well the few times I was required to do it (such as timing execution in clock ticks or milliseconds). I never could get a good grasp on what timer to use since there is a lot of ways to do it, as well as platform specific ones such as linux timer functions.
So what I need to do is create a 1 second interval. This would be so easy on a microcontroller! It would go like:
while (some condition)
// do a lot of stuff, so it's not like a simple ISR
end while
I need to run through a bunch of code inside that while loop once per second. I have no idea how long that code will take to run, so it's not like I can delay for the remaining time of one second each iteration.
Any ideas on how to do this and what timer function I should use? It needs to be very close to 1 second (a few clock ticks difference won't matter but 1.1 seconds wouldn't be acceptable).
So what I need to do is create a 1 second interval. This would be so easy on a microcontroller! It would go like:
while (some condition)
// do a lot of stuff, so it's not like a simple ISR
end while
I need to run through a bunch of code inside that while loop once per second. I have no idea how long that code will take to run, so it's not like I can delay for the remaining time of one second each iteration.
Any ideas on how to do this and what timer function I should use? It needs to be very close to 1 second (a few clock ticks difference won't matter but 1.1 seconds wouldn't be acceptable).