LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure input event question

I'm using a state machine to do some data decoding stuff. The default initial state is Idle, which checks an output boolean value from a FIFO buffer. If the boolean value is True, go to the next state; otherwise, keeps waiting. See attached "idle_noEventStructure.vi" for part of the code. But this method will consume a lot of CPU usage.

 

In order to save CPU time, I try to use an event structure in Idle state to wait for the output boolean value change. But I don't know how to add an event for the boolean value change. See attached "idle_eventStructure.vi".

 

Any one could help?

 

Thanks.

 

Download All
0 Kudos
Message 1 of 5
(2,631 Views)

MileP,

 

First off, in the state machine example you give "idle_noEventStructure.vi" the reason you may be experiencing poor performance (high CPU) is that your while loop is running as fast as the OS will allow sicne there is no timing implemented.  You should always you a "wait" function inside the loop (see attached file).  The loop should only run as fasat as you need to check the FIFO for new data.

 

If you want to use an Event structure you can use dynamic event registration to create an event for the FIFO data.  I have outlined this in the attached code.  It may not be eactly what you need but should give you he right idea.  An event is created for the boolean output from the FIFO and this event is registered with the event structure.  I am simulating the FIFO data using the "Producer Loop" and the Trigger control.  I am simply stopping all the loops when the Trigger button is pressed, but this is done using the event creation.  This method still requires a polling loop ("Consumer Loop" in my example) to check for FIFO data, but the lopp rate can be handled more carefully this way.  And I am not sure there is anyway around using some method of polling.

 

Dan

0 Kudos
Message 2 of 5
(2,609 Views)

Thank you very much, Dan.

 

I used Wait function in Idle for 100ms but forgot to put it in the attached VI. The reason I didn't want to use it because there is no certain time that the boolean value from FIFO will change. It's from UI and it depends on user clicking on a "connect" button. It may stay untouched for a long time, so I think Wait function still doesn't have a good performance.

 

I will try the dynamic event registration.

 

Have a nice weekend.

0 Kudos
Message 3 of 5
(2,600 Views)

If the event is being gerenated from the UI, then it is best to add an event in your event structure for the "Connect" button.  Even if you need the FIFO for storing the value of the Connect button you should not use the FIFO for generating the event.  It will be more efficient to have a Connect button event which will only fire when that specific event has been generated (see attached).

 

Also, are you running on an RT system?  Why are you using RT FIFOs if you are running on a non-RT platform?  

 

Dan

0 Kudos
Message 4 of 5
(2,594 Views)

Thank you, Dan.

 

I'm using VeriStand to create custom devices. The "Connect" button is available at VS WorkSpace, its value is stored in RT FIFO by VeriStand and decoded in custom device RT driver.

 

I think your solution of dynamic event registration looks good. There may be a way in RT driver to retrieve the "Connect" event as well, so I don't have to create a user event but just register the event only.

 

Thanks again.

0 Kudos
Message 5 of 5
(2,542 Views)