From b1ad31b4ed9efa096a45767cb04bca6e3e9e3e22 Mon Sep 17 00:00:00 2001 From: Pradeeban Kathiravelu Date: Fri, 24 Mar 2023 15:39:20 -0400 Subject: [PATCH] Update with nidaqmx --- nintan/pstim.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nintan/pstim.py b/nintan/pstim.py index ef06aa4..a458ece 100644 --- a/nintan/pstim.py +++ b/nintan/pstim.py @@ -3,6 +3,11 @@ import time import threading +from hardware.util_functions import * +import nidaqmx +from nidaqmx.constants import AcquisitionType +from nidaqmx.stream_writers import DigitalSingleChannelWriter + global uglobal uglobal = 0.5 PULSE_WIDTH = 10 @@ -14,13 +19,23 @@ def pwm(): ulocal = 0.0 if ulocal > 1.0: ulocal = 1.0 - print("+") - time.sleep(PULSE_WIDTH*ulocal) - print("-") - time.sleep(PULSE_WIDTH*(1.0-ulocal)) + + writer.write_one_sample_one_line(data=1,timeout=10) + accurate_delay(PULSE_WIDTH*ulocal) + writer.write_one_sample_one_line(data=0,timeout=10) + accurate_delay(PULSE_WIDTH*(1.0-ulocal)) + + # print("+") + # time.sleep(PULSE_WIDTH*ulocal) + # print("-") + # time.sleep(PULSE_WIDTH*(1.0-ulocal)) pwm_thread = threading.Thread(target=pwm, daemon=True) +task = nidaqmx.Task() +task.do_channels.add_do_chan("Dev1/port0/line0") +writer = DigitalSingleChannelWriter(task.out_stream) + concore.delay = 0.001 init_simtime_u = "[0.0, 0.0, 0.0]" init_simtime_ym = "[0.0, 0.0, 0.0]"