LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Please Help!?!?

Can anyone open the attached and tell me what I'm doing wrong?  All I'm trying to do is read in data from a spreadsheet (1khz example attached), generate two analog output waveforms (from columns B and C) and a digital output waveform (column D) from the values, and then "run" the profiles (with tight time synchronization) while also recording 6 channels of analog input data.  The behavior I'm seeing doesn't make sense and no matter what I do the measured time the loop is running never matches the duration in the input spreadsheet (in this case it should be 10 seconds exactly).

 

I have an 8-slot cDAQ chassis (9189), a 9202 analog input module, a 9264 analog output module, and a 9403 digital IO module.

 

Thanks for your help in advance!

Download All
0 Kudos
Message 1 of 6
(2,277 Views)

You'll get more eyes on your code if you back-save to an earlier LabVIEW version.  A lot of us aren't using LV 2019 yet.   Go to the File menu, pick "Save for Previous Version..." and then pick 2014 or so.  A lot more of us will be able to to have a look.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 6
(2,215 Views)

Great suggestion - attached!

0 Kudos
Message 3 of 6
(2,190 Views)

As a quick suggestion, I'd guess that you probably never want to both be loading and running a profile. As a result, you could reorganize your code to use something along the lines of a State Machine to go from an Idle -> Load -> Run -> Idle or similar cycle. At the very least, you can set your buttons to be Mechanical Action = Latch (when clicked, released) so that they reset themselves to false when you've read.

 

At present, you're reading the same data over and over again whilst the "Load" is true, then Writing over and over again whilst the "Run" is true (if this takes 10 seconds, maybe you're cancelling out of it by clicking again during the run, but still...) Sorry - missed the property node setting false. None-the-less, you could avoid this by using a different mechanical action.

 

The default setting for "sample mode 1" (AI) is "Finite Samples" and you don't set the number of samples. Is this typically set to Continuous when you're acquiring data?

If so, I'm not sure what's wrong. As a follow-up question, is the time measured always less than 10s? (is it usually 1s?)


GCentral
Message 4 of 6
(2,175 Views)

Looking at your code, I think I know what you want to do, but it is sometimes a good idea to "write it down" (Document First) and explain it to us.  Here's what I think:

  • You have a Delimited Spreadsheet that has Time, two Analog Signals, and a Digital Signal that should represent 10 seconds of Analog and Digital Data.
  • You want to read this Profile, then "play" it into two Analog Output Channels and a Digital Output Channel, while simultaneously sampling from an unspecified number of Analog Input Channels.
  • It is not clear if you intend a fixed order to these two steps (though it seems "logical" to read the Spreadsheet before playing its Profile and collecting data).  
  • While collecting data (which should take 10 seconds), there does not seem to be any simultaneous output, only a Chart display after all the data are collected.

If you code an Event Loop to handle the "Load Profile" and "Run Profile" buttons, they could serve as a "Producer" (of Messages) for the Message Handler loop (acting as a Consumer).  To force the user to push Load Profile before Run Profile, start with Run Profile not visible.  Make both Buttons the Rectangular buttons (like Stop) that are Latch when Released (any Boolean button can be set this way, but by a convention spanning at least a decade, square ones latch and round/oval ones are Switch when Pressed).

 

The Message Handler should have several Messages to which it responds.

  • Initialize DAQ (which could be automatically sent in when the program starts) sets up the three DAQ devices and saves their Task lines in Shift Registers.
  • Load Profile might have several sub-Messages, particularly if you want to query the User for the Profile to use.  It should Load the Profile and do any displays, make the "Run Profile" button visible, and save all relevant parameters in Shift Registers in the MH Loop.
  • Run Profile should run the Profile.  You may want have additional Message cases to separate starting the Profile (starting the Clock and the DAQ devices), collecting data (you currently have a While loop, but it looks like the DAQ devices should be able to do all the timing for you "at once", no need for checking "am I done?", and possibly a final Message to process/display/compute timing for the Run)

Use the Event Loop to send the Message Handler the Load Profile and Run Profile Messages when you press their buttons.  You should also have it process the Stop button and send an Exit (or Stop) Message to stop the Message Handler (and it should also stop the Event Loop).

 

Note that this scheme gets rid of all Local Variables and also removes the need for any need for Value Property nodes for variables, substituting Wires in Shift Registers to hold "Variables", and using the Controls to initialize them.

 

While you are at it, you don't need any Sequence Frames in this routine.  You are doing most of the sequencing using the Error Line (good!), and can do more using the Message Handler's "Message" states and Shift Registers.  Let Data Flow work for you.

 

Since you are using DAQmx, and your DAQ devices (typically) have much better clocks than your Windows PC, you should not need any timing functions in this code (except, if you want, a timer to verify that playing a 10-second Analog Signal to an Analog Output device at the same sampling rate used to acquire it does, indeed, take 10 seconds).

 

Don't be afraid to "hide messy details" in a sub-VI (for which you create a VI Icon, using the Icon Editor, possibly a Square with White interior on which you write 2-3 short words that say what the VI does).  I'll admit your code is simple enough that you might not need such encapsulation (yet).

 

Bob Schor

 

 

Message 5 of 6
(2,120 Views)

Thanks guys!  The state machine suggestion is awesome - I was first exposed to labview about 15 years ago (briefly) and a number of things are starting to come back to me...like the ability to make state machines!  I’ll digest the great suggestions here and report back tomorrow. Thanks again!

0 Kudos
Message 6 of 6
(2,096 Views)