05-26-2020 03:36 AM
Hi everyone,
i got a problem with my python live measurement from a 9217 Module. I used the code given by NI, which helps setting up the measurement, but when adding more sensors to the system the sampling rate goes down with every added sensor.
import nidaqmx
from nidaqmx.constants import TemperatureUnits
from nidaqmx.constants import VoltageUnits
from nidaqmx.constants import ResistanceConfiguration
from nidaqmx.constants import RTDType
from nidaqmx.constants import ExcitationSource
import matplotlib.pyplot as plt
import numpy as np
import time
plt.ion()
i = 0
timestep = 0.2
Dateiname = "Messdaten"
samples = 1
def Header():
f = open(f"{Dateiname}", "a")
f.write("\n******************************************************\n* Measurement from " + time.asctime() + " *\n******************************************************\n*Info:\n* Timestep: " + str(timestep) +"s\n* Averaged over " + str(samples) +" samples\n******************************************************\n* Sensor_1 ; Sensor_2 ; ... ; Sensor_n ;\n*\n")
f.close()
Header()
vektor = np.array([])#create empty vektor
with nidaqmx.Task() as task:
task.ai_channels.add_ai_voltage_chan("cDAQ9185-1D1960BMod3/ai0:2")
task.ai_channels.add_ai_rtd_chan("cDAQ9185-1D1960BMod1/ai0:2", units=TemperatureUnits.DEG_C, resistance_config=ResistanceConfiguration.FOUR_WIRE, current_excit_source=ExcitationSource.INTERNAL, current_excit_val=0.001)
#task.timing.samp_clk_rate=5
while i<20:
data = task.read(number_of_samples_per_channel=samples)
sensorNumber = 0
for list in data:
Mean = np.mean(data[sensorNumber])
f = open(f"{Dateiname}", "a")
f.write(str(Mean) + " ; ")
vektor = np.hstack((vektor, Mean))
sensorNumber = sensorNumber + 1
print()
f.close()
f = open(f"{Dateiname}", "a")
f.write("\n")
f.close()
#matrix = np.vstack()
plt.scatter(i,data[0],color="red")
plt.scatter(i,data[1],color="green")
plt.scatter(i,data[2],color="blue")
plt.scatter(i,data[3],color="black")
plt.pause(timestep) #time between data points
i=i+1
In my thinking the module should be capable of way more than 5Hz. When i put 3 Sensors in the system, the error occurs, that the maximum sampling rate from the device 1.6667. And this rate goes even more down when adding more, which absolutely makes no sense to me.
Best regards!
PS: sorry for the wrong code view, dont know the right way
05-26-2020 11:53 AM
In the code you posted, your task is not hardware timed, but software on-demand as no hardware timing is configured for the task. Is that what you wanted to do?
From the 9217 specification
Conversion time
High-resolution mode 200 ms per channel, 800 ms total for all
channels
High-speed mode 2.5 ms per channel, 10 ms total for all channels
9217 has 2 ADC timing modes. It defaults to the slower but more accurate high resolution mode which runs at 5 Hz. That is in line with what you observed.
See knowledgebase: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8jtSAC&l=en-US
Setting the channel attribute ADC timing mode to be high speed should yield a higher sample rate.