Showing results for 
Search instead for 
Did you mean: 

Bad Duty Cycle readings

Go to solution


 I’m building an application in which I want to measure a duty cycle.  I can control the “Duty Cycle In” and the FCM analyzes the info and sends a signal to the Motor. I want to measure the “Duty Cycle Out” of the motor. (I attached diagram) For this measurement I just connected a wire to the negative side of the motor. To calculate this Duty Cycle I am measuring the period and the pulse width. The program works very good when I have a “Duty Cycle Out” from 1% to 99%, but whenever is 0 or 100% it shows wrong info. I would expect that the pulse width at 0% or 100% is cero, but LabVIEW shows a value (1,1E-5 s) and calculates a Duty Cycle of about 23% which is totally wrong.  Also, if I run the program for the first time and I measure this pulse width with a “Duty Cycle In” of 0%, pulse width is cero., but whenever I change the “Duty Cycle In” to 10% or higher, and then I go back to a “Duty Cycle In” of  0% it shows a value, and calculates a bad Duty Cycle. I don’t know why this only happens when I put higher “Duty Cycles In”, and then I go back to 0%. I measured the signal with an oscilloscope and there is nothing, not even noise! I don’t know how the card gets these lectures.  

Do you have any suggestions of what can be wrong?







Message 1 of 8
I'm using the NI PXI 6232, and LabVIEW 8.2.
0 Kudos
Message 2 of 8

Hello Hernar,


its not so easy for me to help you in this case without your labview program. So please post your code for test. Its necessary that you deal with TTL signals and use the counter pins on your card.


Or use this example to generate a duty cycle of 0 without the counter modul.


Kind regards,



0 Kudos
Message 3 of 8

Hi Elmar


Thanks for the reply. I attached my Code. I am measuring the period with ctr0 and pulse width with ctr1. I divide Pulse Width / Period to obtain the Duty Cycle. To detect 0% and 100% I compare the value of pulse width to zero. I created an additional Digital Input, with this channel I check if the signal is high or low. So if Pulse Width is zero, I read from the Digital Input the level of the signal, and then I know whether is 100% or 0%. My problem is when I have a Duty Cycle of 0 or 100%, the DAQ keeps sending a value for the pulse width, and I cannot apply the method explained before. I think this value should be zero, I don’t know if I am mistaken.  


Download All
0 Kudos
Message 4 of 8

Hello Henar,


you use the right functions but inside a timed loop with 50ms (software timed) therefore the calculation will be wrong.

Please generate the pulse for test in the Measurement & Automation Explorer (testpanel).

And calculate the Duty Cycle with the original example "C:\Programme\National Instruments\LabVIEW 8.6\examples\DAQmx\Counter\Measure Period or Pulse Width.llb\Meas Duty"


Kind regards,



0 Kudos
Message 5 of 8

Ok, so I need to get rid of the while loop? and the time delay?


I tried the example you told me, it works good, but when I have 0% or 100% it shows the next error:

 "Error -200284 occurred at DAQmx Read (Counter 1D DBL 1Chan NSamp).vi:1"


I'm not sure if the Trigger Source is correct, I selected the PFI2, and I connected the signal to measure to this PFI2 line. For the Counter input I selected ctr0.


I need these duty cycle readings as fast as possible. If the motor changes the Duty Cycle I should be able to see it instantly in the computer (without delays). With your example I cannot make this happen, I change Duty Cycle and some seconds later the readings change. In my code this is not a problem, readings are pretty good.


Do you recommend me to change my code? to use the code you gave me? I think this is a very simple task, but its driving me crazy! Hope you can help me to solve this.



0 Kudos
Message 6 of 8

Hello Hernar,


the error code -200284 describes that the read function waits for new values.

Or the read function wait for a trigger signal wich not occur.

Here more info about that issue.


Please check your trigger source if the trigger occur or not.

For example with a analog DAQmx Task in the measurement & automation Explorer (right click "Datenumgebung").

Select the trigger source pfi 2 and start the task"ausführen".

You will see data if the trigger occur.

If not you will get the timeout message as before in you lv code.


Kind regards,






0 Kudos
Message 7 of 8
Accepted by topic author Hernar

Hello Elmar,


My program finally is working well. I just removed the DAQmx Timing for measuring the Pulse Width, and reduced the DAQmx Read Timeout to 1. Now when I have 0 or 100% I have a pulse width value of zero, and I can do the right Duty Cycle calculations.


I dont know if this is the correct way to solve this, but for me works. I have been testing it for 2 days without any problem.


Well, thanks for your advices, and until the next one!



Best Regards,


0 Kudos
Message 8 of 8