From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you automate a pwm signal?

Solved!
Go to solution

I think I need to do exactly what this guy wants:

 

http://forums.ni.com/t5/LabVIEW/Dynamic-Duty-Cycle-Change-for-PWM/m-p/2360002/highlight/true#M735803

 

Except I don't need sinosoidal waves, the pulse train is fine.

 

I need automation because I have to generate a pulse train that looks like the inputs 1,2,3,4 below:

 

 

PWM_Allegro_3901.jpg

 

so that the output gets generated in the osciloscope.

 

Basically, my question is how do you automate changing the duty cycle after, say, "x" milliseconds?

 

In case anybody is curious, I'm using Figure 8 from this data sheet

0 Kudos
Message 1 of 10
(4,468 Views)

looking at the output ...there's capacitance on it. is that what you want or do you want a square wave instead?

0 Kudos
Message 2 of 10
(4,461 Views)

I want to generate the square wave and feed it in as input to the motor. 

 

That is the first step.  

 

The next step will be to see if I actually get the output they have shown in Figure 8 on pg. 10 of the data sheet. 

0 Kudos
Message 3 of 10
(4,447 Views)

What device are you using? If your device supports it, you want to output a hardware-timed digital waveform. I don't believe there's an easy way to get a counter output to do what you want. You might be able to use one counter as a trigger or gate for the second one such that it would turn off the PWM generation after a specific amount of time, but digital waveform generation will be much easier and more flexible.

0 Kudos
Message 4 of 10
(4,437 Views)

I am using the DAQ 6259.

 

Ideally I would like to generate a pulse train on hardware and be able to automate the switching ON/OFF of the pulse train.

 

0 Kudos
Message 5 of 10
(4,419 Views)

invasion2121 wrote:

Ideally I would like to generate a pulse train on hardware and be able to automate the switching ON/OFF of the pulse train.


Please be more specific than "automate." What determines when you need to turn on and off the pulse train? There are lots of possibilities. If you need the pulse train to fire a fixed number of pulses and then stop, you can tell the counter output to generate that number of pulses. If you need to turn the PWM on and off regularly, but the on and off times stay mostly constant, then I think you could use two counter outputs - one as the PWM, the other as a gate (but you'd need to confirm that setup, I've never tried it). If you need to generate a number of pulses followed by an off time over and over where the number of pulse and off time varies, then as I suggested before a digital waveform is probably the best approach.

0 Kudos
Message 6 of 10
(4,417 Views)

Hi Nathad -

 

If I understand correctly your response has 3 possibilities:

 

1. fixed # of pulses and stop

2. pulses are on and off regularly (i.e. constant period)

3. varying frequency and period pulse train

 

My goal is to put some measurements around the Figure 8's outputs (the wavey fast and slow decays).  Currently the data sheet does not provide them so I have to measure them myself using an oscilloscope.  

 

Using the Complete PWM example counter code I can dynamically update the frequency and duty cycle using the front panel controls. 


Looking at your suggestions I believe ultimately #2 will be what is needed to get the motor behaving the way we want, however we may need to do testing with #3 in order to figure out what is needed for #2.

 

Is it possible to modify the Complete PWM Example code to change frequency and duty cycles after, say 10 seconds? What is the easiest way to do this?

0 Kudos
Message 7 of 10
(4,391 Views)
Solution
Accepted by topic author invasion2121

How accurate do you need the timing to be? If you just want to adjust the signal after approximately 10s, then it's easy. Put in some timing code that counts 10s, and change the value when the timer expires. You could store a range of values in an array and index through them sequentially, or just increment/decrement the duty cycle and frequency each time the timer expires, depending on what you need. The simplest way to do this is the "Elapsed Time" function (I'm not usually a fan of Express VIs, but in this case it's easy).

 

There is no time scale in your Figure 8, and your original post said you need to change the duty cycle after some number of milliseconds. That's very different than changing it after some number of seconds, because to get accurate milliseconds you'll need hardware timing, whereas you can get approximate seconds in software.

0 Kudos
Message 8 of 10
(4,387 Views)

Hi Nathand -

 

I went ahead and accepted your solution because I think what you are saying at a conceptual level is what I needed to hear.

 

To be honest, I do not know whether I need seconds or milliseconds as the Allegro 3901 data sheet does not give specifics.  Unfortunately, I will have to experiment and figure this out. 

 

Regarding your previous post about milliseconds you suggested I should do it in hardware.  Is there any sample code that does this?

 

 

0 Kudos
Message 9 of 10
(4,376 Views)

invasion2121 wrote:

Regarding your previous post about milliseconds you suggested I should do it in hardware.  Is there any sample code that does this?


Search a bit, you should be able to find examples. A search for "gated pulse generation" returned this: https://decibel.ni.com/content/docs/DOC-11762 as the first result and I'm sure there's more further down the results.

0 Kudos
Message 10 of 10
(4,360 Views)