A-B SLC500 DIV command. Saving the remainder as a fp word for vending machine project

limeyfellow

Member
Join Date
Sep 2008
Location
North Carolina
Posts
3
Hi,

I'm pretty new to PLCs (about 2 weeks experience) and still learning all the commands but I had a problem and after spending a long time with the manual am no further along the way of figuring this out.

I am using an Allen-Bradley SLC 500 and been designing a program for a vending machine, and yes I didn't come up with this idea.

Anyway, I am at the stage of getting the machine to release the change, after coming up with a total in an f8 word. So I thought to myself, okay I'll just divide that amount by the first coin value.

When I do this I get a quotient saved in another f8 word, but I don't know how to save the carried remainder value to a third word so I can then divide that amount with the lesser value coin. I'm I just doing this all wrong or is there an easier way of doing this I haven't considered? For the live of me I just can't figure out how to save that remainder to use elsewhere.

Thank you for any help.
 
Last edited:
Sounds like homework.

Floating point division isn't going to give you a remainder, remainders only exist in integer division. There are ways to truncate floats, but that is very advanced programming, so lets stick with integers and basic instructions. Since we want to work with integers, convert your price to pennies, not dollars.

Hint: When you perform double integer division using the DDV instruction, S:13 and S:14 will contain the quotient and remainder. To get an integer value into the math register you can use a couple of move MOV instructions, but its easier to just multiply by 1 and ignore the destination. The MUL instruction places a 32 bit value in the S:13 and S:14 math registers.

MUL N7:0 1 N7:1 //ignore the value in N7:1
DDV 25 N7:1 //divides the value that was in N7:0 which is now in the math register by 25. Once again, we don't really care about N7:1.
MOV S:13 N7:2 //remainder
MOV S:14 N7:3 //quotient


You can download an instruction set reference manual from AB's literature library - it will come in handy for your class.
http://literature.rockwellautomation.com/idc/groups/literature/documents/rm/1747-rm001_-en-p.pdf
 
Last edited:
You may want to re think using Floating Point. Instead work with the total as number of cents. ($2.00 = 200).

Next check out the DIV instruction as far as using the Math Registers. (S:13 and S:14). This from SLC Instruction help for DIV.

The unrounded quotient is placed in the most significant word of the math register; the remainder is placed in the least significant word.

Let's say you have the total in N7:0 (can hold up to 32767 or $327.67 - probably enough)

Let's say the change to be released = $1.27. You have quarters, dimes, nickles and pennies.

First divide N7:0 by 25. Store the result (DEST) anywhere, it doesn't matter.

S:14 has the number of quarters (5). You can store that. (Let's say N7:10)

Now move S:13, the remainder (2) into N7:0.

Divide by dimes (10) - the result (0) is in S:14. Store that (Let's use N7:11)

Move the remainder from S:13 (still 2) into N7:0

Divide by nickles (5) - the result (0) is in S:14. Store that (Let's use N7:12)

Move the remainder (which has to be less than 5 cents) into N7:13

Now you have:

Quarters in N7:10 (5)
Dimes in N7:11 (0)
Nickles in N7:12 (0)
and Pennies in N7:13 (2)

You may not use exactly this method but I think you get the idea.

Alaric beat me again - faster typer.
 
OK, forget the DDV. Sometimes I have a one track mind. o_O The DIV instruction will also stick the remainder in S:13 and dividend in S:14, Bernie's post remined me of that obscure detail, and its simpler, since you don't have to get the number into the math register in the first place.
 

Similar Topics

I cannot add SLC500 analog input tag (I: 8.3) to EZSeries Touch Panel Editor (V 5.3). I used all the listed tag datatype but it all says "Invalid...
Replies
10
Views
258
can the slc500 5/05 send a email and text over Ethernet ?
Replies
3
Views
185
Hello, did anybody know, if there exist an converting cable like the1492-CM1746-M01 (for an 1746-IB16 to an 5069-IB16), for an 1746-HSCE to an...
Replies
3
Views
389
Customer is buying several spare 504 CPU's to have one handy when there's an issue with the ones in operation. Having them on the shelf for years...
Replies
15
Views
2,835
You have to go offline to create the 'Trend' but do you have to download the program to go back Online with the Trend ?
Replies
0
Views
344
Back
Top Bottom