Can you help me with this problem? (Fibonacci sequence in tia portal)

citythunder

Member
Join Date
Apr 2024
Location
Turkey
Posts
5
Hello, I need to write the following program in Ladder language, but I could not integrate the Fibonacci sequence into the ladder. Can you help me, thank you.

Enter your ID Number (11 Digits) into the number entry. Add the first two digits (from the left) of the number you entered with 150 and throw it into a variable. Print the Fibonacci Number in the step corresponding to the number you found on the screen in Decimal and Hexadecimal formats.

Example:
If ID Number: 42xxxxxxxxx, the term that must be found is the 192nd (150+42) term. Note: Use the basic Fibonacci sequence.


I did the first part as above. I would appreciate it if you could guide me for the rest, thank you. I am using Tia Portal v17.

1714370493298.png
 
Use the program control operations to perform the loop contruct in laddder.
 

Attachments

  • pcc.jpg
    pcc.jpg
    44.1 KB · Views: 13
The loop may not help much. If your ID starts with 99, then the 249th (150 + 99) Fibonacci number is 4880197746793002076754294951020699004973287771475874. I am pretty sure that neither that Fibonacci number nor the 99 before it can be represented in that PLC

Perhaps a better solution would be to store the 150th through 249th Fibonacci numbers in two arrays of strings, one decimal, one hexadecimal, and use the first two digits as the index into the arrays to get the answer.

Note that, even if you could implement the sequence algorithm, you do not need to add 150, because you could start with the 149th and 150th Fibonacci numbers and go from there.

The only time to add the 150 offset would be if you were using the one-step formula to calculate the number directly.
 
The loop may not help much. If your ID starts with 99, then the 249th (150 + 99) Fibonacci number is 4880197746793002076754294951020699004973287771475874. I am pretty sure that neither that Fibonacci number nor the 99 before it can be represented in that PLC

Perhaps a better solution would be to store the 150th through 249th Fibonacci numbers in two arrays of strings, one decimal, one hexadecimal, and use the first two digits as the index into the arrays to get the answer.

Note that, even if you could implement the sequence algorithm, you do not need to add 150, because you could start with the 149th and 150th Fibonacci numbers and go from there.

The only time to add the 150 offset would be if you were using the one-step formula to calculate the number directly.
Oh, yes it sounds like a better solution. I should try to do that but i am relatively new so it's kinda hard for me sorry.
And it is not a homework, I am working as an intern in industrial automation.
Can you guide me more if you have time? Thank you.
 
Last edited:
If your ID starts with 99, then the 249th (150 + 99) Fibonacci number is 4880197746793002076754294951020699004973287771475874. I am pretty sure that neither that Fibonacci number nor the 99 before it can be represented in that PLC
The largest native data type in S7-1500 is ULINT (unsigned long integer). Max value is 18446744073709551615. That falls rather short of 4880197746793002076754294951020699004973287771475874.

And it is not a homework, I am working as an intern in industrial automation.
I wonder which industrial application can require such large numbers ?

The task does look like some kind of test. Who would specify a real automation task like that ?
And the 'use the basic fibonacci sequence' sounds as if you are not allowed to use a look-up table.
I would be perplexed as how to solve the task, the S7-1500 cannot compute numbers larger than ULINT's.
 
The largest native data type in S7-1500 is ULINT (unsigned long integer). Max value is 18446744073709551615. That falls rather short of 4880197746793002076754294951020699004973287771475874.


I wonder which industrial application can require such large numbers ?

The task does look like some kind of test. Who would specify a real automation task like that ?
And the 'use the basic fibonacci sequence' sounds as if you are not allowed to use a look-up table.
I would be perplexed as how to solve the task, the S7-1500 cannot compute numbers larger than ULINT's.
They gave me warm up questions before starting real ones. So i am trying to learn while doing these questions. Yes i know about not handling large numbers like this but someone said you can split the number data into parts, Thanks.
 
Yes, thinking about it since the fibonacci sequence is relatively simple, just adding the previous 2 numbers, it can be done by splitting the number.
I think you have to split each number (the 2 previous numbers) into 2 64-bit ULINTs. Add the two higher ULINTs, Add the two lower ULINTs. If the addition of the two lower ULINTs rolls over, add 1 to the resultant upper ULINT, and put the remainder in the resultant lower ULINT.
(just a quick thinking about, not tested and not sure that I have got it right).

Not much industrial programming related. More like what a math teacher would ask.
 
Nice way of thinking, but if you are able to do it can you show me how its done with ladder logic ? Please
Yes, thinking about it since the fibonacci sequence is relatively simple, just adding the previous 2 numbers, it can be done by splitting the number.
I think you have to split each number (the 2 previous numbers) into 2 32-bit ULINTs. Add the two higher ULINTs, Add the two lower ULINTs. If the addition of the two lower ULINTs rolls over, add 1 to the resultant upper ULINT, and put the remainder in the resultant lower ULINT.
(just a quick thinking about, not tested and not sure that I have got it right).

Not much industrial programming related. More like what a math teacher would ask.
 
Nice way of thinking, but if you are able to do it can you show me how its done with ladder logic ? Please
No this is the extent of how much time I can spend on this.
And if this is a test, you should show your own abilities.
By the way, just checked and I have found that even 128 bits are not enough to represent 4880197746793002076754294951020699004973287771475874.
 
Loops in ladder logic can be accomplished much the same as loops in other programming.
Iterate a counter every-time the ladder is run and have a check to see if the counter is higher than needed.
 
Jesper's idea of the two UDINTs is the right one, fundamentally, but we need to think more generally.

The 249 the Fibonacci number has 55 decimal digits, so it will take 180+ bits (55 / log10(2) = 55 / 0.3010 binary digits), so three 64-bit UDINTs, with manual carry, should be adequate, at least for the hexadecimal output requirement because it is easy to convert them to a hexadecimal string. Those 3 UDINTs can represent the value of those Fibonacci numbers, but converting them to the corresponding decimal string is a mess that would require essentially the same algorithm it would take to calculate the 56 decimal digits individually.

I might have time later to say more later, but right now I am going to read Hairy Hettie the Highland Cow to my granddaughter.
 
Oh, yes it sounds like a better solution. I should try to do that but i am relatively new so it's kinda hard for me sorry.
And it is not a homework, I am working as an intern in industrial automation.
Part of engineering is recognizing when a problem is outside the bounds of reality as you understand it (read: unsolvable). It COULD be that the correct answer is "this is a trick question, that's bigger than this PLC can handle". It could also be that they want you to do the "splitting it into several numbers and handling the math yourself" solution. It could also be that you've (and we) have missed the point of the problem, and they want to refocus you on the part they think is important.

I'd say it's perfectly fair to go back to your manager/supervising enginer/team lead/mentor/whoever and say "hey look, i'm trying to Do The Thing, I'm stuck here, what should we do next". That said, it's best if you have a suggestion on what the next to do should be. In this case, that might mean you just signed yourself up for doing some complicated "roll your own high bit math" programming, because your mentor was GOING to let you off at "can't be done because X" but now wants to see if you can do the complicated thing you suggested. Not as a punishment, but as an opportunity to learn.

In a real system, this could mean "hey boss, can't solve the problem for the budget you've given me" or "hey boss, we need a panel 1 foot wider to fit these components in with proper spacing for cooling" or "hey boss, the operator is spending too much time walking back and forth between point A and point B as part of the machine cycle, there's no way we can build parts fast enough, we need to change the machine layout". Sometimes your boss comes back with "oh don't worry about the proper spacing, we have a powerful AC unit in that panel, it'll be fine", or "make it work with the budget you have, and let me know what features have to get cut to make it fit".
 

Similar Topics

This is the problem, I need to solve it using a ladder diagram: Write a table of inputs and outputs and propose a control solution for a screw...
Replies
22
Views
4,072
Hey all, I am having an issue concerning the Modicon System Responsible for the operation of our Generator System. (Particularly Dresser-Rand...
Replies
5
Views
2,612
Replies
49
Views
10,967
please help i didn't solve this problem with rslogix. I counted but i am not using timer. How i will fix this situation? Please anyone solve this...
Replies
18
Views
5,012
Good day to every body I am trying to replace old touché screen [omron nt20s-st121-v1] To new one [[omron nt20s-st121b-v3] they look identical and...
Replies
2
Views
2,008
Back
Top Bottom