Weekend ASCII...

Eric Nelson

Lifetime Supporting Member + Moderator
Join Date
Apr 2002
Location
Randolph, NJ
Posts
4,346
Since the last time I posted a 'weekend question', it got answered (thanks, AK!). I figured I'd try again THIS weekend... ;)

I have used the following code in the past to send an ASCII string from an A-D DL06 PLC to a PacSci servo drive with great success... :nodi:

[attachment]

On the first rung, I convert the 'user units' (.001") to encoder counts. IOW, to move 2.500", the value 2500 is used. 2500 x 3306 / 100 = 82650 encoder counts, which is placed in V2022 and V2023 (0008 2650, or is it 2650 0008?).

The string that must be sent to the drive is:

<STX> 255 W 10093 = {my value} <CR>

For those who care, <STX> means "I'm sending you something", 255 is the drive axis (all), W means WRITE, 10093 is the move distance, and <CR> means "I'm done chatting"

So, if I want to move 82650 encoder counts, the string will be:

<STX> 255 W 10093 = 00082650 <CR>

The 'VPRINT' command on the second rung "Prints" this string to V-memory, starting at V3000. My (convoluted)

"$02" "255W10093=-" V2023:B V2022:B "$R"

successfully places the correct string in V-memory. "$02" is 'start of text' <STX>, and "$R" is the carriage return <CR>. The ":B" just prints my variables as BCD.

The last line simply sends this out the secondary COM port of the PLC, which the drive receives.

Notice that I have "Byte Swap" enabled in both print instructions. Why? I dunno. I wrote this a LONG time ago, and for some reason, that was the only way I could get it to work... :confused:

My problem is that on THIS machine I want the motor to turn in the opposite direction. Therefore, I need to send it a NEGATIVE number. The number will ALWAYS be negative, so it can in the text portion of the string.

All I need to do is add a "-" before the value, like this:

<STX> 255W10093 = -00082650 <CR>

By the way, the drive will ignore the spaces.

I have tried to finagle my string to produce a negative value, with no luck. The 'byte swap' **** has me thoroughly confused. I'm sure I didn't need the byte swap in the first place, but as I said, for some reason that's the only way I could get it to work... :unsure:

Anyone wanna give it a shot?... utoh

A possibly easier solution would be to tell me how to reverse the motor electrically. I tried swapping two phases on the motor, plus inverting the Sine+ and Sine- connections from the resolver, but the drive didn't like that one bit! What's the CORRECT way?

Though I'd STILL like to know how to do it within my program.

beerchug

-Eric

asciiprint.jpg
 
Oh, nevermind...

Looks like I didn't need the byte swap after all. All that was doing was screwing me up. I turned off both byte swaps and just typed in exactly what I wanted to print... šŸ™ƒ

Works fine now... (y)

[attachment]

I still see something odd when I watch what is sent via hyperterminal. The new program adds a percent character (%) to the beginning of the string. The drive doesn't seem to mind though... ;)

Feel free to ridicule me anyway...
9.gif


beerchug

-Eric

asciiprint.jpg
 
Last edited:
Damned Eric, for once I thought I could help but now you answered your own question :rolleyes:

Good it worked out...
 
You asked for it, so why don't we bring up the topic of documentation?

I have always believed that a description of what the code is accomplishing in laymans terms to be a great benefit when revisiting code at a later date or when working on someone else's code. For example on rung 1007, you could have stated the formula in the rung description:

V2022 = V20221 * K3306/V2017

You could also have stated how you arived at the scaling factor K3306.

For the print instructions, a brief explanation of why the expression is formatted the way it is could help. I am not asking for instruction help in the ladder documentation, but stating some of the weird quirks that resulted in the code could be beneficial. You included the documentatio in the post, but it was not in the laddder. I assume that you must have a great memory.
 
I meant to be ridiculed about my byte swap screwup, but documentation is a great issue. Guilty as charged... :oops:

Although inexcusable, here's my 'attempt' at an excuse anyway... ;)

The company I work for is an OEM, but we don't have a standard product line. We build custom assembly machines, so we basically start with a clean slate each time. I don't have the liberty to continually refine my documentation over time. As most programmers know, we are always the LAST people working on the machine, so the 'final' program usually exists only as the machine is heading out the door. Documentation has to ship with the machine, so whatever I have done 'to date' is what goes... :(

I'm also stuck writing the operation manual for the machine, since for some strange reason, only I seem to know how the machine operates... :rolleyes:

I do reuse code from machine to machine, so THAT code SHOULD be better documented. This was an excellent example. This is the third time I've used this chunk of code, so the comments should reflect the fact that 'I've been here before'... :nodi:

Derek McFarland said:
I assume that you must have a great memory.

I used to think that was true. Lately, scandisk is reporting more and more 'bad sectors'... utoh

beerchug

-Eric
 
Eric Nelson said:
A possibly easier solution would be to tell me how to reverse the motor electrically. I tried swapping two phases on the motor, plus inverting the Sine+ and Sine- connections from the resolver, but the drive didn't like that one bit! What's the CORRECT way?

On a three phase power ciruit, all you should have to do is swap two phases. But, it sounds like you're using an indexing table (is it an NSK? I've had some experience with those). I'll bet the controller converts your voltage to DC or something, so swapping phases would do zippo.

I think you are sending the extra % sign because many PLCs store ASCII (8 bits) in a 16 bit word. You are probably sending an "undetermined" character, and you might actually want to see what you can do to fix that (to avoid a 3am phone call). Can you add a space somewhere to ensure that your string length is even?

AK
 
Re: Re: Weekend ASCII...

akreel said:
On a three phase power ciruit, all you should have to do is swap two phases. But, it sounds like you're using an indexing table (is it an NSK? I've had some experience with those). I'll bet the controller converts your voltage to DC or something, so swapping phases would do zippo.

I swapped two phases between the drive and the motor, so I'm quite sure that will make the motor rotate the opposite direction. I think the error is in my attempt at reversing the resolver. With an encoder, swapping the A and A leads does the trick. I'm not sure how to accomplish the same thing with a resolver... :confused:

Nothing fancy here. The motor simply advances a 4" wide web (cap lining material) whatever distance the operator selects. The previous machines PUSHED the material. This one PULLS, so the motor must turn the other way.

akreel said:
I think you are sending the extra % sign because many PLCs store ASCII (8 bits) in a 16 bit word. You are probably sending an "undetermined" character, and you might actually want to see what you can do to fix that (to avoid a 3am phone call). Can you add a space somewhere to ensure that your string length is even?

That sounds plausible. I'll give that a try the next time I'm online with the machine. Thanks (again)... (y)

beerchug

-Eric
 
I've slept since then, but a resolver has an exciter circuit to energize the 'armature' and two outputs like a simple A/B encoder.

Swap those two outputs

Rod (the CNC guy)
 
Rod said:
I've slept since then, but a resolver has an exciter circuit to energize the 'armature' and two outputs like a simple A/B encoder.

Swap those two outputs

Thanks, Rod, that's what I thought. I had reversed the "U" and "V" phase to the motor, AND reversed the Sine+ and Sine- connections. When I powered on the drive, it took off like a bat out of hell, then faulted. I didn't investigate, but I figure the fault would have been a following error... IOW, the drive is saying "I'm givin' her all I got, Captain, but she's not respondin'!"... :D

Now that I have my negative value, I can leave the motor/resolver connections alone.

beerchug

-Eric
 
Re: Re: Re: Weekend ASCII...

Eric Nelson said:
That sounds plausible. I'll give that a try the next time I'm online with the machine.

Hey, Eric! I'm curious. Did you resolve the issue with the extra ASCII character?

AK
 
akreel said:
Hey, Eric! I'm curious. Did you resolve the issue with the extra ASCII character?

Um, no... :oops:

The machine hasn't shipped yet, so "I'll give that a try the next time I'm online with the machine".

Where have you heard that before?... :D

beerchug

-Eric
 
I finally got a chance to try removing spaces.


STRING SENT FROM PLC HYPERTERMINAL DISPLAYED

<STX> 255 W 10093 = {my value} <CR> %*255 W 10093 = {my value}

<STX> 255W 10093 = {my value} <CR> $*255W 10093 = {my value}

<STX> 255W10093= {my value} <CR> 0*255W10093= {my value}


* is the 'black smiling face' unicode character (LINK), which can't be displayed with the font sets in the forum.

The drive accepts the string in all cases, so it doesn't seem to matter. It may be a hyperterminal thing? I'm satisfied with leaving it as a mystery unless someone wants to explain further... :confused:

beerchug

-Eric
 
no phase swap

On a three phase power ciruit, all you should have to do is swap two phases

In terms of a servo drive this is an absolute NO NO!
You must never swap wires from the drive to the AC servo motor!
You must always confirm to the manufacturer's manuals! Failure to do so will result in a damage to the drive.
Unlike three phase induction motor, AC servo has a specific phase sequence that needs to be adhered to.
Reversing the direction is accomplished by reprogramming the drive as indicated above.

In as far as byte swap goes. It is a common practice to have data organized in a big endien format, i.e. high byte first and then low
byte or bytes. This is not a rule and is dependent on the
protocol specifications, hence the byte swap instruction.
 

Similar Topics

I'm trying to build my Classic Step 7 programming skills this weekend. I get stuck on little things that are not covered in YouTube tutorials. I'm...
Replies
7
Views
314
Hello! We are using a ControlLogix 1756-L72 PLC with two identical servo motors running separate conveyor belts. The machine this is on runs...
Replies
4
Views
961
I was at a customer's today and 2 of 3 SLC 5/03s had the Battery Light on. I showed it to the maintenance guy and asked him when the last time the...
Replies
8
Views
3,329
Hope you all have a happy and safe Memorial Day weekend. Drink a couple of cold ones for me, will ya. A special shout out to all of you who are...
Replies
1
Views
1,968
Summer is finally here, and I would like to wish all my fellow Canadians a happy and safe Canada Day weekend, and to my American neighbors, a safe...
Replies
12
Views
3,145
Back
Top Bottom