08-16-2011 06:04 PM
I'm new to LabVIEW (using it for a subject at university) but I've coded up a short program that counts rising and falling edges of a signal (to be used with input of a quadrature encoder).
I've tested it at low frequency using the Simulate Signal block and it works fine, but as soon as I pump it up to anything above 4 Hz, it starts playing up (counting a positive edge as a negative edge). At 10 Hz, it doesn't count any edges at all. Same thing with the encoder - when we turn it very slowly the counts register fine, but turn it at even a moderate speed and it'll start missing.
Not sure what the issue is. The code is pretty simple so I'm not sure how that'd cause the problem. Here's a copy of my counter block (the true/false input tells it whether to count up or down).
Solved! Go to Solution.
08-16-2011 06:18 PM
How are you running this? It is setup as a single run VI. It runs, it ends. There is no while loop around your code to keep it running. (Please don't tell me you are using the Run Continuously button.)
I doubt you'll get this working. You are really on software timing. Meaning the code has to run fast enough in software to detect all the transistions.
There are some odd constructs in there as well. A case structure that has a False constant in the True case and a True constant on the False case. Just use a Not function. The number of feedback nodes you are using seems excessive as well.
08-16-2011 06:48 PM
That's the subVI - it's being called from another VI which has the while loop and signal inputs.
Currently on a computer without LabVIEW so I can't edit the file, but surely the software should be able to easily manage 10 Hertz (or even 5, for that matter), despite the convoluted constructs?
08-16-2011 08:31 PM
You might try some of the functions in the Waveform functions palette for your application.
08-16-2011 09:58 PM
The loop will probably need to run at least twice as fast as the pulse signal you are trying to measure to guarantee that you won't miss a pulse. So that would be 20 Hz or about a 50 msec loop iteration. That should be doable.
Put some timing functions into your main VI and subVI to see how long each section of your code is taking to run. In order to really give more suggestions, we'd have to see the main VI so we can see how the loop is setup. Are you using a continuous data acquisition, or are you starting and stopping your DAQ task in the main VI?
08-16-2011 11:22 PM
I've editted the counter file to include time measurement and also included a test file from which I run the counter. It seems to struggle above 5 Hz. I've ran it in my actual file (which is similar to the test but also counts edges of a second signal) and get the same interval between codes, so the actual code doesn't seem to be the limiting factor here.
08-16-2011 11:40 PM
I don't have LV 2011 installed, so I can't view those files. If you could attach them as 2010 or earlier, please.
08-16-2011 11:48 PM
I'd look but.... I'm installing 2011. YAWN!
08-16-2011 11:54 PM
I've attached version 9 compatible files. Appreciate the help.
08-17-2011 12:13 AM
Are you adjusting the length of your simulated waveform when you vary the frequency?
Your subVI appears to only be looking for one transition within a waveform.
Your simulated signal Express VI is set up for 1000 Hz sample rate and 100 samples. So the outer loop iterates at 10 Hz. If your frequency is 5 Hz, then you are only going to have 1 transition in the section of waveform and you'll detect it. You go higher in frequency, then you might have multiple transitions in your waveform, but the subVI is only looking for the first one, and it might not even get that one. Remember when I said you need to run your loop twice as fast as the incoming waveform? Well you are now seeing that 2:1 ratio.
Adjust you length of your simulated waveform as you adjust the frequency so that you don't get multiple transitions on the waveform you are generating each loop iteration.