12-26-2009
11:41 AM
- last edited on
05-23-2025
12:13 PM
by
Content Cleaner
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 https://www.ni.com/en-us/support/model.usb-6251.html (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 ..
12-28-2009
10:21 AM
- last edited on
05-23-2025
12:14 PM
by
Content Cleaner
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.
Even though I didn't come with explicit example, I hope it helped 😉
Regards,
Stefo
12-29-2009 11:34 AM
12-30-2009
03:51 AM
- last edited on
05-23-2025
12:15 PM
by
Content Cleaner
Hi Krasi,
thanks for perfect detailed explanation of your task ![]()
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
12-30-2009 05:24 PM - edited 12-30-2009 05:31 PM
12-31-2009 11:14 AM
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
01-12-2010 02:05 PM - edited 01-12-2010 02:07 PM
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
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
01-12-2010 02:20 PM
01-14-2010 01:35 AM
Hi krasi85,
now I'm bit confused. So what part does work for you and which does not ?
Stefo
01-14-2010 04:49 AM
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 =
[]
>>