Timing a case structure

I have a push button with mechanical action set to switch until release(so that it gives an impulse boolean ON for 1 sec). I want to know a way so that the case structure remains active for a specified time after the push button goes off.
Thanks in advance.
Solved!
Go to Solution.

If you are interfacing to real sensors, you probably need to poll them at regular intervals and an event structure is not the solution.  A simple state machine would suffice.
You have several states, e.g.:
no sensor triggered
sensor 1 triggered
sensor 2 triggered
if you are in state 1, simply wait for any sensor to trigger and proceed to the relevant state
if you are in state 2, and sensor 1 triggers again, don't increment, because the person has left. if sensor 2 triggers, increment the count and go back to state 1.
if you are in state 3, and sensor 2 triggers again, ignore. If sensor 1 triggers, decrement the count and go back to state 1.
... or similar.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • Timing in case structure

    Its clear, i have a push button, when its triggered on, it should green the led (which occurs, no problems), but when triggered off, it should turn off the led immediately, (which doesnt happen), how is it done ?
    Solved!
    Go to Solution.

    try "Event Structure" for reacting on events.
    Attachments:
    event structure.vi ‏9 KB

  • Case Structure timing/ writing data to a excel

    Hi all,
    I have written a program that has the main functions of allowing the user to generate a random number between either 0-10 or 5-15 by using the labelled switch. I also have a control which can switch this function on or off. When this switch is true it will display the random number and also write this number to an excel spreadsheet every 1 second (I hope). When false this will stop displaying the number and hence not write the number to a file.
    However, I am having the following issues:
    1. Excel file is corrupt once I begin to write the generated numbers to the spreadsheet. (I am trying to write to a .xlsx file)
    2. Once I begin to try write the numbers to file, the elapsed timer only displays the time is 1second intervals rather than the full time.
    I changed the .xlsx file to a .csv file and this solved issue 1. but it only recorded one random number rather than the numbers that were generated in that time since switched on/off.
    Should I have the write to spreadsheet function in the timed case structure?
    Should the file path control be outside this case structure?
    Have I set up the write to spreadsheet VI correctly?
    If anyone could help with these issues that would be a big help.
    Thanks!
    Attachments:
    Random Number tester.vi ‏30 KB

    lneill65 wrote:
    There is still an issue with the elapsed time. Once I begin I turn the top boolean control to true, the elapsed time begins changing at the set time increment inside the case structure. Is there anyway to stop this from happening?
    Your elapsed time display is independent of the boolean switches because it is on the toplevel loop diagram. I am not sure why you place a five second wait inside the case structure if you want to write once per second.
    I am not sure why you have two sequential case structures since the calculations of the first structure is not needed unless the other case is also true. Why not place it inside the true case?
    You should also adhere to some basic coding styles. Avoid overlapping and floating objects, hidden wires, right-to-left wiring.
    If it is sufficient if the code reacts once per second, just run the loop with a 1 second wait. If you don't want to display a stale random number if the switch is off, place the indicator after the case structure.
    Here's a quick draft. Modify as needed. I probably would use an event structure, but let's keep it simple at this stage. You should also modify it so it does not try to write with an illegal path and also retain the selected path once selected. I propably would use a file dialog instead of a FP Path control.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Random Number testerMOD.vi ‏9 KB

  • Timed sequence with individual​ity for case structures

    Hello All
    The attached vi is one that I found by trolling on the forum, and made some slight modifications to it.
    If you look at the BD, you can see that the timing between the action of each case structure is the same.
    I would like to modify it even further and have each case structure have its' own individual time control.
    I can do this by using a sequence and place a wait in each frame.
    Would this method be both suitable and the simplest ( I have been giving some thought to using one case structure, but this solution eludes me at the moment)
    Regards
    Ray
    Attachments:
    TabAutoScroll.vi ‏16 KB

    Single case, single property node, single wait.
    Attachments:
    TabAutoScroll_mod.vi ‏9 KB

  • Execute Case Structure with Button Press Slows Down VI

    Hi -
    I'm fairly new to LabView, and I am having some issues with using a button to run a timed while loop.
    I am writing a VI that outputs a timed voltage pulse to an output channel on a DAQ; meanwhile, the VI reads and graphs the voltage on three input channels on the DAQ. When I use a timed loop that automatically executes when the VI runs, the program works. However, I would like to include a button so I can control the timing and number of voltage pulses sent to the output channel, instead of sending only one voltage pulse each time the VI runs. I have tried to do this using a button wired to a case structure. If the button is 'true,' the VI should send the voltage pulse. If the button is 'false,' the VI should keep the voltage at zero.
    When the button is 'false,' the VI runs normally; however, when the button changes to 'true,' the VI slows down and never sends the pulse. Why does this happen? How can I fix it?
    Also, how can I send the voltage pulse only when the value of the button changes?  I only want the timed loop to execute once when the button changes value.
    Thanks for any help or advice!!!
    Attachments:
    Sensor Read6.vi ‏85 KB

    The graph is in the same while loop as the case structure.  The while loop won't iterate until all the code inside of it has completed.  So the graph only gets updated once, and won't update again until the while loop iterates again.  If you need more continual updating you may want to put that in a loop that executes a couple of times, or completely separate your code into 2 while loops.  Is it that long of a wait considering your pulse length is 1 second?
    Your analog output code is just writing a voltage out (7 volts) until it eventually writes out 0 volts.  There is no reason for it to drop down unless you have some sort of electrical problem between your DAQ device and the device on the other end that is reading the 7 volts.  What are you connecting that analog output too?
    What if you don't use LabVIEW and try to test out that analog output using Measurement and Automation Explorer?  Does it do the same thing?

  • Need help with case structures- please help :)

    Hey all.
    I'm currently trying to program a infrared furnace. I'm setting a temperature, subtracted my set temperature from the actual temperature (thermocouple hooked up to SCB-68), and voltage is being sent to the controller of the furnace accordingly. However, I need to hold the set temperature for a certain amount of time. I need help programming this: when the VI reads the set temperature from the thermocouple, it results in a timer running down. When the timer runs down to 0, the While Loop ends. I'm thinking case structures is most appropriate, but if you have a better suggestion, please let me know.
    Thanks

    You should probably implement a state machine.
    The state machine would keep track of the temperature and making ajustments on a timely basis.
    There is a template of a state machine is you select under the File menu > New > From Template.
    You can also look under Help > Find Example > and do a search for state machine.
    There are lots of state machine examples on this forum, some of which may be quite useful.
    RayR

  • How do I delay 1 of many outputs exiting a case structure?

    I have a system here which is sort of a finite state machine, using digital I/O, I am monitoring a series of digital inputs which in turn form a binary number which is the input to a case structure. Depending on the binary string (number) that is read by the case structure, a particular series of boolean constants (T or F) exit through the case structure which are then used as my digital outputs (in my case they are controlling a series of relays). Basically, I have a condition where I would like one of the relays to be time delayed when switching in one direction, but not in the other. The problem is that when I do delay this bit, it also delays all of the bits coming from the case structure.
    i.e. all the relays are delayed. How can I delay just one of them?

    Well, I can't think of a really easy way. You could generate a delayed pulse on a counter output, instead of using a digital line. Otherwise you will need to keep track of the delay time in your loop somehow. The timing is only going to be as accurate (deterministic) as your loop rate, and will be operating system dependant. You may have some jitter. Attached is an example of a software delayed boolean indicator. Download both VIs.
    -Jim
    Attachments:
    delayed_relay.vi ‏30 KB
    boolean_trigger.vi ‏14 KB

  • Property node for case structure

    Is there any way to programatically pull out the list of cases (strings) from a case structure at run time?

    Thank you tbob and tst.  I do use the enum "trick" in other places (I once saw it used in an example somewhere) and I am nervous about the Selector Strings property available through scripting after reading about it on the LAVA forums site (I am a novice LabView user and I mostly didn't know what they were talking about).
    I have a VI that processes "tags" embedded in various text fields that many of my collegues use.  As an example we have a custom front end to the LabView simple error handler that processes our custom error codes and handles timed popups, writing to the device error log, etc.  The default behavior can be modified by inserting tags (<popup 60> for a dialog box with a 60 second timeout or <no device log> to supress writing an entry to our device error log) into the "source" string of a standard error cluster -- just like the <append> tag used by the Simple Error Handler.
    In most instances there are only a few tags so I just use a case structure in the "tag processing VI" to select the desired action indicated by each tag.  When people are parsing their strings for tags, they like to have a qick and easy way to test if a string is a vaild tag.  I provide a separate "validator VI" to do this.  I frequently add and remove tags from the case structure as things evolve, but I often forget to update the list of valid tags used by the validator VI or some one runs into an older version on another machine.  I wanted to have the vaildator VI access the case structure on the tag processing VI to get the current list of vaild tags.

  • Can I put a READ function in a TRUE/FALSE case structure?

    Hi,
    I have a vi that operates as controller for a mechanical system of motors.  There are several sensors of various types, that provide input to the vi, including encoders, whose period is being measured.  The attached vi is the encoder period measuring part. It measures 15 periods and tells me the average of the 15 with each loop iteration.
    In my application, the encoder period measurement is not needed unless the vi knows that ALL THE OTHER sensors in the hardware configuration are measuring values within the desired range.  For example, Sensors A, B and C should all measure between 5-10.  If they are all showing values between 5-10, then, we want the encoder value to read and display.  If only one of the sensors, say A, is measuring 12, then, we don't want the period value to READ or be subsequently processed.  So, it is easy to set up the sensors A, B, C, to give a TRUE or FALSE based on whether they are within range or not, and if all 3 are TRUE, then, that value can easily be passed to the case structure that holds my READ function for the period.  Is this a good way to do this?  The goal is to eliminate unnecessary execution time that the period READ function would consume, as well as all subsequent calculations that are performed on the period value collected.  The period data is of no use if any one of the other sensors is not in the correct range.
    If any one of the other sensors is out of range, we want to skip the encoder READ step altogether.  So, it is easy to structure a BOOLEAN in my vi as shown in the attachment.  If I do it this way, will it throw an error, or just skip the READ until the BOOLEAN is true again?  Is there a better way to prevent the READ from happening if one of my other sensor values is not within the correct range?
    Thanks,
    Dave
    Solved!
    Go to Solution.
    Attachments:
    forum JUly 18.vi ‏26 KB

    Sure, you can put a Read inside a case structure. For your application, just check that your sensors are all within range (Comparisons palette), then AND the T/F's and use the result of that for your case structure. (If you are already doing the in-range check, I can't see it here because you have 5 subVIs that I cannot open here.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • How do I use a Case Structure with Strings?

    I need to use a string list to set up a set of cases to be performed. Is it possible to tell a single case structure to do "a, b, c, and d, but not e or f" or "do a, c, d, and f, but not b or e" etc... when you use a string containing the cases to be used?

    Blackavar,
    A case structure will only execute a single case at a time. If you want to have multiple cases execute in parallel, then you would need to have multiple copies of the case structure and split the string apart and wire them to all of the needed case structures.
    This could be done with reentrant subVIs to run truely in parallel. Anther method would be to have 6 different case structures, all with 7 cases each. The 7 cases would be "a", "b", "c", "d", "e", "f", and "0". Your input sting will need to be built up so that it will always be 6 characters long and then split up so that each character goes to one of the case structures. You would have your needed code for cases a - f. Case "0" would do nothing.
    Randy Hos
    kin
    Applications Engineer
    Nationsl Instruments
    http://www.ni.com/ask

  • Can I use a formula node to start the execution of a case structure?

    Hi,
    I am working on editing a VI to make it much easier to understand (for colleagues and non LV users). For one reason or another, the VI's creators did not fully make use of the power of case structures and other structure types. In the application we need it for, the instrument cycles and repeats measurements on several objects. We are interested in measuring the motor currents for several motors in the system. As it stands now, for each sample object's run, there is a separate sub-vi diagram which displays its waveform trace and several indicators such as max current, time at max, etc. That code was contained within a T/F case structure and copied and pasted 20 plus times.... Obviously the vi became extrememly cluttered and needed a huge screen to see. The trigger for the current case structures is an EQUALS comparison between one input (which is the sample object counter; and this part I will likely leave unchanged since it makes a lot of sense already) and a constant which was defined 1 through 20+ for case. 
    I have since made one case structure and 20+ instances of that case and have labeled them (at the top selection box near the detent arrows) "1", "2", 3, etc. I am wondering if I can use a formula node to act as the "trigger" which sets each case structure running? I believe that a simple IF statement should work. Please see a snippet of my attempt at making this in C below.
    For the node, I defined X as the input and Y as the output. The input to the node, X, is connected to the sample object counter. The output, Y, is connected to the case selector of the case structure. My attempt at the code is below:
    int32 y
    For(x == 1)
       y = "1";
     For(x == 2)
       y = "2";
    etc, etc.
    Is that above code snippet correct? Do i need something like "ENDIF" or "end if" at the end? Does "y" have to be defined as "int32" or can it be something else?
    Thanks for the help!

    Is your formula node doing anything else besides what is shown?
    Why don't you just wire the value that is going into it at X directly into the selector of the case structure?
    Attachments:
    Example_VI_BD.png ‏2 KB

  • How can I pass data generated in a SubVI inside a Case Structure out of the Case Structure?

    Hello,
    I am using a USB 2701 to control a heater.  I have three SubVIs that are all working properly on their own.  I'd like to use an Enum to select which of the SubVIs is running at a given time.  The problem is that no data is passing out of the case structure.  How can I pass the temperatures and heater outputs acquired by the SubVIs to the main VI?  I've attached my some of my code below.  I can't attach more than 3 files, but you can see how the main VI is configured.  Like I said, the SubVIs are working individually, so you shouldn't really need to look at them.
    Thank you,
    CJones581
    Attachments:
    RampHeater6-21-07.vi ‏305 KB
    69_Heater_Case.vi ‏23 KB
    HeaterTCD6-21-07.vi ‏210 KB

    CJones,
    You might check a couple of things.
    Your HeaterTCD... VI has a While loop with a stop button condition.  HeaterTCD pass out values only when it finishes running.  If it doesn't pop open the front panel (which usually doesn't happen when running a SubVI) you could run into a stuck loop because you don't have access to the Stop button.  This could appear in the form of no data being passed out (because the SubVI never stops running).  The primary VI opens the HeaterTCD VI, starts it, and waits for the VI to finish and pass final values .
    Secondary note: Unless you want your SubVI panel (which probably isn't open when running the main VI) to update continuously, consider moving your Temperature Graph and Temperature oC indicators outside the while loop.  Pass final values to them via a tunnel, since the main VI will only read their values after the loop finishes running, anyway.
    It might help to add error management to HeaterTCD like you have for RampHeater.  If you connect error lines with Error Outs to your main VI, that will help tell if there is an error somewhere that is preventing info output.
    RampHeater SubVI has the same issue with the stop button.  It is also probably getting stuck in the While loop waiting for a manual push of that SubVI's Stop button.
    An easy way to test this would be to set up a logic circuit so that when the While loop iteration counter reaches a certain number, it registers True and sends it to the conditional.  I know this isn't what you want to do long-term, but if that lets your SubVI return outputs it means that the SubVI was just never stopping.
    Hope that helps.
    David C, Applications Engineering
    David C
    Applications Engineering

  • How can I have multiple inputs into the selector terminal of a case structure

    Hi everyone
    I have a question on how to wire multiple inputs in to the selector terminal of a case structure. 
    Currently, I have three switches, each switch determines different case. So if I switch the switch 1 is on, the numeric indicator will show 1. If the switch 2 is on, the numeric indicator will show 2, so on and so forth. However, the selector terminal will not allow me to wire multiply inputs into the case structure, I tried Bundle by Name, Bundle and Array to Cluster, but they did not work. I set the case structure with 3 cases, they are 1, 2 and 3.
    Could someone help me please. I have attach an image and the VI of the work I did so far.
    I have another question, is there a function which can toggle other switches to off when there is a switch has been toggled on.
    Thank you very much
    Tommy
    Attachments:
    Trial - Case Structure.vi ‏7 KB

    Tommy, attached find a cheeseball way of doing this that has given me a LOT of mileage over the years.  IT lends itself nicely to a couple of really good practices that NI recommend, but I have given you the bare-bones to "see under the hood".  
    The recommended practices:
    1. You can make this a nice tight sub-vi where you can put it into a core library of routines that you'll use over the years, even extending the logic to look only for changes, etc.
    2.  If you are thinking about Front Panel design considerations, you'll want to use arrays of controls where possible, as that's a nice neat way of containerizing your switch for both the FP and Block Diagram.
    Have fun.  I have TONS of these types of things, so feel free to PM me if you have any other needs.
    Wes
    Wes Ramm, Cyth UK
    CLD, CPLI
    Attachments:
    Boolean Switch Logic.vi ‏11 KB

  • How do i output multiple arrays from a case structure to create one larger array

    I currently have a vi that has one hardware input that i needed to take a measurement then be moved and take a similar measurement at a different point.  To accomplish this i used a while loop inside a case structure.  The while loop takes the measurement  and finds the numbers i need while the case structure is changed per the new measurement location.  I want to take the data points i have created in each case and output them into a single table.  I assumed to do this the best way would be to get the data from each case into its own built array and build a larger array but I cant get the information out of the case structure so that it all inputs at different places.
    thanks for your help
    Attachments:
    Array.vi ‏30 KB

    Hi Ross,
    attached you will find a solution for your table building problem.
    I would suggest thinking about program design - having the same case content in several cases doesn't make sense. I also would not want my user to press several stop buttons depending on choosen measurement...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    Array.vi ‏45 KB

  • How can i use a string as a control for case structure?

    my vi is reading data. the output is a string,how can a string can control the case structure? because the there's a constructed vi in that case structure that wll perform a tast after the main vi read.
    Thank You
    (Can you please give me a simple example how can do this)

    Try this vi. You shouldn't have any problems just connecting a string to the case selector.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor
    Attachments:
    string_to_control_case_structure.vi ‏10 KB

Maybe you are looking for