Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM duty cycle update in DAQmx Base

I am trying to generate a PWM (standard servo, 50 Hz, duty cycle 5-10%) with a USB-6211.  I am on a Linux system so I am using the DAQmx Base C API.  Following the example code supplied with DAQmx Base, I can define the frequency and duty cycle I want and start the task with no problems.  However, I will need to update the duty cycle as the task is running.  I have done this using the DAQmx Write VI on a full LabView Windows system in the past.  However, I don't see the relevant write function in the DAQmx Base API.  Does anyone know the proper function in the API to update the duty cycle of a running PWM generation task?

0 Kudos
Message 1 of 6
(8,223 Views)

Hi Mgreytak,

 

Have you tried using a channel property node?

 

http://digital.ni.com/public.nsf/allkb/82C9F3C15F62974E86256EBA0058CAF5?OpenDocument

 

 

Sunaina K.
Product Marketing Manager for CompactRIO & TSN

Making the intangible, tangible
0 Kudos
Message 2 of 6
(8,211 Views)

Hello,

 

I can do that with a VI when running LabView, but I am using DAQmx Base (the C API).  Do you know how to do it in DAQmx Base?  I have tried using the DAQmxBaseSetChanAttribute function to change the DAQmx_CO_Pulse_HighTime attribute of the counter output channel but I get a runtime error "Specified property is not supported by the device, is not applicable to the task, or is not implemented."

 

Thanks,

Matt

0 Kudos
Message 3 of 6
(8,204 Views)

Hi Mgreytak,

 

I found a document which shows a different approach:

 

http://zone.ni.com/devzone/cda/epd/p/id/5712

 

I believe this will work with DAQmx Base.

 

 

Sunaina K.
Product Marketing Manager for CompactRIO & TSN

Making the intangible, tangible
0 Kudos
Message 4 of 6
(8,193 Views)

mgreytak wrote:

 

I am trying to generate a PWM (standard servo, 50 Hz, duty cycle 5-10%) with a USB-6211.  I am on a Linux system so I am using the DAQmx Base C API.  Following the example code supplied with DAQmx Base, I can define the frequency and duty cycle I want and start the task with no problems.  However, I will need to update the duty cycle as the task is running. 

 

<snip>

 

I have tried using the DAQmxBaseSetChanAttribute function to change the DAQmx_CO_Pulse_HighTime attribute of the counter output channel but I get a runtime error "Specified property is not supported by the device, is not applicable to the task, or is not implemented."


Unfortunately, the error text in this case is correct: changing the value for the DAQmx_CO_Pulse_HighTime attribute while a task is running has not been implemented for NI DAQmx Base [1]. Since it appears your application requires on-the-fly updates, as opposed to stop-reconfigure-start updates, please contact your local NI representative and he or she can work with my group to evaluate further options.

 

[1] NI-DAQmx Base 3.5 for Linux "SUPPORTED FUNCTIONALITY" section 

http://download.ni.com/support/softlib//multifunction_daq/nidaqmxbase/3.5/Linux/README.txt

Joe Friedchicken
NI Configuration Based Software
Get with your fellow OS users
[ Linux ] [ macOS ]
Principal Software Engineer :: Configuration Based Software
Senior Software Engineer :: Multifunction Instruments Applications Group (until May 2018)
Software Engineer :: Measurements RLP Group (until Mar 2014)
Applications Engineer :: High Speed Product Group (until Sep 2008)
0 Kudos
Message 5 of 6
(8,189 Views)

Thanks Joe.  For now a workaround is to generate one pulse at a time; after each one, stop and clear the task then restart it with the new duty cycle.  It takes some time to stop and restart the task so instead of my desired 20 ms period it's more like 45 ms... however, the servo I'm controlling does not seem to mind the longer period as long as the hitime is consistent.  Not ideal, but good enough for now.

 

Thanks again,

Matt

0 Kudos
Message 6 of 6
(8,183 Views)