LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create PWM using a NI 9402 with phase shift

Solved!
Go to solution

Hello,

what do i need to create a 100kHz Signal with DutyCyle 40/60 and 180° phase shift on two channels of the NI 9402?

Are the needed VIs part of the "normal" labview installation?

Is there an example available?

The NI9402 is in a cdaq9171 connected via USB to windows computer.

 

Thanks

0 Kudos
Message 1 of 43
(4,603 Views)

You can use the DAQmx examples for Digital Outputs, and configure the output to regenerate automatically. Then you only need to Write an appropriate pattern into your two channels and start them at the same time (if they're in the same task, this is impossible to not do).


GCentral
Message 2 of 43
(4,573 Views)

Thanks for your answer.

I checked the examples - can someone give me a hint which example to use?

I think it should be the DAQmx -> Counter Output -> "Counter Contionous output.vi"

 

I select Counter = cDAQ/_ctr0

OutputTerminal = cDAQ1/ai/SampleClock

RUN

The Active LED blinks once

What do i have to select at OutputTerminal.

How to add a second phase shifted channel? @cbutcher What did you mean wth creating patterns?

 

Thx

0 Kudos
Message 3 of 43
(4,522 Views)

Hi One,

 

use a simple DigitalOutput example!

 

Then create waveforms to resemble the needed duty cylce and phase shift:

  • For 100kHz pulses with 40/60% you need atleast a 1MHz signal with 10 samples per pulse.
  • First DO channel: Create 10 samples of TTTT FFF FFF to get your 40% duty high.
  • 2nd DO channel: rotate the sample array of the first channel by 5 samples to achieve your 180° phase shift.
  • Now output both DO channels…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 43
(4,512 Views)

Hi GerdW,

is the attached screenshot the correct vi?

If yes, then i understand what you desribed and i can just copy and rotate the array.

But: Is there a way to select both lines in the "Line(s)" control and insert both values in the array?

Like (binary):

10

10

10

10

00

00

01

01

01

01

 

Thanks

0 Kudos
Message 5 of 43
(4,506 Views)

Although it's true that you can more easily set up a PWM using the Counter Outputs, I'm not sure if you can easily configure two channels with a relative phase shift using that method. Perhaps someone else has a simpler solution that uses that idea.

 

However, here is what I meant with Digital Outputs. I set the sample rate to 100k * N_samples (=5, so 500k) since you wanted 40%, 60%, both of which are integers when multiplied by 5.

The 9402 can output at that speed without problems, and I don't think you need an FPGA to do it (so it should be fine with cDAQ).

digOut.png

 

Tested using a 6356 USB X-series at 10kHz output rate (so 50kHz) so that I could get AI to read back the output at 200k and not have to sample too quickly.

 

I used the Stall Data Flow.vim to set a duration (in ms) before stopping, but you might want it to run continuously (in which case, just don't stop it, or use some sort of While loop and Event Structure with a button to stop it, etc, depending on your application.

 

Two channels are selected at the "Physical Channels" input to Create Virtual Channel.

The attached file is saved for 2017 and includes an analog input task. You'd need to rename the device probably to test with something yourself, and to run it on the cDAQ may be more involved.


GCentral
Message 6 of 43
(4,504 Views)

Hi,

thans for the example.

This is working so far. I changed the bool array to size 10.

In your example you have the 100k * N_Samples. So after the change i have 1.000.000 as input for sample clock

This is the problem now. I have no signal any more at the two output channels.

if i change the 100k to 10k then everything is fine (only the frequency is wrong)

I measure with a real scope at the outputs and i see the 10kHz at the outputs.

So there is a problem with the 1.000.000 sampleClock in the vi.

I opened then the MAX Testpanel and output the 100.000 khZ (using counter tab). This can be measured at the scope. So it seems not to be a problem of the 9402 hardware, or?

Do you have an idea what to change to output the 1.000.000?

 

Thanks

0 Kudos
Message 7 of 43
(4,491 Views)

Well, I'm sure that you already considered this but I'll ask the simple quick questions first:

1. Do you get any errors in LabVIEW? 

2. Are you sampling fast enough on the oscilloscope to see?

3. Why 10 not 5? Did I misunderstand something? 


GCentral
0 Kudos
Message 8 of 43
(4,486 Views)

1. No error in Labview

2. The last working frequency is 23.400 which is visible in the 300MHz / 2 GSa/s -Scope with 200us/div.

3. I changed to 10 to create the 60/40 (the - are the 180°

TTTTF-FFFFF

FFFFF-TTTTF

i think this is different to you 5 sample array:

TTFFF

FFFTT

0 Kudos
Message 9 of 43
(4,480 Views)

1 and 2 sound good. I'm confused by 3, I think I would have thought that was 40/40, with 180deg on the second, so I suppose I misunderstood the naming.

 

I don't see any reason for the limit there, but I'll try running in DAQmx mode on our cRIO tomorrow if you don't get any earlier answer. It's still not the same as cDAQ but might give me a clue.


GCentral
Message 10 of 43
(4,470 Views)