08-09-2018 01:23 AM - edited 08-09-2018 01:27 AM
Hi
I'm using a cdaq 9181 with an ni 9230 module. Reading 3 analogue signals simultaneously and writing to a file using the python API.
The task timing is set as following inside the task context along the lines of:
with ni.Task() as task:
# setup channels with
for channel in channels:
task.ai_channels.add_ai_accel_chan(
physical_channel=config_data["device_id"] + '/ai' + str(channel['pin_id']),
name_to_assign_to_channel=channel['sensor_id'],
min_val=-30,
max_val=30,
sensitivity=100,
sensitivity_units=asu.M_VOLTS_PER_G,
terminal_config=TerminalConfiguration.PSEUDODIFFERENTIAL
)
)
task.timing.samp_clk_rate = 10000 # sample rate Hz
stream_reader = AnalogMultiChannelReader(task.in_stream)
buffer = np.empty(shape=[3, 1000])
chunk = 0
while chunk < sample_per_file:
stream_reader.read_many_sample(
data=buffer,
timeout=NEVER,
number_of_samples_per_channel=1000
)
... code to append buffer to file ...
chunk = chunk + 1000
see attached file for actual code.
I've noticed that the files are being written faster than the sample rate specified.
e.g. time stamps on files are
546 seconds apart instead of 600.
This faster than expected sampling can be duplicated across different daqs on different systems so I'm assuming its a problem with reading the stream onto the buffer in the acquisition/write loop?
Despite this the data in the file is the correct shape and is recording the signals sequentially in the chunks specified correctly i.e. there is no re-sample/re-writing of old data.
Is this normal behaviour for this hardware? is there a way to resolve it such that file are written at the expected rate
task.timing.samp_clk_rate = 10000 # sample rate Hz
not necessarily map onto the system clock that's running the acquisition?
Any insight would be greatly appreciated
-Lyle
Solved! Go to Solution.
08-09-2018 02:03 AM
NI 9230 is DSA module so, the sampling rate wouldn't be what you specified.
See "Data Rates" section in this document.
DATA SHEET NI 9230
http://www.ni.com/pdf/manuals/374829a_02.pdf
08-09-2018 02:21 AM
Setting:
task.timing.samp_clk_rate = 10240
or any sample rate specified in:
Table 1. Available Data Rates with the Internal Master Timebase
found in http://www.ni.com/pdf/manuals/374829a_02.pdf
has fixed the problem.
Thank you Emboar, quick response and right solution!
08-09-2018 02:39 AM - edited 08-09-2018 02:40 AM
As Emboar stated the DAQ you are using only allows decent samplerates noted in table 1 in the manual.
The DAQ driver coerces unvalid samplerates to the next higher valid one.
Hint: It's always a good idea to check the 'actual samplerate' property after configuration 😉
EDIT: You got it 😄