how to do longint if there is none?

sapoleon

Member
Join Date
Aug 2003
Location
salta, salta
Posts
315
I am currently using a UNITRONICS M91. It's a small plc with included HMI. (2 line display)

In this processor there are only a few functions for long int, and they are only in the ladder part.

The user want their operators to enter numbers up to 99Million. (I can only enter 16bit integers).

Does someone have any idea of how to make the trick? i am trying to make it with 2 normal integeres.... but i still didn't get how to...

thanks in advanced.

sapoleon
 
What are you trying to do? Is it multiplication, division or just an accumulator?
 
bobb,
like i said, the M91 have some maths functions for long int. so is no problem with that. (it takes 2 consecutives int and treats them like longint).

the part of the accumulator, i have already managed.

so, my only problem, or the part that i didn't managed to do up to now, is the operator entering the data from the hmi.
like i said before, the hmi in this oplc, is a 2 line display, with a numeric keyboard all included.

i dont have functions to get a long int. i have to make it with 2 int. and then, i have to do some math to get the upper part and lower part of the long int. and that, is what i didn't manage to do.

thanks
 
DAMN!

I can answer this... however, too much MGD at this time.

Sorry!

I hate to "bait" you like this but the answer is rather simple.

Hang on... You WILL get an answer... eventually.
 
Hint

Use the carry flag and add the two least significant words and if there is a carry then add one the sum of the two most significant words. This is kind of like first grade where you added the ones and then added the carry to the tens. I do this all the time when programming 16 microcontrollers.

If you don't have a carry flag then you have a problem unless you can do unsigned compares. If you add the low word of the second number to the low word of the first number and the resulting low word is less than the low word of the first number then a carry has occured.
Don't forget to add the carry to the sum of the high words.

Note,on some processor you will have to ignore the overflow errors.
 
M91 series controllers are integer based. They have some limited "long" functions.
Theoretically, it's possible to enter the number as ASCII string and then to retreive the number to a "long", but this way is quite complicated. pressing twice <Enter> seems to be the common sense solution. If, anyway, the customer needs an elegant solution, you can use Unitronics Vision 120, which has the same dimentions and I/O configuration, but is much more powerful.For you can be important, that it supports 32 bit registers, including floating point ones.
 
hi again.

thanks for all your inputing.

like i said my big problem were the inputs to the system.
emil, the answer you gave me is more or less what i wanted to know... the user is going to do with the two enter for each number, because they whant the cheapest solution.

for the display, i used two integers, up to 9999 each one, one up to the thousands, and the other from the tenths of thousands to the tenths of million. then, i show the two variables consecutively. making the lower part to show ceroes if needed.

sapoleon
 
Code:
if input then
  answer = ( answer shl 4 ) + ( answer shl 2 ) + ( input - 30H )

Input is an ascii character from 0 to 9.
Answer is a 32 bit number. you must be able to shift all 32 bits for this to work. In a pinch you can add answer to itself to shift left the bits.
You need to add clearing answer before you start and limit checking the ascii character to '0' to '9'
 

Similar Topics

I am learning Modbus and having a issue writing some code to write a value to a specified register where I also need to write the 1's complement...
Replies
7
Views
2,079
This is a total novice question... hopefully I can describe clearly. We have a Windows 7 machine with an Allen Bradley 1784-PKTX Card installed...
Replies
3
Views
1,642
Hi, Does anybody know how I can get my PG/ PC settings list back? It now just lists 'None' (please see the attached screenshot) I have tried to...
Replies
5
Views
6,177
I have an RSView32 project where very occasionally the primary communications driver changes itself from AB_ETH1 to 'none loaded', stopping the...
Replies
1
Views
2,077
I'm using a 6ES7-134-4FB01-0AB0 ET200S Analogue input module. The smoothing available is described as NONE, WEAK, MEDIUM and STRONG ! Does...
Replies
7
Views
2,093
Back
Top Bottom