LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW messes with wave generated by Python on DAQ

Solved!
Go to solution

Hello,

 

I'm currently using the NI USB-6259 DAQ to provide voltage I/O to another device. Most of this is done with a LabVIEW program just setting and reading voltages, while I have a Python script generating a sin wave as an output on pin AO3. The problem is, whenever the LabVIEW I/O stuff is running, the wave appears flattened.

 

This happens ONLY when the LabVIEW program is running, no matter what calls the Python script. But I don't mention AO3 at all in my program, so I don't see how any of the I/O stuff could possibly interfere.

 

Correct Wave:

 

scout3682_0-1720792740839.png

 

Wrong Wave (while my VI is running):

scout3682_1-1720792800360.png

 

Any advice would be greatly appreciated.

Download All
0 Kudos
Message 1 of 10
(1,974 Views)

Just to confirm, you share a hardware resource between two programming languages? 

 

How many AO tasks can your device handle ? 

0 Kudos
Message 2 of 10
(1,965 Views)

Yes, I'm using the same DAQ device with both LabVIEW and Python, just not the same pins. There are 4 separate channels for AO, all of which I'm trying to use. AO0-AO2 are just setting basic DC voltages.

0 Kudos
Message 3 of 10
(1,959 Views)

Most of these USB DAQs can only handle 1 task. That is, you can make an Analog Input task in LabVIEW and run it, but you are then precluded from making another AI task either in LabVIEW or any other programming language while it is running. This is due to the number of timing engines in the device. If you are already using the AO in LabVIEW, you cannot make another AO task in Python, even if it is a different channel. You only have so many resources and they cannot be shared.

Message 4 of 10
(1,918 Views)

Finally looked at your code. Since on the LabVIEW side it looks like you are doing software timed output, you should be able to handle multiple tasks. Looking at your scope traces, it looks like the frequency is shifted to lower frequencies, rather than being "flattened".

 

Your LabVIEW code leaves a lot to be desired:

  1. You are spinning your loop as fast as possible, this probably interferes for the Analog output from Python.
  2. Your outputs are mostly DC why do they need to be updated as fast as possible.
  3. You should get roughly 100 ms of data from your Analog Input loop.
  4. Why not generate the sine wave in LabVIEW?
  5. Are you familiar with State Machines? I think I would rewrite this to use the JKI State Machine to handle everything. Use DAQmx Events for the Analog Input.
Message 5 of 10
(1,872 Views)

This is my first LabVIEW project, so I'm not very familiar with the software. Sorry if I'm a little slow.

 

1. I'm assuming this can be fixed with the JKI state machine.

 

2. I suppose they don't - I'll take them out of the loop.

 

3. Why 100ms?

 

4. I thought Python would be better since I'm more familiar with it and I need the wave to be configurable. Specifically, I need the user to input the DC vertical shift, while the amplitude is a function of that shift. I couldn't figure out how to do that with a DAQ Assist.

 

5. I'm not very familiar with state machines. It looks like JKI provides more control over the loop, but I can't tell if it allows configuration of the wave itself.

 

Thanks.

0 Kudos
Message 6 of 10
(1,845 Views)

@scout3682 wrote:

 

1. I'm assuming this can be fixed with the JKI state machine.

You can download it form VIPM, I'll see if I can whip something together quickly.

 


@scout3682 wrote:

 

2. I suppose they don't - I'll take them out of the loop.


If you have a State Machine, you can respond to an Event, like the value changing, then initiate a change, They can still be in a loop.

 


@scout3682 wrote:

 

3. Why 100ms?

There is overhead with each DAQmx call, 100 ms is a good compromise.

 


@scout3682 wrote:

 

4. I thought Python would be better since I'm more familiar with it and I need the wave to be configurable. Specifically, I need the user to input the DC vertical shift, while the amplitude is a function of that shift. I couldn't figure out how to do that with a DAQ Assist.


Look in the example finder. Unless you need to use Python, I suggest staying with one Programming language, either all Python or all LabVIEW.

 


@scout3682 wrote:

 

5. I'm not very familiar with state machines. It looks like JKI provides more control over the loop, but I can't tell if it allows configuration of the wave itself.


You make a state that configures the wave.

0 Kudos
Message 7 of 10
(1,832 Views)
Solution
Accepted by scout3682

Attached is a quick example of your original program in a JKI State Machine. Download JKI State Machine from VPIM in order to run modification.

  1. You need to have labels for your controls!!
  2. In your original you are writing to and trying to read the same digital line; you cannot do that. I changed the write to a different digital line.
  3. Tested on a simulated instrument; may be some differences with a real instrument.
  4. Changed your A/D conversion to sample rate; set it to an appropriate value, right now it is 1000 Sa/s.
  5. Have not implemented the sine out, see if you can do it. It may work in Python now since the loop is not spinning so fast.
  6. Lots of improvements can be made.
Message 8 of 10
(1,820 Views)

The program works great. Even while running the Python script, the wave looks exactly the same. Thanks!

0 Kudos
Message 9 of 10
(1,783 Views)

Glad it's working. It is trivial to add some states so you can do the output in LabVIEW also. You should give it a try.

0 Kudos
Message 10 of 10
(1,747 Views)