
adccommunitymod (AutomationDirect) asked a question.
Created Date: December 03,2013
Created By: mudger
**** 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.****
When doing BCD math what happens to the fractional part of the calculation? Is it rounded off automatically or if not can I force it to round off? I’m trying to build a line speed indicator by timing the time between prox pulses and then divide the distance (K1050 for 10.5”) per pulse by that time (1/100th second) for distance for that pulse and then divide by K12 for in. per second then multiply by K60 for feet per minute and then OUT to V2020 for the Micro graphic display. The display numbers look a lot like the fractional part of the calculation. I tried using double words but end up with 0’s everywhere but TA0. The PLC is DL06 dc in using X0 for prox. Max line speed= 5 pulse per second. Distance per pulse=10.5” :confused:
Created Date: December 03,2013
Created by: bcarlton
Try the following rung. Adjust the V2000 etc storage places as needed.
PLC 06
// Rung 1
// Address 0
#BEGIN COMMENT
"Load the time and convert to a REAL with 2 decimal places (hundreths of a second) "
" save this result in V2000/1 "
"Load (as a REAL) 60 seconds (1 minute) "
"Divide that by the time to get pulses/minute "
"Multiply by 10.5 to get inches/minute "
"Divide by 12.0 to get feet/minute - save in V2002/3 "
"Convert the REAL result back to BCD in V2020 "
" "
"Note: there will be no fractional parts in the BCD fpm reading. "
#END
BCDTOR TA0 K2 V2000
LDR R60
DIVR V2000
MULR R10.5
DIVR R12
OUTD V2002
RTOBCD V2002 K0 V2020
// Rung 2
// Address 122
NOP
// Rung 3
// Address 123
NOP
Created Date: December 03,2013
Created by: Tinker
First of all, instead of dividing by 12 then multipling by 60, I'd just multiply by 5 (60/12), and I think I'd multiply that K1050 by 5 to start with, or K5250, so that you just have do one divsion. Multiplying before you divide sould help quite a bit.
If you can use double words you might try K52500 or even 525000 and set the decimal point apropriatly on the HMI.
I have no idea what is invloved with double word BCD division, I mostly use the CLICK and it's the same math box for any numeric data type (about as complicated as punching number into a calculator) and no BCD at all.
I strongly suspect the fractional part is truncated, or "rounded " down, not rounded to the nearest integer.
Created Date: December 03,2013
Created by: mudger
Thanks bcarlton I will try that :)
Created Date: December 03,2013
Created by: mudger
Thanks tinker I will try that. or anything that works. At some point in my life I would like to understand what happens to the Mantissa in a BCD calculation because any math with a divide is bound to produce a long string of fractional numbers at some point if one of the components is a variable. I assume.
Created Date: December 03,2013
Created by: bcarlton
Part of my answer is to use REAL if at all possible. The time spent in the conversions is made up for by the speed of the calculations compared to the same in BCD. When done you can keep as much of the answer as you want.
Created Date: December 03,2013
Created by: mudger
thanks Bernie. It makes sense to me. At one point I considered using a different format than BCD But had no idea whick would be better. Fortunately the line speed is only for operator refference and has no effect on the rest of the line.
Thanks Ron
Created Date: December 03,2013
Created by: mudger
When doing BCD math what happens to the fractional part of the calculation? Is it rounded off automatically or if not can I force it to round off?
I’m trying to build a line speed indicator by timing the time between prox pulses and then divide the distance (K1050 for 10.5”) per pulse by that time (1/100th second) for distance for that pulse and then divide by K12 for in. per second then multiply by K60 for feet per minute and then OUT to V2020 for the Micro graphic display.
The display numbers look a lot like the fractional part of the calculation. I tried using double words but end up with 0’s everywhere but TA0.
The PLC is DL06 dc in using X0 for prox. Max line speed= 5 pulse per second. Distance per pulse=10.5”
:confused: