Quantcast
Channel: Counter/Timer topics
Viewing all articles
Browse latest Browse all 1271

Measuring duty cycle with NI-DAQmx Python on USB-6218

$
0
0

Hi everyone ! I am a student and very new to this and am still getting familiar with the basics. I am working on a project with an electronic card.

I have to send some commands on the serial link of the card to activate and deactivate some I/O in order to measure different voltages on the card and to validate some tests. I want to automate these tests using python and the NI-DAQmx Python API.

 

Currently, I have 28 analog voltages to measure and 2 analog voltages to send that's why I am using the DAQ USB-6218 with its 32 analog inputs and its 2 analog outputs. Also, the input range of 10 V suits me perfectly due to the fact that most of my voltages are between 0 and 10 V.

I need also to measure a current of 241 mA, but it would be better to measure its duty cycle which is at a frequency of 5 kHz, Pulse width = 111 μs, Period = 199 μs, so duty cycle = Pulse width / Period = 111/199 = 0.56.

 

Even if I managed to code the acquisition of my analog voltages and to send the analog voltages I wanted, I am currently struggling for the duty cyle part ...

 

For the voltage acquisition I am currently using this sample which is working very well :

################################################################## # imports ################################################################## import nidaqmx import time from builtins import input ################################################################## # Function definition ################################################################## def first_test(): #Function for first test voltage_ai0 = task_ai0.read() print("Voltage on port AI 0 : ", voltage_ai0) if 2.475 < voltage_ai0 and voltage_ai0 < 2.525: First_test = True else : First_test = False return First_test ################################################################## # main function ################################################################## if __name__ == '__main__': print("------------------------------------") print("Starting Voltage Acquisition..") print("------------------------------------") input("Press Enter to continue...") print("------------------------------------") #First test task_ai0 = nidaqmx.Task() task_ai0.ai_channels.add_ai_voltage_chan("Dev1/ai0",terminal_config=nidaqmx.constants.TerminalConfiguration.RSE) time.sleep(2.0) first_test()

For the duty cycle acquisition, I tried this :

import nidaqmx import pprint pp = pprint.PrettyPrinter(indent=4) with nidaqmx.Task() as task: task.ci_channels.add_ci_duty_cycle_chan("Dev1/ctr0") print('1 Channel 1 Sample Read: ') data = task.read() pp.pprint(data) print('1 Channel N Samples Read: ') data = task.read(number_of_samples_per_channel=8) pp.pprint(data)

 But I get this error ... :

error_duty_cycle.png

I read on this link : https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kHAPSA2&l=fr-FR that there are three new counter pulse measurements  available in DAQmx 9.0 and later that are only supported on X Series devices, 661x devices and newer cDAQ devices. If you attempt to create these tasks with unsupported hardware, you will receive the above error.

I tried to use the Task Type : "CI Pulse Freq" with the resulting measurement values :" Frequency and Duty Cycle" by testing this example : https://github.com/ni/nidaqmx-python/blob/master/nidaqmx_examples/ci_pulse_freq.py, but I get the same error message ...

 

That's why I am wondering if I am using the good measurement type and if not, can you tell me which one should I use and how to program it please ...

 

Any help would be greatly appreciated!! Thank you.


Viewing all articles
Browse latest Browse all 1271

Trending Articles



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