LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM duty cycle output

Solved!
Go to solution

Hello!

 

I am trying to have accurate control of an SG90 servo motor using LabVIEW. I have my code attached below.

 

The issue I am having is that when I read the signal with an oscilloscope, the duty cycle of the signal will change pulse by pulse by as much as 3% when it should stay constant.

 

I have tried messing with many parts of my program like frequency, duty cycle, and samples of the wave form generator but I can't seem to have a steady duty cycle of my pulse.

 

Using a CDAQ-9174 and an NI 9263

 

I'm pretty new to LabVIEW and DAQ hardware so any and all tips are appreciated.

0 Kudos
Message 1 of 9
(262 Views)

Please downgrade the VI to LV2019 or earlier.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 9
(251 Views)

Hopefully this works for you.

0 Kudos
Message 3 of 9
(243 Views)

@21Matthews wrote:

Hopefully this works for you.


@Santo13 requested that you "Save for Previous Version" and specify LabVIEW 2021.  Instead, you provided LabVIEW 2023.

 

So I'll (politely) ask that you save it for LabVIEW 2021 or LabVIEW 2019, both of which I have on my Work PC.  We really want to help you, but if we can't see what you are doing, ...

 

Bob Schor

0 Kudos
Message 4 of 9
(240 Views)

My mistake. Here I selected version 19.0 so i assume that corresponds to the 2019 version.

 

Thank you

0 Kudos
Message 5 of 9
(231 Views)

You are using software timing hence there is a jitter of at least 1ms. You should use sample clock timing. Refer to shipping example Help >> Find Examples... >> Hardware Input and Output >> DAQmx >> Analog Output >> Voltage - Continuous Output.vi

-------------------------------------------------------
Control Lead | Intelline Inc
Message 6 of 9
(199 Views)
Solution
Accepted by topic author 21Matthews

I'm really glad that @ZYOng responded -- I presume he was able to open at least one of the VIs you posted.  Sadly, even though you attached something in response to my request, I am still unable to open it.  This time, it didn't tell me that the file was of a newer version of LabVIEW (which was the problem with the first two of your attachments) -- it just hung, showing me a partial Front Panel and then a red "Close Window" control in the upper right hand corner -- oops, it just loaded after about 3 minutes ...

 

So there are a number of problems with your VI.  As it happens, I recently wrote a VI whose responsibility was to generate a sinusoidal waveform with a frequency of 2800 Hz that would play for 0.3 s.  Like you, I generated this as a Waveform and then played out the Waveform as an analog output through a USB-6212 driving a small audio amplifier (connected to a speaker).

 

There are two parts.  One is generating the waveform.  I chose a frequency of 14000 Hz (which is 5 points per cycle, pretty lo-fi, but adequate for my needs), so I need to generate 2100 samples at 2800 Hz to get a 0.15 s waveform when played at 14000 Hz.  So now I have my sound wave.

 

When using NI's DAQ hardware, you need to remember that DAQ devices frequently have internal clocks that are far superior to the timing functions in LabVIEW (not the least because PCs running Windows have no "dedicated" clocks -- the more you do (in parallel) the slower the code runs.

 

The next thing you need to learn (maybe you should read "Learn 10 Functions in NI-DAQmx and Handle 80 Percent of your Data Acquisition Applications" -- find it on the Web) how to handle DAQmx for reading and writing Waveforms.  You need about four DAQmx functions:  a DAQmx Create Channel (where you find the DAQ device and say you want to do a AO Voltage), a DAQmx Timing function where you set the sampling frequency and number of points in your Waveform, then when you want to play your sound, do a DAQmx Write Analog Waveform (1 Channel, N Samples), followed with a DAQmx Wait until Done and Stop Task.  "Beep".

 

Your VI generated a Waveform (many samples).  You send it to a DAQmx Write, but say "1 sample", though you generated 20,000 samples!  You also have a Wait (to clock the speed of the loop) with a Wait time of 0 ms -- what does this mean?

 

Do study the examples that ship with LabVIEW.  But you might also try to understand how I generated my little "Beep" and see if you can duplicate the ideas I mentioned in your code.

 

Bob Schor

 

Message 7 of 9
(186 Views)

I have managed to eliminate the jitter using one of the functions in the article you recommended as a guide.

 

Thank you!

0 Kudos
Message 8 of 9
(153 Views)

@21Matthews wrote:

I have managed to eliminate the jitter using one of the functions in the article you recommended as a guide.

 

Thank you!

You are most welcome!  And finding the "solution" yourself (with, perhaps, a little "extra study" on the side) is a great feeling, isn't it?

 

Bob Schor

0 Kudos
Message 9 of 9
(123 Views)