09-22-2020 11:42 AM
I'm not sure I'm doing this right. The object of this application is to select a LED light using digital out then send an analog out at the same time. That voltage that will control the current to it. I am creating an array with different analog voltages to be indexed in a FOR loop. Also the digital out part of it reads an array of different selected LED lights. The two arrays should run simultaneously so a certain LED is chosen and a corresponding voltage is output to control the hardware that drives the source current for that particular LED. Right now it works somewhat but the two loops I use (a While loop and an inner FOR loop) run a few iterations before anything happens. Then the While loop is at 4 iterations and the FOR loop reaches 3 iterations then I finally get an analog and digital out. The loops run for a period of time at start before I get a actual analog output, then the digital out is not correct. I would need both to start a 0 iterations and produce outputs. Seems possibly a buffer issue maybe with the Analog. It shouldn't take that long to read the array to create the analog output. Seems the digital out is running for sometime before the Analog output gets going. I am using a USB-6341 DAQ and LabVIEW 2015. The VI I am including is a simplified example of my problem. I also need to do a Digital read of a port line but have not included it in this example. It should continuously monitor one line of a single port at all times. Help would be greatly appreciated.
Solved! Go to Solution.
09-23-2020 12:09 PM
Well I guess what the actual problem is that there is nothing controlling the "for" loop timing for the digital output until the Analog output runs. There is a delay or lag before the Analog output actually does output something. So the for loop timing is just running as fast as it can. That's what I'm seeing.
What I need is to set 3 Digital port lines right before the Analog outputs a value. Instead it's reading the array that sets the 3 digital outputs (indexing them) several times before the analog output executes. I am not sure of the right way to address this issue. Doe's anyone have any suggestions it would be appreciated.
09-23-2020 01:01 PM
Hi Brian,
@BrianSw wrote:
Instead it's reading the array that sets the 3 digital outputs (indexing them) several times before the analog output executes. I am not sure of the right way to address this issue.
Surely not.
In each iteration one element from "DO signal array" (aka "DC mode array") is indexed and written to those DO outputs. In the same iteration one waveform is indexed from "DC output arrays" and written to the AO channel.
It doesn't make sense to place the DAQmxStart in the loop: from 2nd iteration on the DAQmx tasks are already running when you write new data!
What exactly do you want to syncronize? Do you want to output those waveforms containing 200 samples for each DO write? Which timing should be applied?
09-23-2020 01:46 PM - edited 09-23-2020 01:49 PM
Yes, that's exactly what I want to do. Write 200 samples of waveform data every time I do a write to Digital out port. I thought by using the waveform data of 200 samples, with a DT of .05 sec. Waveform data can't exceed 20hz sampling rate. I thought it would control the timing of the loop just from indexing of it. The timing should be based off the analog waveform.
As I explained in the first post I select an LED light by specific color with the digital out, then analog out is going to set the source current through a hardware circuit. The purpose of the waveform is to apply different steps of source current for any particular LED light. The waveform data is generated or constructed by a different LabVIEW VI.
The whole thing needs to repeat until stopped. Hence why I put it in a WHILE loop.
The test.vi I uploaded is a simplified version of want I wanted to do.
I can use the "Call First function" on a case statement to only run the DaqmxStart only once I am aware of now.
09-23-2020 02:01 PM
Hi Brian,
@BrianSw wrote:
I thought it would control the timing of the loop just from indexing of it. The timing should be based off the analog waveform.
When the waveform should provide the sample rate information then you need to use a different instance of the DAQmxTiming function!
@BrianSw wrote:
As I explained in the first post I select an LED light by specific color with the digital out, then analog out is going to set the source current through a hardware circuit.
Then you need to apply THINK DATAFLOW to enforce "first DO, then AO"!
Use the error wire to chain both DAQmxWrite functions!
09-25-2020 01:05 PM
Well thanks, I finally figured it out with some of you help of course. To get it work in the for loop after the Analog write out I placed a start task, then a Wait Until Done, then a Stop Task. That didn't exactly fix the problem completely. What did, was removing the Shift Registers for the Analog Out Task and the Digital Out Task and replaced with regular tunnels. Still haven't figured why the Shift registers were causing an issue with the way the for loop was running. I indexed both arrays as before going into the For loop. I didn't need to use the VI's error lines to direct which VI's ran first. They just work the way I wanted them to with out doing that.
09-25-2020 01:24 PM
@BrianSw wrote:
Well thanks, I finally figured it out with some of you help of course. To get it work in the for loop after the Analog write out I placed a start task, then a Wait Until Done, then a Stop Task. That didn't exactly fix the problem completely. What did, was removing the Shift Registers for the Analog Out Task and the Digital Out Task and replaced with regular tunnels. Still haven't figured why the Shift registers were causing an issue with the way the for loop was running. I indexed both arrays as before going into the For loop. I didn't need to use the VI's error lines to direct which VI's ran first. They just work the way I wanted them to with out doing that.
If I'm understanding you correctly that doesn't sound right at all. Could you share your code? Your start task should be outside the loop, and your stop task should be outside the loop. You don't need to call these every time. Also, what shift registers are you talking about? I don't see any shift registers in the code that you shared.
10-08-2020 11:33 AM
Sorry I didn't check if there were any more replies to this. As soon as I can I'll provide code for you to see what I was talking about. I still have some issues, especially with loop timing. My loop is taking longer then it should.
10-08-2020 12:23 PM
It was confusing doing an analog write out because it's different then doing a read.
It seems that you cannot put a Task Start before an Analog Write because you would get an empty buffer error. So, within a loop I have a DAQ Write.VI (waveform), then and Start task, a Wait Until Done VI, then a Stop Task. I am constructing a basically an arbitrary waveform with another VI that I wrote, then outputting that waveform with another VI at the same time as I need to set specific Digital output port lines to coincide with my analog waveform.
As I mentioned the whole purpose of this is to set a digital port line for 1 of 4 LEDs colors (Red, Blue, Green, Amber). And then output a specific voltage from an analog out port to control source current to the chosen LED. This would run in a continuous loop until stopped. So I can create 2 arrays ahead of time, one for digital out control of which LEDs I'm going to turn on or off, and another array that contains voltage out values to for the analog out.
In the program I read through both arrays at the same time, Set the Digital port with one and Analog out value with the other. After the Analog out has completed the duration that I have it set for (say 500ms), Then it indexes to the next set of values in both arrays. After both arrays are read completely the loop starts over again.
It's really not a complicated task thinking about what I need to do. It's just difficult to figure out the best way to implement it. I have it working now but my loop that does the reading of the arrays and outputting of the digital port lines and Analog out channel it taking too long. It is messing up my Analog out timing. If for instance I want a specific LED to turn on and stay on for 500ms it winds up staying on for 560ms.
I'll create a better example of what I have now and upload when I get the chance in a day or two.
10-08-2020 01:25 PM
Ok, here is a simplified example of what I have. It sets a specific digital port that chooses a blue LED in external circuit using a multiplexer with a 3 bit address.
It at the same time sets my ch0 analog out to a specific voltage that sources current to that LED through an external circuit . The LED is suppose to illuminate for 500ms, then go out for 500ms. The cycle then starts over. This is working except for the fact the LED on and off time measured are 560ms not 500ms on a scope.