adccommunitymod (AutomationDirect) asked a question.

Negative Numbers

Created Date: March 28,2008

Created By: samr

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

I'm using a C-More to load an index distance into V-memory in a DL-06 and then it is going out the serial port via ASCII to a servo drive. The servo drive is looking for an integer range of around 10,000 to 500,000 counts. The distance from the C-More is comming in as inches (BCD 32bit), being scaled and converted (BIN) and going to the drive as counts. 3.145 " goes to the drive as 16384 counts. This works OK. The problem is that to spin the drive backwards, the drive needs a negative count. When I want to spin the drive 3.142 " in reverse, how can the 16384 be converted to -16384?


  • adccommunitymod (AutomationDirect)

    Created Date: March 28,2008

    Created by: bcarlton

    You said the distance is being sent as ASCII to the servo drive. Can you just send the minus sign immediately before the number?

  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: samr

    The string being sent to the drive is "i r0 "V10000 "$R " The distance is in V10000. Where would I put the minus sign?

  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: franji1

    You will need 2 rungs of ladder logic, one that prints a positive value, one that prints a negative value.

    See if this works:

    ORIGINAL LOGIC

    AND backwards // reverse logic below if bit is ON for forwards

    OUT Temp bit // ON when you want negative

    STR Temp bit // negative

    PRINT "i r0 - " V10000 "$R "

    STRN Temp bit // NOT temp bit, positive

    PRINT "i r0 " V10000 "$R "

    The one issue is that this will have leading spaces between the negative sign and the number, for example, if V10000 contains the value 100:

    "- 100 "

    If this does NOT work with your drive's protocol, since you are using an 06, you can use VPRINT and PRINTV in combination. VPRINT prints to a V memory buffer (NOT the serial port, and PRINTV prints V memory as character data out a serial port. The reason why this can work is that VPRINT has much more formatting options (it's "newer " than the PRINT instruction, so it has more features).

    This makes it more complicated, but it can work. Hopefully the first way will work.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: franji1

    Note that HTML is taking out the extra spaces, so it is not obvious. Also, the minus sign character is very small in the first PRINT statement, but it is there http://forum1.automationdirect.com/board/biggrin.gif

    Here's monospace type for each:

    CODE:

    PRINT "i r0 - " V10000 "$R "

    PRINTOUT W/LEADING SPACES ON THE VALUE -100:

    "- 100 "

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: Merzo59

    I had the do the same thing with a stepper motor. I used the INV statement and it worked like a champ..

    LDD V4000

    INV

    ADDB k1

    OUTD V3000

    Had to add 1 to make it work correctly.

    Hope it helps.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: franji1

    He's dealing with ASCII in the PRINT statement, which doesn't support signed values, so he has to do it himself via the "direction " bit (the sign bit) and the value, so he doesn't need to do any 2's complement conversions.

  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: franji1

    Man, I messed up big time. Here's the input logic to the PRINT statement:

    ORIGINAL LOGIC

    AND backwards // negative

    PRINT "i r0 - " V10000 "$R "

    ORIGINAL LOGIC

    ANDN backwards // not backwards, positive

    PRINT "i r0 " V10000 "$R "

    (forget the temp bit stuff, doh!)

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: March 31,2008

    Created by: krak

    this might be a good idea for a new Ibox. dealing with negative numbers seems to hang up a few poeple.

  • adccommunitymod (AutomationDirect)

    Created Date: April 01,2008

    Created by: samr

    The motor is now spinning backwards. I want to thank every one who responded. This forum and the people who monitor and respond is a valuable asset.

10 of 12