01-20-2018 12:47 PM
Hello,
I am attempting to program a myDAQ device to generate square waves of various duty cycles using the nidaqmx library in Python. The library features a number of properties for a function generation channel, including 'add_ao_func_gen_channel' (found in 'ao_channel_collection').
Here is a test code I have set up:
test_Task = nidaqmx.Task() test_Task.ao_channels.add_ao_func_gen_chan("myDAQ1/ao0", type= FuncGenType.SQUARE, freq= 0.2, amplitude= 10) for i in range(1, 10): test_Task.channels.ao_func_gen_square_duty_cycle = i /10 test_Task.start() time.sleep(5) test_Task.stop()
Which gives the error:
nidaqmx.errors.DaqError: Selected physical channel does not support the output type required by the virtual channel you are creating. Create a channel of an output type that is supported by the physical channel, or select a physical channel that supports the output type. Property: DAQmx_AO_OutputType Requested Value: DAQmx_Val_FuncGen Possible Values: DAQmx_Val_Voltage Task Name: _unnamedTask<0> Status Code: -200432
I'm not sure if this is a problem with the code or with the hardware. As far as I understand, any channel that can output voltage should be able to output a waveform. Are there other NI devices that would support a function generation channel?
Solved! Go to Solution.
01-22-2018 09:49 AM
The error states that the channel selected does not support the Analog Output Function Generator type. Based on your current setup, you can use the Analog Output Voltage channel type.
The NI ELVIS II boards support the AO-FuncGen channel type. I understand you are using Python, but the following document provides an overview on how to use the myDAQ and the NI ELVISmx Function Generator: http://www.ni.com/tutorial/11503/en/.
05-03-2018 02:29 PM
Hi,
Continuing this topic. Brian, you say that "you can use the Analog Output Voltage channel type". Could you please give an example of the Python code that will create periodical signal at the Analog Output pin.
I'm using USB-6361 (BNC) device.
Thanks!
05-03-2018 04:17 PM
Here is some code I'm running to generate waveforms:
test_Task = nidaqmx.Task()
test_Task.ao_channels.add_ao_voltage_chan('myDAQ1/ao1')
test_Task.timing.cfg_samp_clk_timing(rate= 80, sample_mode= AcquisitionType.FINITE, samps_per_chan= 40)
test_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(test_Task.out_stream, auto_start=True)
samples = np.append(5*np.ones(30), np.zeros(10))
test_Writer.write_many_sample(samples)
test_Task.wait_until_done()
test_Task.stop()
test_Task.close()
This will generate a single cycle of a square wave with 75% duty cycle and 0.5 sec period. The 'samples' could be anything you want and increasing the 'samps_per_chan' parameter will allow you to write for a longer duration. Keeping the same array but increasing 'samps_per_chan' will actually regenerate the 75% square wave until the specified samples have been generated.
05-03-2018 05:20 PM
Dear aisaly,
Thanks, it works for me. Do you know if there is a way to loop this indefinitely?
05-04-2018 07:42 AM
You could just change the 'FINITE' Acquisition Type to 'CONTINUOUS'.
05-04-2018 12:13 PM
Of course, thanks! I really appreciate your fast responses.
05-28-2018 09:02 AM
Hi,
I just ran into the same error
ao_task.ao_channels.add_ao_func_gen_chan('Dev1/ao1',type=FuncGenType.SAWTOOTH,freq=1000,amplitude=9,offset=1)
I use the code to generate sawtooth,but i got the same error you got , could you please tell me how to generate a sawtooth wave?
Thanks
05-28-2018 07:47 PM
You'll have to generate an array of the samples yourself. Numpy has a function for making sawtooth waves. You can buffer them using the 'write_many_samples' method, in the same way I did above.
05-29-2018 10:29 AM
Dear Anticode,
I did this with numpy according to aisaly's instructions. Here is code that works at least for NI USB 6361 device.
import nidaqmx
import numpy as np
from nidaqmx import *
test_Task = nidaqmx.Task()
test_Task.ao_channels.add_ao_voltage_chan('Dev1/ao1')
test_Task.timing.cfg_samp_clk_timing(rate= 10, sample_mode= nidaqmx.constants.AcquisitionType.CONTINUOUS, samps_per_chan= 5)
test_Writer = nidaqmx.stream_writers.AnalogSingleChannelWriter(test_Task.out_stream, auto_start=True)
samples = np.append(5*np.ones(10), np.zeros(10))
test_Writer.write_many_sample(samples)
test_Task.wait_until_done(timeout=100)