Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Counter with external Timing stops after a few measurements

Hello everyone!

 

This is my first project using Nidaqmx and I've run into a problem:

I want to measure the incoming signals with respect to a timing signal I create with the following code:

 

    DAQmxCreateTask("timing", &task_timing);
    DAQmxCreateCOPulseChanFreq(task_timing, timing_ctr, "timing",DAQmx_Val_Hz, DAQmx_Val_Low,0.0,hz,0.5 );
    DAQmxSetChanAttribute(task_timing, "timing", DAQmx_CO_Pulse_Term, timing_slot);
    DAQmxCfgImplicitTiming(task_timing,DAQmx_Val_ContSamps,1);
    DAQmxStartTask(task_timing);

 

This seems to be working as intended, but in my counter there seems to be a mistake:


    DAQmxCreateTask("counter", &task_ctr);
    DAQmxCreateCICountEdgesChan(task_ctr,counter_ctr, "counter", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp);
    DAQmxSetChanAttribute(task_ctr, "counter", DAQmx_CI_CountEdges_Term, counter_slot);
    DAQmxCfgSampClkTiming(task_ctr, timing_slot, hz, DAQmx_Val_Rising, DAQmx_Val_ContSamps, hz);

 

or in the function responsible for reading from the counter:

 

    while (true)
          {
            DAQmxReadCounterU32(task_ctr, -1, 10.0, data, hz, &read, NULL);
            for (u = 0 ; u<read; u++)
            {  delta_t++;
                if (data[u] > cnt)
             { cnt=data[u];
              cout<<  delta_t << '\t' << cnt;
                 delta_t = 0;
            }
        }
   }

 

Shouldn't this function write a continuous stream as such:

    1000   1

    1000   2

        ...

        ...

        ...

 

Instead it stops after 2 or 3 lines.

 

Thank's in advance!

Markus

 

 

0 Kudos
Message 1 of 2
(2,358 Views)

Hi h_markus,

 

It looks that the code you have posted is missing proper error handling, which I would strongly advise you to add. It will allow you to better understand what is happening with your application and potentially to find the reason why it stops after the second iteration.

I suggest starting with a built-in example - Cnt-Buf-Cont-ExtClk, which you can find in LabWindows/CVI after clicking help>> find examples. It shows the functionality you are looking for. 

 

Best Regards,

---
CLA,CTD,CLED
0 Kudos
Message 2 of 2
(2,264 Views)