Discussion:
calculate duty cycle using a USB-6009 Data acqusistion unit
(too old to reply)
83rocketscientist
2008-04-06 03:40:04 UTC
Permalink
Hello everyone,
 
I am trying to calculate the duty cycle of a digital signal using a USB-6009 Data acqusistion unit. While I am aware of the shortcommings of this unit for this type of application, if I calculate the duty cycle 100 times per second, that should be enough. The period of my square wave is about 10 milliseconds.
 
My first attempt (accelerometer_vi_2) I tried to use the "Pulse Measurement.vi" block, however, I think I am using the wrong data type for this block. Is there a way to convert the data type so I can use this block?
 
My second attempt was to replicate some of the ideas discussed here:
<a href="http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=182210&amp;query.id=50252#M182210" target="_blank">http://forums.ni.com/ni/board/message?board.id=170&amp;message.id=182210&amp;query.id=50252#M182210</a>
Basically, for each period, you create an array where the duty cycle can be calculated by summing every 1 in a boolean array and dividing it by the length of the array. Instead of a boolean array, I used a binary array because I could not use the sum tool for a boolean array. Even with the binary array, however, the VI does not work!
&nbsp;
I am sure the answers to some of this stuff is fairly simple, however, this is my first Labview VI, so I know I have a lot to learn! If there is a better way then the options I have discussed, to calculate the duty cycle, I am all ears!


accelerometer_vi_22.vi:
http://forums.ni.com/attachments/ni/70/8590/1/accelerometer_vi_22.vi


accelerometer_vi2.vi:
http://forums.ni.com/attachments/ni/70/8590/2/accelerometer_vi2.vi
83rocketscientist
2008-04-06 06:10:05 UTC
Permalink
Correction...here is the VI i used to try and calculate the duty cycle using a binary array as described in my first post! Sorry to add more confusion!
&nbsp;
&nbsp;


accelerometer_vi2.vi:
http://forums.ni.com/attachments/ni/70/8591/1/accelerometer_vi2.vi
83rocketscientist
2008-04-06 06:10:05 UTC
Permalink
Ok lets try this one more time...here is the vi that uses a binary array for the duty cycle calculation...


accelerometer_vi3.vi:
http://forums.ni.com/attachments/ni/70/8592/1/accelerometer_vi3.vi
samantham
2008-04-08 16:40:08 UTC
Permalink
Hello,
I attached some code that will run a post process analysis on the data to calculate the duty cycle.&nbsp; Please note that the constant for Wait Until Next ms Multiple is set to 1.&nbsp; Thus, the loop will run every 1 msec. (On Demand timing), which&nbsp;equates to a sample rate of 1,000 Hz.&nbsp;&nbsp;Since your period is 10 ms in duration, this should hopefully allow for enough samples during one period to compute an accurate duty cycle.&nbsp;
This code is used for monitoring one line/channel.&nbsp; I saw that the original code was setup to acquire across several lines in a port.&nbsp; Do you need to monitor more than one channel in order to measure several channels duty cycle?&nbsp; Please also note that I used DAQmx function calls instead of the DAQ Assistant.&nbsp; Let me know if and where you need flexibility and I can make some suggestions.
&nbsp;


PostProcessingDutyCycle.vi:
http://forums.ni.com/attachments/ni/70/8611/1/PostProcessingDutyCycle.vi
83rocketscientist
2008-04-15 18:10:07 UTC
Permalink
Thanks for your help Samantha,
I got your code to work, however, I am not sure that 10 samples will provide the kind of precision I need to work with my particular application. Is there any way to set that wait function to less then one ms???
&nbsp;
Thanks!
samantham
2008-04-17 20:10:08 UTC
Permalink
Hello,
If you are looking for more accuracy, I would highly recommend getting a Multifuctional DAQ 62XX or Counter 66xx&nbsp;device with a counter so you can run a Counter Input Task for semi period.&nbsp; There is actually a shipping example in the Example Finder titled Measured Duty Cycle - Buffered - Finite.vi that used this type of task with a counter to measure duty cycle.&nbsp; The USB 6009 that you currently have only does event counting.&nbsp;&nbsp;It is recommended to use a counter input task for duty cycle measurements.
You can set the constant input of Wait Until Next ms Multiple.vi to a number lower that 1.&nbsp; For example .5 or .2, however this type of software timing (vi posted above) is system dependent.&nbsp; The loop it set to run every 1 ms if the processor allows it.&nbsp; In addition if the DAQmx Read.vi or code for building the array makes the loop take longer than 1 ms, than you are not actually achieving this rate.&nbsp; Thus,&nbsp;the constant can be set to a value less than 1, however you may not get that timing.&nbsp; The same is true for the 1 ms, since it is system dependent.
&nbsp;

Loading...