Jump to content

Recommended Posts

I am trying to move the decimal point of a counter value by dividing by 1000.  I think this is a binary issue because when the result reaches 32 it goes to -32 and decrements. This is  back and forth from negative to positive.  How do I work around this? I added a picture of my block to see.

divide.jpg

Share this post


Link to post
Share on other sites

Make sure you're not overflowing your Memory Integer. Just to be sure, use MLs instead and see if the situation improves.

Share this post


Link to post
Share on other sites

An MI is a signed value from 32767 to -32768.  When you divide by 1000, I would expect to see what you are seeing due to word wrap to a negative value when the value gets larger than 32767 (accessing the sign bit/MSB).  As said by Flex727, you will probably need to utilize one of the double word formats ML, DW etc. to allow values large enough to not roll over the word.  You could also cascade counters by making one counter count to 1000 and counting the number  times it gets there with a second counter.

Share this post


Link to post
Share on other sites

bbird suggests a good workaround. I fully understand the issues with binary-decimal conversion, but I've personally never seen the problem you experiencing. I would request that you post the rest of your code and let's take a look.

Share this post


Link to post
Share on other sites

You can also try converting the value from the counter to a Float before dividing by 1000 and placing the result in a float as below.  MI 3 can be substituted for your counter value.  MF1 will be = (MI3/1000)

float.png.227bab3729fa1b47b530971d1bdc219f.png

 

 

logic.png

Edited by bbird
wont' let me delete incorrect logic image
  • Upvote 1

Share this post


Link to post
Share on other sites

Hi Visco and all,

I'm not completely sure what you're trying to do here, Visco, as your input being an MI is a bit self-regulating for possible amounts.  Doesn't my screenshot below do it easily?  But if you put 1000 into MI0, your result here will be 1, without any dec point.  So this raises my question of what exactly are you trying to do with the result?  Is it simply maths, displaying etc?

cheers,

Aus

Ausfloat.jpg

Share this post


Link to post
Share on other sites
On 5/6/2017 at 5:01 AM, Ausman said:

Hi Visco and all,

I'm not completely sure what you're trying to do here, Visco, as your input being an MI is a bit self-regulating for possible amounts.  Doesn't my screenshot below do it easily?  But if you put 1000 into MI0, your result here will be 1, without any dec point.  So this raises my question of what exactly are you trying to do with the result?  Is it simply maths, displaying etc?

cheers,

Aus

Ausfloat.jpg

I am trying to display 1000's of an inch. like 123.375"

Share this post


Link to post
Share on other sites

Visco

 

leave your number as an integer (whole number, no decimal) in the logic,

apply the decimal point in the display settings......

 

JohnR

Share this post


Link to post
Share on other sites

Exactly, JohnR.

Visco, remember my comment about sometimes things can be simple, sometimes complex.  A major part of programming is pinning down exactly what you need to achieve, and then finding the easiest way to do it.  I often put all my known methods into the washing machine called the brain, and ages later I still end up with something not even considered in the first place!  It is a constant learning curve.

cheers,

Aus

Share this post


Link to post
Share on other sites
On 5/8/2017 at 1:24 PM, JohnR said:

Visco

 

leave your number as an integer (whole number, no decimal) in the logic,

apply the decimal point in the display settings......

 

JohnR

I added the decimal point in the display and now it just rolls over at 37. 

Share this post


Link to post
Share on other sites
On 5/5/2017 at 4:43 PM, bbird said:

You can also try converting the value from the counter to a Float before dividing by 1000 and placing the result in a float as below.  MI 3 can be substituted for your counter value.  MF1 will be = (MI3/1000)

float.png.227bab3729fa1b47b530971d1bdc219f.png

 

 

logic.png

BBird, That worked. Thank you!! Much appreciated

Share this post


Link to post
Share on other sites

Thanks,

I think Ausman's version will do the same thing more efficiently with one less block, as the conversion is done automatically in the floating point divide block.  Lots of ways to accomplish the same result.  Glad it's working.

Share this post


Link to post
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

×