Jump to content

extracting one number from a integer


d.wilcox

Recommended Posts

I am trying to count rotations of a servo. It doesn't have to be exact, +/- 1 rotation is good enough. The only way of measuring the position of the servo is the encoder count, which i can read via serial coms from the drive. It's an int32 value. Unfortunately it does not output the index of the encoder, otherwise i'd just use that. This number will continue to grow at the rate of 4000 pulses per rev until it reaches the limit of the int32 and then i believe it resets to zero and starts over. I was thinking the best way to count the revs is to only pay attention to the 4th digit. Is there any way to do that? I was thinking of adding the int32 to an array and extract it that way, but i'm not 100% sure on that.

Link to comment
Share on other sites

  • MVP 2023

In the event you are unable to obtain the encoder index, it's simple enough to count revs. Just do the following:

-Compare the servo count with a temporary register.

-If different, increment another register for pulse count.

-Store the servo count to the temporary register.

-When the pulse count equals 4000, you have one revolution and can reset the pulse count.

Repeat.

Link to comment
Share on other sites

1 hour ago, Flex727 said:

In the event you are unable to obtain the encoder index, it's simple enough to count revs. Just do the following:

-Compare the servo count with a temporary register.

-If different, increment another register for pulse count.

-Store the servo count to the temporary register.

-When the pulse count equals 4000, you have one revolution and can reset the pulse count.

Repeat.

i'm not sure if i'm following correctly.  it is a continuous count. it'll go to 2,147,483,647 and then start back over at zero. i dont think that would work, but maybe i'm misunderstanding. 

Link to comment
Share on other sites

  • MVP 2023
15 minutes ago, d.wilcox said:

i'm not sure if i'm following correctly.  it is a continuous count. it'll go to 2,147,483,647 and then start back over at zero. i dont think that would work, but maybe i'm misunderstanding. 

Maybe this will be a bit more clear. Sorry it's written in VisiLogic rather than UniLogic, but I think you'll get the gist. And a signed 32-bit integer will go to -2,147,483,647, not zero, but that's irrelevant to this issue.

image.png.fe2f720dbdbba9dc2829dcfffa011ae9.png

  • Like 1
Link to comment
Share on other sites

  • MVP 2023

The method proposed here by Flex will probably not work.

With a rapid change in speed, the network feedback will be inconsistent and uneven.

Therefore, the 4000 counter (Temp)  will not correctly correspond to the revolutions of the shaft.

p.s. Please post servo model #  and  if possible max shaft speed

Link to comment
Share on other sites

  • MVP 2023

Then the third rung may fail.

As Joe said using "="  in counter track gives a 1 in 4000 chance that the rung won't work and very often...

So even after modification this method will fail. Since it is impossible to predict that exactly 4000 will be accumulated as a result. And if there is a difference (you try to use >= in rung 3), the total revolution counter will have an error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.