01-16-2014 02:55 PM
Somewhere I saw an algorithm in LabVIEW to adjust the timing of a software loop so that it tuned itself to an external event. It involved something like a subtraction between actual time elapsed and expected time elapsed (or expected - actual), divided by one or the other, and subtracted or added to one or the other. Clear as mud? It was a pretty simple algorithm that could be done in any language, but I can't find a good search term to discover it.
Why I need this: I have a piece of hardware that I query for data at periodic intervals. The clock on the device and the clock on my computer are not synced, and so there is some drift that causes me to lose data. I can correct the drift because I can compare the actual data with what I expect it to be, and keep the delta from drifting. I know this will work becuase I can tune the loop timing manually while the loop is running and watch the delta become fixed at a single value for every iteration. There must be a way to get the software to do this for me.
(aside: It is a stepper controller and I am querying position while it is moving. I want to get 1 degree precision but because of the timing I get more like 1.1 degrees. By using the position deltas to correct the timing I can get the precision I need.)
TIA
Ed K.
01-16-2014 03:00 PM
It would be easier to just use a Timed Loop.
01-16-2014 04:17 PM
If I use a timed loop, I can't change the loop timing on the fly. The system clock and the clock on my motor controller are not synced and will drift apart over the course of my measurement. I need to vary the time I wait based on the drift.
01-16-2014 04:59 PM
@yafoteer wrote:
If I use a timed loop, I can't change the loop timing on the fly. The system clock and the clock on my motor controller are not synced and will drift apart over the course of my measurement. I need to vary the time I wait based on the drift.
Sure you can (change the loop timing on the fly). You have to do it from inside the loop, but that shouldn't be a problem. Here's how:
01-16-2014 06:32 PM
OK, I am with you - thanks for showing me that. But my question is how do I determine the updated timer value? I want to calculate it, but can't remember the recipe.
01-17-2014 04:19 AM
If you know the stepper resolution you can easily calculate how many pulses is needed to move X degrees and generate a clock pulse of that many pulses.
/Y