01-04-2021 02:59 PM - edited 01-04-2021 03:10 PM
Hello,
I developed a state machine that would run parallel with a DAQmx analog input device that would be used for a PID controller. However, on the state 'Acquire' there is an error for 50103, and I believe that it is because I have two tasks in the code. Is there a possibility that I can run this in parallel? My hardware is an NI cRIO with a NI 9205 with DSUB. Attached in my VI.
Thank you!
Solved! Go to Solution.
01-04-2021 03:24 PM
01-04-2021 03:48 PM
Hi Gregory,
Thank you for responding. I attempted combining them into a single tasks by adding the Mod1 ai4 on the physical channel constant, but to no avail. I am confused what do you mean by creating a new task for ai0 and ai3, and then adding ai4. The hardest part thinking about the architecture is where would the DAQmx read go if I were suppose to do this.
01-04-2021 03:52 PM - edited 01-04-2021 03:52 PM
It means add channel 4 to your task set up. Like this.

01-04-2021 04:10 PM
It looked like kepham wanted ai4 to be an RMS voltage measurement, so that's why I suggested using 2 "create virtual channel" VIs. When I use a simulated NI 9205 device though, it says RMS voltage is not supported. If all the channels are configured the same, then you can do it as RavensFan showed. If you need to configure them differently, you can chain the VIs together like so:
Note, this gives an error because it said Voltage RMS in the second function is not supported.
01-04-2021 04:34 PM
Hi Gregory,
Thanks for replying! Sorry the RMS Voltage is not supposed to be there! It is supposed to be AI Voltage, sorry about that! I have attempted to do what you did. But my question is, would I be able to still use the PID in parallel with the state hits "Acquire?" The goal is to use the PID constantly until the while loop ends, and won't stop when the state machine hits "Acquire." If I move the Read DAQmx outside of the for loop inside the case structure, won't it cause errors?
01-04-2021 04:58 PM
You probably want your state machine in 1 loop, your "VFD PID Loop" in a 2nd loop, and your Analog read in a 3rd loop. Then your only problem is interloop (interprocess) data communication. This can be super simple, using a local variable if you only need the "latest" data. Or you could queues, channels, functional globals, and several other ways.
I would just have the Analog read loop running very quickly, and depending on your data you might want to keep a running average of the last N samples and update a local variable.
01-05-2021 12:40 PM
Hi Gregory,
I did some research and implemented our idea on using 3 loops with interloop communication. I chose to manipulate local variables in order to do this. However, when I execute the code, the while loop the is in the center (with DAQ channels Mod1:ai0 and ai3) are not executing. Could there be a reason why it is not executing? I thought there would be parallelism due to having 3 separate while loops.
01-05-2021 02:00 PM
There sure is a reason. You have a wire which is an output from Loop 1 going to Loop 2. It doesn't matter what kind of wire this is (channel wires exempt), the second loop cannot run until the first loop stops and passes the data along. I recommend finding a different way to stop your loops. The simplest way is to have your boolean control on a "switch" mechanism and use local variables, but that will not provide the best user experience. An event structure would work well, you would have to wire a timeout to it at whatever period you want your loop to run at, 50 or 100ms for example.
01-07-2021 01:51 PM
Hi, Would the event structure be triggered by a stop boolean or user interface? Or can I use the event structure to interact with the enum constant I used for the state machine? And would the smarter idea be to place the event structure within the state machine at the final state?