Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Count input impulses

Solved!
Go to solution

The task is input impulses counting. Pulses are shown in attachment.

 

How can I do it  effective for perfomance reasons ?

 

I see two ways.

 

The first way is using continuous accuring 1 value and check exceeding the threshold (as in example NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Slow Varying Signal\One Sample):

...

int32 error=0;
TaskHandle taskHandle;
float64 value;
char errBuff[2048]={'\0'};

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev3/ai6","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,""));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogScalarF64(taskHandle,10.0,&value,0));

printf("Acquired reading: %f\n",value);

 

 

 

The second way is to read buffer (set of samples like shown in example NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Sound Pressure\Cont Acq Snd Press Samps-Int Clk):

 

int32 error=0;
TaskHandle taskHandle=0;
int32 read,totalRead=0;
float64 data[10];
char errBuff[2048]={'\0'};

/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev3/ai6","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",100.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));

/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxErrChk (DAQmxStartTask(taskHandle));

printf("Acquiring samples continuously. Press Ctrl+C to interrupt\n");
while( 1 ) {
/*********************************************/
// DAQmx Read Code
/*********************************************/
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle, 10, 10.0 ,DAQmx_Val_GroupByScanNumber, data, 10, &read, NULL));

if( read>0 ) {
printf("Acquired %d samples. Total %d\r", (int)read, (int)(totalRead += read));
fflush(stdout);
}
}
printf("\nAcquired %d total samples.\n", (int)totalRead);
getchar();

 

0 Kudos
Message 1 of 3
(3,178 Views)
Solution
Accepted by topic author forcety

Hello,

 

I can see from your screenshot that you have some pulses coming in and you only want to print values when the pulse goes over a certain threshold. When trying to count pulses, it is best to use the continuous measurements from the second example you sent down.

 

The reasoning for this is that measuring using single point is limited by your computer. If your computer cannot perform it’s read loop at the speed you would like, then the entire process will slow down your data acquisition rate. If that happens, then you cannot accurately determine when the pulse rises, and you may just completely miss pulse counts..

 

The second option will continuously take data at the rate you want and store it on the onboard memory. From there, you pull the data off the memory and then analyze it in batches shown in your second example.

 

Since you have square wave impulses coming in, what device are you using? Do you have any counter devices that you could use in a more reliable manner?

 

Best,

 

Shamik C

Applications Engineer

National Instruments

http://www.ni.com/support

0 Kudos
Message 2 of 3
(3,134 Views)

Hello.

Thank you for your feedback!

This is special sensor for axes counting.

0 Kudos
Message 3 of 3
(3,117 Views)