Reading encoders with PCI 6602

Hi,
I'd like some help to understand correct general purpose counter (GPCTR)
calling sequence.
Once configured with a GPCTR_Control (..ND_PROGRAM)call, it is not clear
what should be done, if at a later stage one would like to set (write) a
specific value to the counter. I suppose the counter should be un-armed (with
a GPCTR_Control (..ND_RESET)call). In this case is the previous configuration
lost (things defined with the Set_Application and Change_parameter calls)
If negative, what is the shortest sequence call to set a new value to a counter
already armed ?
Please mail the answer to
[email protected]
Thank you

 Hi Sweety,
What type of measurement do you want to make with the servo motor (edge count, frequency, pulse width, etc.)?  What wires are output from the servo motor?  Depending on the answers to these questions it will give more information into whether you need to use the gate terminal or just the source. 
I would recommend to review the User manual for the PCI-6602 (referenced below) because it has information on the pinouts (pg 31) and different application considerations.  Also, the M series user manual discusses some of the different measurements (in the counter section) and how to make the proper connections.
660x User Manual
http://www.ni.com/pdf/manuals/372119a.pdf  
M Series User Manual
http://digital.ni.com/manuals.nsf/websearch/2025C99AB0614F9E8625748000577B9A
Regards,
Jordan F
National Instruments

Similar Messages

  • Count digital events on a Counter with pci-6602 with callback on CVI

    Hi,
    I'm using a PCI-6602 card with CVI 8.5 and I need to trig on event.
    On every pulse I received, I need to do some actions like increasing a counter, send a message on Rs232 etc.. I don't want to do any loop checking that the counter value has changed. I would like to use a callback to execute this code only on the edge or counter value event.
    My problem is that I don't know which function can do this. Is there any way to get an event on a pci-6602? 
     Thanks 
    James 
    Solved!
    Go to Solution.

    Hello.
    It's completely possible to create a callback that will allow you to do what you want when a edge will occur on an external signal you define.
    To do this, you can for exemple create a counting edges task that will use one of the 6602 counters,and the set your external signal to be the source of your sample clock.You'll then be able to register a callback with the function DAQmxRegisterSignalEvent, and your callback will be called each time an edge will occur on your specified sample clock source.
    Here's 2 links that explain the events in DAQmx and how to handle them in CVI. The example ReadDigChan-ChangeDetectionEvent.pr that ships with DAQmx examples (Hardware Input and Output<<DAQmx<<Digital measurements) can be very useful to understand how to do. This example creates a signal event callback to detect change detection for digital inputs.
    Regards.

  • Triggering the reading of counter totals (PCI 6602)

    Hi,
    thanks for reading these lines,
    for a special application I need to read the totals of multiple counters
    simoltanouesly. The inputs of the counters are connected to quadrature encoders.
    Is there a way to reroute the gate to another input pin?
    Thanks for taking the time to support me.
    live long and prosper
    Michael

    Dear Jochen,
    (1) Principally, I'd like to use PCI-6602 to be a motion encoder also be a counter (Is it possible? Due to the manual, it is possible). I expect to have all information, such as position, time, velocity, etc. from that motion encoder (or at least the position and time). It is also expected of using PCI-6602 to do all measurements that I mentioned before . My meaning is, after having a signal from the counter, that 'count' will be converted to desire units under other programs. So, in this case, PCI-6602 is only used to get the 'count'.
    Simplified, the voltage command will send to the system (linear motor) through PCI-6052E (-10V to 10V). The actual position or other actual information will be catched (read) by using PCI-6602 (as a motion encoder, also as a counter). Then, this actual position will be used as a feedback, that will be compared to desired position.
    Is that also possible to use PCI-6602 be a motion controller + a counter + a frequency measurement in a same time parallely?
    I don't decide yet (I don't know) which acquisition rate will be needed/required, higher is better.
    (2) I'd like to apply an adaptive robust controller (yes, it is a closed loop system) under matlab with their feature called Real-Time-Workshop instead of using LV.
    (3) Power drive for the linear system will be driven by AC servo drive.
    Thanks for your help before,
    Warmly regards,
    hendro

  • Counter using PCI-6602 for multi output

    Hi guys,
    currently I tried to control a linearmotor using PCI-6052E and PCI-6602.
    The questions is, how to use PCI-6602 to be a counter which will be converted to several output (multioutput):
    (1) converted to position >> 1count = ...[mm] --> position measurement
    (2) converted to voltage >> 1count = ...[mV] or [V] --> voltage measurement
    (3) converted to current >> 1count = ...[mA] or [A] --> current measurement
    (4) converted to velocity >> 1count = ...[mm/s] --> velocity measurement
    (5) converted to acceleration >> 1count = ...[mm/s^2] --> acceleration measurement
    (6) converted to force >> 1count = ...[N] or [kg.mm/s^2] --> force/load measurement
    (7) converted to frequency >> 1count=...[Hz] --> frequency measurement
    (i) Please assist me how to connect the driver's encoder (Ch. A A/ B B/ Z Z/) with PCI-6602, so I can get all informations above (7 measurements). What/which port of PCI-6602 connect to where from the driver.
    (ii) Please assist me how to connect the feedback signal to the PC. What/which port of PCI-6602 connect to PC.
    (iii) How to test those 7 measurements above using Measuremant and Automation Explorer (MAX) ver.4.4.1?
    Thank you for your kindly help and assistance.
    Best wishes,
    hendro

    Dear Jochen,
    (1) Principally, I'd like to use PCI-6602 to be a motion encoder also be a counter (Is it possible? Due to the manual, it is possible). I expect to have all information, such as position, time, velocity, etc. from that motion encoder (or at least the position and time). It is also expected of using PCI-6602 to do all measurements that I mentioned before . My meaning is, after having a signal from the counter, that 'count' will be converted to desire units under other programs. So, in this case, PCI-6602 is only used to get the 'count'.
    Simplified, the voltage command will send to the system (linear motor) through PCI-6052E (-10V to 10V). The actual position or other actual information will be catched (read) by using PCI-6602 (as a motion encoder, also as a counter). Then, this actual position will be used as a feedback, that will be compared to desired position.
    Is that also possible to use PCI-6602 be a motion controller + a counter + a frequency measurement in a same time parallely?
    I don't decide yet (I don't know) which acquisition rate will be needed/required, higher is better.
    (2) I'd like to apply an adaptive robust controller (yes, it is a closed loop system) under matlab with their feature called Real-Time-Workshop instead of using LV.
    (3) Power drive for the linear system will be driven by AC servo drive.
    Thanks for your help before,
    Warmly regards,
    hendro

  • Genral How do I get syncronize​d encoders to work with a PCI-6602

    I am new to the DAQmx and need some general help writting VB code that works.
    I can get some things to work, but others don't work at all and I don't have enough knowledge of these drivers to get up the learnign curve hump.
    I wanted to post this as a follow-up
    to the thread:
    http://forums.ni.com/ni/board/message?board.id=40&​message.id=5430&query.id=215100#M5430
    But I couldn’t figure out how.  
    Anyway, my problem is that I will
    eventually have to do much the same thing as the above thread with two encoders in
    sync.
    I have a pci-6602 card, and my code
    snippet is at the bottom  The 6602 doesn't have the analog in to syncronize to like the thread above
      (yes, it is in Visual basic
    6)
    I can’t figure out the
    DAQmxCfgSampClkTiming.   Why do I want to have a sample clock at all?   (okay,
    when I have two channels synced I do – but this sample I want to get working and
    I don’t see why)?
    Can’t I just get a new counter value
    with each quadrature input change?   (That’s what the DEV/PFI39 is, the same as
    encoder channel A )
    Okay, so hopefully you tell me how
    to get that to work.
    Next question:  What can I use for
    the DAQmxCfgSampClkTiming when I am doing two channels in sync?  Nothing seems
    to work, and I have tried a bunch of things.
    Brynn
    Rogers
    DeltaTech
    Controls
    952-403-7400
    x431
    //// code that doesn't really work.   "Dev1/PFI39" is the channel A encoder input, I just want new data whenever the encoder changes (for now)
        ' DAQmx Configure
    Code
        DAQmxErrChk
    DAQmxCreateTask("count", TaskHandle)
        TaskIsRunning =
    True
        DAQmxErrChk
    DAQmxCreateCIAngEncoderChan(TaskHandle, "Dev1/ctr0", "",
    DAQmx_Val_EncoderType2_X4, 0, 0#, DAQmx_Val_EncoderZIndexPhase1_AHighBHigh,
    DAQmx_Val_AngleUnits2_Ticks, 500, 0#, "")
        DAQmxErrChk
    DAQmxCfgSampClkTiming(TaskHandle, "Dev1/PFI39", 1, DAQmx_Val_Rising,
    DAQmx_Val_AcquisitionType_FiniteSamps, samples)
        'DAQmx Start
    Code
        DAQmxErrChk
    DAQmxStartTask(TaskHandle)
        ' DAQmx Read
    Code
        DAQmxErrChk
    DAQmxReadCounterF64(TaskHandle, -1, 0.05 * samples, data(0), samples, ReadCount,
    ByVal 0&)
        ' All done!
    StopTask
        'DAQmxErrChk
    DAQmxStopTask(TaskHandle)
        'Stop task isn't needed because
    Clear Task also stops task
        DAQmxErrChk
    DAQmxClearTask(TaskHandle)
    Solved!
    Go to Solution.

    Okay,   Here is the working routine to get syncronous data from two encoders, and it seems to work okay.
       I have this working with my two 2000 CPR encoders, we'll see how it works when I get the 500,000 CPR encoders later.
    The three big problems that caused it to not work were:  
    1)   Theduty cycle argument for the createCOpulsechanfreq task needed to be between 0 and 1.  I had '50.0' before, it works when it is '0.5'
    2)   The sample timebase that I used (ctr7) needed to be started before either of my two angle encoder tasks were created
    3)   The "dev/PFI8" string needed to be changed to "/dev/PFI8".   I don't really understand why, but that was what seemed to fix it all.
    So this question has been answered...      Now I have a different problem while reading 8 PWM values at once with the Semiperiodcounter,  which I will post in a new a different thread.
    Thanks!
    ''''''''''''''''''   Working code here
    Public Sub Aquireposition(samples As Long, data0() As Double, data1() As Double)
    Dim BaseTaskHandle    As Long
    Dim encoder0TaskHandle    As Long
    Dim encoder1TaskHandle    As Long
    Dim TaskIsRunning As Boolean
    Dim ReadCount As Long
    Dim strCounterString As String
       On Error GoTo ErrorHandler
        DAQmxErrChk DAQmxCreateTask("base", BaseTaskHandle)
        DAQmxErrChk DAQmxCreateCOPulseChanFreq(BaseTaskHandle, "/Dev1/ctr7", "base", DAQmx_Val_FrequencyUnits2_Hz, DAQmx_Val_Level1_Low, 0#, 200#, 0.5)
    'Specify continuous timing
        DAQmxErrChk DAQmxCfgImplicitTiming(BaseTaskHandle, DAQmx_Val_AcquisitionType_ContSamps, 200)
         'DAQmx Start Code
        DAQmxErrChk DAQmxStartTask(BaseTaskHandle)
    ' DAQmx Configure Code
        DAQmxErrChk DAQmxCreateTask("encoder", encoder0TaskHandle)
        TaskIsRunning = True
        DAQmxErrChk DAQmxCreateCIAngEncoderChan(encoder0TaskHandle, "/Dev1/ctr0", "", DAQmx_Val_EncoderType2_X4, 0, 0#, DAQmx_Val_EncoderZIndexPhase1_AHighBHigh, DAQmx_Val_AngleUnits2_Degrees, 500, 0#, "")
        DAQmxErrChk DAQmxCfgSampClkTiming(encoder0TaskHandle, "/Dev1/PFI8", 1, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, samples)
        ' second encoder
        DAQmxErrChk DAQmxCreateTask("encoder1", encoder1TaskHandle)
        TaskIsRunning = True
        DAQmxErrChk DAQmxCreateCIAngEncoderChan(encoder1TaskHandle, "/Dev1/ctr1", "", DAQmx_Val_EncoderType2_X4, 0, 0#, DAQmx_Val_EncoderZIndexPhase1_AHighBHigh, DAQmx_Val_AngleUnits2_Degrees, 500, 0#, "")
        DAQmxErrChk DAQmxCfgSampClkTiming(encoder1TaskHandle, "/Dev1/PFI8", 1, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, samples)
        'DAQmx Start Code
        DAQmxErrChk DAQmxStartTask(encoder0TaskHandle)
        DAQmxErrChk DAQmxStartTask(encoder1TaskHandle)
        ' DAQmx Read Code
        DAQmxErrChk DAQmxReadCounterF64(encoder0TaskHandle, -1, 0.05 * samples, data0(0), samples, ReadCount, ByVal 0&)
        DAQmxErrChk DAQmxReadCounterF64(encoder1TaskHandle, -1, 0.05 * samples, data1(0), samples, ReadCount, ByVal 0&)
        ' All done! StopTask
        'DAQmxErrChk DAQmxStopTask(TaskHandle)
        'Stop task isn't needed because Clear Task also stops task
        DAQmxErrChk DAQmxClearTask(encoder0TaskHandle)
        DAQmxErrChk DAQmxClearTask(encoder1TaskHandle)
        DAQmxErrChk DAQmxClearTask(BaseTaskHandle)
        Exit Sub
    ErrorHandler:
    '   MsgBox "Error: " & Err.Number & " " & Err.Description, , "Error"
    '    mlngPWM_ErrorCount(lngChannel) = mlngPWM_ErrorCount(lngChannel) + 1
        'MainForm.PWMErrorCount = "Errors(" & lngChannel & "): " & mlngPWM_ErrorCount(lngChannel)
        Resume Next
    End Sub

  • How to visualise continues Data aquisition from a PCI 6602 with 2121 BNC connector board in C++ ?

    Hello everyone,
    We are trying to get on the screen the aquired pulses from our  PCI 6602 with a 2121 BNC connector board, from several devices. We are able to read the data and save without problem, but we cannot look at it while we are measuring. Anybody has an idea to how program this in C++ ? Any suggestion is welcome!
    Thanks for the help

    Hi,
    try to look for some example programs and Tutorials:
    Examples Results
    http://search.ni.com/nisearch/app/main/p/bot/no/ap/tech/lang/en/pg/1/sn/catnav:ex/q/DAQmx%20C%2B%2B/...
    Tutorials Results
    http://search.ni.com/nisearch/app/main/p/bot/no/ap/tech/lang/en/pg/1/sn/catnav:tu/q/DAQmx%20C%2B%2B/...
    You should also have a look at the "C Reference Help" which is installed with the NI DAQmx driver.
    Acquire N Scans (Visual C++ 6.0, CW++, NI-DAQ)
    http://zone.ni.com/devzone/cda/epd/p/id/207
    Continuous Analog Acquisition with Producer Consumer Architecture in C#
    https://decibel.ni.com/content/docs/DOC-4253
    Good Luck!
    Matteo

  • Error -200141 when doing buffered events with DAQmx and PCI-6602

    When doing buffered events with DAQmx and PCI-6602 I get error 200141 - Data was overwritten before it could be read by the system.
    This error is generated ONLY with random inputs >200/sec.
    My setup is :
    DAQmxCreateCIVCountEdges(taskhandle,"Dev1/ctr3"....
    DAQmxCG+FGSampClkTiming(taskhandle,"/Dev1/FPI35",...
    DAQmxSetCICountEgdesChan(taskhandlem,"", "/Dev1/80MHZTimeBase")
    DAQmxSetChanAttribute(taskhandlw,",",DAQmx_CI_DataXferMech,DAQmx_Val_DMA,0);
    Can somebody help ?

    i'm getting the same Error-200141, while reading semiperiods. (Meas_Buffered semiperiod continous)
    while loop ex.rate seems to be pulsewidth*no.Samples to read. in my case PW=60ms
    Input buffer size measured with Property node= 10000
    why this error happens?? i cant use any mode other than implicit timing for semi-period measurement right??
    more info: all the ai channels are used ~ 16 differencial.
    i found one solution which is _ reinitializing the whole task if an error occur. is this the right way??
    Kudos always welcome for helpful posts
    Attachments:
    Counter_1_Meas Buffered Semi-Period-Continuous_main_lv09.vi ‏34 KB
    SemiPeriod_Reconnect Counter on Error.vi ‏35 KB

  • Connect NI PCI-6602 with NI PCI-6503

    Hello,
    I want to connect a NI PCI-6602 Counter/Timer with the NI PCI-6503 DIO-Card. The problem is the varying number of pins. (6602->68 pins; 6503 -> 50 pins). Is there a possibility to connect both? Maybe a complete adapter?
    regards Thomas

    Thomas,
    You are correct both cards have male connectors. You could still use the 68M-50F connector if you use a 68-68 cable. Or if you had a 68F-50M then you would need a 50 pin cable. I have found another option, the R6850-D1 Cable(part number 777419-01) . This is a digital cable that was made to use our 68 pin digital devices with 50 pin breakout boxes. It ties the ground lines together and you also loose access to PFI 37,the up/down pin for counter 0, and you loose the +5V line. I think you may want to check the pin mappings to make sure that you really want to connect these 2 boards directly together. When using a 50 pin conversion with the 6602 you will get the following pin mapping:
    Pin Number (1-50) 6602 Signal Name
    1 PFI_25
    2 PFI_28
    3 PFI_27
    4 PFI_24
    5 PFI_30
    6 PFI_31
    7 PFI_26
    8 PFI_29
    9 PFI_21
    10 PFI_23
    11 PFI_19
    12 PFI_17
    13 PFI_18
    14 PFI_16
    15 PFI_22
    16 PFI_20
    17 GND
    18 PFI_34
    19 GND
    20 PFI_35
    21 GND
    22 PFI_33
    23 GND
    24 PFI_32
    25 GND
    26 GND
    27 PFI_38
    28 GND
    29 Reserved
    30 GND
    31 PFI_36
    32 GND
    33 PFI_39
    34 GND
    35 PFI_4
    36 PFI_6
    37 PFI_0
    38 PFI_2
    39 PFI_1
    40 PFI_3
    41 PFI_7
    42 PFI_5
    43 PFI_13
    44 PFI_10
    45 PFI_15
    46 PFI_14
    47 PFI_8
    48 PFI_11
    49 PFI_12
    50 PFI_9
    You will loose half of the cards functionality since half the pins (even numbered pins) will be connected to ground on the 6503. It would be easy for you to short lines to ground this way. It would probably be better if you get a breakout box for each card (SCB-50 and SCB-68) and then connect only the lines you want to share between the cards. So in answer to your question, yes you CAN connect then directly together, but do so with caution, and I do not feel this direct connection is the best solution for y
    ou.
    Hope this helps.
    Kevin R

  • Can I trigger the read of a buffer period measuremen​t with a external signal (PFI line) with my 6602 card? How can I do it?

    I am doing a buffered period measurement with a 6602 card, Labview real time. I want to measure the period of 6 rising edges of a TTL, but I want to do it exactly when an edge comes on other external signal (of course slowler than the previous one), that is to say that I want an external start trigger. Can anybody help me? I have hardly searched at the web and I have not found an example of code of what I am looking for.
    Another question:
    After reading the buffer, how does my program know that the data has been refreshed in a continuous measurement? I attach two VIs I am trying to make work and a quite explanatory bmp of what I
    want to do.
    Thanks.
    Attachments:
    rtc_regimen.zip ‏3 KB
    Buffered_Period_pulse_generation.vi ‏283 KB
    simgle_counter_pulse_generation.vi ‏177 KB

    Hello;
    I can't think of any way to accomplish that task. Once the counters have only two input pins, and both are in use when one configures the counter to do buffered measurements, there isn't a way to trigger that operation in hardware.
    I'm not sure if I understood your second question, however, the buffered operation on a counter is hardware controlled, meaning that a pulse on its gate input triggers the transfer of the count value from the counter register to the PC memory buffer. That is therefore a continuous measurement.
    Regards
    Filipe A.
    Applications Engineer
    National Instruments

  • Generating two pulse trains with on a PCI 6602 (2 CWPulse)

    I am writing an application that should generate 2 pluse trains. I'am using ComponentWorks 3. I've tried to use 2 CWPulse but after configuring the 1st, i cannot start the other one because "too many controns are configured for this DAQ device".
    Do you know how to use 2 CWPulse with a 6602 device ?

    Dear Sir,
    If you need to use two CWPulse components you will not be able to set a finite number of pulses to be generated. When you set the component to produce a finite number of pulses, it actually uses two counters to perform the operation. One is used to generate the pulses and the other one is used to count the pulses that are generated. You can use multiple CWPulse components as long as the pulse type is set to continuous on both components.

  • Generate two different pulses or more continuous​ly with a PCI -6602

    I have a PCI-6602 and Labview 8.0. I need to create a complex wavefrom output  and I don't know how to create this waveform with the 6602, I know that I can create this pulse format by using the Agilent Pulse Generator  but I would like to use the National Instruments. If somebody has an idea about how many counters and the physical connections that I need, also about how can I use labview to generate a complex waveform output.
    I've attached the waveform that I need to generate continously and I hope that I can use the PCI-6602 for this purpose.
    Attachments:
    Pulse format.doc ‏24 KB

    This is a duplicate post, for the main post please see:
    NI Discussion Forums: How to generate two diferent pulses and re-trigger such pulses continously
    Regards,
    Dan King

  • PCI 6602:How can I use the digital lines of the board and in the same time to generate pulse train using a counter?

    Hello!
    My problem appeared when I tried to update my code from Traditional NI-DAQ Legacy to DAQmx.
    I am using 2 counters (counter 5 and counter 7)  from PCI-6602, to generate pulse train, and also the Digital I/O lines of the port 0 (the lines form 0 to 7). What I do in my application is that I am starting to generate the pulse train on the output of the 2 counters, and after that I am playing with the state of the digital lines.
    In traditional there was no problem using the counters and the digital lines in the same time, everything was going perfectly, but in DAQmx this is not possible.
    What happens: I start to generate pulse train on the output of the counters,  no errors encountered, but when I try to modify the state of one line of the digital port the generation of the pulse train is stopped. This is happening when I start the task associated to the digital port.
    My question is: it is possible to create a channel on the digital lines without altered the channels created for the counters?
    Another thing what I manage to see using the  "Measurement & Automation Explorer" and Test panels for PCI-6602, basically is the same thing, I generate pulse train on the output of the counter 7 and try to start a task on the digital line, but I get one error :
    "Error -200022 occurred at Test Panel
    Possible Reason(s):
    Measurements: Resource requested by this task has already been reserved by a different task.
    Device: Dev4
    Terminal: PFI8"
    Instead if I use the counter 0 or counter 1 to generate pulse train I don't encounter the same problem.
    Which resources are used by the counters 2 to 7 from the PCI-6602 board and the counters 0 and 1 do not use?
    Thank in advance for any replies!
    Ciprian
    Solved!
    Go to Solution.

    Hello Jordan, thank you for your reply.
    I am sorry but I can not see or run your example, I don't use LabView, I use Visual C++ for developing.
    Here is the code for generating the pulse train:
    GeneratePulseTrain(unsigned long ulCount1, unsigned long ulCount2)
        short nStatus = 0;
        nStatus = DAQmxCreateTask("",&m_taskHandle);
        nStatus = DAQmxCreateCOPulseChanTicks (m_taskHandle, "Dev4/count5", "", NULL, DAQmx_Val_Low, 0.0, ulCount1,ulCount2);
        if( bTriggerMode == true) // if hardware trigger is enabled
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_ArmStartTrig_Type, DAQmx_Val_DigEdge);
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Edge, DAQmx_Val_Rising);
            nStatus = DAQmxSetTrigAttribute (m_taskHandle, DAQmx_DigEdge_ArmStartTrig_Src,"Dev4/PFI17" );
        //set the internal timebase
        nStatus = DAQmxSetCOCtrTimebaseSrc(m_taskHandle,"Dev4/count5","20MHzTimeBase" );
        nStatus = DAQmxStartTask(m_taskHandle);
        return nStatus;
    And the code where I try to set the digital line:
    SetChannelState(short nState)
        short nStatus = 0;
        uInt8 wrtBuf0[1]={0};
        nStatus = DAQmxCreateTask("",&m_taskHandle);
        // Configure line as output 
        nStatus = DAQmxCreateDOChan (m_taskHandle, "Dev4/port0/line0", "", DAQmx_Val_ChanPerLine);
        nStatus = DAQmxStartTask(m_taskHandle);
        wrtBuf0[0] = nState;
        nStatus =DAQmxWriteDigitalLines (m_taskHandle, 1, 0, 0, DAQmx_Val_GroupByScanNumber , wrtBuf0, NULL, NULL);
        nStatus = DAQmxWaitUntilTaskDone(m_taskHandle,10);
        nStatus = DAQmxStopTask(m_taskHandle);
        nStatus = DAQmxClearTask(m_taskHandle);
        m_taskHandle = 0;
        return nStatus;      

  • Conceptual problem in using a PCI-6602?

    Hi, All You Wild and Crazy NI/LabVIEW Types --
    I have a problem that's been close to sending me off the deep end for more than a month now, and I think that I'm so enmeshed in it that I can't see the forest for the trees anymore. I'd like to apologize in advance for the length of this post, but there are some details that might or might not be important, and I'd rather make the mistake of giving you too much information than not enough.
    We do impact-cratering experiments, using a gun to launch (usually) spherical projectiles at a variety of targets. One of our big efforts is to measure the velocities at which material is ejected from growing craters. We do that with a line-generating laser, oriented so the "sheet" of laser light is perpendicular to the target's surface and through the impact point; we strobe the laser at a programmed rate (with our PCI-6259 board) and take a time exposure of the scene with a Nikon D100 DSLR. When target material -- usually grains of sand -- is ejected, the laser illuminates a "slice" through the curtain of ejecta, illuminating a small portion of the fragments numerous times in their trajectories. Since we know the scale of the photograph and its orientation relative to the laser's illumination, and we also know the rate at which the laser is flashing, we can easily calculate the velocities of the illuminated particles. I'm attaching a picture (file 4044, cropped.jpg) of an example taken with an older camera to give you an idea. In the picture, the laser's illuminating the scene from the right of the frame and the projectile flew into the picture from the top of the frame, traveling along the left-hand edge. The brightest portion is the flash from the impact, and the rest of the parabolic trajectories are the grains of sand in flight. The target bucket, full of coarse sand, is the elliptical looking cylinder at the bottom of the picture. It's roughly 28 cm in outside diameter, if you'd like a scale.
    As you might imagine, with our projectiles moving anywhere between 0.7 and 3 km/s, sequencing everything is pretty important. We're using (or trying to use) LabVIEW to do all of the sequencing, instrument control, and data storage. Things are going pretty well so far, except for what I'll describe in more detail below. A couple more things, though, first. It's important that we measure the projectile's speed in each shot, as that controls impact energy and momentum, which are critical to know in a given experiment. We do that with simple laser-photodetector pairs (which we normally call "velocity stations") arranged along the projectile's trajectory. As the projectile passes between a laser and its detector, its shadow is detected and a TTL pulse is sent to our PCI-6602 board. Depending on the experiment, we use three or four such laser-dector pairs. They use counters 0, 1, 2, and 3. We know the distances between the laser stations and, once we get the times between detections, it's s simple matter to calculate the projectile's velocity.
    We also use LabVIEW to fire the gun, and we do that because opening the camera's shutter has to be synchronized with the firing pulse, which currently is sent via P1.1 on the 6259. Here's the problem: when we test the laser-detector arrays in a "standalone" mode (that is, without any other tasks or operations being done with LabVIEW), they work infallibly. It's when we try to use LabVIEW to fire the gun that we get either very erratic results from the velocity stations/6602 or no results at all.
    I've tried a range of things, from starting the two-edge measurement task before the firing signal is sent, to trying to force things with a timed sequence, to doing things with brute force via a seuqence structure. When I try to start the two-edge measurement task first, though, the firing signal isn't sent until the counters time out. This of course, wrecks the experiment, because all of the timing is then messed up. The VI that I've attached (Version 1.vi) is a HIGHLY simplified version of the initial attempt I made at doing this, with all sorts of background stuff removed just so I can cut to the chase. (Only one two-edge measurement task is shown, for instance.)  I think that the VI is pretty self-explanatory (and embarrassingly primitive), so it probably doesn't need much in the way of explanation. Counter 7 and PFI 0 on the 6602 are used to accept the signal from the firing button and trigger the event structure, which contains the two-edge separation and gun-firing tasks. (In reality, I use a separate VI to have three to four concurrent two-edge separation tasks running concurrently, one for each velocity station.) I start the two-edge separation tasks first so the detectors and counters are ready for the projectile. It's not necessary here, but I kept the 500 ms wait frame in this example because that's why the sequence structure exists -- to allow the shutter of the Nikon to open completely before the gun fires. After those 500 ms, the firing signal is sent to the circuit that actually fires the gun.
    What happens in this configuration is that the second frame of the sequence structure doesn't execute until the 5-s timeout transpires in the two-edge separation task. I've also tried this using a line on the 6602 to fire the gun instead of P0.1 on the 6259, but that ends up with the same result. (Both counters are used on the 6259 to strobe the main illumination laser, so they're unavailable, if you're wondering. In any case, we need four counters for the four velocity stations.)
    FINALLY, my question: What am I doing wrong, here? If I put the two-edge separation tasks in the same frame of the sequence structure as the firing task, the gun fires when it's supposed to, but we get no velocity measurements. I've also tried to force the timing with another version of a sequence structure; I'm attaching another very simplified version below as Fire and speed example.vi.
    After you recover from your violent fits of laughter, I'd really appreciate hearing what you might recommend. (And no, surrender isn't an option.)
    Thanks for taking all of your valuable time to read this huge post -- I really appreciate it!
    Mark
    Attachments:
    4044, cropped.jpg ‏197 KB
    Version 1.vi ‏35 KB
    Fire and speed example.vi ‏30 KB

    I agree with all 3 of Kevin's points.  His first suggestion will probably fix your problem (see below).  The 2nd and 3rd suggestion would improve efficiency and responsiveness, but #2 might not be possible since independently triggering four outputs in hardware would require the use of 4 counters (on the 6602 anyway) which might be busy doing other tasks in your application (although if you don't need the stations to trigger independently then you could implement this with a single counter).
    I think I have an explanation of the problematic behavior you are seeing based off of the following bits of information from your post:
    1.  Running the small example code by itself works flawlessly, but adding other simultaneous functionality fails.  You mentioned you are doing this on 4 stations, so I'm assuming 4 counter input tasks running in parallel.
    2.  The behavior you are seeing is that the 2nd sequence does not execute until after the read times out (note that the sequence is supposed to be executing in parallel with the read).
    It sounds like the problem is coming from a combination of calling into DAQmx Read before data is available (this consumes one of the threads that LabVIEW has allocated to your application until DAQmx Read finishes executing) along with the fact that LabVIEW allocates 4 threads per execution system per priority by default.  Since all of your threads (from what I can tell) are executing on the same priority, the 4 reads you are calling will block anything else from executing until they have completed.  By then it's too late and the firing of your gun happens after the counter task has already timed out.
    You *may* increase the number of threads allocated to your application by using a VI that is included with LabVIEW (vi.lib\Utility\sysinfo.llb\threadconfig.vi) and this would also probably remedy the behavior you are seeing.  However, rather than throwing more threads at this application I think the better solution would be to change the sequencing of your tasks like Kevin suggested ("create and start the 2-edge task before entering the sequence structure, and defer the 2-edge *reading* until *after* firing the DO")--in doing this you would now expect to see data immediately upon calling DAQmx Read and you avoid the situation where Read is blocking indefinitely and consuming an application thread.  You could take this a step further by checking the Available Samples per Channel property (or using the DAQmx EveryNSamplesAcquiredIntoBuffer event) to ensure that data is actually available before calling Read.
    Best Regards,
    John Passiak

  • Maximum number of PCI-6602 cards in 1 computer?

    Is it possible to have 4 PCI-6602 cards in 1 computer?
    Are there any DMA channels or IRQ limitations we need
    to worry about?
    Our computer will have 1 graphics card in the AGP slot,
    possibly a PCI NIC ethernet card and possibly a PCI
    based sound card. It will also have an IDE controller
    with 2 hard drives and 1 CDRW.
    The PCI-6602 manual seems to imply that if you are
    using more than 3 counter channels that you must
    use the slower Interrupt based transfer mode which
    has a maximum transfer rate specified as 2000
    Reading/second. If there are 4 PCI-6602 boards in
    the same computer and all 8 of the channels are
    used on each board does that mean the total
    transfer rate is still 2000 Readings/sec? Or
    wo
    uld the total transfer rate be 8000 Readings/Sec
    since there are 4 PCI-6602's (2000 Readings/Sec
    for each of the 4 PCI-6602's)?

    Hello;
    The only concern you need to have is the number of IRQs available. As far as DMA channels, as the PCI bus itself has only 3 DMA channels available, all the devices that use DMA will share those 3 channels. But, as IRQs can't be shared, the number of counters you will be able to use will be the exact number of available IRQs you still have on your machine.
    As far as transfer rate, the maximum transfer rate will be 2000 Readings/sec, regardless the number of counters you are using.
    Hope this helps.
    Filipe

  • How to generate a pulse on x number of events PCI-6602

    I am running LabVIEW 5.1 full development with a PCI-6602 counter board.
    I would like to generate an output pulse after counting x number of input pulses. I would also like to reset the counter with an external signal.
    My application is I am trying to generate a second index pulse for an encoder.
    I would like to count the pulses from encoder phase A and generate an output pulse on x number of counts. Then I would like to reset the counter using the encoder’s index pulse. This way I can change the phase of the “generated” index pulse with respect to the “real” index pulse by x number of counts (degrees) and maintain that regardless of encoder rpm.
    Thanks
    Brian

    Brian,
    There actually is a way to do what  you want, but it gets a little complicated.  I don't have LV on this machine so I'll have to just describe the idea.  First a summary: the counter will repeatedly countdown to 0.  Each time it reaches 0, it will generate a brief pulse which will in turn hw-reset the counter value to N.  Then it will countdown to 0 again, etc.  The same brief pulse could also be wired to a different encoder-measuring counter to create a "delayed" reset to 0 (or some other #).
    1. Configure your counter for "position measurement" instead of "simple event counting".  Set the encoder type to, um, I forget the name -- something like "two pulse encoder."  It's the setting that will increment with every SOURCE edge and decrement with every AUX edge.  Wire your encoder channel A to the counter's default AUX input (in position encoder mode, you must use the default input pins).  Hard wire from the default SOURCE input to GND.  Now every encoder edge will decrement the count, and nothing wlil ever increment it.
    2. Configure the counter to use z-indexing.  Set the z-index reload value to be N-1, where N is the # of encoder counts by which to delay the encoder's real z-index pulse.  Set the z-index reload phase appropriately, probably to A low B low.  Wire the real z-index pulse to the counter's GATE input.
    3.  Configure the counter to "pulse on terminal count" -- you do this using 'Counter Set Attribute.vi'.  So N encoder edges after the real z-index pulse, you'll generate a pseudo-z-index with this counter.
    4. You can wire this pseudo-z-index to the GATE input of the encoder-measuring counter.  Now the encoder's z-index pulse is delayed by an amount you can program.
    5. Note: this method requires the motion to be uni-directional.
    Good luck!
    -Kevin P.

Maybe you are looking for