Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NIDaqmx Python: Analog Function Generation

Hello,

 

I am attempting to program a myDAQ device to generate continuous sign waves of various cycles using the nidaqmx library in Python.

I used below code for generation.

but when I execute code, it is worked just one time.

how can I modify this code to execute in specific time or controlled time?

 

 

amp = 4         # 1V        (Amplitude)
f = 40000       # 40kHz      (Frequency)
fs = 2000000     # 200kHz    (Sample Rate)
T = 1/f
Ts = 1/fs

x = np.arange(fs)
y = [ amp*np.sin(2*np.pi*f * (i/fs)) for i in x]
y_new = np.tile(y,1)

x1 = x[:100]/2000000
y1 = y[:100]

test_Task = nidaqmx.Task()
test_Task.ao_channels.add_ao_voltage_chan('Dev1/ao0')
test_Task.timing.cfg_samp_clk_timing(rate= 2000000, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS)

test_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(test_Task.out_stream, auto_start=True)

samples = y_new

test_Writer.write_many_sample(samples)
test_Task.wait_until_done()
test_Task.stop()
test_Task.close()

 

0 Kudos
Message 1 of 2
(2,473 Views)

You are sending a CONTINUOUS signal.

Therfore you can not use:

test_Task.wait_until_done()

 import time and try replacing it with:

time.sleep(5)

 to get a 5s impulse.

0 Kudos
Message 2 of 2
(2,424 Views)