Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange Output of PCI-6289 DO

Solved!
Go to solution

I'm using Python(nidaqmx package) to control phi-6289. I want to generate a digital pulse of given length on port 0, line 0 of PCI-6289, but I get some really strange results on the oscilloscope.

My code is as: 

import nidaqmx
import numpy as np
from nidaqmx.stream_writers import DigitalSingleChannelWriter
from nidaqmx.constants import AcquisitionType
from time import sleep


def done_event(*args):
print('measurement done')
return 0


def pulse(time):
waveform = np.ones(time, dtype=np.uint32)
ending_sequence = np.zeros(100, dtype=np.uint32)
waveform = np.append(ending_sequence, waveform)
waveform = np.append(waveform, ending_sequence)
return waveform


if __name__ == '__main__':
virtual_task = nidaqmx.Task()
do_task = nidaqmx.Task()
# create a virtual analog input channel
virtual_task.ai_channels.add_ai_voltage_chan('Dev1/ai0')
virtual_task.timing.cfg_samp_clk_timing(1000, sample_mode=AcquisitionType.CONTINUOUS)
virtual_task.start()
# configure the digital output task
do_task.do_channels.add_do_chan('Dev1/port0/line0:31')
do_task.register_done_event(done_event)
do_task.timing.cfg_samp_clk_timing(1000, source='/Dev1/ai/SampleClock') # set digital sampling time
do_task.write(pulse(500),auto_start=False)
print('start to write')
do_task.start()
# start the measurement
sleep(3)
virtual_task.close()
do_task.close()

(the parameter of pulse() is the central length of the pulse, and I add 100 zeros on both side of the pulse)

I wire the port0line0 to the oscilloscope and get:

pulse(100): three 0.1s pulses, separated by 0.2s each

(looks like the code is executed for three times)

pulse(300): two 0.3s pulses, separated by 0.2s

(looks like the code is executed twice)

pulse(500): singel 0.5s pulse and the output is not returned to zero

 

Does anyone know what is going on here? Thanks. 

IMG_0874.JPG

IMG_0875.JPGIMG_0876.JPG

0 Kudos
Message 1 of 3
(2,498 Views)
Solution
Accepted by MadSciSoCool

I can't fully explain it, but I suspect part of what's going on is that your DO task is defaulting to be a *continuous* task that allows regeneration.  The config isn't explicit about either setting.

 

In regeneration mode, the buffer of values is repeated indefinitely until you stop the task.  You have a constant sleep() time, so when you define a shorter sequence of values, it gets more time to repeat itself before you end the DO generation task.

 

What doesn't totally add up for me is that the total duration doesn't seem to me to correspond to the "sleep(3)" statement.  (I don't know python, but I figure the sleep units would be either seconds or milliseconds.  Neither fit with what you see).

 

If you want a single pulse, you could configure the task for *finite* sampling.  Or use a counter if you have one available.

 

 

-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).
Message 2 of 3
(2,483 Views)

Thank you very much for your explanation, which covers my problem mostly. The sleep time is 3s. It is timed by the software. Thus, I guess the inconsistent output time is probably due to some delay or mismatching between the software and the device. I believe a more accurate total output time can be set by changing the number of sample points in a finite generation. Thank you again for your helpful answer.

 

Best Regards,

Jiahe

0 Kudos
Message 3 of 3
(2,468 Views)