05-23-2017 04:03 AM
Dear community,
I am having trouble measuring the duty cycle of a TTL signal. I generate analog signals through aoX (about 10 Hz signal) and feed them to an electronics module. The module converts these signals into pulse signals and I would like to measure the duty cycles within the analog output duration (20 seconds). However, within the timeout period no pulses are captured which results in an error message.
I use a python-C wrapper so I am looking for a working example in C.
The TTL signal is connected to ctr0 gate. I am not sure which timeclock is used but since I do not set it, I guess the default clock of 20 Mhz is used. Do I need to route the clock to ctr0 source? The main lines of code are:
counter1 = Task()
counter_channel="Dev1/ctr0"
counter1.CreateCIPulseChanFreq (counter_channel,"", 1, 200, DAQmx_Val_Hz);
[...]
analog_output.WriteAnalogF64(samplesPerChan,1,0,DAQmx_Val_GroupByChannel,data_out,byref(sampsPerChanWritten),None)
counter1.ReadCtrFreq(samplesPerChanCtr,timeout,DAQmx_Val_GroupByChannel,duty_freqA, duty_cycleA, buffer_size_counter,byref(read),None)
[...]
I would really appreciate any help.
Solved! Go to Solution.
05-24-2017 01:52 AM
As a LabVIEW programmer, I will not be able to help you to change your code.
A different solution would be to use this IC which is a PWM to voltage converter.
05-31-2017 01:36 AM
The NI Card provides the ability to measure duty cycles via Counters so I do not see the Point in using an additional IC.
Nevertheless, after some random copy/paste I found the solution. Apparently the Timing Settings needed to be called. For anyone with the same Problem:
counter1 = Task()
counter_channel="Dev1/ctr0" # connect pulse signal to ctr0 gate (on NI 6343)
counter1.CreateCIPulseChanFreq (counter_channel,"", freq_low, freq_high, DAQmx_Val_Hz);
counter1.CfgImplicitTiming(DAQmx_Val_FiniteSamps,samplesPerCount) # <- that was the missing line
counter1.StartTask() # armed
# wait for pulses to be recorded, then:
counter1.ReadCtrFreq(samplesPerCount,timeout,DAQmx_Val_GroupByChannel,duty_freqA, duty_cycleA, samplesPerCount,byref(read),None)