Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

generate wave voltage output (Python)

Hey Guys,

im using Python with an NI USB-6366. My task ist to create a voltage with a waveform (sine and saw). Both should have an offset, frequency and amplitude that can change according to your own settings. I am using a oscilloscope to view my results. I already createt a few saw waveforms but they all had a way to high frequency. If i changed the frequency to something lower, the output would not generate the whole wave. There might be a problem with my clock timing but i am not sure. 

My 2nd problem is that the waves i generate dont generate continuously. They generate just a few times (only generate with a high frequency). 

My Code: 

# Continuous write single channel
from re import I
import numpy as np
import matplotlib.pyplot as plt
import time
import nidaqmx
from nidaqmx.stream_writers import (AnalogSingleChannelWriter)
from nidaqmx import constants
from nidaqmx.constants import AcquisitionType
import math

#variables
global rate_outcfg
global counter_limit
global voltage
global stream
global counter
global v_inc
global i
num_samples = 4294967295
rate_outcfg = 500
len_list = 101
v_inc = 0.01
task = nidaqmx.Task()
counter = 0
i = 0
offset = 0    
amplitude = 3
#Voltage list
voltage = np.empty((len_list,))
voltage [:] = -v_inc



while counter < len_list:  
    voltage[i:] = voltage[i:] + v_inc
    counter = counter + 1
    i = i+1
voltage_fin = voltage[:] * amplitude + offset
#voltage = np.array([0.2, 0.4, 0.6, 0.8, 1])
#voltage = np.array([0, 0.5, 1, 1.5, 2, 2.5, 3])
print(voltage_fin)

def SAW ():
    task = nidaqmx.Task()
    task.ao_channels.add_ao_voltage_chan("Dev1/ao0")
    task.timing.cfg_samp_clk_timing(rate = rate_outcfg, sample_mode = AcquisitionType.CONTINUOUS) #, samps_per_chan = num_samples)

                                       

    stream = AnalogSingleChannelWriter(task.out_stream, auto_start=True)
    stream.write_many_sample(voltage_fin, timeout = 10.0)
    nidaqmx.Task.start()

SAW ()

task.close()  


Sorry for my bad english (not mother tongue).

all the help is greatly appreciated.

Best reagrds,

Jo_dkt

0 Kudos
Message 1 of 1
(468 Views)