Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Goofy quantization error in edge counting

Hello,

I have an issue with my counter that I hope someone can help me resolve. Essentially, all I want to do is turn the counter on, wait for a period of time that I specify, read the counts (coming from a TTL pulsetrain with a variable frequency of 0 to 100 kHz) that have occured over the elapsed time, and turn the counter off or reset it. This sounds simple and I have been able to get it to work, however I am experiencing a quantization error of sorts. The digit in the ones place of the number coming out of the counter has a funny dependence on the time that I tell the VI to wait. For example, if the wait time is 250 ms, the ones digit is only an even number; for 200ms, the ones digit will only be 0 or 5; for 100ms, the ones digit is only a 0. I have tried a number of things, including changing the clock source and gating the counter with a pulse from another counter, all to no avail. I have attached my VI to illustrate what I mean. If anyone else has had a similar problem or has any ideas, please help! By the by, I am running a 6229 board with Labview 7.1.

Thanks,

~Glenn Wolfe
Dept. of Chemistry
University of Washington
0 Kudos
Message 1 of 4
(3,770 Views)
Hi Glenn,

This appears to be a problem with that specific piece of code.  I did see what you were seeing, and I found that you could get a change in the 1's place if you shifted to either 199 or 201 ms of wait.

I then decided to start from scratch and see if this is an actual software problem, a hardware problem, or a particular quirk.  Fortunately, it looks like this will fall into the last category. 

I went ahead and created an almost identical program that should accomplish the same thing for you.  I hope this helps. 

Also keep in mind that you are doing software timing in this program, so you may not get a very accurate count.  For more accurate counts you may want to do something like look at the Count Events with Pause Trigger and then create a pulse that is the desired length of time.  When it comes to accuracy in timing it's generally not a good idea to trust your OS.

Regards,
0 Kudos
Message 2 of 4
(3,756 Views)
Thanks for looking at that Otis. I saw the same behavior that you mentioned, and I have since discovered what I think is the root of the problem. I think it has to do with the fact that the VI calculates frequency as the final output, and the "resolution" of that calculation is limited by the fact that the number of counts is always a whole number (no fractions) and they are then multiplied by another whole number (1/counttime) to get the frequency.  This essentially means that the frequency will always be some increment of 1/counttime.

Out of curiosity, how would I impliment hardware timing like that? I looked at the count w/pause trigger example vi, but I don't quite see how I can synchronize the start of the counter with the start of a vi that would send out a pause trigger pulse . . .  I guess ideally I would just want to set it up so that I can send out a pulse from the ctr0 out, and have that be the gate of ctr1 so that ctr1 only counts when the gate is high. It sounds really easy to do in theory, but it doesn't seem to be so straightforward in the programming. Tips? Suggestions? Thanks again!

~Glenn
0 Kudos
Message 3 of 4
(3,753 Views)
Hi Glenn,

To set up your ideal situation where ctr1 will only count your external signal while your ctr0 signal is high, you would want to combine the Count Dig Events-Pause Trig.vi and Gen Dig Pulse.vi examples (these can be found in the LabVIEW Example Finder).  You would set up your event counting on ctr1 in the Count Dig Events-Pause Trig.vi and set the "Pause When" control to "Low."  You can then set your Pause Trigger Source to be the internal ctr0 output by using the Browse option in that field.  It should be listed under your 6229 device as "Ctr1InternalOutput."  Next, you would use the Gen Dig Pulse to set up the pulse you will output from ctr0. The routing from ctr0 out to ctr1's pause source will be made internally.  You can also combine these two examples together into one VI, making sure you start the event counting task before you start the task to output the pulse from ctr0.

Thaison V

0 Kudos
Message 4 of 4
(3,732 Views)