7

I am getting stack overflow problems and I can clearly see that it happens with the introductions of some new arrays. I cannot find the option to increase the stack size on the soft PLC (Twincat) running on my machine.

Any help is appreciated

gone
  • 81
  • 1
  • 2
  • Can you post the full text of exception?, take care you can not create more than 1024 notification handles! – Michele Nov 04 '15 at 09:24
  • Any ideas on this ... I have the same issue in Twincat 2 with the "Error 3252 : Size of stack exeeds 6144 bytes (_CALLTASKNEWTASK)" – ramp Jun 14 '16 at 07:33

4 Answers4

6

I'm currently using 4024.7 and there you can change the stack size under SYSTEM > Real-time. And then under the Settings tab you'll find Maximal Stack Size [kB].

enter image description here

Roald
  • 2,459
  • 16
  • 43
2

Here is the official answer that I got from Beckhoff:

You can’t change TC3 stack size, it use fix size of 60KB. Only function uses the stack memory, FBs & programs not.

The stack size is very limiting. You can't do large memory operations inside function. Also you can stack limited number of functions in one operation.

Still, Beckhoff may increase the stack size in future versions of TwinCAT 3.

Ilya Dan
  • 301
  • 1
  • 8
  • Also applies to VAR declared inside of methods of function blocks as I just found out ;). Does not apply to VAR_INST of methods. – Uwe Hafner Nov 15 '19 at 10:42
  • Yes, stack is only used for temporary variables. VAR_INST is class member same as VAR in Function Block (FB). Methods in FB can have VAR_INST (or VAR_STAT in program). Functions can't have VAR_INST and there is no way to make large memory manipulations in function without using pointers (VAR_IN_OUT). – Ilya Dan Nov 16 '19 at 11:17
2

I realise this is a little late, but instead of trying to increase the stack size, you can take steps to reduce the size of the stack you need. When calling a method or function, try passing in a reference to an existing array and using that for the calculation. Even if it is for some intermediate processing that isn't returned directly as your response, this will dramatically improve your stack management. There are two way to manage this in TwinCAT.

The easy way is to create a VAR_IN_OUT variable to pass in. This works well, but you should not be using this if your block calls the variables from other methods. The other way is to pass in a REFERENCE TO your ARRAY and using that.

This approach will work for both returned and intermediate processing type issues.

Mark Lazarides
  • 366
  • 2
  • 13
1

regedit: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Beckhoff\TwinCAT3\System add a costum DWORD with the key: DefaultStackSize value: Hex(80) or Decimal(128)

Regedit DWORD

this will set your stacksize to 128 instead of 64 :) change it to whatever you want, not sure what happens when it's too high. but this works, we use it on all our PLC's as we always have issues with the amount of strings parsed with Json converters etc.

this works with 4022.xx versions of twincat. trailed and tested for a couple of years already.