Jump to content

Recommended Posts

Hello,

 

I have created a vi that controls multiple writes (individually) by a switch. I have it so one individual switch controls one individual write (And is linked to individual clear, stop, error daqmx blocks). I do not think this is efficient as it takes about 4-6 seconds for the switch to actually write (True or False). 

 

So, I was wondering if someone could help me make my code more efficient so it would run a bit faster.

 

Thank you

Digital Outs fine.vi

Link to post
Share on other sites

That example can only write to one line at a time since the channel line entering through that while loop only contains one line (At least that is what I think it does).

 

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? Or could it be that I have a fatal flaw in my program that I am not realizing through this example and my program.

Edited by pkeny
Link to post
Share on other sites

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. 

Yes

 

 And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? 

No

 

Use a DAQ Assistant (1 for each device) in a loop.  Its a beginners friend (and sometimes advanced users).  It automatically sets up things for you so you don't have to worry about starting and stopping every loop.  If possible write to the whole port at the same time.

 

Hint:

post-549-0-59932200-1436994029.png

  • Like 1
Link to post
Share on other sites

Thank you guys for your answers,

 

After moving my stop, clear, and error daq blocks to outside the loop, the program now is able to switch on and off in about a second. 

 

I have been told using daq assistant is a very bad idea from other people. They tell me they always get errors and using daq accomplishes the same task as using daq assistant but more efficiently (I'm probably not using daq correctly so using daq assistant might be better). So, anyways I really want to learn efficient use of daq.

Link to post
Share on other sites

Thank you guys for your answers,

 

After moving my stop, clear, and error daq blocks to outside the loop, the program now is able to switch on and off in about a second. 

 

I have been told using daq assistant is a very bad idea from other people. They tell me they always get errors and using daq accomplishes the same task as using daq assistant but more efficiently (I'm probably not using daq correctly so using daq assistant might be better). So, anyways I really want to learn efficient use of daq.

 

When starting out with simple tasks, get a task to work with the assistant.  Then copy it and open the front panel to convert it to a VI and poke around in the Block Diagram.  Basically ready-made example code for your simple application which will help you understand how to make more complex operations.

  • Like 1
Link to post
Share on other sites

That example can only write to one line at a time since the channel line entering through that while loop only contains one line (At least that is what I think it does).

 

However, I think the reason why my code is inefficient is because I am stopping and clearing every time in my while loop. And my stop button logic has way to many not gates I could probably combine it into one not gate and send that out to multiple writes.

 

Is that something that would fix my inefficiency? Or could it be that I have a fatal flaw in my program that I am not realizing through this example and my program.

 

No, that example writes to many lines at the same time. Look at the channel input: Dev1/port0/line0:7. That means that the "channel" is 8 lines. The input being an array goes along with this. Writing all the lines at the same time should be more efficient that writing them individually.

Edited by infinitenothing
Link to post
Share on other sites

No, that example writes to many lines at the same time. Look at the channel input: Dev1/port0/line0:7. That means that the "channel" is 8 lines. The input being an array goes along with this. Writing all the lines at the same time should be more efficient that writing them individually.

Ah, thank you for clarifying that.

 

I believe I have made a much more efficient daq VI. 

 

However, I have a problem that I cannot figure out. In this VI, I have made a task that includes 8 lines. Then I have a boolean array of push buttons which will toggle the write data on/off. I also have a stop button that will end the while loop and stop writing. However, I want to make it so that the when the user presses the stop button, it will reset all the boolean switches to off (false).

 

So, in order to do that I made an event structure that contains a local variable for the boolean switches. However, for some reason when the timeout is at 5ms and I press the stop button it switches all the boolean switches to on (true). But, if I make the timeout at 1ms and I press the stop button it switches all the boolean switches to off (false), which is what I want.

 

Can someone explain to me why it is doing this, and maybe what would be a better way in accomplishing my task?

 

Thanks

Digital Outs.vi

Link to post
Share on other sites

To me, it seems that the logic is correct. When the stop button is pressed it returns a value of true. So I send it through a not gate, which will make it false. Then use that false value to initialize an array containing all false values with the same size as the number of elements in the switch array.

 

Next, I send it to the event structure which will execute if the stop value changes. So when the stop value changes, it will give a false value to the boolean switch array's local variable, which should set them all to false.

 

I cannot understand why it would set them to true. And especially I cannot understands why it would set them to true if I change the timeout constant to 5ms, versus 1ms.

 

What do I seem to be missing in my thinking?

 

But, regarding the picture with the conditional event logic. Can someone explain to me the shift register's role in that? I somewhat understand how shift registers work but I am unable to figure out how to incorporate them into a program. I know that they are used to pass data along a for loop, and they can store previous iteration values.

Edited by pkeny
Link to post
Share on other sites
  • Your VI is going to read the stop button (False)
  • then invert that (True)
  • make an array from that
  • Sit at the edge of the event structure for a bit
  • Lets say you press stop 2 ms into the event structure wait—you have an array of true waiting at the incoming edge of the event structure. That true is going to go into your "data array".
  • The next iteration starts, the "true" at the stop control is read at the begging of the loop, you wait and execute the timeout event

You can verify the above sequence if you are patient and set a really long timeout (~30 seconds) and turn on highlight execution

 

In the picture, the shift register is just a way to make the first iteration different from all the others. On the first iteration, the timeout is 0. All other iterations have a timeout of -1.

 

Most of us like trigger our actions based on events rather than letting the timeout lazily pick up changes as needed. To that end, you can create an event that will start executing as soon as your "data" array changes.

 

Also, your DAQmx clear and stop are being performed in the wrong order. Follow the examples.

Edited by infinitenothing
Link to post
Share on other sites

Thank you Infinite,

 

I could not figure out how to setup my event structure so that it will execute when my data array changes, and it will still set the local variable to false. However, I found a workaround using a case structure instead of an event structure. The case structure will occur when the stop button is pressed and then it will set the local variable to false.

 

Now, I have another question, hopefully this is the last one. 

When I open my program my boolean array is not initialized on the front panel. It is grayed out. So, the program will have an error since my task contains 8 lines, and when the boolean array is grayed out is has zero lines. 

 

How can I make it so when the VI file is opened, it will have all eight, false initialized boolean array, versus a grayed out boolean array. I have attached a picture of my front panel when I open the file.

 

 

 

 

post-53751-0-41252000-1437317840.png

post-53751-0-29554800-1437317847.png

Link to post
Share on other sites

Also, you have no wait in your loop. Check your processor use—It's probably at 100% (not a great idea) for one of your processors. Try ~100 ms.

 

If you still want to give the array event a try, here's an example of an event that is triggered by the array value change.

post-15670-0-33910500-1437411319.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Similar Content

    • By paulofelora
      I have a requirement that I thought would be SIMPLE, but can't get it to work.  I have a 9205 card in a little 9174 cDAQ USB chassis.
      My *intended* behavior is to wait (block) at the DAQmx Trigger/Start Analog Edge on, say channel ai1, until I get a falling edge thru, say, -0.050V.  So I have a little vi (that contains 2 parallel loops) that I want to sit & wait for the trigger to be satisifed.  I'm doing "routine" voltage measurements in another AI loop on a different channel.  I want this vi to run separately from my "routine" voltage measurements because I want the app to respond "instantly" to input voltage exceeding a limit to prevent expensive damage to load cells.  I was afraid that if I used either Finite or Continuous sampling to "catch" an excessive voltage, I might miss it while I'm doing something else.  Yes, yes, a cRIO real-time setup would be better for this, but this is a very cost-sensitive task... I just want to "Arm & Forget" this process until it gets triggered, whereupon it fires an event at me.  SO... I'm also reading the same voltage on channel ai0 for regular-ole voltage measurements, and just jumpering them together.  I did this because I read somewhere that you can't use the same channel for multiple DAQ tasks - I *thought* I would need to set up the tasks differently.  {but now that think about it, the setups can be the same...}.
      I've set up the DAQmx task the same as shipping examples and lots of posts I've seen.  I'm supplying a nice clean DC voltage to a 9205 card using a high quality HP variable power supply.  Using NI-MAX, I've verified that my 9174 chassis & 9205 are working properly.
      THE PROBLEM - When I run it, the vi just sails right through to the end, with no error, and an empty data array out.  No matter WHAT crazy voltage I give the "DAQmx Trigger.vi" (set up for Start Analog Edge), it never waits for the trigger to be satisfied, just breezes on through as if it weren't there.  If I set the Sample Clock for "Finite Samples", the DAQmx Read fails with timeout - makes sense, since the trigger wasn't satisfied.  What could I possibly be doing wrong with such a simple task???????
      So my fundamental misunderstanding still vexes me - does the DAQmx Trigger vi not block and wait for the trigger condition to be satisfied, like the instructions state - "Configures the task to start acquiring or generating samples when an analog signal crosses the level you specify"?
      I stripped my requirement down to the bare essentials - see the 1st snippet, the 2nd is my actual vi.  Any ideas, anybody?


    • By Zyga
      LAVA users,
      We are looking for alternatives for NI DAQ devices for industrial automation. Since NI has its devices mostly focused on advanced/high speed/high precison data acquisition/processing its prices are inadequate to simple automation tasks. 
      I would also say that NI PC based daq systems are expensive if need to be distributed systems (found this but still relatively expensive cRIO required).
      Just now we need to extend our compactDAQ based system with two DIO modules. We even have free chassis slots for this, but station that needs this IOs is few meters away from PC. How easier would it be if we could use single ethernet cable..  Ofcourse we can add another small cDAQ (what we probably going to do) but this is slightly expensive solution for our customer.
      Does anyone have some experience with 3rd party solutions? Any known daq devices vendors? Standalone ethernet daq modules?

      Regards,
      Zyga
    • By Gab
      Hello Everyone,
      Need some verification with daq program.
      I have one force sensor that connectd with my usb daq device. with this force sensor, unknown object is connected(hanging) and i want to find the mass of this object (F=ma) so i am taking continous sample and generate waveform graph. After the scaling, my waveform will be in Newton unit.
      my question is: if i take RMS of this waveform(1d Array data point) and divide by g (9.8 m/s2) then whatever value come is my correct mass? (F=ma).
      Thank you in advance
    • By neunited
      Dear All, 
      I'm new to this forum and I'm really glad I became a member.
      I am currently in the phase of designing a simple program which can control all the DAQmx channels using a configuration file (.ini) which is capable of change voltage range during mid-simulation. 
      At the moment my .ini file reads as follows: 
      [AO Channel 1] 
      Name = T2
      Physical Channel = cDAQ1Mod1/ao0
      Max Value = 10 
      Min Value = 0 
      [AO Channel 2] 
      Name = T3
      Physical Channel = cDAQ1Mod1/ao1
      Max Value = 10 
      Min Value = 0 
      [AO Channel 1] 
      Name = T2
      Physical Channel = cDAQ1Mod1/ao0
      Max Value = 5 
      Min Value = 0 
      [AO Channel 2] 
      Name = T3
      Physical Channel = cDAQ1Mod1/ao1
      Max Value = 10 
      Min Value = 0 
      My LabVIEW VI for the .ini script  is attached. I'm relatively new to using configuration file functions and I don't really understand where "Get Key Names" section should be wired to. I have placed a constant on it for now which reads the "AO Channel 1" but how can I get it to read all the channels in the .ini file.
      I am welcome to all suggestions here, I just want to make sure that I don't cause any problems to any of the channels and use best practice methods. All constructive criticism welcome!
      Thank you. 
       
       

      Read Configuration (INI) File (1).vi
    • By Atron100
      hi
      i have a question in basic understanding of update rate sample rate samples per buffer and cycles per buffer.
      i have DAQ 6343 and electronic circuit. 
      i'm using AO0 for generation sine wave at these frequencies 10Hz, 100Hz, 500Hz, 1kHz, 3kHz this signal enters to electronic circuit.
      and after conversion i must to measure two outputs of this circuit by AI2 and AI3.
      from my understanding of tech spec of the daq analog output update rate is 900kS/s and analog input update rate is 500kS/s
      as i understand if i have freq = 3kHz the maximum sample rate per buffer is 300 samples
      and if i have freq = 10Hz i can generate this signal with 90000 samples per buffer?
      for analog input the formula is the same?
      that meaning of cycles per buffer?
      which sample rate of AI i need to setup to measure data fast and accurately? 
       
      thanks for answers
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.