LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset Quadrature Encoder Count DAQmx

Solved!
Go to solution

Hi there,

 

Is it possible to reset the angular count of a quadrature encoder programatically using DAQmx?  We use an encoder and photoeyes to measure the length of a passing object on a conveyor belt (that can go forwards and backwards).

 

Encoder works fine but I just cant work out how to reset it to zero when the object hits the first photo eye.  Our code used to work like this with a previous encoder card and it was great.  Now changing to a cDAQ I would like to keep the same code structure.

 

I have thought about using a variable to hold an initial count vlaue to subtract from a final count value but that involves a structural code change as well as the risk of the count overflowing as it would keep incrementing forever!

 

Any suggestions?

 

Regards

 

Ashley

 

0 Kudos
Message 1 of 12
(6,811 Views)

Can you make use of the Z input terminal?  Maybe set your first photocell to drive that...

 

Maybe try a channel property: Position. Z Index Value.  Set to 1, then set to 0.

 

Or try using a channel property: Count Edges.Count Reset. Reset Count.

 

Check for errors on that - you're not in the COUNT EDGES mode, so it might not work.

 

How about setting General Properties.More.Count = 0 ?

 

Haven't used any of those to do what you're asking - just guessing.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 12
(6,799 Views)

Hi, thanks for your ideas.

 

I cant find any class types or properties available to write to that would reset the count.  None of the properties you mentioned are available.

 

Maybe the Z input is the only option.  That would be a pain.  Already had to wire another input in parallel to get around another DAQmx quirk!

 

Regards

 

Ashley

 

0 Kudos
Message 3 of 12
(6,783 Views)
Solution
Accepted by topic author ashesman1

Actually the solution was quite simple.  Just stop and restart the DAQmx task and it is reset to zero!  Ugly but effective...

0 Kudos
Message 4 of 12
(6,780 Views)

Sorry to rain on the parade, but I'm not so sure your solution solves the right problem.  Are you stopping and starting your encoder task while your object is in motion on the conveyor belt?  Is it a software-based decision from polling a photoeye input signal?

 

If either (or both) are true, you're adding variability to your designated 0 position.  A hardware Z-index signal would be much more repeatable.  If you want repeatable measurements, I'd highly advise working with the hardware-based Z-index feature.

 

That said, it may not be a trivial implementation.  Z-indexing requires you to define a specific encoder A/B quadrature state when it will be active.  A high state on Z-index will reset the count *only* when the encoder is in the defined A/B quadrature state.  This works out well for encoders with an internal Z-index which will always align with a particular A/B quadrature state.  It will also have a fixed pulse width.

 

In your situation, you want an external photoeye signal to act as Z-index and it won't be aligned to your encoder.  The pulse width is likely long relative to your encoder's quadrature cycle, which will result in *multiple* resets each time the encoder cycles back to the designated state while the Z-index signal remains high.

 

Some clever-ish tricks would probably be needed and probably be possible.  But before getting into those, I'd think a different approach might be simpler to understand.  Don't you mainly just want to identify the encoder positions where the photoeye is first blocked and then again where it's unblocked?  Couldn't you create 2 encoder tasks for the same encoder, both using the photoeye input as an external sample clock, but one sampling on rising edge and the other on falling edge?  Then you'd capture data exactly at the photoeye transitions you care about and nowhere else. 

 

 

-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 5 of 12
(6,724 Views)

Thanks for your feedback.

Unfotunately there seems to be no documentation (that I can find) on the actual latency of the stop and start functions.  A bit of variablility is fine if it does not have significant impact on the results.  eg for this job losing 10 counts out of 1000 is not an issue, but losing 100 would be.

My concern about leaving the encoder running forever would be that it could eventually overflow the angle count (probably impossible due to the size of a double!).  Also, as I previously said, I do not want to restructure the existing program.

Hopefully during testing we will be able to determine if the variability is significant.

Regards

 

Ashley

 

0 Kudos
Message 6 of 12
(6,705 Views)

None of the properties you mentioned are available.

 

I don't understand why you say that. 

Here are two of them:

Prop.Reset.PNG

 

 

Prop.Count.PNG

 

As I said, the RESET COUNT may not work because it's in COUNT EDGES mode.

 

But I would try setting COUNT = 0, using the second pic above.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 12
(6,701 Views)

This is all I see:

 

Untitled.png

 

Although I did create another forum post with a similar problem not being able to see properties, so maybe my labview is broken.  I did a fresh install a few weeks ago but...

 

Regards

 

Ashley

 

0 Kudos
Message 8 of 12
(6,693 Views)

Based on your other postings, I gather that you're running under Linux.  It's been almost 10 years since I did any DAQ under Linux, but back then we had to use a reduced-feature-set driver known as "DAQmx base".

 

Don't know if Linux gets full feature set support these days or not.  If so, then you've got some install/config things to iron out.  Sorry, I'm no help there either, I've never done any sysadmin work on Linux.

 

Meanwhile,  I'm pretty sure the ability to set a count value is only available when the task is stopped. Also, the "reset count" feature is *only* available for edge counting tasks, not for encoder position measurement tasks.  I'd really like to see more of my 2010 wishlist (actually 2006 if you keep following links) make it to implementation. 

 

The Stop / re-Start latency will be partly system dependent.  There are advanced property nodes (maybe only available under DAQmx for Windows?) that can help reduce this latency, but possibly at the expense of not being able to change the count value.

 

As to concerns about overflowing the counter if you let it run forever: I honestly don't know what would happen.  I almost always read raw integer counts and do my own scaling.  In that realm, 32-bit count overflow definitely can happen, but I also know exactly how to handle it.  In the mode where you ask DAQmx to scale from counts to degrees, I don't know how DAQmx behaves.  It might handle the overflow for you seamlessly, but then again it might not.  I know it *does* handle moving from positive degrees to negative degrees automatically, something the RAW 32-bit count register doesn't do.

 

 

-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 9 of 12
(6,681 Views)

I almost always read raw integer counts and do my own scaling.  In that realm, 32-bit count overflow definitely can happen, but I also know exactly how to handle it.  In the mode where you ask DAQmx to scale from counts to degrees, I don't know how DAQmx behaves. 

 

I don't know why one would measure it in degrees.  If the object is to measure the length of an object, then my first thought is to take a reading (N1) of the I32 count value when the sensor is first blocked (object first appears), and another (N2) when it becomes unblocked.

the length of the object is (N2 - N1) * K, where K is (inches traveled per encoder revolution) / (Nlines per encoder revolution).

To handle overflows, you have to preprocess it only a bit:

detect overflow from 7FFFFFFF to 80000000 and underflows 80000000 to 7FFFFFFF.

I use another U32 as a high-order quad for that and bump it up or down by one if an over/under occurs.

Then combine the two into one I64 and use it.

If 

If N1 > 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 10 of 12
(6,665 Views)