LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Encoder data VI questions

Hello all,

 

I am working on an encoder vi. The encoder is a 200 ppm quadrature and the goal is to record rpm's at every second and submit it to a data file that has a timestamp for every second and what the rpm at that second was.

 

To do this I used the DAQ Assistant to convert the frequency to RPM's. 

 

The program seems to work okay, except I would like it to run indefinitely until the user decides to end it, even when the encoder is not turning. Currently, the program seems to end itself after about 15 seconds or so of the encoder not rotating. Also, when the encoder is not rotating, I would like the program to read and record a "0" for rpm and submit this to the data file along with the timestamp. As of now, the program only records RPM's when the encoder is turning. 

 

The DAQ assistant is currently set to run 1 sample on demand with -1 second timeout.

 

Using LabVIEW 2011. 

 

Thanks,

 

Matt

0 Kudos
Message 1 of 6
(3,390 Views)

You didn't wire the Timeout input on the DAQ Assistant, so it took its default value of 10 (not 15) seconds.  This is good -- it means "If I Time Out, which I'll know about because I'll get an Error, then I've gotten 0 counts and can say the RPM is 0".  Be sure to also clear the Error.  Doing this, of course, will mean you'll need some other method to stop the While loop -- how about using a Stop button?  I see that you are "clocking" this loop at 1 Hz -- do you want to register "0 RPM" every second if the encoder isn't turning?  If so, make the TimeOut 1.0 (or maybe 0.99) seconds.  You might want to use "Wait until next multiple" rather than "Wait" (otherwise the TimeOut's will corrupt your timing).

 

Bob Schor

0 Kudos
Message 2 of 6
(3,369 Views)

Thank you for getting back to me. I wired a timeout into the DAQ assistant so the program runs indefinitely. I need this program running until the user decides to end it because it will be recording ground speed for a planter in a tractor. The driver will not have time to mess with the program during stops and so on. That is why I also need it to be recording "0" rpm when the tractor is not moving. I also tried putting a stop button on it, I couldn't figure that out but I will worry about it later when the rest of the program is working correctly.

 

However, it still will not record "0" when the encoder is not turning, without otherwise ending the program or setting an error. I tried messing with the TimeOut, and that didn't seem to help, it just seemed to end the program.

 

I also changed the "wait" to a "wait until Next multipe."

 

Very simply, as the tractor moves, stops, moves, stops (say moving is a constant 5 rpm, moving and stopping each at 2 seconds) I need the program to record 5, 5, 0, 0, 5, 5, 0, 0 (along with the time stamps) without setting any errors or ending, and no limit to the amount of "0's" that can be recorded.

 

Attached is my updated VI.

 

Thank you!

 

Matt

0 Kudos
Message 3 of 6
(3,345 Views)

Sorry, you either didn't read what I wrote or you didn't understand it.  If you wire -1 into the Timeout and the encoder is not running, you will never exit from the DAQ Assistant and your loop will simply halt.  Do what I said (or try the code snippet shown below -- if you are working on a 1-second loop, set the timeout to 0.999.  If no pulse is counted, the DAQ Assistant will tell you this by registering an Error.  Trap the error in a Case Statement (I've shown the no-error case here) where you clear the Error (use Clear Error on the Dialog palette) and wire 0 into RPM.  What I'm showing here is to replace the Dynamic Wire (grrrr) with a "Convert to Scalar" and do arithmetic (note no coercion dots!) to get RPM.  To stop the loop, add a Stop button (as I said).  To be sure that the first loop gets the full 1000 milliseconds, be sure to wire an "extra" Wait before the loop, as illustrated.

 

Encoder.png

Bob Schor

 

P.S. -- this is a Snippet.  If you have LabVIEW 2014, open a blank Block Diagram and drag this image from your browser onto the Block Diagram -- presto, LabVIEW!

 

P.P.S -- you seem to be running LabVIEW 2011.  I'll try to save/attach a 2011 VI.

0 Kudos
Message 4 of 6
(3,318 Views)

Wow! Thanks! I'm going to have to study up on what you did. You were right, I didn't really understand what you wrote that first time. Your program works very good, now I just need it to copy the data to a file. I tried to do what I did on my original program, and it is making a file for every second. How would I remedy this? I just want one file for when the program is running, and to start a new file when the program is restarted. I tried to put the "Write to Measurement File" outside the loop and that didn't seem to work at all. Do I still need to wire a "0" into the RPM? I tried to do that but that would give me an error.

 

Mattencoder demo 3.PNG

0 Kudos
Message 5 of 6
(3,290 Views)

Oh, dear.  I (almost) never use Express VIs (such as Write to Measurement File or the DAQ Assistant) and never use Dynamic Data wires.  Write to Measurement File wants Dynamic Data as its "Signal" input -- I have no idea what happens if you wire in a Dbl (which you did because I so dislike the Dynamic Data format that I "threw it away" in the Data Acquisition loop).  You could, I suppose, go back to doing the arithmetic on the Dynamic Data wire (though I'm uncertain how you would put in a zero value), or you could use another File Format (or someone who knows about how Write to Measurement File is supposed to work could chime in at this point ...).

 

Bob Schor

0 Kudos
Message 6 of 6
(3,276 Views)