Host Engineering Forum

General Category => DirectSOFT => Topic started by: 8bits on October 17, 2008, 08:18:40 PM

Title: IB-521 example for mod results
Post by: 8bits on October 17, 2008, 08:18:40 PM
Hello, can any one give an example on getting the remainder from a IB-521 where it is just simple as:
(V2000/k600). Not sure how to specify to get the remainder and as there is only one destination for the results do I have to
do two separate math operations? :-\
Title: Re: IB-521 example for mod results
Post by: Controls Guy on October 17, 2008, 09:57:59 PM
The MOD operator is '%', so to get the remainder enter "V2000 % K600" in the expression box.  If you want both the integer quotient and the remainder, yes, you will have to do two operations.
Title: Re: IB-521 example for mod results
Post by: franji1 on October 18, 2008, 11:26:04 AM
If you need both, and you have both the numerator and denominator in a V memory register, it's best to do it "the old way" because the DIV PLC instruction does both at the same time.  The MATH IBoxes have to do funky math accumulator stack manipulation to work properly to do JUST a divide or JUST a mod.  You actually would end up doing TWO DIV instructions with the two expressions
MATH divresult "Numerator / Denominator"
MATH modresult "Numerator % Denominator "

You would be best off doing in the native math instructions (no IBox)
LD  Numerator
DIV Denominator
OUT divresult
POP
OUT modresult
Title: Re: IB-521 example for mod results
Post by: 8bits on October 18, 2008, 12:51:00 PM
Thanks for the information, I will do it that way.
 :)