Forum Italiano sui Prodotti NI

annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

Analog Input RelativeTo problem

Hello,

I'm trying to acquire an analog signal coming from an accelerometer. My software calls DAQmxReadAnalogF64 in a callback function whose frequency is set to 1KHz by TimeSetEvent windows function. My aim is to implement a digital low-pass filter: at each reading the last 20 samples have to be multiplied by 20 digital filter's coefficients (sampling rate is 20KHz). Here is reported the code of the configuration part:

 

    " DAQmxErrChk( DAQmxCfgSampClkTiming(TaskHandle,"",SamplingRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,2*NumCoefFilter));

     DAQmxErrChk( DAQmxCfgInputBuffer (TaskHandle,2*NumChannels*NumCoefFilter));

     DAQmxErrChk( DAQmxSetReadOverWrite(TaskHandle, DAQmx_Val_OverwriteUnreadSamps));        
     DAQmxErrChk( DAQmxSetReadRelativeTo(TaskHandle, DAQmx_Val_MostRecentSamp));
     DAQmxErrChk( DAQmxSetReadOffset(TaskHandle, -(int)NumCoefFilter));"

 

 NumCoefFilter is 20 and NumChannels is 9. In the callback function I read the samples:

"timeout=(double)mNumCoefFilter/mSamplingRate;

DAQmxErrChk( DAQmxReadAnalogF64(mTaskHandle,(int32)NumCoefFilter,(float64)timeout,(bool32)DAQmx_Val_GroupByScanNumber, (float64*)DAQmxReadBuffer,(uInt32)DAQmxReadBufferSize,(int32 *)&mNumSampsRead,NULL));"

 

My first question is: last samples are stored in DAQmxReadBuffer at initial or final position?

 

In execution I receive the following error:

 

"Measurements: Requested value is not a supported value for this property.

Property: DAQmx_Read_RelativeT

You have requested: DAQmx_Val_mostRecentSamples

You Can Select: DAQmx_Val_CurrReadPos

Status code: -200007"

 

The same kind of configuration doesn't give error to me when I calculate a linear regression on 20 last samples. Where is the error?

0 Kudos
Messaggio 1 di 6
6.057Visualizzazioni

Hi Dario,

may you please tell us which card are you using and which version of the drivers?

I looked at your code and I actually found nothing wrong...

Thank you,

regards,

Lucius

0 Kudos
Messaggio 2 di 6
6.048Visualizzazioni

Finally I've found a silly error (missing break) that cause initialization to zero value of NumCoefFilter, so I didn't have offset in DAQmxSetReadOffset.

Now I have only the following question: where the last samples are stored in DAQmxReadBuffer? at initial or final position in the array?

I'm using a PCI-6220 and NI-DAQmx 8.9 software.

Thank you,

Dario


lucius wrote:

Hi Dario,

may you please tell us which card are you using and which version of the drivers?

I looked at your code and I actually found nothing wrong...

Thank you,

regards,

Lucius


 

 

0 Kudos
Messaggio 3 di 6
6.043Visualizzazioni

Hi Dario,

when you set a continuous acquisition the buffer is used as a circular buffer; that means that there is an index which is incremented by one for each sample that is acquired. When the index equals the size of the buffer, it is resetted to zero and the sample is put in the first position of the buffer.

In the meanwhile there is another index relative to current read position which moves in the same way (but in chunks), emptying slices of the buffer preceding (in the circular way) the most recent sample index. 

I hope it's clear.

Regards,

Lucius

0 Kudos
Messaggio 4 di 6
6.037Visualizzazioni

This is clear. So, with DAQmxReadAnalogF64 function I put in a ReadBuffer array the N last samples acquired. Now, my question is: the last sample is in position ReadBuffer[0] or ReadBuffer[N-1]?

Thank you,

Dario

0 Kudos
Messaggio 5 di 6
6.028Visualizzazioni

Hi Dario,

accordingly to the NI-DAQmx Help the last sample is in ReadBuffer[N-1]:

 

from DAQmxReadAnalogF64 help page:

readArray    float64[]    The array to read samples into, organized accordingly to fillMode

 

and from the Interleaving help page of fillMode:

 

Interleaved samples prioritize samples before channels, such that the array lists the first sample from every channel in the task, then the second sample from every channel, up to the last sample from every channel.

 


Non-interleaved samples prioritize channels before samples, such that the array lists all samples from the first channel in the task, then all samples from the second channel, up to all samples from the last channel.

 

Regards,

Lucius

 

 

0 Kudos
Messaggio 6 di 6
6.024Visualizzazioni