Im trying to control two servo motors with the NI USB X 6341 at the same time. One pulse width cable is connected (servo 1) to AO0 and the other (servo 2) is connected to the AO1. Both servos are connected to the same ground and 5V source.
The problem when running the vi is that the motors dont work simultaniously, only one works at the time. When I run the VI only 1 motor works, when I stop it and run it again the other one works. Is there anything wrong with this VI?
Yes, there is something wrong. You simply cannot have more than one task for an analog output. This has been discussed often and the solution is to have a single task with both channels. You can only use a single task because of the shared clock. This also means you have to have a single rate.
I tried to do it with a single task but the DaqMX Create Channel needs a physical channel input.. So I don't know how to do it with a Task.. Could you help a little?
You can simply select the Browse option and shift-click or ctrl-click to get multiple channels. To enter manually, the syntax would be Dev1/ai0:1 for consectutive channels or Dev1/ai0,Dev1/ai2 for non-consecutive channels.
Then how would the VI know which channel to use for which servo? I don't really get how to work with tasks:(
You should know which analog channel is connected to which servo. Your older code shows that you do so I don't understand the question. The only difference is that you would have an array of waveforms passed to the DAQmx Write. The DAQmx Writes have to be changed to NChannel. The first element in the waveform array is the first channel in the physical channel control, the second element is the second channel, etc.
p.s. Clean up your block diagram. You have hiddent functions and wires going every which direction.
You would have one DAQmx Create Channel (unless the settings are different), one DAQmx Timing, one DAQmx Write (Analog 1D Wfm NChan Nsamp), one DAQmx start, one DAQmx Clear.