LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Where to put communication with NI USB-6212

Solved!
Go to solution

I’m building an instrument which is measuring on to soil samples.

Each soil sample is controlled by 1 state machine. Both state machine are using data from an NI USB-6212

The state machine is both going to send data to NI USB-6212 (opening and closing valves) and receive data from NI USB-6212 (pressure transducers).

The 2 state machines are not going to run parallel.

I been advised to use and attached vi’s.

Where to put the communication to the NI USB-6212?

 

 

 main.png

 

 

0 Kudos
Message 1 of 40
(5,443 Views)

The 2 state machines are not going to run parallel.

 

You start the two subVIs in my example, so the two state machines will actually do run in parallel! Maybe you mean that, you need only to make valve opening operation, etc, at once only using one state machine? So at a time, your user will only interact with one of the two Front Panels of the the 2 subVIs (and the other state machine will "sleep" in Idle mode?)?

You have different options here. Depends on your actual requirement. Could you specify a measurement scenario in details, so we can give better advice?

 

Right now just pure guessing, so I give one possible option which might be or not as you want.

What is the data acquisiton frequency, and how many analog input channels you need? And I guess you will use the two analog output channels to control the valves? Or the digital outputs?

 

I would just create an Action Engine (AE) which has four actions:

  1. Initialize USB HW
  2. Control Valve1 or Valve2
  3. Acquisite data from AI channels
  4. Close HW resources properly

Just to make it simple, only Initialize and Close the HW resources at the very beginning and end of the MAIN VI (so you do not need to reinit between state machine operations, but this depends on your actual needs).

When you have an actual State Machine running, you place the AE in the required case, so in the subVI. Actually it would be even safe to run the two State machines (2 subVI clones) in really parallel, since the AE eliminates race condition. But this can cause slight time delays, depending on your DAQ rate, number of samples, etc...

Here is a nice tutorial how to wrap up an AE, so you can even hide the reference wires inside:

http://forums.ni.com/t5/LabVIEW/Community-Nugget-4-08-2007-Action-Engines/td-p/503801

 

If you specify your requirements more in details, I can guide you further...

Good luck!

Message 2 of 40
(5,413 Views)

The 2 state machines are not going to run parallel.

 

Just some new thoughts. If you never wanna run the two state machines in parallel, why you need the two clones of your State Machine subVI at all???

If you want to operate only one State Machine at a time, just create a single MAIN VI, and you just do not need the complexity of dynamic VI calls, etc...

Your state machine should have an "Initialize" and a "Close resources" state. When you want to do a new measurement, you just specify the COM ports (DEV number, Valve port, etc...) via a pop-up dialog window or in the main FP itself, and you initialize your hardware. You do your measurement, save data to file, and in the end you release your HW resources.

Your whole project would be much simpler... I would just use in this case a producer/consumer design pattern with a single state machine...

0 Kudos
Message 3 of 40
(5,378 Views)

And I'll chime in--- (I do that from time to time)

 

Let us (Re-)define an Action Engine.  An AE that holds access to a specific piece of hardware is, in my lexicon, a "Resource Module"  

 

The trick is defining the "Resource" Smiley Wink

 

With the 6212- you get 1 AO Task and 1 AI task.  SO you need a RM for each and a method of getting or setting data into each.  That AI is simple- put the data out of the loop that controls the data rate on a Notifier!  

 

With the output you may need a SR that contains the current state and an input that changes the state of one or, more line(s) 

 

 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 40
(5,367 Views)

Thank you for your answers so far.

To be more specific I have 2 soil samples in which the tension (humidity) is going to be controlled. This is done by adding water from top of the soil sample with pump 1 and suck water out from the bottom into a vacuum container. The humidity is logged by using 5 pressure transducers, which is connected to the sample through so called tension meters.

I have planned to use 2 state machines – 1 for each sample.

 

The state machines are going to through several steps, and through all steps the vacuum in the plate under the sample have to be controlled and also the speed of the pump 1 have to be controlled and changed from time to time.

 

The analyze will take around 12 – 24 timer depending of the soil type. Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample.

 

What I have to control for each of the 2 soil samples

  • Log data from the 5 transducers, using digital output from NI6212, 1 time each 1 minute. From these reading decide whether the vacuum and pump speed of pump 2 have to be adjusted.
  • Control vacuum in vacuum container using 2 valves (digital output from NI6212) and 1 pressure transducer (analog input NI6212). I will have to read the signal from this pressure transducer every 1 sec .
  • Control speed of pump 1 (RS232)
  • Read balance (RS232) and if the reading of the balance is lower than 500 g start pump 2 (digital output from NI6212) and when the reading is higher then 5000 g stop pump 2.

 

I attached the main program as it is now. I am aware, I have to make changes.

 

Right now the reading of the 5 pressure transducer,  are done by a loop, where I open and close the connection to NI6212 for each reading. In the program the 5 pressure transducers are called tension meters (T1-T5).

The init values is so far stored in a cluster called Settling.

 

As I understand you I have to collect all communication with NI6212 in an Action Engine and only open connection in the start of the program an close in the end ?

 

0 Kudos
Message 5 of 40
(5,327 Views)

"Log data from the 5 transducers, using digital output from NI6212, 1 time each 1 minute."

I guess you wanted to write "using analog inputs" of the NI-6212? You cannot measure analog signal using digital outputs of a DAQ card...

 

The "Pressure.vi" is totally wrong. Get rid of the Sequence structure! Do NOT use the local variables! Are you aware you can just connect the wires to the other functions directly? I cannot comment on your regression calculations, since I do not know exactly what you want to calculate and how, but it also looks strange...

 

Comments on the "Voltage - Continuous Input.vi" :

  1. How do you connect your pressure transducers to the DAQ card pins? Usually differential connections are recommended. Your DAQmx Create Channel VI is using "RSE" input, and not differential. Check the pins of your card, and how you connected the wires. I recommend to connect them in a differential way. 
  2. You said you wanna sample from 5 channels, yes? The default value of the Physical Channel in your VI is set as "Dev1/ai0:5" This means 6 channels, not 5! (channel 0,1,2,3,4,5) You need to set the channels as "Dev1/ai0:4"
  3. You set the rate as 1000 Hz, and number of samples as 100. This means, the while loop iteration time will be 0.1 sec. After 1 second roughly, you will stop the while loop. Do not use the DAQmx Read to get 1D Waveform data, set it to get 2D Doubles! Much easier to work with 2D doubles. Also, your two other subVIs are not needed!
  4. I would reconsider the measurement, you could also do simply a Finite sample DAQ, for example 1000 samples per channel with a rate of 1000 Hz. After 1 second you will get 5000 samples in a 2D array, you wire this to a FOR loop, autoindex it out, and using a Mean function calculate the averages per channel. The code will be much simpler!

About the MAIN.vi:

  1. Totally wrong!
  2. Full of race conditions, local variables, and indicators/controls not connected to anything. I just cannot make a full list of the problems...You could make the whole code using a single While loop and an Event structure...You could use a Queued state machine, so you can Enqueue multiple states...You should study a bit more and look for State Machine examples. Also how to properly use Event Structures...

EDIT: but I wanna say, you are not far, but you need to refine/restructure some parts...

Edit2: there are also timing problems, like inside your Main.Vi, in the "Get data from tensiometers weights" Case structure, you use a "Wait" function with 1 second. But you have already the Pressure.vi inside this Case, which execution will take 1 second! It means that, this case structure will iterate at every 2 seconds only! Remove the Wait function from this case. But anyway, the DAQ subVI should be inside the State Machine loop...

 

EDIT3:

And the project is still not enough clear to me:

"Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample."

So if you have two soil samples, and you wanna do measurements on them, you need every HW elements doubled, yes? So you need 2 x 5 pressure sensors, valves doubled, etc? Correct?

 

 

 

 

 

Message 6 of 40
(5,306 Views)

I can see I have a LOT to learn Smiley Sad

And I also forgot to put out the scetch of the setup. I will return later. 
draft.PNG

0 Kudos
Message 7 of 40
(5,289 Views)

If these are all your HW elements in your experiment, how do you want to measure TWO soil samples at the same time???

 

"Therefore I have to have the two samples running at the same time, but not in necessary in same speed. By that I mean, that one step in the state machine can be repeated several times for the one sample but not for the other sample."

0 Kudos
Message 8 of 40
(5,283 Views)

First: thanks for taking the time to read my unreadable code !

Comments to your comments starting from the top:

You are right about “using analog inputs". Of course I want to use analog inputs to read signas form pressure transducers.

Pressure.vi:
I know it is not popular with local variable, but will it course any errors in this case – any race condition? The reason for using them, is that I found it more readable. But if it’s wrong I will get read of local variables. When is it legal to use local variables?

About "Voltage - Continuous Input.vi" :

  1. The pins in the 6212 is connected RSE. I will discuss with my hardware man to change to difference. This part was his decision. I trust he knows what he is doing, but I will check it with him. But isn’t difference mostly used in case of low voltage? I’m having voltage between 0 and 5 V
  2. The "Dev1/ai0:5" is the 5 pressure transducers connected to the soil sample and the 1 connected to the vacuum box. Should I have split the cannels up in "Dev1/ai0:4" and "Dev1/ai5"?
  3. Could you make an example? I’m aware about stopping the loop after 1 sec. What do you want me to do?
  4. Have a look at the snippet. Am I far from what you mean?

Main:

Edit:
I have a look at Queued state machine and state machine. I remove all locals.

Edit2:
“But anyway, the DAQ subVI should be inside the State Machine loop...”

Inside state Machine and in an Action Engine?

 

Edit3:

 I only showed half the set up. I have 2 soil samples, 2 “pump1”, 2 “pump2”, 2 balances etc.

 

 

finite input.png

0 Kudos
Message 9 of 40
(5,264 Views)

A Quick thought:

 

you seam to have 2 identicle sets of hardware that have very little overlap except at the DAQ device.  Why not buy two cheaper DAQs and simplify the whole problem of "Where to put the code?"  A pair of 6003's would even be a cost savings over the single 6212 and easier to implement and maintain.


"Should be" isn't "Is" -Jay
Message 10 of 40
(5,249 Views)