Jump to content

CPU crashing


Kpotmake

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;
    }
    else
    {
   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.

B.R.

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.