LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Repeated sequence in a case structure

Solved!
Go to solution

Hi,

 

Thank you for your help. Here is my actual code. 

 

Initial mass is recorded just for once and then kept as a global variable. It is not read always. I am new to Labview so I do not know much about it. I will check "feedback note" and see if that works for me.

 

255/80 is a good idea. I will change it.

 

The screenshot was a previous edition, it is not broken now and works fine. But, I've never thought of CPU usage since this is a relatively simple task.

 

I used that shift register to store the filepath for the array. I think I should link the file path out of the while loop to the shift register and then link it to "write to spreadsheet file.vi" Right?

 

 

 

0 Kudos
Message 11 of 24
(2,098 Views)
Solution
Accepted by akifyalcinkaya

OK, you code is still a jungle with way too much duplicate code. Here's a quick draft how it could be organized better, eliminating duplicate code and using arrays wherever possible.

 

(This was modified blidly, so there are probably quite a few errors. I cannot test. Modify as needed).

 

Some points:

  • Write to spreadsheet file is inefficient, because it opens and closes the file with each call. Open the file once and append using lowlevel functions instead. Close file when the loop is done.
  • Writing the tick count to a file is pointless. It is random. Either calculate the elapsed time from [i] or use relative tick counts.
  • Shouldn't the "recod initial mass" button be latch action?
  • You should probably place the wait on the toplevel loop diagram.
  • Controls belong on the toplevel loop diagram, not inside case structures (performance issue)
  • Are you sure the subtraction is correct? Shouldn't the inputs be reversed.
  • All your communications are sequential, so don't run them in parallel.
  • If you show the digital display of the chart, you can eliminate the "output 1" indicator. same thing!
  • You could re-use the valve controls also as indicators, eliminating the green LEDs. (update them via a local variable as needed).
Message 12 of 24
(2,079 Views)

Thank you for the revision. It seems a little complicated for me but I will try to understand it. Looks very nice 🙂

0 Kudos
Message 13 of 24
(2,050 Views)
I think all I did was simplifying. 🙂
0 Kudos
Message 14 of 24
(2,038 Views)

Hello altenbach,

 

What do you mean when you said,

 

 "Writing the tick count to a file is pointless. It is random."

 

I don't understand the random part?

 

Thanks

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding. Proverbs 4:7
0 Kudos
Message 15 of 24
(2,027 Views)

The tick count outputs a U32 value that represents the number of milliseconds elapsed since the sytem has started. once it runs out of numbers it starts again from zero. Unless you start your program exactly after a defined time after the computer has started, the value will be random.

 

In order to get elapsed time, you need to take the difference of two tick values

Message 16 of 24
(2,015 Views)

I am trying to understand your revision and learning a lot from it. I would be very happy if you could answer the following questions:

 

1 - You put a delay for the main loop, but this also reduces the data frequency of the balance. I just want to put a delay to adjust the on/off interval of the valves. In this case, shouldn't it be in the case structure (i.e., Case#2)?


2 - The "for loops" are used to write data to Arduino pins. How many times are they executed ? I see that "N" is not defined.

 

3 - 255/80 is valid for 2 pins of Arduino but one of them should be 255/130. How would you change this?

 

4 - In Case#2, you created a 1D boolean array and it looks nice but I cannot do it that way? How did you do that? (see the picture)asddffff.png

0 Kudos
Message 17 of 24
(1,991 Views)
  1. Your delay inside the case will delay the entire outer loop whenever that case is active, making the outer loop rate variable. How fast do you really need to read the data? If you want to toggle at a different rate, you need to use a seperate loop.
  2. They execute for each element in the autoindexing array. No need to wire N. The number of iterations is fully determined by the shortest autoindexing array input. LabVIEW 101!
  3. You can create an array of calibration factors and autoindex over them instead. same difference (See picture for an example).
  4. What can't you do it that way? Drop an empty array container on the diagram and drop a boolean diagram constant into it. Set all desired elements to the desire value..

 

Message 18 of 24
(1,980 Views)

Thanks for the help! If you look at my replies, I have just 11. I think this shows that I had no idea about Labview, meaning I even don't have Labview 101 knowledge. Sorry for taking your time but I learned a lot from you. Thank you so much again!

0 Kudos
Message 19 of 24
(1,966 Views)

Hi altenbach,

 

I have another problem. I thoguht about it for a few days and tried hard but couldn't do it. I need to add another valve (V3) to release the pressure instantly before Valve 2 is opened (regarding case #2). So it should be like the following:

 

 

V1 = open,    V2 = closed, V3 = closed                                                              (duration = 100 ms)

V1 = closed, V2 = closed, V3 = open and closed                                            (duration = 1-10 ms "like a latch action")

V1=  closed, V2 = open  ,  V3 = closed                                                              (duration = 100 ms)

 

V1 = open,    V2 = closed, V3 = closed                                                              (duration = 100 ms)

V1 = closed, V2 = closed, V3 = open and closed                                            (duration = 1-10 ms "like a latch action")

V1=  closed, V2 = open  ,  V3 = closed                                                              (duration = 100 ms)

....

 

I may even need to change the duration of various stages but I am not sure about that. How would you do that?

 

Thank you!

 

0 Kudos
Message 20 of 24
(1,891 Views)