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.

Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize counter outputs with second one inverter from the first

I am using a NI USB-6363 and need to synchronize counter outputs with second one inverter from the first. This seems like a trivial thing for the powerful DAQMX libraries. I found a help file topic and forum thread content that give some hint it is possible but still the functions to use elude me.  Sorry for the cross post but only discovered this more specific forum after posting in LabVIEW general forum

The DAQ-Mx help under Counter Sychronization say "share the CO Counter Timebase and Start Trigger signal". I can't find an example of how to do this? Also, I need to have the second counter output (PFI1) be the inverse of the first counter output (PFI0). 

I found this forum thread https://forums.ni.com/t5/Counter-Timer/synchronize-two-counter-outputs-on-6071E-card/m-p/2772312#M12...
that says "Trigger one counter with the internal output of the other", but I am not clear on how to do that

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 1 of 13
(3,636 Views)

Both your counters will derive their timing from the same internal timebase, so *that* part of sync will be covered for you without any effort on your part.

 

The other thing you need to do is configure both to be started by the same Start Trigger signal, and *then* also make sure the trigger isn't asserted until both counter tasks have been started.  I usually generate a trigger pulse by double-toggling a DIO line, then I have control over when it happens.  The thread you linked suggested this method first and it's the one you should stick with.  

 

Don't forget to confirm the behavior of how "high time" and "low time" get interpreted when you change the idle state away from default.  (See my reply in your other thread.)

 

 

-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 2 of 13
(3,618 Views)

Thanks. I am still digesting this but how would you invert one counter output from the other?

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 3 of 13
(3,612 Views)

1.  The first key part of making two counter outputs with opposite polarity is to configure them with opposite values for idle state.  This makes sure their outputs are inverses when they start.

2.  The second key is to configure them both to start on the same trigger signal AND make sure both tasks are started before the trigger edge can happen.  Usually this means that your code will generate the trigger at the appropriate time.  This gets their phasing lined up properly when they start.

3. The third thing is to give them the same timing parameters so all their future pulse edges keep lining up.  Here you *might* have to be careful and check some things out ahead of time as I described before in that other earlier thread.

 

Try something easy like defining a pulse train in terms of freq and duty cycle.  Give it a 75% duty cycle.  Try it with idle state both high and low while observing how it behaves on a scope (or you could wire to an analog input and capture with an example program if you use a slow pulse frequency).

 

Then do the same kind of thing again where you define high time and low time.  Try a 0.075 sec high time and 0.025 sec low time.  Observe with with idle state both high and low so you know what to expect.

 

 

-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 4 of 13
(3,608 Views)

I have a working vi but for the counter whose idle state I set to high at the start, I can't seem set it's idle state back to low. I found the Channel Property node but setting the idle state to Low didn't change it, as seen on my O-scope.

Sync two counters_DO+Invert.png

 

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 5 of 13
(3,605 Views)

   After stopping the task and changing the idle state, start it up again!  The idle state property gets committed to affect the hardware signal when you *start* the task again.

 

   Does that code work as-is?  I didn't know that you could put multiple counters into a single task like that on a regular multifunction board. 

 

 

-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 6 of 13
(3,598 Views)

Thanks Kevin, yes that is working code - except for resetting the idle state. I didn't realize you had to start the task to set a property. After I added a start task immediately followed by a stop task (then the clear task) it worked great.  Is there a way to alter the frequency or duty cycle once the task has started, or does one need to stop and re-start the task? It tried putting a channel property node inside the loop to change the frequency.  This works except that sometimes the pulses get out of sink. My range is 100 Hz to 500 Hz. In the posted snippett, the property node comes after the digital triggers in the loop, otherwise an error results saying that you can't change the channel property until at least one cycle has completed.Sync two counters_DO+Invert+Change Freq.png

 

 

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 7 of 13
(3,590 Views)

Change of request/focus - I reviewed my application requirements and I don't need to alter frequency or duty cycle "on the fly". What I would like to do is eliminate the usage of a digital output. The other thread I mentioned states "...to avoid any additional wiring, you could split the counters into two separate tasks.  Trigger one counter with the internal output of the other ". The side effect of the 100ns initial delay is acceptable in my application.  I have the following that seems to work.  Any 'gotchas' or anything you would do different?Sync two counters_internal trigger.png

 

 

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 8 of 13
(3,580 Views)

It looks like you're not doing any error handling in the while loop, so I would recommend adding the Is Task Done VI. That way you'll be polling your hardware on each loop iteration to make sure it's still working.

 

IsTaskDone.png 

 

 

Bill B.
National Instruments
0 Kudos
Message 9 of 13
(3,572 Views)

Thanks. Yes, of course. This was a quick test to learn how to synchronize counter outputs. My current version does connect the error wire to the loop's Stop. By the way, in 2017 (and some earlier versions)  you can connect the error line directly to a Boolean input.


It turns out that I DO need to change the frequency and possibly the duty cycle "on the fly".  Is there a way to do this without stopping and restarting the task and have the counters remain in sync? As mentioned in a previous post, I change the frequency inside the loop but then the pulses get out of sync.

^TeraTech.

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? (Check out this lengthy post of mostly complaints)
0 Kudos
Message 10 of 13
(3,563 Views)