Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Example Program
NI Supported: Yes
Publish Date: Sep 6, 2006

DAQmx - Analog Input to Control Pulse-Width-Modulated Counter Output

0 ratings | 0.00 out of 5
Print

Downloads

Filename: 2503.vi
Requirements: View

I. Description:
This example demonstrates how to do Pulse Width Modulation using Analog Input and Counter Output.

II. Instructions for Running:
1. Select the physical channel to correspond to where your signal is input on the DAQ device. Also, select the corresponding channel for where your signal is being generated.
2. Enter the minimum and maximum voltage ranges.
Note: For better accuracy try to match the input range to the expected voltage level of the measured signal.
3. Set the sample rate of the acquisition.
Note: The rate should be at least twice as fast as the maximum frequency component of the signal being acquired.
6. Set the initial frequency and duty cycle of the output pulse.

III. Block Diagram Steps:
1. Create an analog input voltage channel. Also, create a counter output pulse channel.
2. Set the rate for the sample clock of the analog input and the counter output. Additionally, define the sample mode to be hardware timed single point for both tasks.
2a. Call the Get Terminal Name with Device Prefix. This will take a Task and a terminal and create a properly formatted device + terminal name to use as the source of the sample clock for the CO task. By sharing the sample clocks the tasks will be synchronized.
3. Call the Start VI to arm the two functions. Make sure the counter output is armed before the analog input. This will ensure both will start at the same time.
4. Read the data.
5. Call the Proportional Gain VI. This takes specified set point and gain and calculates the output value given the process variable.
Note: For better accuracy the LabVIEW Real Time Toolset provides an optimized PID VI.
6. Check to see if the analog data has changed since the last iteration. If it has not then there is no need to redo the pulse width calculations.
7. Determine the pulse specs. The output of the proportional gain is converted to a percentage. This percentage is limited to .1 and 99.99. Duty cycle must be a number between .001 and 9.99 so divide by 100.
8. Write the new duty cycle.
9. Call the DAQmx Wait for Next Sample Clock VI. This VI determines if the application is keeping up with the specified rate. An error is returned if the application falls behind.
10. Call the Clear VI to Clear the Tasks
11. Use the popup dialog box to display an error if any.
Note: If you are using this VI with LabVIEW Real Time, normally controls and indicators should not be placed inside the time-critical loop. However, for the purpose of instruction and simplicity, a few controls and indicators are used in this example. Before deploying such an example, the controls and indicators should be replaced by RT FIFO VIs, and data should be communicated to the Host PC through a separate normal priority VI running in parallel to the time-critical application.

IV. I/O Connections Overview:
Make sure your signal input/output terminals match the Physical Channel I/O controls.

Requirements


Filename: 2503.vi

Software Requirements


Application Software: LabVIEW Professional Development System 7.1
Language(s): LabVIEW

Hardware Requirements


Hardware Group: Multifunction DAQ (MIO)

 
0 ratings | 0.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This example program (this "program") was developed by a National Instruments ("NI") Applications Engineer. Although technical support of this program may be made available by National Instruments, this program may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this program with each new revision of related products and drivers. THIS EXAMPLE PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).