You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
Thread Tools Display Modes
Unread January 28th, 2019, 10:46 AM   #1
phdz12401
Member
United States

phdz12401 is offline
 
Join Date: Jan 2019
Location: New York
Posts: 4
Ladder Logic Calculator

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
  Reply With Quote
Unread January 28th, 2019, 11:11 AM   #2
harryting
Lifetime Supporting Member
United States

harryting is offline
 
harryting's Avatar
 
Join Date: May 2002
Location: Puget Sound
Posts: 2,083
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.

Quote:
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.
  Reply With Quote
Unread January 28th, 2019, 11:30 AM   #3
phdz12401
Member
United States

phdz12401 is offline
 
Join Date: Jan 2019
Location: New York
Posts: 4
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)
  Reply With Quote
Unread January 28th, 2019, 11:36 AM   #4
harryting
Lifetime Supporting Member
United States

harryting is offline
 
harryting's Avatar
 
Join Date: May 2002
Location: Puget Sound
Posts: 2,083
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 by harryting; January 28th, 2019 at 11:47 AM.
  Reply With Quote
Unread January 28th, 2019, 01:03 PM   #5
phdz12401
Member
United States

phdz12401 is offline
 
Join Date: Jan 2019
Location: New York
Posts: 4
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
  Reply With Quote
Unread January 28th, 2019, 04:53 PM   #6
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 601
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?
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Unread January 28th, 2019, 08:54 PM   #7
phdz12401
Member
United States

phdz12401 is offline
 
Join Date: Jan 2019
Location: New York
Posts: 4
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 by phdz12401; January 28th, 2019 at 08:58 PM.
  Reply With Quote
Unread January 29th, 2019, 09:51 AM   #8
LoganB
Lifetime Supporting Member
United States

LoganB is offline
 
Join Date: Apr 2017
Location: Michigan
Posts: 601
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
__________________
Present: Controls Engineer
Future: Skynet Engineer
  Reply With Quote
Unread November 9th, 2019, 03:51 AM   #9
bosnak54
Member
Turkey

bosnak54 is offline
 
Join Date: Nov 2019
Location: Istanbul
Posts: 1
Quote:
Originally Posted by phdz12401 View Post
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?
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Assigning INT values with ladder logic David.Reed.Schmidt LIVE PLC Questions And Answers 10 May 25th, 2016 09:35 AM
Sequencer logic. Ladder or SFC? AJZ LIVE PLC Questions And Answers 6 February 21st, 2011 12:56 PM
CarWash Ladder Logic sicminds LIVE PLC Questions And Answers 30 November 14th, 2007 02:54 AM
Slow Release Relay in Telepace Ladder Logic BillRobinson LIVE PLC Questions And Answers 3 October 25th, 2006 03:28 PM
Need help with ladder logic problem RickGilbert LIVE PLC Questions And Answers 10 June 5th, 2005 02:38 PM


All times are GMT -5. The time now is 04:26 PM.


.