Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Counter Output examples #583

Merged
merged 3 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions examples/counter_out/co_pulse_time.py

This file was deleted.

21 changes: 21 additions & 0 deletions examples/counter_out/cont_gen_dig_pulse_train.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Example for continuously generating digital pulse train.

This example demonstrates how to generate a continuous digital
pulse train from a Counter Output Channel. The Frequency, Duty
Cycle, and Idle State are all configurable.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, Level

with nidaqmx.Task() as task:
channel = task.co_channels.add_co_pulse_chan_freq(
"Dev1/ctr0", idle_state=Level.LOW, initial_delay=0.0, freq=1.0, duty_cycle=0.5
)
channel.co_pulse_term = "/Dev1/PFI12"
task.timing.cfg_implicit_timing(sample_mode=AcquisitionType.CONTINUOUS)
task.start()

input("Generating pulse train. Press Enter to stop.\n")

task.stop()
33 changes: 33 additions & 0 deletions examples/counter_out/cont_gen_dig_pulse_train_buff_ext_clk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Example for continuously generating digital pulse train with external timing.

This example demonstrates how to generate a continuous buffered
sample clocked digital pulse train from a Counter Output
Channel. The Frequency, Duty Cycle, and Idle State are all
configurable. The default data generated is a pulse train with a
fixed frequency but a duty cycle that varies based on the Duty
Cycle Max/Min and the signal type. The duty cycle will update
with each sample clock edge.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, Level
from nidaqmx.types import CtrFreq

with nidaqmx.Task() as task:
duty_min = 0.5
duty_max = 0.8
duty_step = (duty_max - duty_min) / 1000
ctr_freq_data = [CtrFreq(1000, (duty_min + duty_step * i)) for i in range(1000)]

channel = task.co_channels.add_co_pulse_chan_freq(
"Dev1/ctr0", idle_state=Level.LOW, initial_delay=0.0, freq=1.0, duty_cycle=0.5
)
channel.co_pulse_term = "/Dev1/PFI12"
task.timing.cfg_samp_clk_timing(1000.0, "/Dev1/PFI0", sample_mode=AcquisitionType.CONTINUOUS)
task.out_stream.output_buf_size = 1000
task.write(ctr_freq_data)
bkeryan marked this conversation as resolved.
Show resolved Hide resolved
task.start()

input("Generating pulse train. Press Enter to stop.\n")

task.stop()
32 changes: 32 additions & 0 deletions examples/counter_out/cont_gen_dig_pulse_train_buff_implicit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Example for continuously generating digital pulse train with implicit timing.

This example demonstrates how to generate a continuous buffered
implicit timed digital pulse train from a Counter Output
Channel. The Frequency, Duty Cycle, and Idle State are all
configurable. The default data generated is a pulse train with a
fixed frequency but a duty cycle that varies based on the Duty
Cycle Max/Min and the signal type. The duty cycle will update
with each sample generated.
"""

import nidaqmx
from nidaqmx.constants import AcquisitionType, Level
from nidaqmx.types import CtrFreq

with nidaqmx.Task() as task:
duty_min = 0.5
duty_max = 0.8
duty_step = (duty_max - duty_min) / 1000
ctr_freq_data = [CtrFreq(1000, (duty_min + duty_step * i)) for i in range(1000)]

channel = task.co_channels.add_co_pulse_chan_freq(
"Dev1/ctr0", idle_state=Level.LOW, initial_delay=0.0, freq=1.0, duty_cycle=0.5
)
channel.co_pulse_term = "/Dev1/PFI12"
task.timing.cfg_implicit_timing(sample_mode=AcquisitionType.CONTINUOUS)
task.write(ctr_freq_data)
task.start()

input("Generating pulse train. Press Enter to stop.\n")

task.stop()
19 changes: 19 additions & 0 deletions examples/counter_out/write_single_dig_pulse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Example for generating a single digital pulse.

This example demonstrates how to generate a single digital pulse
from a Counter Output Channel. The Initial Delay, High Time, Low
Time, and Idle State are all configurable.
"""

import nidaqmx
from nidaqmx.constants import Level

with nidaqmx.Task() as task:
channel = task.co_channels.add_co_pulse_chan_time(
"Dev1/ctr0", idle_state=Level.LOW, initial_delay=0.0, low_time=0.5, high_time=1.0
)
channel.co_pulse_term = "/Dev1/PFI12"

task.start()
task.wait_until_done(timeout=10)
task.stop()
Loading