10-18-2013 03:50 PM
Good afternoon,
I've been running into a few problems with my vi, and I'd like to give a bit of the background information before I ask my questions. I'm using Labview 8.5 and the NI USB-6009 DAQ. I want to use an encoder to control values that are being written to a file for DMA. I found that I couldn't use the encoder as an external clock since the 6009 DAQ doesn't have this capability. So I've been trying to go a differenet route by using a case structure with a True/false statement to allow me to input values from a simulated signal into a write vi (each time the encoder pulses, a value from the simulated signal should be inputed into the write data storage vi). From there, I want to then read those values and put them into an array. So the plan is to have a 10 element array that reads in values from the storage file (just like in FIFO for FPGA). As I continue reading values, the oldest value of the 10 element array will leave the array and be replaced by a new value.
Now here come the questions, I'm using the Write/Read data storage vi's and I keep getting errors. First, if I'm wanting to use DMA to read these values am I using the correct vi's, or is there a different route? Also, once I read these values into the array how would I be able to constantly update the array in a descending order from begining to end of the stored values?
I'm posting my most recent vi that I've been editing. Also, in advance, thank you!
-tjm
10-18-2013 04:43 PM
Please clarify what you're trying to do. What does DMA have to do with it? There's no DMA involved anywhere here (except maybe from the 6009 into your computer, but that's out of your control). Why are you using the File Storage VIs, if you want to maintain a rotating array of values? It would make much more sense to use an array of 10 elements, stored in a shift register around the while loop. Then you would use "Rotate 1D Array" to move all the elements by one index, and overwrite the oldest (now first, after rotation) with the newest value. Opening and closing a file every time you get a new value is very slow and inefficient.
How long are the encoder pulses? There's no guarantee in this system that you'll get every encoder pulse, and conversely, it's possible that you'd get two values for the same pulse if the pulses are high for long enough.
Despite the apparent simplicity of the Express VIs, I highly recommend avoiding them. Often in their simplicity they obscure details in ways that make the code more confusing, not less. The DAQmx and file IO VIs are not that complicated to learn.
10-22-2013 01:05 PM
Thank you for your reply.
First, I'm ultimately trying to use the array as input into a visual display for a meter (to display the mean of the array). I've been successful (in the past) with inputting into an array by not using DMA and using the Sort 1D Array point by point vi. The only problem is the timing mechanism with the encoder, and you are correct with stating that there is uncertainty with the encoder when trying to retrieve values from the input signal (sine wave). I thought about going down the route of using the encoder as a counter (since I am able to see the counter increase by a single digit with each pulse).
My question would then be how to control the case structure with a counter input?
I'm posting both my setup with the Sort 1D Array Point by Point and the simple vi for the encoder as a counter. My idea is to try to merge the two and have the counter control the case structure.
Is there a way I can do this?
10-22-2013 02:50 PM
I don't understand why you are using the Sort 1D Array PtbyPt function - do you care if the values are sorted? If you just want to maintain a buffer of the last 10 values, use an array.
You can look for encoder edges, or changes in the encoder count, by keeping the previous value (count or digital input level) in a shift register, and comparing that to the current value on each loop iteration. When it changes, that's an encoder count (if using the digital level, make sure to have appropriate logic depending on whether you want to count rising, falling, or all edges). You can use the output of the comparison as the condition for a case structure. This won't guarantee that you catch every count - your hardware isn't capable of it - but it might be an improvement.
If you're not familiar with shift registers and array operations in LabVIEW, you will want to spend some time going through LabVIEW basics to become more comfortable with the programming environment. That will help you implement the logic you want.
10-22-2013 03:20 PM
I don't particularly care if the array is sorted. I used that vi to show that I was able to store into an array by taking out the last value and inputting a new value. My main objective was to figure out the case structure, and I think I should be able to achieve what I want based on what you mentioned. I've worked with shift registers before, but it has been a while. I'll definitely try it out and see if it works. Thank you once again for your help.