Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Determine if a signal has a duty cycle or if it is digital high/low on a PXIe-6612?

Solved!
Go to solution

Hello,

I would like to perform a task with very high precision (preferably to within at least a microsecond of precision) using Python and the NI-DAQmx API that involves performing several task.start() and task.stop() calls at very particular times for separate tasks. I am attempting to determine whether or not a signal I am reading has a duty cycle, and if it doesn't, whether or not it is High or Low, and need to perform this task within a very short amount of time (preferably less than 0.1 ms.) It appears that there is not an existing function in the NI DAQmx API that can handle both duty cycle measurement and a digital (high/low) input measurement. In this case, my plan is to measure the signal from a digital input task to determine if it is high or low. Then, to confirm that it does not have a duty cycle, I intend on using the add_ci_pulse_chan_freq, as the add_ci_duty_cycle_chan function does not appear to be supported on this device, to determine the duty cycle, if it exists. Given that calling the read() function on the add_ci_pulse_chan_freq task will result in a timeout if the signal is High or Low (i.e. does not have a duty cycle), I intend on calling the read() function for the add_ci_pulse_chan_freq task with a timeout time of either 0 or a very small (i.e. < 0.0001 s) amount of time, and catching the error as an exception so that my code continues to compile. Since these tasks (add_ci_pulse_chan_freq and add_di_chan) share the same pin/resource name, I'll need to be starting and stopping them very quickly, as they can't run using the same resource. I am concerned that Python is not inherently quick enough to precisely handle the starting and stopping of these tasks, as I believe that Python can often have delays of up to 20 ms between function calls (although I am not sure if this in fact the case, especially on a PXI.) Are there any resources available (preferably existing code in Python, if any exists) that provide methodology that can be used to 'schedule' task start/stop times ahead of time? Alternatively, if there is an existing function or other methodology that is capable of performing both duty cycle or digital input measurements at the same time (which I don't believe there is) on the same resource line, please let me know.

I believe that most functions inherently handle this problem by utilizing cfg_samp_clk_timing to set a sampling rate, however given that the two functions share resources, I believe that method unfortunately is not an option here.

Similarly, are there ways to access the precision clocking available on the PXI from Python? Given that time.sleep() is not very accurate for shorter time intervals, I was wondering if there is a way to ensure that a specified amount of time has passed/elapsed with a very high level of precision. I am using a PXI-6612 module on a PXI 1085 chassis.

0 Kudos
Message 1 of 4
(2,152 Views)

You're trying to read a state which is mutually exclusive, a duty cycle means there is both high and low, a static high or low means there is no duty cycle, in fact, even a duty cycle will look like a static state in a smaller time division. IMO there is no instrument that can perform your requirement.

 

An alternate method, connect the signal to two DAQ channels, where one channel is configured as counter input (for duty cycle measurement) and the other channel as static DI. Now you can run both parallel (I assume it would work because the counter does not use a sample clock), if there is no duty cycle measured, use the value read by DI.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 4
(2,119 Views)
Solution
Accepted by topic author brogers33

Thanks Santhosh. We realized we can essentially perform this functionality by performing a large amount of digital I/O samples at a high clock rate (i.e. 10,000,000 samples at 10 MHz) to manually determine the duty cycle as needed. Nevertheless, thanks for the suggestion; we may "clone" signals to multiple lines in the future as needed.

 

 

0 Kudos
Message 3 of 4
(2,084 Views)

Another method you might consider:

 

Configure your DI task for "change detection" that's sensitive to both rising and falling edges of the signal in question.  Then also set up a counter task that measures the period of the special internal signal known as the "change detection event".  You can get all the same info and timing precision that you get from a 10 MHz sampling task, but with maybe 100x less data bandwidth to deal with.  However, it *is* a little more tricky and involved to get the task config and data processing exactly right.  Very possible, but not really necessary unless you find that 10 MHz sampling is too much to sustain.

 

 

-Kevin P

ALERT! LabVIEW's subscription-only policy coming to an end (finally!). Permanent license pricing remains WIP. Tread carefully.
0 Kudos
Message 4 of 4
(2,002 Views)