Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ matlab lowpass filter enabling

Hello everybody,

 

I'm trying to activate the internal lowpass filter of the NI6120 DAQ with Matlab. I tried the following skript but I didn't work.

 

Additionally I'd like to know if it is possible to use the DAQ-Toolbox of Matlab to use the counter for frequency measurement. If not is it difficult to implement it?

 

Thanks a lot

Markus 

 

 

    %Filter Property
    DAQmx_AI_Lowpass_Enable = hex2dec('1802'); % Specifies whether to enable the lowpass filter of the channel.

    %Activate LOWPassFilter

    taskLP=uint32(1);
    [a,b,taskLP] = calllib('myni','DAQmxCreateTask','LP',taskLP)
    disp('LOWpass');


    %--- C-Code to enable Filter
    %int32 __CFUNC DAQmxSetAILowpassEnable(TaskHandle taskHandle, const char channel[], bool32 data);

    disp('set LowpassEnable');
    Data = DAQmx_AI_Lowpass_Enable;
    [a,b]=calllib('myni','DAQmxSetAILowpassEnable',taskLP,taskchans1,Data)

    %--- C-Code to get if Filter is enabled
    %int32 __CFUNC DAQmxGetAILowpassEnable(TaskHandle taskHandle, const char channel[], bool32 *data);

    disp('Get LowpassEnable');
    DataPtr = libpointer('uint32Ptr',Data);
    [a,b,cc]=calllib('myni','DAQmxGetAILowpassEnable',taskLP,taskchans1,DataPtr)
      

    [a] = calllib('myni','DAQmxStartTask',taskLP)%for LP added
    [a] = calllib('myni','DAQmxStopTask',taskLP);%for LP added
    [a] = calllib('myni','DAQmxClearTask',taskLP);%for LP added

0 Kudos
Message 1 of 5
(4,902 Views)

Hello Markus,

I think the problem is related to the fact, that no channel is created before calling the function DAQmxSetAILowpassEnable(...). You should call the function DAQmxCreateAIVoltageChan(...) before calling the function  DAQmxSetAILowpassEnable(...).

A C-Example with these function calls could look like this:

int main(void)
{
    TaskHandle  taskHandle=0;

    /*********************************************/
    // DAQmx Configure Code
    /*********************************************/
    DAQmxCreateTask("",&taskHandle);
    DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","aichann",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL);
    DAQmxSetAILowpassEnable(taskHandle,"aichann",TRUE);

    .

    .
     

The only information I have concerning your question about the Matlab DAQ-Toolbox is a list of the supported NI-hardware which can be found under: http://www.mathworks.com/products/daq/supportedio14005.html.


I hope I could help you.

Best regards,

Blase

0 Kudos
Message 2 of 5
(4,872 Views)

Hi Blase,

 

thank you for your response.

 

The code I have written was only an excerpt of my programme, that's the reason I have forgotten to mention the create function. 

 

 -----THis was missing-------

% Other constants must be searched in the NI installation directory
DAQmx_Val_Volts= 10348; % measure volts

%Filter Property
DAQmx_AI_Lowpass_Enable = 1; % Specifies whether to enable the lowpass filter of the channel.

disp('NI: Create Tasks')
taskh1=uint32(1);
[a,b,taskh1] = calllib('myni','DAQmxCreateTask','master',taskh1)
% a will be the error code

disp('NI: Create AI Channels')
taskchans1=['Dev1/ai0:' num2str(numofchans-1)];
[a,b,c,d] = calllib('myni','DAQmxCreateAIVoltageChan',uint32(taskh1),taskchans1,'',-1,-10,10,DAQmx_Val_Volts,'')

---------

followed by the older code sequence

--------------

    %Activate LOWPassFilter
    taskLP=uint32(1);
    [a,b,taskLP] = calllib('myni','DAQmxCreateTask','LP',taskLP)
    disp('LOWpass');


    %--- C-Code to enable Filter
    %int32 __CFUNC DAQmxSetAILowpassEnable(TaskHandle taskHandle, const char channel[], bool32 data);

    disp('set LowpassEnable');
    Data = DAQmx_AI_Lowpass_Enable;
    [a,b]=calllib('myni','DAQmxSetAILowpassEnable',taskLP,taskchans1,Data)

    %--- C-Code to get if Filter is enabled
    %int32 __CFUNC DAQmxGetAILowpassEnable(TaskHandle taskHandle, const char channel[], bool32 *data);

    disp('Get LowpassEnable');
    DataPtr = libpointer('uint32Ptr',Data);
    [a,b,cc]=calllib('myni','DAQmxGetAILowpassEnable',taskLP,taskchans1,DataPtr)
      

    [a] = calllib('myni','DAQmxStartTask',taskLP)%for LP added
    [a] = calllib('myni','DAQmxStopTask',taskLP);%for LP added
    [a] = calllib('myni','DAQmxClearTask',taskLP);%for LP added

-----------

 

I'm not sure what's the reason so that it's not working properly. I have also changed the entry of the filter value

DAQmx_AI_Lowpass_Enable to 1 instead of true.

 

best regards

Markus 

 

0 Kudos
Message 3 of 5
(4,857 Views)

Hi Markus,

 

I had the same problem and was able to get it to work by writing a shared library (ni6120.dll) and then calling the external functions in my matlab code.  I've attached the code I used.  You can look at the script lowpass.m to see how to call the library functions.  Setting dofilt=1 in the code will use the 100 kHz AA filter, and dofilt=0 will disable the filter. 

 

-Dave 

0 Kudos
Message 4 of 5
(4,838 Views)

Hi Dave,

 

Thanks a lot. And sorry for the late response, but I was ill the last view days.

 

Markus

0 Kudos
Message 5 of 5
(4,765 Views)