Jump to content

CPU crashing


Recommended Posts

I just created a C function in an Unilogic project that looks like this:


static void CircleFromCenterCutpos(int Cutpos, int Diameter, int Knifewidth, int Overlap, volatile int* Knifepos)
    // User code starts below this comment
    int totalcuts = (Diameter / 2 / (Knifewidth - Overlap) + 1) * 2;
    bool FirstHalf = Cutpos <= totalcuts/2;
    int TempCutPos = 0;
    if (FirstHalf == true)
    TempCutPos = totalcuts/2 - Cutpos;
    *Knifepos = Diameter / 2 - (Knifewidth - Overlap) * TempCutPos - Knifewidth/2;
   TempCutPos = abs(totalcuts/2 - Cutpos)-1;
    *Knifepos = Diameter / 2 + (Knifewidth - Overlap) * TempCutPos +Knifewidth  - Knifewidth/2;
    // User code ends above this comment


This code crashes the CPU. How can I see what the cause is for the CPU crash in such a case? Because the traditional approach of commenting out lines/ changing code is taking WAAAY to long with Unitronics because of the long reboot time after chrashing the CPU and long compile & download times


Edit: I found the problem and it is that in Unilogic in C you are not allowed to divide by using c = a/ b  but you have to use ARITHMETIC_DIV(1, a, b, c);. same goes for ABS() function. This makes some C functions close to unreadable unfortunatly. Also, the code compiles fine, but doesnt work if you dont use the arithmetic functions... which can be confusing

I'm still interested in a solution how to troubleshoot this next time in a time efficient way

Link to comment
Share on other sites

29 minutes ago, AlexUT said:

You can start by reading comments in C-Examples.

Then follow recommendations.

There are some limitations in PLC C-code realization.



But is there a way to figure out why the CPU crashes? For instance other PLC brands give an error message 'zero division' when dividing by 0 or 'array out of bounds' when accessing an element of an array that doenst exist etc. Does Unitronics also give some sort of explanation to a CPU crash?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...