Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

generate PWM signal using C# and measurement studio

Hi.
 
I try to generate a pulse width modulation (PWM) signal from a counter output of PXI-6259.  I am using a C# language and Measurement Studio 7.1.  My understanding is to first create a new DAQmx task (myTask), then use myTask.COChannels.CreatePulseChannelFrequency to create a digital counter channel, and start the task.  My question is that how can I change the pulse duty and frequency on the fly?  I check the other post, and I think it is done by set the property of pulse duty and frequency.  But how to do it in C#, I am not clear.  Thanks. 
 
0 Kudos
Message 1 of 3
(5,091 Views)
Hello Thresh74,

Below are some functions that allow you to get/set or reset the duty cycle. You will just need to call these functions from your application. I cut an pasted them directly from the DAQmx C reference Help.

Get/Set/Reset CO_Pulse_DutyCyc

int32 __CFUNC DAQmxGetCOPulseDutyCyc(TaskHandle taskHandle, const char channel[], float64 *data);

int32 __CFUNC DAQmxSetCOPulseDutyCyc(TaskHandle taskHandle, const char channel[], float64 data);

int32 __CFUNC DAQmxResetCOPulseDutyCyc(TaskHandle taskHandle, const char channel[]);


Purpose

DAQmxGetCOPulseDutyCyc gets the Counter Output >> Pulse >> Frequency >> Duty Cycle property.

DAQmxSetCOPulseDutyCyc sets the Counter Output >> Pulse >> Frequency >> Duty Cycle property.

DAQmxResetCOPulseDutyCyc resets the Counter Output >> Pulse >> Frequency >> Duty Cycle property.


0 Kudos
Message 2 of 3
(5,070 Views)
thresh74:

There are actually two ways of doing this:
  1. Change the PulseDutyCycle and PulseFrequency properties on the COChannel object
  2. Write a CODataFrequency object to the task with the new frequency/duty cycle pair that you want
The second method of these is strongly recommended over the first. That is true for the DAQmx API in all languages.

Here's an example of the second method.

// I've configured a task called myTask and
// want to change the frequency/duty cycle to
// the values newFreq and newDutyCycle
CounterSingleChannelWriter writer = new CounterSingleChannelWriter(myTask.Stream);
writer.WriteSingleSample(true,new CODataFrequency(newFreq,newDutyCycle));

Hope this helps

-- Chris
0 Kudos
Message 3 of 3
(5,048 Views)