Professional Documents
Culture Documents
DAQ addendum
ME 2e semestre
rev. 1
Christophe Salzmann
Photo Martin Klimas
Module 2
Data acquisition & real-time control
– Intro
– Acquisition chain - from sensor to CPU
– Multi-functions DAQ board
– DAQ on Windows
– DAQ on OSX
– Selected examples
– Simple control solution
• Wirelessly
Data AcQuisition (DAQ) @ LA
0x6544
Perturbations
Sensors
device that measures a physical quantity and converts it into a signal
which can be read by an observer or by an instrument
Digital
– State
– Rate
digital signals can be treated as analog signals
Signals conditioning
Make your signal easier to measure by the DAQ device
Reduce the effects of perturbations
• Isolation
– protect your hardware
• Filtering
• Multiplexing
Signals conversion – DAQ
clk, sync., trig.
RTSI connector
I/O connector
PCIe connector
0x12F884B1 0x12346D31
0x67C12893 0x856A7727
Signals conversion – to CPU
Interrupt
- every sample
- ½ buff.
- full buff. CPUs
FIFO buffers
PCI/PCI-express Bus
DMA access
RAMs
Data acquisition board
Focus on
– NI PCI 6229 (G5)
– NI PCIe 6259 (MacPro)
Multi-functions DAQ board
PCI 6229
2 x 16-bits AD, 250kS/s
Analog IN 4 x 16-bits DA, 833 kS/s
Mux G AD FIFO 48 x DIO
2 x counters
Analog OUT
DA FIFO
Digital I/O
DIO Buff
Cntr Counter
STC
PFI
0x12F884B1 0x12346D31
0x67C12893 0x856A7727
Analog IN
Select input line Amplify signal Convert to
binary
Select input mode
Filter Bufferize
Analog IN - multiplexer
conversions concurrently …
ADC
Analog IN – GND reference
AI+
+ NRSE
Differential
+ – input signal low level > 1v
– RSE
require 2 inputs
AI- – connection length < 3m
– –
– – low
avoid level signal (<1v)
grounds
input signal potential
low level > 1v
– difference
noisy environment
– connection length < 3m
– long connection (>3m)
– subject to common
– require separate GND ref
AI SENSE ground
Non-Referenced
Single-Ended
Differential (RSE) AI GND
Single-Ended (NRSE)
Analog IN - Amplifier
+ 10 V + 10 V
+
G
–
- 10 V - 10 V
Analog IN - Filter
• Nyquist Theorem
You must sample at greater than 2 times the maximum
frequency component of your signal to accurately
represent the FREQUENCY of your signal
You must sample between 5 - 10 times greater than the
maximum frequency component of your signal to
accurately represent the SHAPE of your signal
http://zone.ni.com/devzone/cda/tut/p/id/4869
http://zone.ni.com/devzone/cda/tut/p/id/3016
http://www.ni.com/swf/presentation/us/sampling/
Analog IN – A/D converter
[v]
+ 10 1111
11111111
11111110
1110
11
1101
1100
1011
ADC
10 "10
("10)
10b bb10 ""("10)
("10)
1010
10
1001
1010
10101001 2
"10"10
= ==
"10
1000 48
0 0111.
.
10
1010
10101001 2 22
0110.
01
0101
0100
(3*
(169 *(10 5) "10"10
*1.25)
0.078125) 5[v]
="10 ==2.5[v]
3.20[v]
0011
0010
00
0001
00000001
- 10 0000
00000000
! !
2 bits ->
4
8 2842 = 256
4 levels
16 levels
levels
Analog IN – A/D converter
[v]
+ 10 1111111111111111
10 " ("10)
= 308 [µV]
216
200 mV" ("200 mV)
= 6.10 [µV]
216
65536
0 ADC
!
-5% of codes for calibration
!
± 10 V -> 320 [µV]
- 10 0000000000000000
± 200 mV -> 6.4 [µV]
sampling period h
http://zone.ni.com/devzone/cda/tut/p/id/2825
http://digital.ni.com/public.nsf/allkb/73CB0FB296814E2286256FFD00028DDF?OpenDocument
Analog IN – recap
• Multiplexed inputs
• Multi-channels acquisition
• Ground reference mode
• Sampling frequency
• Quantification
channel 1
channel 2
conversion period
sampling period h
http://zone.ni.com/devzone/cda/tut/p/id/2825
http://digital.ni.com/public.nsf/allkb/73CB0FB296814E2286256FFD00028DDF?OpenDocument
Analog OUT
Convert to Analog signal
Buffer
Analog OUT – FIFO buffer
• The FIFO buffer can store waveforms to
be written to the DA converters thus
without CPU interaction
• Hardware timed waveforms generations
- The time between samples can be much shorter
- The timing between samples can be
deterministic
- Hardware-timed acquisitions can use hardware
triggering
- Allow regeneration (replay)
No fly zone
90°
A
B
counter value
PFI and RTSI
• 16 Programmable Function Interface (PFI)
- can act as DIO
- used to route internal/external signals to clocks, triggers, gate, etc.
LabVIEW C, Matlab, …
User space
Board registers
Board Hwd
http://digital.ni.com/public.nsf/allkb/1C3988D7D33B925C86256C59007FB4B4
Acquiring data
• At the lowest level the DAQ board is configured/
programmed via its registers (RLP). It s tedious!
Write32 (0x1234 @ 0x0019B8F)
…
Write32 (0x1234 @ 0x0019B8F)
• On Mac
DAQmx base
• Standalone application
Timed loop
Acquiring data on MacOS 9
Traditional DAQ
RT DLL
Measurement Hardware DDK
• Provides register level access to DAQ boards
• Abstract board components into Chip Objects
…
10 x
…
4x
on a 30 screen
DAQmx base
Task logic
Board logic
Register logic
DAQmx base – Static Tasks
Similar to MAX
Configured outside of LV with mxbaseconfig
LabVIEW
Hardware
Create
Task
Create
Channel
Access
Hwd FIFO
Configure Stop
Clear
Start
DAQmx base – Create task
Create an empty task
The task name is optional
Other parameters are currently
ignored
Stop task
Clear task
Export signal
Route a given signal to the specified
terminal
0.001 ms
– The DAQ card (on board clock)
Very accurate, not disturbed by the OS
LabVIEW RT & FPGA
#include "NIDAQmxBase.h
Function Read_one_Sample_one_Chanel() {
err=DAQmxBaseStartTask(taskHandle);
int32 err = 0;
err=DAQmxBaseReadAnalogF64(taskHandle,
TaskHandle taskHandle = 0;
1, 10.0, DAQmx_Val_GroupByChannel,
float64 data;
&data, 1, &pointsRead,NULL));
int32 pointsRead;
printf ("Acquired reading: %f\n", data);
err=DAQmxBaseCreateTask("",&taskHandle);
err=DAQmxBaseCreateAIVoltageChan(taskHandle,
If (err != noError):
"Dev2/ai0 ,"",
DAQmx_Val_Cfg_Default, // process the error,
-10.0, 10.0, // code removed for clarity
DAQmx_Val_Volts,NULL);
return 0;
}
Samples and channels
Samples k+1
Samples k
only contain 1 channel
Define triggering
Read
AD
Hwd
convert
return
time
Read n samples, software timed
LabVIEW
n
Read
AD
Hwd
return
convert
≠ time
Read n samples, hardware timed
LabVIEW
Config. Read =
clock n AD
Hwd
buffer
return
convert
time
Read continuously, hwd timed
LabVIEW
Config. Read =
clock n AD
Hwd
return
convert
buffer
return
time
Read cont. 1 sample, hwd timed
LabVIEW
Config. Read
clock AD
Hwd
return
convert
= time
Write ONE sample
LabVIEW
Write
DA
Hwd
convert
return
time
Write
DA
Hwd
return
convert
≠ time
Write n samples, hardware timed
LabVIEW
convert
done
buffer
convert
= time
Write n samples cont., hwd timed
LabVIEW
Regenerate AO buff.
Config. Set Write
clock Buff. n DA
Hwd
convert
done
buffer
convert
time
Write n samples cont., hwd timed
LabVIEW
new
Config. Set Write AO buff.
clock Buff. n DA
Hwd
convert
done
buffer
convert
time
Lines and Ports
…
:line32
lines directly, need to mask the
unwanted lines Port1:line1
:line2
…
:line16
Samples k+1
Samples k
Single Digital In - Out
LabVIEW
DIO
Hwd
time
DIO
Digital in Digital out
Digital In, cont., hwd. timed
LabVIEW
Config. Read =
clock D-In
Hwd
read
read
time
# Read!
Incremental Encoder, cont.
LabVIEW
Read
Enc.
Hwd
read
≠ time
Ask for More
/LabVIEW/examples/daqmxbase
software
Tasks running on the DAQ board are
executed in hardware clocked
hardware
- Synchronize board tasks
- Synchronize board tasks and LabVIEW
t
- Ensure that LabVIEW RT code (g) runs faster
than DAQ period h ADAD h
DADA
DIO
DIO
Synchronize DAQ and LabVIEW
• DAQmx base can propagate the DAQ board sample clock to
LabVIEW
• LabVIEW can actively wait until the next clock pulse
✔ ✔ ✔ ✗
Synchronize Multiple Tasks
Share the Sample Clock in the terminal RTSI0
Set the source of the other sample clocks to RTSI0
…
Synchronize DAQ and LabVIEW
DAQmx base can propagate the DAQ board sample clock to LabVIEW
LabVIEW can actively wait until the next clock pulse
Read task
…
Write task
Data exchange, RT -> GUI
The RT task runs at ~1 kHz
1 ms
RT task
The RT task should not be interrupted PID
nor delayed (waiting for resource)
The RT task data display should be
performed in another thread (loop)
Queue
The LabVIEW front panel updates at ~
50 Hz
The RT task data should be stored at 100 ms
GUI task
each interruption and transferred to
a secondary thread for display
This synchronous buffer is implemented
using Queue, others mechanisms
are possible
Data exchange, GUI -> RT
RT task
(e.g. Kp) are updated PID
asynchronously, ~10 s
GUI task
mechanism cannot delay RT task
KP
Class 2 - recap
• Correctly wire your sensors (gnd)
• Configure your DAQ operation accordingly
• DAQ is task based
• Create/Configure/Start – Exchange data – Stop/clear
• RT is possible at ~1ms with plain LabVIEW