LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I NEED HELP CALCULATING THE TIME DIFFERENCE (ms) FOR EACH SENSOR DETECT

Hello sir,
I need help

 

I plan to calculate the RPM of a wheel using a proximity sensor.
The idea is that I will calculate the time difference (ms) every time the sensor detects the metal that I have attached to the wheel. It sounds easy but I'm still very much a beginner and previously only used to using Arduino.

 

- I have succeeded in changing the analog signal so that it produces a clean variable with a value of 1 when the sensor successfully detects it, and 0 when it does not detect it;
- I also managed to get the time value (ms) when the variable was 1.

 

*However, I have difficulty calculating the difference between the current time (ms) and the previous time (ms).

 

Please help
Thank You


Hanif25_0-1718222731171.png

 

0 Kudos
Message 1 of 9
(686 Views)

Please do a "save for previous (2020 or below) before attaching.

 

(I seriously doubt you need more than one feed back node or any formula nodes at all. Your loop termination should probably be "stop of true". How is the DAQ configured? one point at a time?)

Message 2 of 9
(660 Views)

Let's think about how to detect a time difference.  Suppose I have a procedure that I can call once per millisecond and it will say "True" (meaning "I see the sensor") or "False" (meaning "I don't see the sensor").  Let's also assume that this (boolean) signal is "noise-free", that is, it doesn't go "True False True False ..." but rather "False False True True False False ..., so there is a clear "once a revolution" signal that goes from False to True only once per revolution.

 

Note I'm going to try to walk you through the process of "Thinking LabVIEW", and not necessarily talking about Data Acquisition, but rather getting away from coding with "scripts" and into coding with LabVIEW structures and "wires".

 

Have you learned about LabVIEW's While Loop, which just keeps "going around" until you wire "True" to its "Stop" terminal?  Have you learned about the "Timing" functions, one of which ("Wait (ms)") can be used to make the While Loop repeat once a millisecond (making it a not-very-good) "clock"?  [Really, you want to do timing with DAQ hardware, but I'm trying to get you to think "Loops" and "Timing" ...

 

So you have a While loop that "does something" every millisecond.  Let's say what it does is read the sensor, and decide if it is "seen" (or "True") or not seen ("False").  What do you want?  You want to know when it is True.  Even better, you want to know when it becomes True.

 

What does it mean "becomes True"?  It means "Last time it was False, this time it is True".  OK, how do you know what it was "Last Time"?

 

Have you learned about "Shift Registers"?  If you have a While Loop, and you put a Boolean "True" inside the loop, you know you can create a "wire" on the Boolean and drag it to the right edge of the While Loop, where it will become a "tunnel", a way to get the data out of the loop.  But you can also right-click that Tunnel (technically called a "Last Value" tunnel), and change it to something called a Shift Register (which looks like a box with a sideways triangle inside it, suggesting that it "holds" a value from inside the loop, and is automatically paired with another Shift Register on the input side, except the triangle faces the other way).  When you wire to an "output" Shift Register, and the loop repeats, whatever was on the output automagically appears on the input Shift Register.  So the value from the Input Shift Register is the "Value last time".

 

So now you can detect a "rising Edge" -- it is simple "The sensor is True now, but was False the previous time".  You can use Boolean functions, or a Case statement, to take the "Present" and "Past" values, combine them, and get a "Rising Edge" output.  There are many ways to do Rising Edges -- there are even LabVIEW functions that will give them to you directly, but instead of trying to learn the myriad of functions LabVIEW provides, I'm trying to show you how to "Think LabVIEW", "Think Wires = Data and operations = combine data to get answers", and how LabVIEW builds the processing of time into the language.  

 

Bob Schor

Message 3 of 9
(629 Views)

LabVIEW is a "Dataflow" language, meaning that everything that has all its inputs ready will run.

 

Because of this, the "Tick count" you are using to get the time it sensed a "1" is a very bad measurement of time.  It could happen as soon as your loop starts, or it could happen after all your data has been collected.  You might sometimes get an accurate measurement, but other times will be really far off.

 

Instead, look at the graph you labelled "Original wave".  See how the bottom has dates and times on it?  Those dates and times come from your hardware.  You need to figure out how to get those time stamps, and use them instead.

 

I would start by getting rid of that blue "Dynamic data" wire.  What you want is to get the data out of the DAQ as waveform data.

Message 4 of 9
(627 Views)

@
Sorry for keeping you waiting. I use a daq configuration and tone measurement like this

 

Hanif25_0-1718246970532.pngHanif25_1-1718246978398.png

 

 

 

0 Kudos
Message 5 of 9
(602 Views)

Sorry, forgot to attach the application file

0 Kudos
Message 6 of 9
(592 Views)

[UPDATED]

 

Now I have successfully determined the RPN value, but unfortunately, I still use the formula method instead of the overall block diagram method

Hanif25_0-1718251588475.pngHanif25_1-1718251591372.png

 

0 Kudos
Message 7 of 9
(590 Views)

Yes sir, @

 

I initially planned like that, but due to limited abilities I tried it in a way that I thought was easier and that I was able to do.

Please help to guide me to simplify the program that I have created

0 Kudos
Message 8 of 9
(587 Views)

Can you substitute the DAQ with a simulation that generates a typical signal. You seem to do a tome measurement to reduce it to a singe integer followed by code that is pure gibberish.

 

Maybe start with describing the raw signal over time and explain what you are trying to measure from it. The WHAT, not the HOW. We will determine the HOW. 😄

 

"How does the "value 1 detect" change as a function of time? How can a frequency be <0? (n in the first formula node) Is that a sentinel output if no frequency is detected?

0 Kudos
Message 9 of 9
(543 Views)