<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Culverson Software-Custom DAQ Software labVIEW &#187; Timing</title>
	<atom:link href="http://culverson.com/category/timing/feed/" rel="self" type="application/rss+xml" />
	<link>http://culverson.com</link>
	<description>Custom Labview Data Acquisition Software Maine</description>
	<lastBuildDate>Thu, 20 May 2010 20:02:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Speed of En Masse Operations</title>
		<link>http://culverson.com/speed-of-en-masse-operations/</link>
		<comments>http://culverson.com/speed-of-en-masse-operations/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 18:04:03 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Beginners]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://culverson.com/?p=193</guid>
		<description><![CDATA[Zip-zap-zowee and swoosh!
Just in case you thought I was kidding in the article on en masse operations, I decided to offer some proof of the speed advantages they can give you.
I used the Timing Template vi to measure the time it takes to multiply an array of DBLs by two, both with a loop, and [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center; "><strong>Zip-zap-zowee and swoosh!</strong></p>
<p>Just in case you thought I was kidding in the article on <a href="http://culverson.com/operations-en-masse/" target="_blank">en masse</a> operations, I decided to offer some proof of the speed advantages they can give you.</p>
<p>I used the <a href="http://culverson.com/what-time-is-it/" target="_blank">Timing Template</a> vi to measure the time it takes to multiply an array of DBLs by two, both with a loop, and without.  I set up the timing VI to create an array of 1000 random numbers, and then time the multiply operation.</p>
<p>First, the loop method, where you auto-index every value out of the array, multiply it, and auto-index it back in:</p>
<p><img class="alignnone size-full wp-image-194" title="viaLoop" src="http://culverson.com/site09/wp-content/uploads/2009/09/viaLoop.PNG" alt="viaLoop" width="450" height="564" /></p>
<p>As you can see, this took 7.47 uSec per loop.  Not all that shabby.  But just removing the loop lets the <em>en masse</em> operation do it:</p>
<p><img class="alignnone size-full wp-image-195" title="EnMasse" src="http://culverson.com/site09/wp-content/uploads/2009/09/EnMasse.PNG" alt="EnMasse" width="461" height="570" /></p>
<p>Holy Speed Demon, Batman!  That&#8217;s 0.77 uSec or about ONE TENTH the time!</p>
<p>Now, I&#8217;m not guaranteeing that all such operations will save you that much time, but if you have a chance to use them, then you should!</p>
<p>It&#8217;s easier on you and easier on the hardware!</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/speed-of-en-masse-operations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Improved Analog Clock</title>
		<link>http://culverson.com/an-improved-analog-clock/</link>
		<comments>http://culverson.com/an-improved-analog-clock/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:58:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=53</guid>
		<description><![CDATA[Sometimes all that digital stuff is just too bland.
A bug undocumented feature of the original analog clock was that the markers on the scale were at intervals of 1.25 seconds, a consequence of LabVIEW preferring to use 4 intervals per major tick, when we silly humans use 5.  As a result, it looked a bit odd. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>Sometimes all that digital stuff is just too bland.</strong></em></p>
<p>A <span style="text-decoration: line-through;">bug</span> <em>undocumented feature </em>of the <a title="original Analog Clock" href="http://culverson.com/an-analog-clock-first-version/" target="_blank">original analog clock</a> was that the markers on the scale were at intervals of 1.25 seconds, a consequence of LabVIEW preferring to use 4 intervals per major tick, when we silly humans use 5.  As a result, it looked a bit odd.  As I said then, if we’re going for an analog, then let’s go for the analog.</p>
<p>Attempts to coerce LabVIEW into making the scale the way we wanted were not successful; it has a long habit of thinking that four is a nice number and five is just an odd number, so I could not make it work.</p>
<p>So how do we improve it?  Simply disregard the built-in scale and substitute a picture.  After all, we all know where the numbers are on a clock face, if we’ve lined up the 0 and the 12 on our LabVIEW scales at the top of the circle, then all else has to fall into place.</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/08/Clock2Pic.png"><img class="aligncenter size-full wp-image-164" title="Clock2Pic" src="http://culverson.com/site09/wp-content/uploads/2009/08/Clock2Pic.png" alt="Clock2Pic" width="137" height="155" /></a></p>
<p>Click <a href="http://culverson.com/site09/wp-content/uploads/2009/09/Clock2llb.zip">here</a> to download the example LLB file, in LV 8.0 format. It has the same math VI as before (read the <a href="http://culverson.com/an-analog-clock-first-version/" target="_blank">previous post</a> for details), just the clock face is different.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/an-improved-analog-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delays, delays, delays</title>
		<link>http://culverson.com/delays-delays-delays/</link>
		<comments>http://culverson.com/delays-delays-delays/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 15:33:44 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Data Handling]]></category>
		<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=66</guid>
		<description><![CDATA[Can’t you signals just work together?
Usually, in a data acquisition program,  all the signals you measure are “live”, meaning they represent the current conditions at the time they are sampled. However, in some cases you might have some signals which are not live, but delayed. For example, suppose you’re measuring engine operation, and you have [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><strong><em>Can’t you signals just work together?</em></strong></p>
<p style="text-align: left;">Usually, in a data acquisition program,  all the signals you measure are “live”, meaning they represent the current conditions at the time they are sampled. However, in some cases you might have some signals which are not live, but delayed. For example, suppose you’re measuring engine operation, and you have gas analyzers sampling the exhaust airstream. These analyzers conduct the gas from the measurement point in the airflow system around the engine to the analyzer mechanism itself. This gas flows through the sampling tubing at a specific rate, and therefore arrives at the sample point at a specific time AFTER it left the main airstream. These delays might be multiple seconds in duration.  There could be other reasons for this delay, such as an echo-measuring device, or the mechanical response time of some piece of hardware.</p>
<p style="text-align: left;">For analysis purposes, you want to look at the engine holistically and see causes and effects. If the speed changed at a particular point in time, you want to see the CO concentration change as a consequence. But unless you do something to compensate, the change in gas concentration will lag far behind the change in speed that caused it in graphs and tables, making it difficult to judge consequences.</p>
<p style="text-align: left;">To arrange the signals back into time-synchronous alignment, the solution is to think of ALL signals has having TWO delay lines: one physical, and one logical.  In our example case, the physical part is the gas piping conducting the gas. The logical part is completely within the  DAS software. If EVERY channel has a physical delay time (even if it’s zero), and if EVERY channel also has a logical delay time (even if it’s zero), and if EVERY channel has the sum of the physical delay time and the logical delay time equal to a constant, then the signals coming out of the logical delay lines will be time-aligned.</p>
<h4>Example</h4>
<p style="text-align: left;">For example, consider three channels: Channel A records data “live”, i.e. no delay. Channel B has a delay of 3 seconds. Channel C has a delay of 5 seconds.</p>
<p style="text-align: left;">We want to make the entire chain (physical + logical) the same length for all channels, so we pick the longest delay (5 sec) and make that our total delay time. For channel A, which has no physical delay, we have to have a logical delay of 5 sec. For channel B, which has a physical delay of 3 sec, we add a logical delay of 2 sec for a total of 5. For channel C, which has a physical delay of 5 seconds, we have a logical delay of zero. 5+0 = 3+2 = 0+5, so every channel has the same delay, when we count both physical and logical.</p>
<p style="text-align: left;">The logical delay is implemented in queues with every channel having its own queue. Every sample received goes into a queue belonging to that channel; and we pull out one sample from the end of the queue to be recorded. Since one goes in and one comes out, the length of the queue never changes. The initial length of the queue corresponds to the delay time we need for a particular channel. If a queue is empty (of zero length), then the sample we put in and the sample we take out are the same sample. If the queue is of length 10, then the sample we get out was taken 10 sample times ago.</p>
<p>At configuration time, the queues are set up, and populated with zero values to set their length according to how much delay is required. After that, the sample process means putting a sample into a queue and taking one out for use.  Every channel operates the same when actually sampling, it’s only the configuration where they differ.</p>
<p>Note that if you are recording a TIMESTAMP value, then the TIMESTAMP signal requires its own queue as well, so that it comes out in alignment with the signals. Of course this means that the data does not become usable until all the zeroes have been flushed out of the queues. That will happen when the longest delay time has expired. We can judge this by putting a RECORD signal into its own queue. We don’t actually record data coming out of the queues until the RECORD signal coming out is true.</p>
<p>You can keep the data flowing into (and out of) these queues all the time.  When you want to start recording, set the RECORD flag TRUE. When you want to stop recording, set the RECORD flag FALSE.  Pay attention to the value out of the RECORD flag’s queue, and act appropriately. (Don’t act on the RECORD flag itself, act on the delayed RECORD flag).</p>
<p>This also means that when the test is over, there is still data remaining in the queues. We have to keep recording until the valuable data has worked it’s way through the queues, meaning 5 seconds after the last sample (in the example case).</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/delays-delays-delays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Analog Clock (first version)</title>
		<link>http://culverson.com/an-analog-clock-first-version/</link>
		<comments>http://culverson.com/an-analog-clock-first-version/#comments</comments>
		<pubDate>Thu, 07 May 2009 16:07:35 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[LabVIEW]]></category>
		<category><![CDATA[Timing]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=101</guid>
		<description><![CDATA[Sometimes all that digital stuff is just too bland.
If you want to display a time-of-day clock in LabVIEW, it takes three seconds to plop down a TIMESTAMP indicator, and 10 more seconds to enter ADVANCED EDITING mode, and skip the month, day and year, and format it the way you want. Piece of cake.
And it [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><em><strong>Sometimes all that digital stuff is just too bland.</strong></em></p>
<p style="text-align: left;">If you want to display a time-of-day clock in LabVIEW, it takes three seconds to plop down a TIMESTAMP indicator, and 10 more seconds to enter ADVANCED EDITING mode, and skip the month, day and year, and format it the way you want. Piece of cake.</p>
<p style="text-align: left;">And it looks just exactly like every other digital clock out there: six digits, two colons, everybody knows what it means. And that’s fine for a lot of purposes.</p>
<p style="text-align: left;">But sometimes you like to decorate your work a little bit. If you’ve got space on a front panel, and a few cycles of execution time in your run loop, then consider an analog clock.</p>
<p><a href="http://culverson.com/site09/wp-content/uploads/2009/05/clock.png"><img class="aligncenter size-full wp-image-174" title="clock" src="http://culverson.com/site09/wp-content/uploads/2009/05/clock.png" alt="clock" width="160" height="163" /></a></p>
<p>The visual part of this is pretty simple: a custom control with a cluster of three gauges, all with their scales stretched to a full 360° and both ends of the scale at the top:</p>
<ul>
<li>A gauge indicator in the back: single dark red needle, and the scale set to 0..12.</li>
<li>A gauge indicator with an INVISIBLE scale of 0..60, and a bright red needle for minutes.</li>
<li>A gauge indicator with an INVISIBLE scale of 0..60, and a gray needle for seconds.</li>
</ul>
<p>The three indicators are sized identically and lined up identically, with transparent backgrounds, so the needles show through.</p>
<h4>An analog is an analogy</h4>
<p>You might think it’s straightforward to use this thing – just pass a cluster of hours, minutes, and seconds to the indicator, and you’re done.</p>
<p>You’d be wrong.</p>
<p>Consider what would happen: at 9:22:10, as shown above, the hour hand would be EXACTLY on the 9, the minute hand EXACTLY on the 22. Not exactly what you would expect from an analog clock. It’s even worse 35 minutes later: the minute hand would be on the 57, but the hour hand is still EXACTLY on the 9. It looks for all the world like it’s three minutes before nine, but it’s actually 9:57. If you’re going for the analog, then you’ve got to do better than that.</p>
<p>The gauges accept floating point numbers, so we’re in luck. If you think of how an analog clock works, it’s not the same as a digital clock (and you can quote me on that!). The second hand may move smoothly around the dial, or it may snap from one second to the next. We choose the snap idea, as it’s easier. But the minute hand definitely does NOT snap – it moves smoothly.</p>
<p>So we have to incorporate the position of the SECOND hand into the position of the MINUTE hand. Namely, we add SECONDS / 60 to the MINUTES value given, so that 6:30 will be halfway between 6 and 7, and 6:57 will be just before 7. Similarly, we have to incorporate the position of the MINUTE hand into the position of the HOURS hand so that 6:30:00 puts the hour hand at 6.5, halfway between 6 and 7.</p>
<h3>Download</h3>
<p>Click to download the <a href="http://culverson.com/site09/wp-content/uploads/2009/09/clockllb.zip">example</a> (about 12kB ZIP), containing the typedef indicator you can put on your panel, and a VI to do the above math for it. You can display the CURRENT time by leaving the TIME input unwired, or display a specific time by supplying a timestamp.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/an-analog-clock-first-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Time is it?</title>
		<link>http://culverson.com/what-time-is-it/</link>
		<comments>http://culverson.com/what-time-is-it/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 16:01:54 +0000</pubDate>
		<dc:creator>Steve</dc:creator>
				<category><![CDATA[Timing]]></category>

		<guid isPermaLink="false">http://jimdugan.com/culverson/?p=90</guid>
		<description><![CDATA[When you’re trying to make things in your program work faster, it’s important to remember a simple rule. On any given computer…
You cannot make the computer go faster. You can make it do less work.
Of course, to take advantage of that rule, you must be able to judge a given method of doing something, and [...]]]></description>
			<content:encoded><![CDATA[<p>When you’re trying to make things in your program work faster, it’s important to remember a simple rule. On any given computer…</p>
<p style="text-align: center;"><strong>You cannot make the computer go faster. You can make it do less work.</strong></p>
<p>Of course, to take advantage of that rule, you must be able to judge a given method of doing something, and compare that to a different way of getting the same result. In text-based languages, you at least have a hint: the ten-line solution is likely faster than the fifty-line solution. It’s not guaranteed, but if you have the source code to both methods, you can make a reasonable guess.</p>
<p>In LabVIEW, though, everything is a black box. The Fast-Fourier Transform is a single icon on your diagram, so is the function to add two numbers. You can’t judge a function’s speed by it’s icon (there’s an aphorism there somewhere).</p>
<p>Suppose your task is to convert an array of complex numbers to magnitudes. The mathematical rules are not that complicated: <em>M= sqrt(R<sup>2</sup>+I<sup>2</sup>)</em>. That’s two array multiplies, one array addition and one array square root.</p>
<p>But wait: there’s a function in the complex arithmetic palette to do this for you: Complex to Polar (C to P). It takes an array of complex numbers, and gives an array of magnitudes and an array of angles. That’s what you want, right?</p>
<p>The true speed freaks among you will immediately recognize a problem: This function does MORE than you need: you also get the angles associated with the complex numbers. And if you remember your basic trigonometry, calculating the angle is the more complicated of the two rectangular-to-polar operations. There’s the arctangent to compute, and the edge cases to deal with.</p>
<p>So if you’re interested in the speed of getting this done, the question becomes which one is faster? It’s certainly easier to plunk the C-to-P function down and throw away the angle numbers it produces. But suppose the speed of programming it is less important that the speed of executing it. There’s this nagging suspicion that the ANGLE calculations might be a fly in the ointment. So how do you test this?</p>
<p>It sounds simple: Just remember the mSec timer before doing the operation, do the operation, remember the mSec timer after the operation, and figure the difference of the two timers. Version 1 shows this approach:</p>
<p style="text-align: center;">
<p style="text-align: center;"><a href="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion1.png"><img class="aligncenter size-medium wp-image-160" title="testtimingversion1" src="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion1-300x126.png" alt="testtimingversion1" width="300" height="126" /></a></p>
<p>Looks simple enough. When you run a test like this, you generally should disregard the timing of the first run, because the compiler has just run and it is still shutting down as your program starts up. I always take three readings, to verify that this has settled down. And the answers I got are:</p>
<p><em>13, 14, and 12 for the Discrete method, and 0, 0, and 0 for the C to P method.</em></p>
<p>Well, isn’t THAT interesting?</p>
<p>Obviously, that has to raise some suspicion. We’re not measuring what we think we are. Although the code looks right, it can’t do it that fast, it just can’t. Even raising N to 10 million shows the C-to-P operation taking zero time. To see what’s going on, we add indicators to the results. Since we don’t want to measure the display time, we put those indicators OUTSIDE the timing chain:</p>
<p style="text-align: center;"><a href="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion2.png"><img class="aligncenter size-medium wp-image-161" title="testtimingversion2" src="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion2-300x126.png" alt="testtimingversion2" width="300" height="126" /></a></p>
<p>We run it four more times (ignoring the first) and get:</p>
<p><em>19, 18, and 19 for the discrete case, and 7, 7, and 7 for the C-to-P case.</em></p>
<p>What does that tell us? Well, if we give LabVIEW some credit for being smart, then we might say that it doesn’t compute results that it’s not going to use. If there’s no wire on the output, then it doesn’t perform the function at all! This leads to the question: Is it smart enough to do that on for each terminal separately, or does it go all-or-nothing? Simply adding another indicator answers that question – it takes longer to compute magnitude AND angle, than it does to compute magnitude only. No surprise, but that does reinforce our conclusion that LabVIEW is smart enough to help out. It’s only computing what we need to use.</p>
<p>Note that this applies only to built-in (yellow) functions. That’s because the compiler can tell whether we’re using the results or not. This might not apply to library functions, because they don’t have such a direct connection to the compiler.</p>
<p>So, to answer our starting question: it is indeed faster to use the C-to-P function and disregard the angle outputs. But be careful, because the exact answer you get depends on the exact question you ask. The example above assumes you have the numbers in complex form already. Note that in version 3, the Complex-to-Real-and-Imaginary function has been pulled OUTSIDE the timing chain, meaning the discrete version stands a better chance of competing.</p>
<p style="text-align: center;"><a href="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion3.png"><img class="aligncenter size-medium wp-image-162" title="testtimingversion3" src="http://culverson.com/site09/wp-content/uploads/2009/03/testtimingversion3-300x126.png" alt="testtimingversion3" width="300" height="126" /></a></p>
<p>Here the timing results were:</p>
<p><em>10, 10, and 9 for the Discrete method, and 12, 12, and 12 for the C to P method.</em></p>
<p>That’s because the C-to-P method has to convert the real and imaginary parts to complex before using them.</p>
<h3>Template</h3>
<p>If you do a lot of that sort of work, you don’t want to construct the timing thing from scratch every time. I have a template VI that I use for such things, and it has extreme accuracy.</p>
<p>Over and above the example method shown, this VI has the following features:</p>
<ul>
<li>It’s a template, not a VI. That means whenever you open it, it forgets its file name and you have to save it somewhere else. This keeps it clean for the next time. If you want to save a particular version, go ahead, but when you open the template again, it’s empty and ready.</li>
<li>It allows you to set the number of iterations, and provides an AVERAGE time per iteration. An operation that takes a microsecond can’t be timed with a millisecond timer, so you have to use 10000 operations or so. But an operation that takes a second can be measured with only one iteration.</li>
<li>It compensates for the loop-execution overhead. If your loop runs 10 million times, the loop itself takes time. That time is removed for you.</li>
<li>Since the example above proved that you MUST store the results somewhere to time something accurately, you might want to subtract out the storage time. In that case you can STORE (X[]) in the first loop and STORE (f(X[ ]) in the second. The cost of the actual storage is accounted for you.</li>
</ul>
<p><a href="http://www.culverson.com/Public/TimingTemplate.vit.zip">Click to Download the Template</a> (24 kB, unzipped, in LV 7.0 format).</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://culverson.com/what-time-is-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
