Quantcast
Channel: Digital I/O topics
Viewing all articles
Browse latest Browse all 2167

[Python] Help with trigger and counter internal output

$
0
0

Hello everyone !

 

I have a NI 9401 (with 8 DIO) and a cDAQ 9181. I want to send PWM from a DO to a DI (which both have ultrasonic transducers plugged in) and be able to calculate the time transit of my signal between the emitter and the receiver.

 

For that, I'm using Python. I already managed to send and recieve my signal, but now I need to put the writting task and the reading task in sync, since I want to know when my signal is emitted and when it's received (to calculate the difference). I've read that I need to use the counter internal output of my cDAQ 9181 as reference clock source for both my master and slave task and use a trigger to start those task at the same time. But I'm having a hard time doing it. If anyone can help me with this, I'll be glad.

 

Here is the part of my code regarding the use of the NI hardware (which works, but there's no sync between writting and reading) :

 

 

import nidaqmx
from nidaqmx.constants import AcquisitionType, TaskMode, SyncType, LineGrouping, Edge, Signal

with nidaqmx.Task() as master_task, nidaqmx.Task() as slave_task: master_task.di_channels.add_di_chan("cDAQ1Mod1/port0/line5") master_task.control(TaskMode.TASK_RESERVE) master_task.timing.cfg_samp_clk_timing(int(fs), sample_mode=AcquisitionType.CONTINUOUS) slave_task.do_channels.add_do_chan("cDAQ1Mod1/port0/line1") slave_task.control(TaskMode.TASK_RESERVE) slave_task.timing.cfg_samp_clk_timing(int(fs), sample_mode=AcquisitionType.CONTINUOUS) # ---------------------------------------------------------------------------- # slave_task.write(pwm_out) slave_task.control(TaskMode.TASK_COMMIT) master_task.control(TaskMode.TASK_COMMIT) print('Emission') slave_task.start() master_task.start() pwm_in = master_task.read(number_of_samples_per_channel=len(pwm_out)) slave_task.stop() master_task.stop()

 

Now here is another code, in which I tried to put read and write in sync, but it just doesn't work..

 

 

import nidaqmx
from nidaqmx.constants import AcquisitionType, TaskMode, SyncType, LineGrouping, Edge, Signal

with nidaqmx.Task() as master_task, nidaqmx.Task() as slave_task: master_task.do_channels.add_do_chan("cDAQ1Mod1/port0/line5") slave_task.di_channels.add_di_chan("cDAQ1Mod1/port0/line1") master_task.timing.ref_clk_src="cDAQ1Mod1/port0/Ctr0InternalOutput" master_task.timing.ref_clk_rate = 10_000_000 master_task.timing.cfg_samp_clk_timing(int(fs), sample_mode=AcquisitionType.FINITE) master_task.triggers.sync_type = SyncType.MASTER slave_task.timing.ref_clk_src="/cDAQ1Mod1/port0/Ctr0InternalOutput" slave_task.timing.ref_clk_rate =10_000_000 slave_task.timing.cfg_samp_clk_timing(int(fs), sample_mode=AcquisitionType.FINITE) slave_task.triggers.sync_type = SyncType.SLAVE master_task.control(TaskMode.TASK_COMMIT) slave_task.triggers.start_trigger.cfg_dig_edge_start_trig("/cDAQ1Mod1/PFI1", Edge.RISING) start_trigger.cfg_dig_edge_start_trig("/cDAQ1Mod1/PFI5/di/StartTrigger") slave_task.start() master_task.start() pwm_in = slave_task.read(number_of_samples_per_channel=len(pwm_out)) master_task.write(pwm_out)

 

Thanks in advance for your answers.

 


Viewing all articles
Browse latest Browse all 2167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>