Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Reasonable time for updating the duty cycle of a counter generated PWM signal?

Hi All,

 

I would like to update the PWM duty cycle value in a few ms but right now the best I get is roughly 17 ms; is that reasonable?
Is it possible to change the duty cycle for a PWM signal faster?

I am using the counter and hw timer. I am using a high resolution timer to measure the time. My conclusion is that it is the task.start() method that takes roughly 17 ms; is it possible to do it faster?

 

My setup:
Visual Studio 2005 / C#
Measurement Studio 2010
NI USB-6211

 

Here is the code

  

private String hwCounter = "Dev1/ctr0";

public void start(double dutyCycle)
{

  if (state == STATE_GENERATING_PWM)
    stop();

  try
  {
     pwmTask = new Task();
     pwmTask.COChannels.CreatePulseChannelFrequency(hwCounter,"PWM Channel", COPulseFrequencyUnits.Hertz,
     idleState, 0.0,frequency,dutyCycle);
     pwmTask.Control(TaskAction.Verify);

  

    //Measure time
    hiResTimer.Start();

    pwmTask.Start(); // This takes 17 ms, Why?
   

    hiResTimer.Stop();
   
   Console.WriteLine("Duration: {0} sec\n", hiResTimer.Elapsed);
 
   state = STATE_GENERATING_PWM;
 }
 
 catch (Exception exception)
 {
    MessageBox.Show(exception.Message);
    pwmTask.Dispose();
  }
}

 

public void stop()
{
  if (state == STATE_IDLE)
    return;

  pwmTask.Stop();
  pwmTask.Dispose();
  state = STATE_IDLE;
}

 

 

Kind regards,

Suru

0 Kudos
Message 1 of 1
(3,156 Views)