Ladder Logic Calculator

phdz12401

Member
Join Date
Jan 2019
Location
New York
Posts
4
I am currently working on a project to built a fully functional calculator through Ladder Logic Programming and could perform all forms of mathematical solutions(in a way that if switches 1, 2, 3 are toggled the number 123 (One hundred and twenty three) will be executed, and so on) on a Siemens S7-1200 and TIA v14, no specifics have been given only that it must be done in Ladder Logic (No SCL) and no HMI.

Based on readings and online tutorials, I've figured that my best bet (within my level of knowledge in this subject) is that I should use and Array [0..9] and the usage of the MOVE box function to move single digits into a Data Block that holds an array [0..9] blocks and each array block is attached to the output of individual MOVE box functions through Switches assign via %I0.x port addresses and store in each Array element such as the MOVE box function executes and moves data (e.g: 1 -> array.[0]).

The next step that I am deriving to be is, to either use the MOVE_BLK box function or another MOVE box function to grab the integers in each array block and combine them into one as a block of data and convert using either CONV or S_STRING from INT to REAL to a temp_value variable within a second DATA BLOCK that has an array [0..1] . I'm thinking I am only in need of two array blocks. Array block. [0] to store the initial value, and after the input of a Mathematical operation move or to array block [1]as the inputs are broken down by the math operators.

So far I have only being able to generate single digit calculations, but have failed on converting the array into a whole number. I've tried using an index variable in the data block to help me point to the array block, but with no success.

I've also tried a Ladder Logic in the form of Case (Like in Pascal) that utilizes number ranges to define the first number, and once the second number is added multiply the first number by 10 and add the second number to it, but have problems with storing the numbers in memory for later execution of the mathematical problem.

I've also tried to use a mathematical approach (Num1*10) +Num2 and store the new value into a Temp_number Memory Block. My challenge to this approach is how to initiate the values (single digit input) and passing down the values as a single value could have a range of 1 to X amount of digits.

My main three questions are:
1- Is it possible to extract values from array blocks and combine, like if you do on a array to string conversation in standard programming.
2- Could a different approach be taken to solve the input challenge of the program.
3- If the mathematical approach a posibilty for success, how could you determine the size of the number pass through the mathematical logic of (Num1*10) +Num2 and adding a decimal point as the user enters the number to be calculated


I am hoping to see if guidance could be provided on how to execute the above. I've being doing some heavy reading for two weeks on Array to String conversion, Multi digit input conversion, and so on, with little result. Must of the examples have predefined values (which technically is in my case) but haven't encounter solutions on combining the single inputs into a whole number.

The scope and goal of project is that if the user toggles switches each individual number will be combined and form a new whole number (E.g.: 123 * 3 / 456 * 2 + 35 - 6 + 1.252, etc...) Just like any current calculator

I truly appreciate any and all guidance support to complete this project.

Yours Truly
 
I assume this is a class project to learn how ladder works.

You alluded to a lot of subjects that are not relevant for the task at hand. It's just math.

I've also tried to use a mathematical approach (Num1*10) +Num2 and store the new value into a Temp_number Memory Block. My challenge to this approach is how to initiate the values (single digit input) and passing down the values as a single value could have a range of 1 to X amount of digits.

Why didn't this work? I'm guessing you didn't have a proper way to track 10x exponent. You need a variable to track the exponent of the digits entered.
 
Current challenge is to figure out how to initialize the conversion. I've tried using the comparator <> 0 to push the first input into memory and MUL box function by 10 and pass the MUL result to and ADD box function to combine with second input digit. The challenge I've encountered is if the user uses a single digit within the mathematical calculation (E.g.: 565+3) not sure how to direct the number to bypass the first logic. and what will happen if the user inputs a number that is very long (e.g.: 123456789123456789), and then I hve the challenge of the decimal value (E.g.: 875.356)
 
I went down the wrong rabbit hole but on 2nd thought you don't even need to track your 10x unless decimal point is involved. Wheneven user press the next numeric button, you just multiply the existing buffer value by 10, that is, until decimal point is pressed. After decimal point is pressed, then you need to track the Exponent position.


when the decimal point is pressed, you set the Exponent to -1 and add any additional # press by the EXP.

eg. 12.34

when [.] is pressed, set EXP to -1. So the operation is <12 + 3*(10^-1)>


I think I got it right now.. lo
 
Last edited:
Thank you so much for your support on the resolution of my challenge. I've done that and have been able to combine the number as you previously stated. The next challenge is on the length of the number No sure if I need to continue building new MUL and ADD box functions or if there is a way to generate a WHILE Loop tha as long as an operand does not executes continue function of multiplying and adding.
I was thinking of creating the MUL and ADD box functions for 15 digit max but not sure if it truly requires the repetition.

Thank you
 
These types of projects are fun because there are a lot of ways you could do them. I would have the first number input move the correct value into Array[0]. If a second number is then hit, move Array[0] into Array[1], then overwrite Array[0] with the new value. Do this for a total possible 9 numeric entries, so that if someone typed 123456789, the 1 being typed first, it would end up in Array[8].

Once your math command is pressed (+,-,*,/) you can run your array through a hardcoded equation. Array[0]+(Array[1]*10)+(Array[2]*100).... until all 9 entries are represented with their correct multiplier. Any array entry that doesn't have a number value won't figure into the end total. Then you can run that final number through whichever math instruction you need to based on which math function was "pressed" on the calculator.

Do you have to represent the final answer in binary? Or can you just use the answer you get from the math instruction?
 
That is an amazing suggestion. The answer needs to be of type REAL as there is always the possibility of a decimal value. Thank you so much and will attempt to implement.
Once again, thank you so much for your suggestion.
 
Last edited:
It's a pleasure to offer help to students that are asking pointed questions and are obviously doing the work. Too often we get people in here the day before their final project is due hoping that someone will do the whole thing for them :ROFLMAO:
 
Thank you so much for your support on the resolution of my challenge. I've done that and have been able to combine the number as you previously stated. The next challenge is on the length of the number No sure if I need to continue building new MUL and ADD box functions or if there is a way to generate a WHILE Loop tha as long as an operand does not executes continue function of multiplying and adding.
I was thinking of creating the MUL and ADD box functions for 15 digit max but not sure if it truly requires the repetition.

Thank you

I'm working on the same topic. Could you please send a link to the program you made?
 

Similar Topics

Good morning crew! Ok my logic works but I am missing something. When the start button is pushed it should like the red light for 4sec then shut...
Replies
13
Views
344
Working on project will update after it is completed.
Replies
2
Views
335
Can someone help me piece this problem together. I have a lot of it down I think but cannot seem to get it right. Probably an easy one for most on...
Replies
1
Views
285
Hi everyone, I'm working on a project that involves using a Keyence LR-X100 sensor in Studio 5000 V35 ladder logic to determine the object's...
Replies
4
Views
636
There have been many threads started about integrating the signal from an analog flow sensor to get a total volume along with comments (some by...
Replies
4
Views
341
Back
Top Bottom