ASCII string to display

ceilingwalker

Lifetime Supporting Member
Join Date
Mar 2010
Location
Phoenix, AZ
Posts
1,586
Good day all. I have a program that sends an ASCII string to a display via RS-232. The data it is sending is the value of a timers preset minus its accumulator. Currently it sends it in seconds. What I would like to know is, what instruction could I write that would make it possible for the processor to send out minutes, a space or two, then seconds. The operators enter timer preset values via an HMI, in minutes. I was thinking I could create a situation where the timer values could have one that is converted to minutes (which I already have) and then another integer file for seconds and then concantenate the two. My concern is dealing with fractions of a minute which an integer file can't do. Thanks much.
 
If this is an SLC-500, you can perform a DIV instruction on the Remaining Seconds value (divide by 60) to get the Remaining Minutes. Immediately after the DIV instruction, the S:13 math register should contain the integer remainder, in seconds, from that math instruction. Use MOV to put that value into a storage register.

Converting INT to String is straightforward, as is Concatenating (ACN instruction) strings together.

But before we go too far, let's get the basic PLC/OS/application information.
 
If this is an SLC-500, you can perform a DIV instruction on the Remaining Seconds value (divide by 60) to get the Remaining Minutes.
Yes, and I have already done that


Immediately after the DIV instruction, the S:13 math register should contain the integer remainder, in seconds, from that math instruction. Use MOV to put that value into a storage register.
I have never used a math register before. How does it work?

Converting INT to String is straightforward, as is Concatenating (ACN instruction) strings together.
This I have, the processor is currently sending this to the display like a champ. The problem is they want minutes and seconds, not just minutes and not just seconds.

But before we go too far, let's get the basic PLC/OS/application
SLC 5/03 OS302.

information.

If not enough info, let me know. Thanks much
 
Take a look at the Help file for the Math Registers (just hit F1 from inside the Status table tab, or search). That and the Instruction Set Reference should give you a pretty good idea of these internal register functions.

Think of them as math scratchpads for the SLC operating system.

Let's say you perform a DIV instruction, Source A = 265, Source B = 60, Destination N10:0.

The Destination will have the rounded result of the DIV instruction, which is 5.

But the S:14 register will have the unrounded result, which is 4.
And the S:13 register will have the remainder, which is 25.

And that's the value you want: 4 minutes, 25 seconds remaining.

Move these S:13 and S:14 values into storage registers right after the DIV instruction; they will be overwritten the very next time there is a math operation.

Attached is a quick demonstration of this method, which I checked on an emulator to be sure I recalled correctly.
 
If you are afraid to use the math registers, can't you do floating point math to do the remainders? (5/03 supports floating point, doesn't it?)
 
The MOV of the float (F) into the integer (N) in the SLC will round the number. If the rounding was UP (integer is now greater than the float) then subtract one to get back to to the integer part of the float.

MOV 5.2 -> integer leaves '5' in the integer, ok
MOV 5.7 -> integer leaves '6' in the integer. Since the '6' is greater than the 5.7 then subtract 1 to get '5'.

Either way you get 5 which was the integer part of the float.

The example with the DIV (as Ken showed) does, as a side effect, a similar thing. In the math registers after the DIV is the whole number dividend and the remainder which are somewhat easy to use as shown in the 'total seconds' to minutes and seconds example.
 
The MOV of the float (F) into the integer (N) in the SLC will round the number. If the rounding was UP (integer is now greater than the float) then subtract one to get back to to the integer part of the float.

MOV 5.2 -> integer leaves '5' in the integer, ok
MOV 5.7 -> integer leaves '6' in the integer. Since the '6' is greater than the 5.7 then subtract 1 to get '5'.

Either way you get 5 which was the integer part of the float.

The example with the DIV (as Ken showed) does, as a side effect, a similar thing. In the math registers after the DIV is the whole number dividend and the remainder which are somewhat easy to use as shown in the 'total seconds' to minutes and seconds example.


Thank you, I understand it now.
 
Take a look at the Help file for the Math Registers (just hit F1 from inside the Status table tab, or search). That and the Instruction Set Reference should give you a pretty good idea of these internal register functions.

Think of them as math scratchpads for the SLC operating system.

Let's say you perform a DIV instruction, Source A = 265, Source B = 60, Destination N10:0.

The Destination will have the rounded result of the DIV instruction, which is 5.

But the S:14 register will have the unrounded result, which is 4.
And the S:13 register will have the remainder, which is 25.

And that's the value you want: 4 minutes, 25 seconds remaining.

Move these S:13 and S:14 values into storage registers right after the DIV instruction; they will be overwritten the very next time there is a math operation.

Attached is a quick demonstration of this method, which I checked on an emulator to be sure I recalled correctly.

That is very cool Ken, I never thought of using the registers that way. I know of several functions i could use this on. Is there any "gotchyas" to look out for?
 
But the S:14 register will have the unrounded result, which is 4.
And the S:13 register will have the remainder, which is 25.

And that's the value you want: 4 minutes, 25 seconds remaining.

THIS IS AWESOME, thanks Ken! I have a couple of other applications that I tried using these math registers in place of several lines of code I have and it is neat.
 
When I created a quick program for three timers using Kens Program, it worked fine. When I wrote the program and placed it in my project I was getting a number value that wasn't consistent with seconds or minutes. It is however timing and it is updating the slave displays. I attached my project hoping someone might be able to see what I'm doing wrong. It is program file 10 "Timers". Thank you much.
 

Similar Topics

Hello gentlemen, A few days ago I was tasked with converting an old panelview 1400e to a panelview plus 7 application. Everything went well except...
Replies
1
Views
1,314
I have a Horner PLC that is reading Ascii string from a device. When the device responds, it responds with the hex value in Ascii. I need to...
Replies
8
Views
2,388
HI Guys So i am trying to write a real SINt or DINT value into a string tag. If in string browser I write it manually, no problem. But how can I...
Replies
8
Views
5,978
Have an unusual one here, guys... I have a remote machine that is sending my 1769-L33ER five 16-bit integers that represent 10 ASCII characters...
Replies
4
Views
2,232
hi, i try to capture barcode data using UDT with SINT ascii array. i have all the data i need but it in array format, how can i convert to 1...
Replies
5
Views
3,064
Back
Top Bottom