03-17-2022 12:04 PM - edited 03-17-2022 12:06 PM
Hello. I'm writing a labview realtime application which will read the frequency of pulses from a proximity sensor in order to calculate rotation speed of a shaft. The problem is that the frequency of pulses can be as low as 0.2 hz. Configuring the channel's measurement mode as frequency won't work as the signal's frequency is too low.
Setting measurement mode as period measurement is great, as it gives me the time between the last two pulses. The problem with this is that I have no way of knowing when a new pulse happens, so when the shaft stops turning, I have no way of determining how long it's been since I got my last reading. I could compare the new value with the previous value and look for a change to determine if a new pulse has arrived, but this isn't foolproof as the new pulse perioud could happen to be the same as the previous one and is more likely on shafts which have a higher rotation speed and number of triggers.
My last option is to simply set the channel to count edges and have a loop which will keeps track of when the previous pulse came, how many pulses have happened since then, do the simple calculation on rotation speed, and now i can easily implement some sort of timeout logic which will set my "speed" to zero if some time has passed without seeing a pulse.
Am I missing something here? the period measurement option seems like the most accurate option, but I don't see how I can detect when the last pulse arrived.
03-18-2022 07:21 AM
Here's what I'd do:
1. Configure the task for Continuous Sampling, "Implicit" timing.
2. In software, maintain a cumulative sum of all measured periods. This gives you a time for each pulse (relative to task start).
3. In software, be prepared for the possible timeout error from a very slow pulse period. If you set your timeout to something like 0.25 sec (or whatever is appropriate for responsiveness in your app), and you get a timeout error with no data, you can choose to ignore or clear the error rather than propagate it. It's sometimes expected after all. And for that loop, your best estimate of the pulse rate becomes 0. There's no better value to guess in the absence of any new pulses.
-Kevin P
03-18-2022 01:38 PM
Sorry if I seem unfamiliar. This is my first labview application. I looked up tasks and they seem to be a daqmx specific construct. I'm not using daqmx in this project. I'm using shared variables to communicate data with a c# application. We still use many crio-9014 which doesn't support daqmx.
03-25-2022 10:51 AM
Your original post mentioned period measurement, edge counting, and timeouts, all of which seem to imply DAQmx usage. So I'm a bit confused now. Are you trying to figure out how to get the *equivalent* behavior of those DAQmx functions by doing your own FPGA programming?
-Kevin P
04-01-2022 11:42 AM
I don't know anything about the daqmx functions and I'm not trying to write fpga logic. I want to measure frequency of pulses using a labview realtime application. I've found that configuring the channel for period measurement gives the best accuracy. My problem is with detecting when the shaft has stopped moving. Period measurement simply gives me the period between the last two pulses. If the shaft stops moving, the period value simply doesn't change. I implemented a simple timeout which detects if the period value hasn't changed in a certain amount of time and will set the frequency to zero. But I could theoretically run into an issue if the period happens to be the same for a few pulses. Then the system would think there has not been a new pulse for some amount of time and erroneously reset the frequency to zero. Is there a way to detect when a new pulse has arrived besides checking if the value of my module5\ctr0 channel has changed?
04-01-2022 11:48 AM - edited 04-01-2022 11:51 AM
Here's the code. This gets called from another vi which runs in an infinite loop in sync with the scan engine and feeds the period measurement from an ni 9411 into it.
04-01-2022 12:10 PM
Hi aharres,
@aharres wrote:
Here's the code.
There's no code. That's just images of code!
Would you also post images of Matlab code or would you post the m/txt file?
Btw. the inner case structures can be replaced by select nodes.
And the reciprocal/multiply combinations are just glorified divide operations!
04-01-2022 12:31 PM
Thanks for the suggestion on the select statements. I find that the reciprocal and multiply are a more natural way to represent what im doing there. I posted images because thats the easiest way for someone to see the code. I can post the vi as well.