Problem with two parallel While loops

I have a serious problem with controlling two parallel While Loop. Here is the deal:
I have written a VI to send a series of commands called Cycle through Serial Port to a custom hardware. One of these commands is setting motor pressure by sending it's command and changing it's voltage. After setting desired pressure I have to read and control motor pressure, again through serial port in a parallel loop. There is a Pressure Sensor in system and I can obtain current's motor pressure by sending a command and receiving pressure value. In the first While loop I send some commands to hardware including Pressure Setting Command trough a state machine. In the second While Loop I read pressure value and then decide to increase motor voltage or decrease  it. Now the problem is in communicating these two loops. In cycle after "Init" state when state reaches "Pressure 2 Bar" motor voltage will increase. Meanwhile I have to control this voltage in parallel While Loop. As you can see I used Local Variable to communicate between these two loops. The problem is that loops are not synchronized. Specially when I switch to "Pressure 3.8 Bar" state during cycle running control loop (second while) is still working based on "Pressure 2 Bar" state not 3.8 bar. Because of this motor pressure goes to 3.8 bar for a sec (becuase of  "Pressure 3.8 Bar" state) and comes back to 2 bar (because the second while still has not gotten that new state,most probably cause of all the delays in the loop)  and after couple seconds it goes back to 3.8 bar.
I really don’t know what to do. Is there a way to fix this? Or I should consider a better way to do this?
I went through Occurrence Palette but couldnt figure out how to embed that in the VI. 
Sorry for my poor English. I attached VI and it's subVIs as a LLB file. I can explain more details if somebody wants. 
Attachments:
QuickStartCycle.llb ‏197 KB

I make it a point to NEVER have a WAIT function inside a state machine.
It sort of defeats the purpose, which I define as "Examine current state; decide whether you've met the conditions to advance to another state, then get out".
For example, I have a single state machine VI controlling four identical instruments, via TCP connections.
For some functions, that means issuing a command, waiting 60 seconds, then reading results.
If I waited INSIDE the state machine, then it's tied up waiting on one device and cannot handle any others.
Not a good plan.
To handle this, I have a loop which calls the state machine.  After issuing the command, the state goes to "Waiting on Response", and there is a target time of 60 seconds from now.
It's called over and over in that state, and each time merely compares NOW to the target time.  If NOW is past the target, then we read the results.
the state machine can tell the caller when to call back; that's how I distinguish between an urgent need and nothing-to-do.
By having the CALLER do the waiting, instead of the state machine itself, the state machine is free to handle another device, or do something else on the same device.
You should be calling the state machine over and over and over anyway.  So, have the state machine "control the pressure" on every call, and THEN examine whatever state it's in.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com
Blog for (mostly LabVIEW) programmers: Tips And Tricks

Similar Messages

  • Problem with two monitors while using Photoshop, windows move from 2nd screen to 1st screen.

    Problem with two monitors while using Photoshop, windows move from 2nd screen to 1st screen.
    I saved a new workspace and it did not help.
    No problem before I went to Maverick.

    I found the fix, go to System Preferences and open Mission Control and uncheck the box to keep monitors as they were (When switching to an application...........)

  • Problem with DAQ in while loop and Graphs

    Hello,
    I'm new here so I apologize if I posted this on the wrong board  
    This is my "situation":
    I need to make a simple PID controller which takes information (process variable) from an outside source (a NI's DAC connected through the USB port ) which is accomplished using NI-DAQ as an input, and the PID's output goes to the second NI-DAQ which is also connected using DAC to an actuator which in my case regulates the air pressure. (VI attached)
    My problem is the following.
    Both of the NI-DAQ I placed using DAQ Assist, require to be in a while loop.
    -If I place them in separate loops, I have the problem of passing information between the Input NI-DAQ and the PID, and also between the PID and the Output NI-DAQ.
    -If I place them both in one big loop, an error occurs saying that the selected buffer size is too small (Error -200609).
    The timing settings for the DAQ's N samples, 100 samples to read at the rate of 1k (I also tried with Continuous samples and many different combinations of Samples to Read an Rate but without success).
    Should I wire them with the same dt(s)?
    The other thing I need to do (I'm also writing it here in order not to open new topics) is show the following 3 signals on a Graph (process variable (dynamic data type)(range 4mA - 20mA), PID output (double)(range 4mA - 20mA), and the Set Point (double)(range 0 to inf))
    Firstly, is it possible to show the first two on a scale from 0 to 100 without changing the PID's output which needs to be 4-20?
    Secondly, which graph should I use if I have different data types? (I tried the Waveform Chart, and succeeded in showing the first two; the third just messes everything up)
    I would also have to make a legend explaining which signal is which (I see that this is possible with the Mixed Signal Graph).
    I know this is probably too much to ask, but I'd be grateful for any help
    Thank you in advance
    Attachments:
    PID while.vi ‏100 KB

    My problem is the following. Both of the NI-DAQ I placed using DAQ Assist, require to be in a while loop.
    -If
    I place them in separate loops, I have the problem of passing
    information between the Input NI-DAQ and the PID, and also between the
    PID and the Output NI-DAQ.
    This is the best option---Use QUEUE or Functional global or something else to tranfer the data to and fro
    How  do I make that QUEUE or Functional global?
    -If I place them both in one big loop, an error occurs saying that the selected buffer size is too small (Error -200609).
    Have
    you tried increasing the buffer? Is the acquisition happening
    parallelly (means to say the first DAQ not wired (error terminal) to
    second DAQ)
    Well the buffer is, at least how I understood it, the option Number of Samples when in Continuous Samples mode. Concerning the parallel acquisition, do you mean I should wire the error ports of both of the DAQs?

  • How to start/stop 2 parallel while loops

    My question might be simple to answer for experts, but as a Labview beginner would be great to receive your help:
    I hav a VI with two parallel while loops. The first loop runs in a tact of 100 ms to aquire voltage, speed and to output a speed setpoint for a motor in the same tact, read from a table.
    Finally all values are written to a log-file.
    The question: As soon as I run my VI, data logging starts too and my motor runs. How can I implement a button to start all loops parallel, and how can they be parallel be stopped too if I want to stop measurement? Tryed to set a local variable for both stop buttons but it didn´t work.
    Thanx to all, Markus
    Attachments:
    screenshot.JPG ‏74 KB
    Measure and log data.vi ‏147 KB

    SnowMule wrote:
    Starting the two is easy; use the error cluster to enforce dataflow.
    Stopping them is a little trickier; the code you have now isn't very expandable so I'd recommend finding a different architecture.  A notifier functions like a queue with a size of 1, a queue works well for sending commands/data between loops.
    There is one other significant difference between queues and notifiers. A queue can only have one reader. If you have multiple readers of a queue who reads it will be random. A notifier can have multiple listeners. It fact, that is it's purpose.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Problem with avi recording and parallel while loops

    Hi,
    I made a test-VI which captures my webcam and save it to an AVI. (based on a sample I found somewhere)
    This works pretty fine so far (except the fact that the "frames per second"-constant has no effect and I am not able to change the resolution, but that's not the problem).
    I have a VI which controls some hardware and I want to record this with the webcam. For testing I made a dummy-VI which should run in parallel with the VI above:
    The 1st while loop should capture the webcam.
    In the 2nd while loop is a dummy-VI which generates some random values and waits 5000ms (to simulate the hardware).
    The problem is that those while loops do not work in parallel. When the execution is finished I get an AVI-file which is about 100ms long (so I guess it captures just 1 frame).
    If I replace that whole dummy-VI thing with a stop button it works nicely, but if I try to use a "Wait (ms) Function" or a "Wait Until Next ms Multiple Function" the video is always just about 100ms.
    Any idea how to implement multitasking or maybe even multithreading ?
    Attachments:
    lv_avi-recording.png ‏23 KB

    Hi Chris3,
    Just a random suggestion but have you tried removing the sequence structure? You can wire the error cluster from the IMAQdx Configure Grab.vi to both of the VIs for it to start parallely. 
    If you put it in a sequence like that, it is most likely that the middle sequence has to complete execution before it can go to the next sequence but it couldn't because of the wait.
    Let me know how it goes.
    Warmest regards,
    Lennard.C
    Learning new things everyday...

  • Timing in parallel while loops

    Hi,
    I'm having some issues with timing of while loops when two loops execute in parallel.
    I have one loop which writes to a GPIB device every x ms to produce a regular signal, and another that reads from another device continuously (no delay time) to produce a trigger when it recieves a specific output.
    Both of these loops work fine alone, but together they screw up the timing. I can't simply add a delay to the second loop, since the trigger signal must be read and executed straight away, even 1ms delay might cause me to miss the effect I'm looking for...
    Thanks for any help!

    Did you even try Lynn's suggestion of placing a "0ms" wait in the fast loop? Did it work? The problem you are seeing is due to the fact that a loop without any wait will hog the CPU for many iterations, thus potentially stalling the other loop for extended times (see also).
    Depending on your hardware, the two loops can also run on mutliple cores.
    How are you detecting the signal in the fast loop. Can you show us some code?
    I also agree that you need LabVIEW RT or FPGA to implement this in a robust way. Do you need to react to the trigger in a predictable way or do you simply need to ensure that it is not missed?
    LabVIEW Champion . Do more with less code and in less time .

  • How do I create an xy chart using two independent while loops?

    Hi everyone,
    I am trying to develop a data acquisition program. In this program, I have two independent while loops that each output a number of type double each iteration of the loop. I am able to successfully create two independent waveform charts (data vs. time) for each of the loops when it is placed inside. However, I now want to create an xy chart of the live data (the output of one loop is x and the output of the other is y).
    I am having trouble doing this because of the separate nature of the loops...when I try to pull data outside of the loops it (naturally) doesn't refresh with each loop iteration causing the xy chart to not work in the way I intend. Is there an easy way to fix this? If more clarification is needed, please let me know!
    David
    Solved!
    Go to Solution.

    Yes, more clarification is needed. Please attach your code to clarify.
    I'll take a wag at it, though. It sounds like you are trying to pair X and Y data which happen during a single time chunk, then repeat, is this right? (If not, don't bother to read on.) If so, why not just use a single loop. If your VI is getting too big/complicated for comfort, just put the data-generating stuff into subVIs which run to generate a single data point, then stop, put them into a while loop and send the putputs to a graph or chart inside the loop. That way you won't extend your data trace until you get one and only one point from each subVI and things will stay synchronized.
    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

  • Problem with two of my business rule triggers

    Good morning every one,
    I have a small problem with two of my business rule triggers.
    I have these tables:
    pms_activity
    csh_cash
    csh_integrate_leh
    csh_integrate_led
    and my process goes like this:
    upon approval of a row in my pms_activity table I have a trigger that insert a row in my csh_cash - and in the csh_cash table I have a trigger that will insert in the csh_ingerate_leh and csh_integrate_led.
    my problem is pms_activity does generate a row in csh_cash but the trigger in the cash does not fire to generate a row in the csh_integrate_leh and led tables.
    I have generated in the following order after I created my business rule:
    I have generated the table from the designer (server module tab)
    I have generated the CAPI from the head start utility
    I have generated the API from the designer
    I have generated the CAPI from the designer
    I have run the recompil.sql
    I have checked that my business rule trigger is enabled and should run on insert and no where restriction
    === this is my business rule logic ======
    l_rule_ok boolean := true;
    begin
    trace('br_csh001_cev (f)');
    csh_gl_pkg.csh_gen_integ_jvs(p_id
    ,p_ref_num
    ,p_own_id
    ,p_trt_id
    ,p_value_date
    ,p_description
    ,p_amount
    ,p_cur_id
    ,p_gla_dr
    ,p_gla_cr
    ,p_gla_pl
    ,p_gla_rev
    ,p_gla_eqt);
    return l_rule_ok;
    exception
    when others
    then
    qms$errors.unhandled_exception(PACKAGE_NAME||'.br_csh001_cev (f)');
    end br_csh001_cev;
    ==== end =======================
    Any help will be appreciated as I have struggled with this for two days.
    Thanks

    hmmm...
    Try resetting it again and restoring with the same backup file...
    Does the phone work properly once you've reset it before you try restoring? A lot of people here have experienced problems restoring from backups... could be worth forgetting about it and starting from scratch.
    You could try contacting your nearest Nokia Service Centre (www.nokia.com/repair) and see if they can do anything - it may need the firmware reinstalling or upgrading... possibly... give them a call though and see.
    Nokia History: 3110, 5110, 7110, 7110, 3510i, 6210, 6310i, 5210, 6100, 6610, 7250, 7250i, 6650, 6230, 6230i, 6260, N70, N70, 5300, N95, N95, E71, E72
    Android History: HTC Desire, SE Xperia Arc, HTC Sensation, Sensation XE, One X+, Google Nexus 5

  • I have a problem with two PDF's when trying to open them through a link on a web page. The two PDF's open fine with Adobe on my own PC and on the server I have copied it to but when they are opened through a link on a web page (pointing to the server wher

    I have a problem with two PDF's when trying to open them through a link on a web page. The two PDF's open fine with Adobe on my own PC and on the server I have copied it to but when they are opened through a link on a web page (pointing to the server where the PDFs open fine) I get an error 'There was an error processing a page. Invalid function resource' The other one just doesn't open at all. Can anyone help with this please?

    Hello,
    Are the pdf linked correctly in the website? Is this a public website? If yes, please post the link here.
    ~Deepak

  • Problem with Progress DB while using to connect using JDBC Adapter

    Hi,
      I am facing Problem with Progress DB while using to connect using JDBC Adapter. I am getting the following error in auditlog file like,
    Error during database connection to the database URL  jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db using the  JDBC driver "com.progress.sql.jdbc.JdbcProgressDriver" : com.sap.aii.adapter.jdbc.sql.DriverManagerException: Unable to locate a suitable JDBC driver to establish a connection to URL " jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db "
    I tried using the following all URLs,
    1. jdbc:JdbcProgress:T:156.5.31.65:2545:i_apoext.       
    2. jdbc:JdbcProgress:T:156.5.31.65:2545:i_apoext.db     
    3.                                                      
    jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.                                      
    4.                                                      
    jdbc:JdbcProgress:T:156.5.31.65:2545:/mfgprodev/devbadb 
    /devsche/i_apoext.db.                                  
    Can anyone please help me out in solving this issue.
    May be the cause for this is :
    1) The Wrong URL  format
    2) CLASSPATH is not setted properly..
    Can you look more into this stuff.
    Thanks,
    Soorya.

    Hi,
    To access any database fromm XI, using the JDBC adapter, the corresponding drivers have to be installed on the XI server.
    Just check this note 831162.
    Also, check this PDF to install Drivers in XI,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3867a582-0401-0010-6cbf-9644e49f1a10

  • Hi i'm using iphone 4 and i have problem with viber apps while i'm installing

    hi i'm using iphone 4 and i have problem with viber apps while i'm installing & registration process its says error on system mainternance. can you please help me out?
    thank you.

    OK, let's try again. Wind is NOT a supported carrier. In order to use tethering, it must be supported and activated by your carrier for the iPhone. This usually involves an additional fee.  You will have to ask your carrier if they can enable it. Odds are, since they are not a supported carrier, they can not. If you want to use tethering, you will most likely have to switch to a supported carrier that offers this feature on the iPhone.
    A list of supported carriers can be found here: http://support.apple.com/kb/ht1937

  • Exchange rates with two parallel currencies

    Hi all,
    I need to manage a company with two parallel currencies (USD and PKR). To post a document in USD it's necessary to define in TCURR an exchange rate FROM USD to PKR, and to post a document in PKR it's necessary to have an entry FROM PKR to USD.
    Obviously the second exchange rate has to be the multiplicative inverse of the first one.
    For this reason, to avoid redundant and possibly wrong entries, is it possible to manage only one exchange rate in TCURR (for example FROM USD to PKR) instead of two? How?
    Thanks for your attention

    Go to SAP Netweaver> General Settings> Currencies and manipulate the following and you should be able to maintain only one set of exchange rates.
    i) go to Check Exchange Rate Type - and manipulate the exchange rate type you are using (Check Financial Accounting Basic settings>  Ledgers> Define Currencies for Leading Ledger to check the exchange rate type used for each company code - generally M is used) and assign Reference Currency "Ref.crcy" (for example we use USD) for that exchange rate type.
    ii) go to Define Stnadrd Quotation for Exchange Rates and maintain - Forexample we use "Blank" to "USD", so that we just have to maintain Other currencies to USD (ref.crcy) and in In-direct Quotation.
    These setting would give you the ability to maintain just "Other Currencies" to "USD" in in-direct quotaion. Use this example to decide which currency you want to use as reference currency and then maintain accordingly.
    Hope this helps.

  • Little problems with two sensors

    Hi
    I've got a problem with two sensors.
    First, the luminosity sensor. I'd like to set the brightness to a fixed value. It would not vary from darkness to bright sunlight.
    Then, when i'm typing in landscape mode, it often switches back to portrait mode, wich make me terribly angry as i lose too much time.
    How can i solve these two problems ?
    Is there a special app?
    Last, but least, does anyone know if an app that would allow to take HDR/exposure blending pictures exist ? It'd take 3 to 5 photos with different exposures, and if it merged them to a good tonemapped picture it would be perfect.
    Thanks

     The light sensor can't be set to a fixed permanent value using the phones default settings, I'm afraid. You can only adjust it's sensitivity. However, some users have reported using an app to keep the screen set at maximum brightness.
     The motion sensor which switches the phone screen orientation has become more sensitive after the recent PR 1.1 update, so not a lot can be done about that either, apart from trying to hold the phone as steady  as possible when using it.
    Finally, there isn't any HDR available for the N8 at this time, nor is there any setting to increase the exposure time to something like a second, which would be a nice feature to add to  a great camera.
     All the best.
    Ray

  • Problem with two finger scrolling on s440

    Hello everyone
    I have a S440 (touch version) and some Problems with two finger scrolling on the touchpad.
    First, it isn't smooth, i.e.. If I move my fingers it only starts scrolling after a second or so, basically when I've already stopped (unless I move very slow). It then makes up for the lost time by scrolling very fast.
    The more serious problem (that makes it practically unusable) is that it randomly jumps back up, often to the top of the page/document, sometimes just a page or so.
    The problems are worst with firefox and acrobat, with IE and the Microsoft reader there's no response time problem but the jumping upwards still occurs.
    The problem is there with the preinstalled Windows 8 as well as my own Windows 8 Pro (with the original Lenovo drivers). Scrolling with the Trackpoint and an external mouse work fine, as well as scrolling via the touchscreen.
    Does anyone have any suggestion if/how I can fix this?

    I also have a S440 (non-touch screen), the scrolling on the touchpad worked perfectly when I bought it, no jumping, and scrolling perfectly smoothly comparable to an Mac. But after an upgrade to windows 8.1 which broke many things ( despite upgrading all drivers), I reset my thinkpad which brought it back to windows 8, everything working normally again except the two finger scrolling which is no longer smooth (moves incrementally now), and likes to jump randomly up or down the page, (not always, but enough to make it irritating. I notice this mostly with google chrome and adobe reader as these are the apps I use most frequently.
    So my questions is what drivers or settings do I need to bring the scrolling back to the configuration it was when I purchased my S440? My device manager says I'm running thinkpad ultranav with Synaptics driver version 16.6.4.38
    Cheers,
    Paul

  • Threads in while loop with two data acq loops

    Good day, I am using two while loops to perform data acquisition from two different pieces of hardware inside a "main" while loop - a total of three while loops. I want each of the data acq loops to run as fast as possible. With this model will each data acq loop run in a separate thread or will they be running in the same thread because they are both inside the "main" while loop.
    I'm not getting the performance I would like and I'm looking at ways to optimize the execution. 
    Thanks
    John 

    I would have a loop for each of you data acquisition tasks and at least one, possibly two additional loops that will write your data to file. Let the acquisition loops collect the data as quickly as possible and simply queue it off for further processing. When these loops are in parallel LabVIEW will run them on separate threads. In addition you could have a separate loop with an event structure that could handle you UI interaction. This loop could control the overall application with respect to starting and stopping the tasks, etc. You don't really need to contain all these loops in any other loop or structure. They can all reside on the block diagram next to each other. Ideally you will create subVIs for the data acquision and data processing tasks.
    Message Edited by Mark Yedinak on 10-06-2009 04:29 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

Maybe you are looking for

  • Select Multiple Rows in a Table without CTRL

    Expecting the user to press "Ctrl" when selecting multple rows is very unfriendly and unintuitive. We'd like the row selection to work as in ALV where you just select multiple rows by clicking on them. We've set the tables rowSelectable to true and s

  • How to print the content of a text edit ?

    Hi to all, I have a view with a text edit and I want to print its content. I created a button and I want to print text edit content pressing this button. How can I do? Which java code I have to insert in that button? thanks a lot, Antonio

  • Problem In Creating Sales Order Through DI API

    Hi I am Creating The Sales Order Through DI API. the Error Is Coming - " [OACT] , 'No matching records found (ODBC -2028)'" anyone  can help me solving it.

  • Upgrading a Powermac G5

    Hi - I am upgrading from a Powermac G4 Gigabit Ethernet to a Dual 2.0 Ghz Powermac G5. It is the late 2005 model, meaning it has PCI Express slots and a PCI Express 16x video card slot. What is the best video card I can get for this machine? If I am

  • R/3 e-commece

    Hello experts, When we login to b2b shop, select the product catalog. We are unable to seen the products, we are getting the below error. 500   Internal Server Error   SAP J2EE Engine/7.00  ISA Framework: com.sap.spc.remote.client.object.IPCException