LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Edge detection output

Hi, I made a vi as attached below to do edge detection in a While loop (detect edges every few seconds). The results are written to a text file. What I am testing is a rising edge. For the first few loops, since there are no edge occurred, nothing was written to the file. What I want is that "0.0" should be written to the file for no edge situation. Can anyone give me a idea how to do it? Thanks. Rena
Download All
0 Kudos
Message 1 of 6
(3,994 Views)
Not an answer to the question, but the array manipulation in the examples you attached really needs to be commented;

You have an array of clusters containing two double precision numbers and want to convert it into a 2D single precision array to write to a file...

You wire the cluster array to a FOR loop and initialize two shift registers with empty 1D arrays...and then build the two arrays using insert array element...when the for loop is finished you build a 2D array of the two 1D arrays using a build array function...This is the absolutely worst way to do the job. This will resize the two 1D arrays on every iteration an operation that is heavy on memory operations and very slow. In addition you wire the arrays to single precision indicators...causing the whole a
rrays to be converted to SGL in a new very memory costly operation.

Never do this, instead initialize the shift registers with an array already containing the correct number of elements, and then use the replace array subset instead...OR in this case (if you really needed the 1D arrays), forget about the shift register and use the auto indexing of the for loop to produce the output arrays...

Here though you don't really need the 1D arrays, what you want to end up with is a 2D array...the fastest and most memory efficient way to do this is thus to never create those 1D arrays at all...instead initialize a shift register in the for loop with a 2D SGL array with the correct number of elements and then use replace array subset to insert the two new numbers (converted to SGL) on each iteration....

I'll attach an example later.

I would recommend the optimization section of the LabVIEW manual..reading and following it will improve the performance of your code drastically. Or read
:

http://zone.ni.com/devzone/conceptd.nsf/webmain/732CEC772AA4FBE586256A37005541D3?opendocument&node=DZ52068_US
0 Kudos
Message 2 of 6
(3,994 Views)
Attached is an .llb file containing a vi called comparison, it will run and time the performance of the old exampleprogram and a new version of it...(run it and then run it with the code to test set to new...).

On my computer the optimized solution is 30 times faster than the original when the cluster array is 500 elements big...the bigger the array the more dramatic the difference in speed and memory usage...(play around with the array size to see the effect).
0 Kudos
Message 3 of 6
(3,994 Views)
Answer: Check the edge detection array size, if it's zero - don't wire that into the write spreadsheet function, instead feed it with an array constant containing the value you wanted: 0.0....OR use the open, write and close VIs to write 0.0 directly to the end of the file.
Message 4 of 6
(3,994 Views)
Hi Mads - I would like to see this in 6.0 if possible

Thanks, Paul.S
0 Kudos
Message 5 of 6
(3,994 Views)
0 Kudos
Message 6 of 6
(3,994 Views)