Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble measuring duty cycle of signal

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 3
(3,244 Views)

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.

  • Frequency range of the PWM : 30Hz to 100kHz (higher than your ao signal)
  • Output : 2.5V for duty cycle of 100%
0 Kudos
Message 2 of 3
(3,215 Views)
Solution
Accepted by topic author fastro

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)

 

0 Kudos
Message 3 of 3
(3,167 Views)