From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Generating two inverse PWM signals with one counter

Hello everyone,

 

I apologize in advance if I'm asking a silly question or trying to do something impossible, my counter/timer knowledge is spotty.

 

I'm trying to output two varying duty cycle/constant frequency PWM signals from my USB-6216 BNC card. They'll be of identical frequency and duty cycle but I'd like to invert one (in reality, use the complimentary duty cycle and start in the opposite state). I have a few other hardware tasks going on at the same time so I'd like to do this with a single counter. It's a low frequency signal (~66 Hz) and it will be PID controlled so perfect synchronization and accuracy isn't my focus right now. I can't use freqout at that low frequency, the lowest is my 10kHz timebase divided by 16.

 

Given those requirements, I've found some references to running a task like this on M-series hardware in this thread but the example code is incomplete (missing SubVIs):

http://forums.ni.com/t5/LabVIEW/Generate-more-PWMs-than-available-counters-using-DIO-instead-of/m-p/...

 

I think I found a more complete version of that code here but it's built for a PXI card:

https://forums.ni.com/t5/Multifunction-DAQ/PXI-6120-Digital-output-frequency/td-p/2131172

 

My basic understanding of this is that I would be creating a single channel across 4 lines of port 0 and generating an array of signals, all driven with a single counter. But trying to run the code in the second link above throws an error at the sample clock, which is set at Ctr0InternalOutput. My two questions are:

 

Is this possible or have I misunderstood the capabilities of my device?

If it is possible, do I need to manually route the Ctr0 output to a PFI to use as a sample clock at the beginning of my code?

Xander Cesari
Automotive/Internal Combustion Test Engineer
CLAD certified, mainly focused on data acquisition
Been LabVIEWing for a few years, still a lot to learn
0 Kudos
Message 1 of 8
(5,524 Views)

I solved my problem! Can't figure out how to delete this post though.

 

In my experimentation I just used DaqMX Connect Terminals to route two PFIs together with 'invert polarity' checked. Then I outputted my PWM channel to one of them and it did exactly what I was looking for.

Xander Cesari
Automotive/Internal Combustion Test Engineer
CLAD certified, mainly focused on data acquisition
Been LabVIEWing for a few years, still a lot to learn
Message 2 of 8
(5,518 Views)

 

Nice find!  I typically only use task-based signal routing and wouldn't have thought of your solution.  I don't think the task-based routing allows for the polarity inversion you needed.  I take it you used a simple counter output as your PWM signal then?  

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 8
(5,500 Views)

I was unaware that you could invert signals through routing until I was just poking around. I'm just using a CO Pulse Freq task for the output and I added the connect and disconnect terminal VIs at the beginning and end.

 

Unfortunately I'm having an issue with running a CI Freq task in parallel with this. It would seem that routing the 80MHz timebase to the counter I'm using for my read frequency task conflicts with the PFI to PFI routing I'm trying to do for my generate PWM signal tasks. I attached my mash up of the two example codes if anyone wants to take a look but I fear that I'm back to square one.

Edit: I should add that I don't think it will work because the routing diagram in NI MAX lists all the PFI to PFI routes as 'indirect through subsystem' and the subsystem used is Counter 1. I should've got a card with more counters!

Xander Cesari
Automotive/Internal Combustion Test Engineer
CLAD certified, mainly focused on data acquisition
Been LabVIEWing for a few years, still a lot to learn
0 Kudos
Message 4 of 8
(5,497 Views)

Connecting PFIs directly to each other does use one of the counters as per the MAX routing table.

 

Instead, you might try routing the counter's internal output to the second PFI line.  I don't have the hardware handy to validate on though and connect terminals sometimes doesn't behave exactly as one might first expect...

 

 

Best Regards,

John Passiak
Message 5 of 8
(5,481 Views)

John, that's a great idea. Thanks for the response!

Xander Cesari
Automotive/Internal Combustion Test Engineer
CLAD certified, mainly focused on data acquisition
Been LabVIEWing for a few years, still a lot to learn
0 Kudos
Message 6 of 8
(5,455 Views)

Just an update for anyone else checking out this thread:

 

Using the Ctr0InternalOutput routing that John suggested works but the inversion is no longer available. This makes sense to me; with direct routing I suppose there's no opportunity to invert the signal. With the indirect routing I guess the unit is just setting Counter 1 to follow Counter 0 and perhaps by watching for a different edge it can easily invert it.

Xander Cesari
Automotive/Internal Combustion Test Engineer
CLAD certified, mainly focused on data acquisition
Been LabVIEWing for a few years, still a lot to learn
0 Kudos
Message 7 of 8
(5,450 Views)

You could easily create an inverted signal using external circuitry- a transistor or a TTL 7404 Hex Inverter IC.

 

-AK2DM

~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
Message 8 of 8
(5,445 Views)