-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Counter Input examples * reworked as per comments * reworked on comments part 2
- Loading branch information
1 parent
1bc5df5
commit 6ffec7b
Showing
8 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Example of counter input edge count operation. | ||
This example demonstrates how to count digital events on a | ||
Counter Input Channel. The Initial Count, Count Direction, and | ||
Edge are all configurable. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import CountDirection, Edge | ||
|
||
with nidaqmx.Task() as task: | ||
channel = task.ci_channels.add_ci_count_edges_chan( | ||
"Dev1/ctr0", | ||
edge=Edge.RISING, | ||
initial_count=0, | ||
count_direction=CountDirection.COUNT_UP, | ||
) | ||
channel.ci_count_edges_term = "/Dev1/PFI8" | ||
|
||
print("Continuously polling. Press Ctrl+C to stop.") | ||
task.start() | ||
|
||
try: | ||
edge_counts = 0 | ||
while True: | ||
edge_counts = task.read() | ||
print(f"Acquired count: {edge_counts:n}", end="\r") | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
task.stop() | ||
print(f"\nAcquired {edge_counts:n} total counts.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Example of counter input edge count operation. | ||
This example demonstrates how to count buffered digital events | ||
on a Counter Input Channel. The Initial Count, Count Direction, | ||
Edge, and Sample Clock Source are all configurable. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import AcquisitionType, CountDirection, Edge | ||
|
||
with nidaqmx.Task() as task: | ||
channel = task.ci_channels.add_ci_count_edges_chan( | ||
"Dev1/ctr0", | ||
edge=Edge.RISING, | ||
initial_count=0, | ||
count_direction=CountDirection.COUNT_UP, | ||
) | ||
task.timing.cfg_samp_clk_timing( | ||
1000, source="/Dev1/PFI9", sample_mode=AcquisitionType.CONTINUOUS | ||
) | ||
channel.ci_count_edges_term = "/Dev1/PFI8" | ||
|
||
print("Continuously polling. Press Ctrl+C to stop.") | ||
task.start() | ||
|
||
try: | ||
total_read = 0 | ||
while True: | ||
edge_counts = task.read(number_of_samples_per_channel=1000) | ||
total_read += len(edge_counts) | ||
print(f"Acquired data: {len(edge_counts)} samples. Total {total_read}.", end="\r") | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
task.stop() | ||
print(f"\nAcquired {total_read} total samples.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Example of counter input frequency acquisition. | ||
This example demonstrates how to continuously measure buffered frequency | ||
using one counter on a Counter Input Channel. The Edge, Minimum Value | ||
and Maximum Value are all configurable. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import AcquisitionType, Edge, FrequencyUnits | ||
|
||
|
||
with nidaqmx.Task() as task: | ||
channel = task.ci_channels.add_ci_freq_chan( | ||
"Dev1/ctr0", | ||
min_val=2.0, | ||
max_val=100000.0, | ||
units=FrequencyUnits.HZ, | ||
edge=Edge.RISING, | ||
) | ||
channel.ci_freq_term = "/Dev1/PFI8" | ||
task.timing.cfg_implicit_timing(sample_mode=AcquisitionType.CONTINUOUS) | ||
|
||
print("Continuously polling. Press Ctrl+C to stop.") | ||
task.start() | ||
|
||
try: | ||
total_read = 0 | ||
while True: | ||
frequencies = task.read(number_of_samples_per_channel=1000) | ||
total_read += len(frequencies) | ||
print(f"Acquired data: {len(frequencies)} samples. Total {total_read}.", end="\r") | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
task.stop() | ||
print(f"\nAcquired {total_read} total samples.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Example of counter input frequency acquisition. | ||
This example demonstrates how to measure frequency using one | ||
counter on a Counter Input Channel. The Edge, Minimum Value and | ||
Maximum Value are all configurable. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import Edge, FrequencyUnits | ||
|
||
|
||
with nidaqmx.Task() as task: | ||
channel = task.ci_channels.add_ci_freq_chan( | ||
"Dev1/ctr0", | ||
min_val=2.0, | ||
max_val=100000.0, | ||
units=FrequencyUnits.HZ, | ||
edge=Edge.RISING, | ||
) | ||
channel.ci_freq_term = "/Dev1/PFI8" | ||
|
||
task.start() | ||
|
||
data = task.read() | ||
print(f"Acquired frequency: {data:.2f} Hz") | ||
|
||
task.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Example of CI pulse frequency operation. | ||
This example demonstrates how to configure a pulse measurement to acquire frequency and duty cycle. | ||
""" | ||
|
||
import nidaqmx | ||
from nidaqmx.constants import FrequencyUnits | ||
|
||
with nidaqmx.Task() as task: | ||
channel = task.ci_channels.add_ci_pulse_chan_freq( | ||
"Dev1/ctr0", "", min_val=2.0, max_val=100000.0, units=FrequencyUnits.HZ | ||
) | ||
channel.ci_pulse_freq_term = "/Dev1/PFI8" | ||
|
||
task.start() | ||
|
||
data = task.read() | ||
print(f"Acquired data:") | ||
print(f"Frequency: {data.freq:.2f} Hz") | ||
print(f"Duty cycle: {(data.duty_cycle * 100):.2f}%") | ||
|
||
task.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters