Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Hardware-Timed Single Point for Duty Cycle of PWM

Description:
This example configures a DAQmx Counter Task for Hardware-Timed Single Point PWM measurements on an X Series DAQ card. It imitates HWTSP Pulse Measurement, except it will not throw an error if there is no pulse (0% duty cycle or 100% duty cycle).

Steps to implement or execute code

  1. Rename your X Series DAQ Card to 'Dev1' in Measurement and Automation Explorer.
  2. Attach your PWM Signal to specified port on Front Panel (PFI9).
  3. Run the VI.View the Duty Cycle Measurement

I/O Connections Overview:
Connect a PWM signal to the terminal specified in PWM Signal Indicator on the Front Panel. This defaults to PFI9.

Requirements
Software
LabVIEW 2012 or compatible
NI-DAQmx 16.0 or compatible

Hardware
cDAQ with C series Counter Input Module and Analog Output
 
2017-10-30_15-40-23.jpgbd.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

- Regards,

Beutlich
Comments
Member cf57370
Member

Hello,

I had like to know how integrate this VI in a 10 ms cadenced loop.

Cyril

Member Beutlich
Member

What device and form factor are you trying to use?

- Regards,

Beutlich
Member cf57370
Member

I am trying to use a X serie 6343 USB device. What do you mean about form factor?

Member Beutlich
Member

The loop rate is determined by the Analog Output sample clock. The first example had a constant at 5 Hz, which corresponds to a 200 ms periods. I tested with a USB 6343, and I could run this easily at 10 ms by increasing the Analog Sample Clock rate to 100 Hz. I updated the example to call this out as a front panel control, so try looking at the updated version.

USB is the form factor. Example alternatives would be a 6343 for the PC (PCI) or for a test chassis (PXI). USB will be the worst for latency and throughput, but it seems this example runs at the rates you are looking for.

- Regards,

Beutlich
Member cf57370
Member

Thank you, but I fear that I can't go under 15 ms with this solution. Moreover,when I integrate your VI in my whole programm,the execution time is increased to 30 ms. Is there another way to get the duty cycle? At the moment I use a lowpass filter and an analog input to manage the PWM signal but I think that the accuracy is low.

Member Beutlich
Member

USB latency can be poor, which is why HWTSP features are not offered on USB X Series devices. However, when I tested this code with a USB 6343, I could run this loop rate down to 1 ms. I did not stress it past that, I can't comment on how much time your extra code adds.

This code runs expecting the frequency to be much faster than the acquisition, so that there are a plethora of samples that we ignore. You may instead have a slow PWM, so that the PWM has not pulsed often enough to fill the buffer for a new measurement. If this is the case, you may try changing the Read VI to pinch every value. Currently, the Read VI pulls an array (the latest two elements), and computes the PWM from that. Instead, you may just read one value, and store the latest value in a shift register to use as a comparison. It is very critical that you do not loose samples in this setup (that you read much faster than your PWM).

- Regards,

Beutlich
Member hfibonaich
Member

can I use this program with DAQ6624 and 6723