Student Projects

cancel
Showing results for 
Search instead for 
Did you mean: 

Pulse Width Modulation (PWM) with NI myDAQ or ELVIS II

Overview

This document discusses basic concepts of pulse width modulation (PWM) and how to use the NI myDAQ or ELVIS II series to generate a PWM signal.

Description

Pulse width modulation (PWM) is a technique in which a series of digital pulses is used to control an analog circuit. The length and frequency of these pulses determines the total power delivered to the circuit. PWM signals are most commonly used to control DC and servo motors, but have many other applications ranging from controlling valves or pumps to adjusting the brightness of an LED.

The digital pulse train that makes up a PWM signal has a fixed frequency and varies the pulse width to alter the average power of the signal. The ratio of the pulse width to the period is referred to as the duty cycle of the signal. For example, if a PWM signal has a 10 ms period and its pulses are 2 ms long, that signal is said to have a 20 percent duty cycle. Figure 1 shows three PWM signals with different duty cycles.

a.jpg


Figure 1: PWM Signals with Different Duty Cycles


PWM signals can be generated as a digital signal, using counters or digital output line(s), or as an analog signal, using for instance, an arbitrary waveform generator or an RF signal generator. Several National Instruments multifunction data acquisition (DAQ) devices are capable of producing PWM signals. These include the E, S, B, M and the new X Series devices, which represent the next generation of multifunction DAQ from National Instruments, in addition to the NI myDAQ and ELVIS II series.

Requirements

Software

  • NI LabVIEW 2010 or compatible
  • NI DAQmx 9.1.5 or compatible

Hardware

  • NI myDAQ or NI ELVIS II series
  • Wire
  • Protoboard

Steps to Implement or Execute Code


Set Up Hardware:

We will measure the PWM signal with the oscilloscope on the NI ELVISmx Instrument Launcher.  Simply connect the AO0 to AI0+, and AGND to AI0- on the myDAQ or ELVIS II series.  If you want to use the output to drive a servo motor, refer to the Proximity-Controlled Servo Motor document.

a.png

Figure 2: NI myDAQ Wiring Diagram

Software Instructions:

The LabVIEW graphical development environment, combined with NI-DAQmx, gives you the tools needed to easily construct applications using counters to generate PWM signals.  The first step to create a PWM signal is to produce a simple digital pulse train. Below is an example of using LabVIEW to create a digital pulse train signal using NI-DAQmx. Each step of the program, indicated by a number at the bottom of the figure, is described in the VI shown below.  The VI can be downloaded from the bottom of the page.

a.png

Figure 3: Block diagram of ‘PWM.vi’

The user controls, explained in the following section, are shown below in the front panel.

a.png

Figure 4: Front panel of ‘PWM.vi’

How It Works:

With the PWM VI open and the hardware all set up, open the oscilloscope  from the NI ELVISmx Instrument Launcher, and click ‘Run.’ In ‘PWM.vi’, adjust a control inside of the ‘Waveform Information’ cluster to ensure the cluster is not grayed out, make sure you are using the proper physical channel, and run the program.  You should see a digital waveform (square wave) in the oscilloscope.  Adjust the duty cycle, amplitude, and frequency of the waveform, and note any visible changes.  The other parameters (timing, buffer, and max/min) do not need adjustment if you are simply viewing the waveform.

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

Andy G
Applications Engineering
National Instruments
Comments
NickMo
Member
Member
on

Hello,

What is the maximum PWM frequency that could be expected with a myDAQ?

I'm currently using two myDAQs to control a motor, one to read the encoder with the counter, and the second to output a 32 kHz PWM to the motor driver with the counter (the duty cycle is adjusted at 100Hz). If I could use the analog out for the PWM generation (at a sufficiently high carrier frequency), then I wouldn't have to use two myDAQs!

Thanks,

Nick

marigaby
Member
Member
on

Hello,

Please can anyone tell me if i can generate a pwm signal using an usb-6009??

Nothing seems to work !!

tamriel
Member
Member
on

.

Srikanthan
Member
Member
on

Thanks y AndyCandy

 

I am using 9264 to run the experiment provided AndyCandy. I am use an oscilloscpe to verfiy the output waveform and found that the waveform is generated correctly. But, the peak to peak voltage is 4V if I set the amplitude of 2V. I want to generate as 0-2v wavefrom not -2 to -2 V waveform. What changes need to be done in Vi ?

Contributors