Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog Output Glitches Each Time Through Waveform

I'm driving a sine wave through an NI 9260 using the Python nidaqmx library with the following configuration:

 

SAMPLES_PER_SECOND = 12800
vo_task.ao_channels.add_ao_voltage_chan(
vo_line, "zapper", min_val=-3 * np.sqrt(2), max_val=3 * np.sqrt(2)
)
vo_task.timing.cfg_samp_clk_timing(
SAMPLES_PER_SECOND,
sample_mode=const.AcquisitionType.CONTINUOUS,
samps_per_chan=SAMPLES_PER_SECOND,
)

When I look at it on the scope, I see the waveform just stop at zero for about 120 microseconds before starting up again. Here's my sine wave:

 

def sine_wave(freq, amplitude, offset=0):
    """Args:
    freq: frequency in Hz
    amplitude: 0-peak amplitude in V
    offset: DC offset in V"""
    periods = 1
    period = int((periods / freq) * SAMPLES_PER_SECOND)
    t = np.linspace(0, 2 * periods * np.pi, period)
    wave = np.sin(t) * amplitude + offset
    return wave

I'm calling that with a frequency of 100Hz and amplitude of 3V.

 

I thought maybe switching to `vo_task.channels.ao_use_only_on_brd_mem = True` might help, but I get an error:

nidaqmx.errors.DaqError: Requested value is not a supported value for this property. The property value may be invalid because it conflicts with another property.
Property: DAQmx_AO_UseOnlyOnBrdMem
Requested Value: 1
Possible Values: 0

Device: cDAQ9189-1EA34E0

Task Name: vout

Status Code: -200077

 when I try to reserve the task.

 

If I send 100,000 periods worth of sine wave (by setting periods to 100000), my spectrum analyzer stops showing me tons of harmonics, but that's because it's only glitching once per buffer. How do I get it not to glitch at all?

0 Kudos
Message 1 of 5
(2,040 Views)

I don't know enough python to troubleshoot thoroughly, but have you tried simply writing your calculated sine wave data array to a file for inspection?  Can you post the code where you write to the task, start it, then leave it alone until it's time to stop it?

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 5
(2,024 Views)

I have looked at the sine wave data; it doesn't include a bunch of zeroes at the end. Here's the raw data for a single cycle at 100Hz:

 

>>> sine_wave(100.0, 3)
array([ 0.00000000e+00,  1.48361160e-01,  2.96359255e-01,  4.43632109e-01,
        5.89819322e-01,  7.34563147e-01,  8.77509374e-01,  1.01830819e+00,
        1.15661503e+00,  1.29209144e+00,  1.42440589e+00,  1.55323458e+00,
        1.67826224e+00,  1.79918292e+00,  1.91570069e+00,  2.02753042e+00,
        2.13439844e+00,  2.23604324e+00,  2.33221606e+00,  2.42268156e+00,
        2.50721835e+00,  2.58561955e+00,  2.65769332e+00,  2.72326326e+00,
        2.78216892e+00,  2.83426614e+00,  2.87942745e+00,  2.91754231e+00,
        2.94851745e+00,  2.97227708e+00,  2.98876305e+00,  2.99793502e+00,
        2.99977053e+00,  2.99426511e+00,  2.98143222e+00,  2.96130326e+00,
        2.93392749e+00,  2.89937192e+00,  2.85772109e+00,  2.80907695e+00,
        2.75355852e+00,  2.69130167e+00,  2.62245876e+00,  2.54719825e+00,
        2.46570432e+00,  2.37817639e+00,  2.28482868e+00,  2.18588960e+00,
        2.08160128e+00,  1.97221894e+00,  1.85801025e+00,  1.73925469e+00,
        1.61624289e+00,  1.48927587e+00,  1.35866434e+00,  1.22472793e+00,
        1.08779441e+00,  9.48198875e-01,  8.06282937e-01,  6.62393889e-01,
        5.16883852e-01,  3.70108914e-01,  2.22428258e-01,  7.42032818e-02,
       -7.42032818e-02, -2.22428258e-01, -3.70108914e-01, -5.16883852e-01,
       -6.62393889e-01, -8.06282937e-01, -9.48198875e-01, -1.08779441e+00,
       -1.22472793e+00, -1.35866434e+00, -1.48927587e+00, -1.61624289e+00,
       -1.73925469e+00, -1.85801025e+00, -1.97221894e+00, -2.08160128e+00,
       -2.18588960e+00, -2.28482868e+00, -2.37817639e+00, -2.46570432e+00,
       -2.54719825e+00, -2.62245876e+00, -2.69130167e+00, -2.75355852e+00,
       -2.80907695e+00, -2.85772109e+00, -2.89937192e+00, -2.93392749e+00,
       -2.96130326e+00, -2.98143222e+00, -2.99426511e+00, -2.99977053e+00,
       -2.99793502e+00, -2.98876305e+00, -2.97227708e+00, -2.94851745e+00,
       -2.91754231e+00, -2.87942745e+00, -2.83426614e+00, -2.78216892e+00,
       -2.72326326e+00, -2.65769332e+00, -2.58561955e+00, -2.50721835e+00,
       -2.42268156e+00, -2.33221606e+00, -2.23604324e+00, -2.13439844e+00,
       -2.02753042e+00, -1.91570069e+00, -1.79918292e+00, -1.67826224e+00,
       -1.55323458e+00, -1.42440589e+00, -1.29209144e+00, -1.15661503e+00,
       -1.01830819e+00, -8.77509374e-01, -7.34563147e-01, -5.89819322e-01,
       -4.43632109e-01, -2.96359255e-01, -1.48361160e-01, -7.34788079e-16])

The code that starts the task is just

self.task.write(self.wave)
self.task.start()

while True:
    sleep(1)

It writes the waveform data and waits forever.

0 Kudos
Message 3 of 5
(2,019 Views)

Never mind, looks like it was a numpy issue. If I grab the middle 50% of a 2-period sine wave, everything goes back to hunky dory.

0 Kudos
Message 4 of 5
(2,009 Views)

My main familiarity is with desktop data acq boards where I'd be very surprised to see similar symptoms with the code & data you've shown.  I'm also surprised you're getting it from the 9260, but I don't have specific knowledge or experience with that particular module. 

 

Does the same thing happen when you use the device's Test Panel in MAX?   One of the AO options is to generate a voltage sinewave with configurable frequency and amplitude...

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 5 of 5
(2,006 Views)