Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

divide by zero ERROR message


Recommended Posts

Hello everyone,
    I tried to calculate how many pecks in a drill cycle out put and some how I got a message that said:
    "05 Apr 2017 07:24:23 AM - RUN TIME -PST(5569)- The formula is attempting to divide by zero, , Calculation returned zero"

   I also went to line# 5569, the error was at this line,  num_of_pecks = peck_depth / peck1$

   I tried to fix it for a week and honestly, I have to admit it that my knowledge is very limited about this.

ps: I'm using a drill.

Thank you for your help.

 

This is how I defined it:

Under....


# --------------------------------------------------------------------------
# Common User-defined Variable Initializations (not switches!)
# --------------------------------------------------------------------------
peck_depth  : 0     #Calculated depth of hole
total_pecks : 0     #Total number of pecks
 

fmt  "" 4 total_pecks #Format Peck Note
fmt  "" 4 num_of_pecks
fmt  "" 2 mypeck

 

#Region Tool change common blocks
ptlchg_com      #Tool change common blocks
      peck_depth = abs(depth$) - abs(tosz$)
      num_of_pecks = depth$ / peck1$
      mypeck = peck1$
      if tool_op$ = 1, 
       [
        "(", *num_of_pecks, no_spc$, "X PECKS, ", *mypeck, "PER)", e$
       ]

Link to comment
Share on other sites

The error is telling you exactly what the issue is. "You have a formula where you are dividing by 0". So what does that tell you? It tells you that the value of the divisor is zero. What is the divisor in your equation?

.

.

.

The Divisor is "peck1$". When that variable has a "zero value", you're going to get an error.

I'd recommend adding some logic just before that line of code, to check the 'peck1$' value, and set it to "non-zero" if it zero.

ptlchg_com      #Tool change common blocks
       peck_depth = abs(depth$) - abs(tosz$)
       if peck1$ < 0.0001, peck1$ = 1
       num_of_pecks = depth$ / peck1$
       mypeck = peck1$

 

Why would you be adding this logic to 'ptlchg_com' though? By adding it there, this will be calculated for every path, regardless if it is a "Drill Cycle", or not. I would recommend adding some logic to check the 'opcode$', and only execute that logic if you are actually "drilling".

ptlchg_com      #Tool change common blocks
       if opcode$ = 3 | opcode$ = 16, #only for Drill
         [
         peck_depth = abs(depth$) - abs(tosz$)
         num_of_pecks = depth$ / peck1$
         mypeck = peck1$
         ]

 

  • Like 1
Link to comment
Share on other sites
58 minutes ago, Tim Johnson said:

When you format a variable you are in effect also defining it. The variable just won't have a default setting. If you need a default number or name for that same variable then you also need to define it.

Thanks Tim, I've seem that several times and always wondered how it worked.

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.

Guest
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.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...