Measure

cancel
Showing results for 
Search instead for 
Did you mean: 

How to acquire analog input driven by digital output? (NI-6251 with Matlab)

Hello,

Congratulations for the forum!

Excuse me for the bad english. I little use Google translate

My task is to program with Matlab this National Instrument module http://sine.ni.com/nips/cds/view/p/lang/en/nid/202597 (using the "Data Acquisition Toolbox").
It have to download data from the accelerometer sensor ADXL330, which generally earns 3 offset voltages in the middle of its supply voltage and measure the acceleration in the range + / - 3g


At this stage of the project, my problem is as follows:

I have two boards ready: the first is the accelerometer with three issues AD694 for x, y and z axes, ie the circuit board with 4-20mA outputs.

Second board with resistors groups convert current into voltage. Then multiplexer 4052 switches, these three voltages (for x, y, z axes) with a certain frequency.

This chip is: http://www.datasheetcatalog.org/datasheet/philips/HEF4052BN.pdf

Indeed, National Instuments DAQ must read this three voltages switched on 1 wire (ie the output of the multiplexer).


The code for driving the multiplexer is:  mux_control.m

 

Accelerometer will measured vibration.

The code of the program for the analog inputs of the NI DAQ is: ACC_RT.m


The big problem for me is how for each switching of multiplexer for X, Y and Z to read this voltage with NI-DAQ board and write to a file with 3 columns of data? 


or how to acquare this three voltages and store them into a matrix with three columns .. 

May I asked too many questions, but just my time is limited to February 2010 ... by then the project should be ready

Thanks in advance!
I have all the electrical circuits ..
Message Edited by krasi85 on 12-26-2009 11:51 AM
0 Kudos
Message 1 of 12
(9,716 Views)

Hi krasi85!

 

 

I'm not sure whether  I understand properly, but it seems you need to acquire data whenever you switch to different accelerometer, or by other words, when you switch input of your MUX (multiplexer). If this is the case, than what you are looking for is using analog input with external AI Sample Clock.

 

But first of all, I have to say at least 2  thinks - the product you have choosen is realy not the best for measuring signal from accelerometers (and who knows what you will have from the real vibration signal after you run it trough multiplexer ). Try to see what products you can find under products dedicated for vibration and noise measurement - DSA! Those boards have many advanages compared to m series when measuring vibration - start with dynamic range, go to dedicated converters for each input, oversampling, and so on... In fact, programming, however, is very similar (if not the same).

 

 

I'm not sure if I help you with matlab itself, but what as I mentioned, you are looking for using external sample clock. See M-series user manual, part with Analog Input Timing Signals, page 4-25. External sample clock signal can be taken from whichever PFI line.

 

What I found out is, that you can already use pfi routing with Data Acquisition Toolbox, what was not possible in the past. I recomend you to read Data Acquisition Toolbox User's Guide. Focus on chapter 17, as it describes properties.

 

 

Moreover, I'm not sure if this is not question stright for techsupport from Mathworks, as if i'm right, you are using all tools from Mathworks. Anyway, you can find some more usefull information in tutorial An Introduction to NI-DAQmx Tools for Data Acquisition with The Mathworks, Inc. MATLAB® Software.

 

 

Even though I didn't come with explicit example, I hope it helped 😉

 

 

Regards,

Stefo

Certified-LabVIEW-Developer_rgb.jpg

0 Kudos
Message 2 of 12
(9,687 Views)
  Hi Stefo,

Thanks for quick response!

That is the situation..
block diagram.png





I used P0.0 & P0.1 pins for Digital Output in the file with ''putvalue'' & ''pause'' commands, but maximum frequency that i reached was 70hz, which is not more...

I will test with two PFI pins 🙂

So, I have to set PFI0 = 0 and PFI1 = 0 i.e.  [0 0] to output X voltage with multiplexer.
[0 1] for Y output, [1 0] for the Z output ...

How do I set up triggers for analog input?

For example, this is function for multiplexer with parameter "comb", whos is 2x1 vector...


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

function mux_control(comb) %comb=[0 0], [0 1]...

dio = digitalio('nidaq','Dev2');
addline(dio,8:9,'out',{'line1','line2'}); % 8 & 9 must be PFI0 & PFI1 on port1
putvalue(dio.Line(1:2),comb);
% pause(0.001)
% propinfo(dio)
% getvalue(dio)
delete(dio)
clear dio

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


Stefo if I understood correctly I must set these options on "ai"


set(AI,'TriggerType','HwDigital');
set(AI,'HwDigitalTriggerSource','PFI0');


but for Digital Output i am using PFI0 & PFI1 (both at once). 

How to set up the trigger so that every time i call "putvalue" ([0 0] [0 1] or [1 0]) to start the trigger?
Purpose is to record each value of X, Y, Z in a file 😞


Regards, Krasi
0 Kudos
Message 3 of 12
(9,673 Views)

Hi Krasi,

 

thanks for perfect detailed explanation of your task Smiley Wink

 

 

How do I set up triggers for analog input?

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

In general, you can't use 2 signals as trigger or clock (you can in fpga, for example). You have to create one signal out of them to drive your trigger.

 

However, since you are generating those signals, then what you could do is to use one more  PFI line, where you would generate one pulse (Logic High followed by logic Low) each time you want to switch input of the MUX (A,B / PFI0, PFI1). Let's assume you will generate this pulse on PFI2 (dont forget it has to be a pulse High-Low, since you are interested in edges). 

 

 

 

Stefo if I understood correctly I must set these options on "ai"

set(AI,'TriggerType','HwDigital');
set(AI,'HwDigitalTriggerSource','PFI0');

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

I think you are right in this part (i'm not familiar with Matlab, but from documentation it looks you understand properly). From what we assuemd above I would just use PFI2 as HwDigitalTriggerSource.

 

 

One very important think to note is that you will create task starting at digital trigger - but just once! If you need to retrigger, you need to either restart task (the simplest) or you can use some more advanced, counter based retrigger. There is many  resources on how to implement it in DAQmx:

Retriggerable Analog Acquisition in NI-DAQmx

However, if timing is not as essential (i saw you want to use software timed digital outputs), I would maybe go for  the easier method (usualy I'm against, but ... easy is easy)

 

 

 

Regards,

Stefo

Certified-LabVIEW-Developer_rgb.jpg

0 Kudos
Message 4 of 12
(9,659 Views)
Hi again 🙂

Okkkk, this is the new situation

I stil don't know frequency of sample rate of input signal

signals.jpg


I write new functions. 

The first is for PFI0 & PFI1 Outputs:



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

function DIO_PFI0_1(comb)


DIO = digitalio('nidaq','Dev2'); %simulationn device NI-6255 on DAQMX software

Lines_1 = addline(DIO,0:1,1,'Out'); % add PFI0 & PFI1 on port1 as output

putvalue(Lines_1,comb); %output X
getvalue(DIO)

end

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




The second is for PFI2 trigger output:


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

function DIO_PFI2

DIO = digitalio('nidaq','Dev2'); %simulationn device NI-6255 on DAQMX software
Lines_2 = addline(DIO,2,1,'Out'); % add PFI2 on port1 as output which will be used for ai triggering

while(1)
putvalue(Lines_2, 1); %put values "1" and "0" without pause to simulate i.e fastest way i suppose!
getvalue(DIO) %one pulse (Logic High followed by logic Low)
pause(1)
putvalue(Lines_2, 0);
getvalue(DIO)
pause(1)
end

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





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



while (1)                  % switch PFIO and PFI1
DIO_PFI0_1([0 0]);
pause(1)
DIO_PFI0_1([0 1]);
pause(1)
DIO_PFI0_1([1 0]);
pause(1)
DIO_PFI2
end

while (1)
DIO_PFI2                % i don't know where to put this but obviously is not here !
end
---------------------------------------------------------------------------------------------



Since the cycle is endless i can not switch both functions simultaneously 😞

My question is how to start both together so I set them to pause's (for PFI2 it will be a less  according to the picture)?

Regards,
Krasi
Message Edited by krasi85 on 12-30-2009 05:31 PM
0 Kudos
Message 5 of 12
(9,646 Views)

little update 😉

i think this is may be work 🙂


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

DIO = digitalio('nidaq','Dev2'); %simulationn device NI-6255 on DAQMX software

Lines_1 = addline(DIO,0:1,1,'Out',{'line1','line2'}); % add PFI0 & PFI1 on port1 as output,
Lines_2 = addline(DIO,2,1,'Out','line3'); % add PFI2 on port1 as output which will be used for ai triggering
% line1,2,3 are names of PFI0, PFI2 & PFI2

while(1)

putvalue(Lines_1, [0 0]); %output X
putvalue(Lines_2, 1);
getvalue(DIO)
pause(1)
putvalue(Lines_2, 0);
out = getvalue(DIO.Line(3));
disp(out)

putvalue(Lines_1, [0 1]); %output Y
putvalue(Lines_2, 1);
getvalue(DIO)
pause(1)
putvalue(Lines_2, 0);
out = getvalue(DIO.Line(3));
disp(out)

putvalue(Lines_1, [1 0]); %output Z
putvalue(Lines_2, 1);
getvalue(DIO)
pause(1)
putvalue(Lines_2, 0);
out = getvalue(DIO.Line(3));
disp(out)

end
--------------------------------------------------------------------------------------------------------------


getvalue give this values:   



ans =

0 0 1

0


ans =

0 1 1

0


ans =

1 0 1

0


ans =

0 0 1

0



- the first row is: PFI0 PFI1 PFI2
- the second row value is PFI2=0 , because signal fot HWtrigger it might be "1" to "0" write?

in the AI function i must set :

set(AI,'TriggerType','HwDigital'); %can be Immediate, Manual, or Software
set(AI,'HwDigitalTriggerSource','PFI2');
set(AI,'TriggerCondition','PositiveEdge')

But let see how it will act triggers on ai

0 Kudos
Message 6 of 12
(9,624 Views)

 

 

Hi there and Happy New Year ! 🙂


At this stage, after i using pins P0 or PFI as pulse generator can not achieve a switching frequency more then 100HZ because it uses software clock!

- pointer mouse on pictures for more information

pfi0 vs pfi1 (control signals for mux)
pfi0 vs pfi2(trigger signal)
pfi0 vs pfi2 (should be start together, but the delay is 1,3ms

the code is this:


DIO = digitalio('nidaq','Dev1');

Lines_1 = addline(DIO,0:1,1,'Out',{'line1','line2'});     % add PFI0 & PFI1 on port1 as output,
Lines_2 = addline(DIO,2,1,'Out','line3');       % add PFI2 on port1 as output which will be used for ai triggering
% line1,2,3 are names of PFI0, PFI2 & PFI2

while(1)

putvalue(Lines_1, [1 1]);
putvalue(Lines_2, 1);
putvalue(Lines_2, 0);

putvalue(Lines_1, [0 0]);  
putvalue(Lines_2, 1);
putvalue(Lines_2, 0);


with no pause between commands have a delay 😞 


Can I use both on-board counters (ctr0 & ctr1) and output "freqout", i.e. ctr0 & ctr1 should be control signals for multiplexers and "freqout" be used as "HwTrigger" for analog input.

Is there a way to reach onboard counters in Matlab build-in functions or only with NIDAQ-mx functions?


I attach a file with what I found for Matlab & NIDAQmx functions..

 

Please help me, i am new in Matlab and this things but deadline for project is comming! 😞


With greetings, Krasi

Message Edited by krasi85 on 01-12-2010 02:07 PM
0 Kudos
Message 7 of 12
(9,532 Views)
will not get that!
just saw that "freqout" given frequency 100Khz, which is too much..
0 Kudos
Message 8 of 12
(9,527 Views)

Hi krasi85,

 

now I'm bit confused. So what part does work for you and which does not ?

 

 

Stefo

Certified-LabVIEW-Developer_rgb.jpg

0 Kudos
Message 9 of 12
(9,503 Views)
Hi 🙂


So I think the decision of my problem is as follows:

I have to generate digital waveforms on the Port 0 DIO lines using Internal Source (onboard Counter) as Sample Clock (М-series don't have onboard Sample Clock).

This should be done by DAQmx Functions which i import in this way:

addpath('D:\DOCUMENTS\matlab\ACC Project\c,h,lib files');

if ~libisloaded('myni')

    disp('Matlab: Load nicaiu.dll')

    funclist = loadlibrary('nicaiu.dll','NIDAQmx.h','alias','myni');

end

libfunctionsview('myni')     % included function

 

 

i can see functions by type: libfunctionsview('myni')

 

after i try to create a task:

 
 taskh1=libpointer('uint32Ptr',0);

    taskname='SampleTask';

    [a,b,taskh1] = calllib('nicaiu','DAQmxCreateTask',taskname,taskh1);

 

but give me:

??? Error using ==> calllib

Library was not found

I'm using Windows 7 x86

ToolboxName: 'Data Acquisition Toolbox'
ToolboxVersion: '2.13 (R2008b)'
  MATLABVersion: '7.7 (R2008b)'
InstalledAdaptors: {3x1 cell}

I have install NI-DAQmx 9.0.2

When i execute NImess.m  just for test  in command window 



>> NImess(1,0,2,800,800)
Matlab: dll loaded
NI: Define constants
NI: Create Tasks
NI: Create AI Channels

a =

-200088


b =

[]


c =

Dev1/ai0:1


d =

''


NI: Config Sample Clock

a =

-200088


b =

[]


a =

-200088


b =

[]


a =

-200088


b =

[]

NI: Config Digital edge start trigger

a =

-200088


a =

-200088


b =

[]


a =

-200088


b =

[]

NI: Start task(s)

a =

-200088


a =

-200088


a =

-200088

NI: Reading Data!
NI: Stop task
NI: Clear task(s)
NImess finished

ans =

[]


>>


Download All
0 Kudos
Message 10 of 12
(9,500 Views)