viscoelastic Posted May 5, 2017 Report Share Posted May 5, 2017 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. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 5, 2017 MVP 2023 Report Share Posted May 5, 2017 Make sure you're not overflowing your Memory Integer. Just to be sure, use MLs instead and see if the situation improves. Link to comment Share on other sites More sharing options...
viscoelastic Posted May 5, 2017 Author Report Share Posted May 5, 2017 Nope, no workie workie using ML's. Link to comment Share on other sites More sharing options...
bbird Posted May 5, 2017 Report Share Posted May 5, 2017 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. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted May 5, 2017 MVP 2023 Report Share Posted May 5, 2017 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. Link to comment Share on other sites More sharing options...
bbird Posted May 5, 2017 Report Share Posted May 5, 2017 (edited) 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) Edited May 5, 2017 by bbird wont' let me delete incorrect logic image 1 Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 6, 2017 MVP 2023 Report Share Posted May 6, 2017 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 Link to comment Share on other sites More sharing options...
viscoelastic Posted May 8, 2017 Author Report Share Posted May 8, 2017 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 I am trying to display 1000's of an inch. like 123.375" Link to comment Share on other sites More sharing options...
John_R Posted May 8, 2017 Report Share Posted May 8, 2017 Visco leave your number as an integer (whole number, no decimal) in the logic, apply the decimal point in the display settings...... JohnR Link to comment Share on other sites More sharing options...
MVP 2023 Ausman Posted May 8, 2017 MVP 2023 Report Share Posted May 8, 2017 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 Link to comment Share on other sites More sharing options...
viscoelastic Posted May 9, 2017 Author Report Share Posted May 9, 2017 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. Link to comment Share on other sites More sharing options...
viscoelastic Posted May 9, 2017 Author Report Share Posted May 9, 2017 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) BBird, That worked. Thank you!! Much appreciated Link to comment Share on other sites More sharing options...
bbird Posted May 9, 2017 Report Share Posted May 9, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now