LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loop timing correction algorithm?

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.

0 Kudos
Message 1 of 6
(3,342 Views)

It would be easier to just use a Timed Loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(3,337 Views)

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.

0 Kudos
Message 3 of 6
(3,320 Views)

@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:

Timed Loop with Updated Period.png

0 Kudos
Message 4 of 6
(3,311 Views)

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.

 

 

0 Kudos
Message 5 of 6
(3,297 Views)

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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 6
(3,267 Views)