Reading counter in loop .... slow!

I asked this question on the labview board, hoping it gets more response on the counter board.
http://forums.ni.com/ni/board/message?board.id=170&message.id=293236#M293236
Basically I need to read the counter to measure the speed of rotation (quadrature encoders with a max freq of 100 khz) and close the loop with PID as fast as possible, prefereably > 5khz. With one counter I can get around 10 khz, when I go to three counters (which is what I need) I can barely get to 3 khz.  Once I'm actually doing other things in the system I can't get acceptable performance. I've got a PXI-8106 RT and PXI-6608, running RT.  Seems like Daqmx is pretty inadequate at doing counter readings acceptably fast with what should be a top notch system.
I've attached pictures of what I'm doing with the counters which seems like it should work fine.
Any help would be greatly appreciated.
Thanks
Henri
Attachments:
Setup Counter.JPG ‏72 KB
Main Loop.JPG ‏55 KB
Read Counter.JPG ‏67 KB

I *think* you'll get better results with some code work.  I assume the unshown TRUE case in your Read code is pretty much empty and just passes through the data read before the case structure?
1.  One thing I notice that may matter is that on an error in the Read code, you stop the task and then perform a Read without an explicit Start.  I also didn't see an explicit Start in the Setup code, so it appears that you're depending on the "auto-start" behavior that kicks in when you Read from a previously-unstarted task.  I'm not 100% sure of this, but I think the DAQmx State model might make that mode of operation less efficient than if you were to explicitly Start the task outside your main loop (and again inside the error case of the Read).  I've made that a personal habit, and I think I based it on reading something to that effect in the help or here on the site -- somewhere.  In any case, it won't hurt to try.  Also, when you *do* restart on an error, I don't think you should need to call the 'Overwrite' property or the DAQmx Timing vi.  The task should remember those settings if you merely stop rather than clear it.
2. I'm a bit uncomfortable seeing 0-valued timeouts, and wonder if those may cause occasional timeout errors which cause you to execute the slower error case in the Read code.  Not sure though -- maybe it's ok when you also request -1 = 'all available samples'.
3. In the screenshot, the Timed Loop is set for 5 kHz.  I assume you varied the requested rate to try to make the loop run faster?
4. Dunno what's inside the 'Loop % Used' subvi you call, but make sure that isn't bogging you down.
5. When you made calls to 3 counter tasks, were they sequential or parallel?  The timing results you reported sounds like their times were additive, kind of implying a sequence.  Be sure to try dropping them in parallel.  (Of course, there's a chance this might actually become slower as DAQmx negotiates more parallel threads -- you'd have to benchmark it).
6. Dunno much about Shared Variables on RT, but think I recall that you can use them in RTFIFO mode.  If so, do it.  If they aren't in that mode, they may be responsible for some overhead. 
7. This one's more of a style thing than a speed thing.  You read 'all available samples' which returns an array of recent values.  Then you retain only the first element, which is the oldest value there.  I would expect that you'd either want to compute an average on the array, or keep the last array element which is the most recent value.  
8.  There's another way to extract only the most recent data in your calls to DAQmx Read.  In your Setup code you could call the DAQmx Read property node to set RelativeTo = MostRecentSample, and Offset = -n.  These settings will persist.  Then you could call DAQmx Read to request n samples and it will immediately return the most recent ones.
Hope something here proves useful...
-Kevin P.
P.S.  Just followed your link to the other thread.  Should have done it before posting -- looks like that thread is the more active one and I'll direct followups there.
Message Edited by Kevin Price on 01-16-2008 05:35 PM

Similar Messages

  • Error -200429 DAQmx read (counter u32 1ch 1samp).vi -append- Edge count in for loop

    I am receiving error -200429 DAQmx read (counter u32 1ch 1 samp).vi <append>. This is occuring on the second loop of a for loop.
    I have a sequence inside the for loop that is using four DAQmx assistant vi's for edge count at various times in the sequence. All four of these count fine the first time through but at the beginning of the second loop the first edge count receives this error and does not count.
    Any ideas?

    The code you have supplied is similar to the converted subvi but this code will give an empty task error on the DAQmx Create Channel vi.
    Notice on the Daqmx create task vi that there is nothing wired to the "Task to copy" or the "Global virtual channels" connectors - I believe this is why the task is empty when sent to the Daqmx create channel vi.
    The code we are currently using is a modification of a previous code used before a recent upgrade. It may be better in your/NI eyes to re-write this into a State machine but time constraints and resources do not allow that at this time - All other parts of the current program work except for the counter on the second iteration. Would rather not reinvent the wheel at this point. 
    If the task is being cleared was the issue then the other three should also not execute. The issue appears to be the "First Call"
    I have attached a zip file of the complete program as it is now written to give you a better idea of the whole picture.
    Attachments:
    Test Machine current code.zip ‏657 KB

  • Problem with read count

    I am trying to receive 2500bytes via serial port and plot it on a chart, after sending character "S" to the sender device.
    I have set the "read count" to 2500 so it is supposed to receive 2500 byte then wait for another "S" but it just receives 101 bytes and then goes to next program iteration. how can i solve this problem?
    The VI have been attached.
    Attachments:
    2500.vi ‏21 KB

    First, you've posted to the wrong board. Your question has nothing to do with NI digital I/O devices.
    You seem to not understand how a VISA Read works. A read will terminate when the byte count is reached, or the timeout is reached, or the termination character is detected. Disable the termination character or set up multiple reads in order to get multi-line strings. For example, keep reading until the available bytes is zero. With a loop, shift register, and a concatenate string, this is easy to do.

  • Read Table Vs Loop at

    Dear All,
    Please let me know which one of the two should I use to improve the performance, for tables containing a lot of data ?
    Regards,
    Thanks in anticipation.
    Alok.

    Hi,
        Follow below steps.
        In se30 transaction you can look for
        Tip&TRicks button on application toolbar
        apart from below conventions
       Follow below steps
    1) Remove corresponding from select satement
    2) Remove * from select
    3) Select field in sequence as defined in database
    4) Avoid unnecessary selects
    i.e check for internal table not initial
    5) Use all entries and sort table by key fields
    6) Remove selects ferom loop and use binary search
    7) Try to use secondary index when you don't have
    full key.
    8) Modify internal table use transporting option
    9) Avoid nested loop . Use read table and loop at itab
    from sy-tabix statement.
    10) free intrenal table memory wnen table is not
    required for further processing.
    11)
    Follow below logic.
    FORM SUB_SELECTION_AUFKTAB.
    if not it_plant[] is initial.
    it_plant1[] = it_plant[].
    sort it_plant1 by werks.
    delete adjacent duplicates from it_plant1 comparing werks
    SELECT AUFNR KTEXT USER4 OBJNR INTO CORRESPONDING FIELDS OF TABLE I_AUFKTAB
    FROM AUFK
    FOR ALL ENTRIES IN it_plant1
    WHERE AUFNR IN S_AUFNR AND
    KTEXT IN S_KTEXT AND
    WERKS IN S_WERKS AND
    AUART IN S_AUART AND
    USER4 IN S_USER4 AND
    werks eq it_plant1-werks.
    free it_plant1.
    Endif.
    ENDFORM. "SUB_SELECTION_AUFKTAB
    Regards
    Amole

  • Ai read in while loop

    I am acquiring data from a DAQ e series card. i intialized the daq by using AI config out side while loop . i used AI start and AI read in while loop . iam acquiring data from 5 channels. the buffer size ia 1000 and so is the scan rate in AI start.I want to save the acquired data in the file. i am also displaying data o n chart. every thing is working fine. my problem is i want to save 500 points in one seconds. for this i changed the while loop execution time by using waint until multiple sec VI and assign it 10  i was expecting that now iwll save more data point in file as now loop will execute more fast but it does not happen like this. is there any way to minimize the executing time of whil loop.i checked if i deleted AI start and AI read then loop execute very very quickly. should i place AI start and AI read out side loop but then how will it acquire data contiously. I m attaching gif file of the protion of my VI .any suggestion?
    Attachments:
    myVi.GIF ‏72 KB

    I was working quickly, and from memory, so my apologies for errors or non-clarity in my previous post. :-(
    The AI START VI, should be used OUTSIDE the loop, since you only want to START the task ONCE.
    When the task is complete (your WHILE loop is done), then call the AI CLEAR task to clean up (ONCE).
    If you set the NUMBER OF SCANS TO ACQUIRE input to AI START to zero, that has a special meaning: acquire data indefinitely. It will not stop on it's own (assuming no errors occur), you have to explicitly stop it.
    If you do this, you have to read the data often enough to avoid buffer overflow, which means the incoming data is filling up the buffer faster than you're emptying it.
    I have attached a picture of the general idea. If you really want to use the CPU efficiently, then consider the shift-register idea in the picture - you process on batch of data WHILE the next batch is coming in. If you want a simpler solution, forget the shift-reg, and process it directly after reading it. If your buffer is twice the size of your processing size, you'll be OK.
    Message Edited by CoastalMaineBird on 09-14-2005 07:45 PM
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    DAQExample.png ‏16 KB

  • I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    I pull fiftyfour bytes of data from MicroProcessor's EEPROM using serial port. It works fine. I then send a request for 512 bytes and my "read" goes into loop condition, no bytes are delivered and system is lost

    Hello,
    You mention that you send a string to the microprocessor that tells it how many bytes to send. Instead of requesting 512 bytes, try reading 10 times and only requesting about 50 bytes at a time.
    If that doesn�t help, try directly communicating with your microprocessor through HyperTerminal. If you are not on a Windows system, please let me know. Also, if you are using an NI serial board instead of your computer�s serial port, let me know.
    In Windows XP, go to Start, Programs, Accessories, Communications, and select HyperTerminal.
    Enter a name for the connection and click OK.
    In the next pop-up dialog, choose the COM port you are using to communicate with your device and click OK.
    In the final pop
    -up dialog, set the communication settings for communicating with your device.
    Type the same commands you sent through LabVIEW and observe if you can receive the first 54 bytes you mention. Also observe if data is returned from your 512 byte request or if HyperTerminal just waits.
    If you do not receive the 512 byte request through HyperTerminal, your microprocessor is unable to communicate with your computer at a low level. LabVIEW uses the same Windows DLLs as HyperTerminal for serial communication. Double check the instrument user manual for any additional information that may be necessary to communicate.
    Please let me know the results from the above test in HyperTerminal. We can then proceed from there.
    Grant M.
    National Instruments

  • Reading in a loop

    First, I want to thank all of you who answered to any of my questions, I appreciate it and it helps me to progress a lot. My actual question is about reading in a loop. I read a string (Visa read) of a specified lenght of bytes from my serial port. This visa read is in a while loop, and I'd like to cummulate all the readings in a text indicator (and eventually in a file). For now, I'm only able to get the last reading, 'cause if I put my text indicator in the loop, it overwrites at each iteration and if I put it outside, it keeps only the last reading. I'm sure it's just about concatenating or building text but I did not find how. Thanks once again for help.
    Philippe

    Right click on the border of your loop and create a shift register. Once you have created this concatentate the strings together. You can then place an indicator in the loop and see previous iterations data. Look in the help to explain shift registers alittle better. Hope this helps.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor

  • Read Counter/Position Line or Volume Counter

    I have the iPod Nano 4 GB.
    Serial # YM538AJCTK3
    It used to show the read counter or position line that shows at which point on the song/podcast I'm on; or the.
    Now, it's not showing it. Instead it's showing 5 small circles that doesn't indicate the position of the song/podcast nor the volume counter.
    I can't seem to change this setting back.
    Please help.

    Sometimes, if you don't allow the screen to refresh before pressing another button, it gets stuck.
    See this for help.
    iPod "stuck" on the artwork or rating screen.
    As you will see, updating the software can cure this.

  • Messages App (OS 10.8.4) Does Not Correctly Display the Read Count.

    For a while now, the messages app in Mountain Lion does not mark an iMessage as being "read." If I read an iMessage on my iPhone, then it will update the read count in the messages app on my MacBook Pro to show it has been read. If I read an iMessage on my MacBook Pro, the blue dot stays and the read count remains unchanged. Can someone point me in the right direction on getting the read count to work again?
    Thanks!

    The read count is also at the top of the window:
    Not to mention the blue dots that don't go away:
    And yes, the "read" count is updated between devices. This always worked for me until 10.8.2 was released and it broke on my main system. I have another computer and it continues to work. I read an iMessage on that computer, the blue dots go away from my iPhone and no iMessages show up on the lock screen. For some reason my main computer doesn't function this way anymore.

  • Apple mail in lion - show un-read counts?

    I have a main inbox and sub inboxes below.
    Q: How can I get the boxes to show un-read counts?

    Mandatory initial question:
    What do you have selected in Mail, Preferences, "Dock unread count" ?
    charlie

  • PID control loop slows down during execution.

    Hi, I am a attaching a LV8.6 code that i am currently using to control my engine experiment. I use PID control where the input signal is an rpm value that i measure using a counter. The ttl signal from the sensor is not clean and so i use an analog trigger to generate pulses on the counter from where i measure the frequency and hence the rpm. The output is generated as an analog voltage on an output channel. The problem i am facing is that the loop runs really good when i start off but gradually the loop keeps slowing down and this greatly affects my ability to control engine speed. I am not sure why this is happening. I tried increasing the sample size and rate (so as to increase the buffer size) but this didnt have any effect on the speed. I am guessing its a problem with the way i have my loops setup.. any suggestions would be greatly appreciated.
    Thanks, Shyam.
    Attachments:
    PID control loop.vi ‏33 KB

    Hi all..I realised my mistake soon after posting as usually is the case..the create channel vi for doing the analog output to the output channel was within the loop and slowing things down..when i moved it out..it fixed the problem!!
    Shyam.

  • Backwards counting for loop

    Somehow the following is crashing my Flash player. If I run
    it that way, it tells me that something is causing the player to
    run slow. Is there anything wrong with this? I feel like I have
    used a for loop like this before.
    for(var i:Number = numOfPortfolioPieces - 1; i > -1; i--){
    this.portfolio_subnav["p_btn_" + i].enabled = true;
    fFadeInPortfolioSub.push({target:this.portfolio_subnav["p_btn_" +
    i], _alpha:100, time:animationTime6, trigger:triggerTime1,
    ease:"linear"});

    I just figured it out. Sorry for the poste, the problem was
    actually in a different place and this seems to work for a
    backwards count from a for loop.

  • Loop slows down when certain parts of screen are active

    Hi, I've noticed that one of my loops, which is set to run at 50ms, slows down significantly when certain other parts of the screen are active.
    We have a dual screen setup where on the left side we have a bunch of controls and I'm also displaying the time that 50ms loop takes. On the 2nd screen, there is a tab control with several pages. When some of the pages are displayed (and those are the ones that are probably the "busiest" in terms of processing), the loop time slows down to anything in the range of 1-4 seconds.
    The loop runs at 50ms when other lower-processing tabs are showing. It will also run at 50ms when any other window (another VI, another application) is hiding that right tab display. Actually, it'll run at 50ms if another window hides about half of that right tab
    What can I do to be able to watch those tab pages and keep my loop running from slowing down? One of those tab pages is a fault message display, so it's good to watch while you're running a test!
    Thanks.

    I would start by checking what you're displaying in your pages. You might be doing something that doesn't need to be done all the time.
    I once ran into an issue where screen updates to a control in a tab would slow down the computer (100% CPU usage) even when another tab page was selected and would only stop when the tab was moved off the screen or when the control was moved out of the tab. Unfortunately, I was never able to reliably recreate that issue. In that case the problem was with updating the strings in an array of rings using a property node, but yours might be a different case.
    If what I described sounds similar to what you're seeing (increased CPU usage even when the real culprit is not displayed) I would be interested in seeing a demo.
    Try to take over the world!

  • DAQ Assistant with multichannels causing Simulation Loop slow?

    Hi, another LabView newbie here.
    I have in a Real Time Target (NI 9132)  a Control & Simulation Loop with DAQ Assistant block inside, whose signals are fed into a Discrete State Space block. The discrete state space model has 1 second time step. I have set the Simulation Loop parameters so that it executes every 1 second as well (see Fig. A below). *sorry for the big white gap under the figures..
    The DAQ assistant acquisition mode is set as "1 Sampe (On Demand)".
    However, when I run the VI, the plot seemed to be updated much slower than 1 second rate. To confirm this, I put an "Elapsed Time" block inside the Simulation Loop. The "elapsed time" shows the actual time in seconds while the simulation plot show slower time (see Fig. B below).
    I tried to isolate the problem by removing the block one by one. Finally, I found out that this problem was caused by (at least) the DAQ Assistant which acquires multichannels data of NI 9214. When I remove some channels and leave one or two channels, the VI runs at the actual time (see Fig. C below). But when I added more channels reading, it became slower again. 
    Here is the snippet of the block diagram (after all other blocks were removed):
    What am I doing wrong here? I'm going to use all of NI 9214 channels so how not to have similar problem like this?
    I look forward to hearing any relevant comments from the members. Thanks in advance.
    Tian

    Hi Tian,
    why do you need a Sim loop anyway?
    - When it comes to speed you shouldn't use the DAQAssistent. Use basic DAQmx functions…
    - Use parallel running loops for each task. Put DAQmx functions in their own loop, running in parallel to your Sim loop…
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How To Pass A Value Read By A Loop To Main Method

    Hey everybody,
    I'm at this with my code.I'm reading the values of a text file in a loop.I want to pass these values to main method.The importhant point is I want to do this without using a field. The code is below. Thanks.
    //Main
    public static void main(String[] args)throws FileNotFoundException
              DoubleClass AvgScore=new DoubleClass();
    IntClass Messenger=new IntClass();
              PrintWriter writer1=new PrintWriter("D:\\JavaExercises\\CH07EX14out.txt");
              Scanner scan1=new Scanner(new FileReader("D:\\JavaExercises\\CH07EX14data.txt"));
         //1 ogrencinin notlarini okut ve ortalamas&#305;n&#305; hesaplat
         while(scan1.hasNext())
              writer1.print(scan1.next()+" ");
    calcAvg(AvgScore,scan1,Messenger);
    //AvgScore formatlanarak yazdirilacak
    writer1.print(""+AvgScore+" ");
    writer1.print(""+calcGrade(AvgScore)+"\n");
    writer1.close();
    //calcAvg
    public static void calcAvg(DoubleClass x,Scanner y,IntClass z)
         int counter=0;
         double TotalScore=0;
    int NumTests=1;
    int Score=0;
    //Bir ogrenci icin toplam notu ve test sayisini bul.
         while(counter<=4)
              Score=y.nextInt();
    TotalScore+=Score;
    counter++;
    NumTests++;
    //Bir ogrenci icin not ortalamsi bul.
    x.setNum(TotalScore/NumTests);
              }

    Malkavian187 wrote:
    Guys please pay attention,
    I already said I can't use a field(class scoped variable)and can't use a return type method.
    I ve heard that it can be done by passing a reference or primitive variable to my calcAvg method.And than assignin the read values back to this variable.
    But I can't figure out how to make it. I need a complete solution.Including modifications to calcAvg and main method.
    Take care,Malkavian187,
    Maybe you haven't seen other posters asking homework to be done for them, so here is basically what we tell them: DO IT YOURSELF.
    And we realize that very possibly you could fail your class from that and have to drop out. This may be a good thing because it will help keep the demand for technical workers up, and thus, keep the pay high.
    On the other hand, if you choose to actually do the assignment then we will be happy to give comments on your code. Please post it when you have some and until then, best wishes with what ever you choose to do.
    BTW: the solution you allude to requires a field also... and in reality, you already gave the answer--just implement it. If you do not know how: well, maybe you should do one of the following:
    1-read and study the Java Tutorial
    2-pay more attention to class
    3-read your textbook for your class
    4-go to class
    5-stay awake in class
    6-pay attention in class
    7-talk to your teacher
    8-withdraw from the class
    9-change your major

Maybe you are looking for