News:

  • August 29, 2026, 07:56:33 PM

Login with username, password and session length

Author Topic: MATHBCD >> Shift Right  (Read 14489 times)

JoeW

  • Jr. Member
  • **
  • Posts: 12
MATHBCD >> Shift Right
« on: September 25, 2013, 02:47:05 PM »
I am currently attempting to use the shift operator in the MathBCD IBOX but have not figured out the proper formatting.
Normally I would expect  "V3630 >> K3"  to be a valid expression yet this is not acceptable. I've tried several variations of this with no success.
I'm currently using the MATHBCD "V3630 & Kf000" and "V3630 & K0fff" respectively to split the values but am still not able to properly modify the upper values in a CMore BCD box correctly. Can anybody offer a correctly functioning example on how to Shift bits with Directsoft 5? 


Ultimately I'm attempting to split V3630 apart and make the bits modifiable on a CMore panel individually.  Upon modification I'll need to mash to two values back together and feed it back to V3630.  The only way I've seen this is possible currently is to take the value of the entire word in as an integer which is not exactly user friendly without a calculator.



My PLC is a DL06  using DirectSoft 5.

Thanks,
Joe...

rlp122

  • Sr. Member
  • ****
  • Posts: 92
Re: MATHBCD >> Shift Right
« Reply #1 on: September 25, 2013, 03:04:28 PM »
The DirectSoft help file is incorrect.  MATHBCD does not support Shifting.  You will need to do it external to the Math block using the SHFL or SHFR

b_carlton

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 606
    • thePLCguy
Re: MATHBCD >> Shift Right
« Reply #2 on: September 25, 2013, 03:44:49 PM »
Can you possibly use the MATHBIN IBoxes in your calculations?

Quote
"V3630 >> K3"

Was this an attempt to shift the upper nibble (4 bits) to the right 3 BCD positions (12 bits)?

Are you trying to present 4 individual digits to the HMI for modification? There may be better ways around this. Please describe your application with a little more detail.
« Last Edit: September 25, 2013, 03:50:52 PM by b_carlton »
An output is a PLC's way of getting its inputs to change.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: MATHBCD >> Shift Right
« Reply #3 on: September 25, 2013, 04:18:02 PM »
MATHBIN supports bit manipulation (e.g. & | >> <<), so if you kept your arithmetic to stuff that does NOT need to know it's BCD, then MATHBIN will do all that work.

Note that the bitwise-and and bitwise-or operators  (& and |) in MATHBIN are the ONLY MATHBIN operators where the mask K value (i.e. the right-hand-side of the & and |) is interpreted as HEXADECIMAL, i.e. K10 is the binary pattern 00010000, not the decimal 10 binary pattern 00001010.  However, K10 to the right of a + is decimal, not hexadecimal, so it does come out to 00001010.

So,
MATHBIN V2000 "(V1400 | K10) + K10"

will turn on the 5th bit of V1400 ( | K10 is interpreted as | 00010000) but then add the decimal value 10 (00001010) for the + K10 portion.  This was necessary because of the limitations that there is no "hex constant" vs. "decimal constant" designator (there is octal though, and real - but K is K).

That's one nice thing about Do-more, you have complete flexibility specifying the format for constants across all instructions, including MATH:
MATH V2000 "(V1400 | 0x10) + 10"
« Last Edit: September 25, 2013, 04:20:57 PM by franji1 »

JoeW

  • Jr. Member
  • **
  • Posts: 12
Re: MATHBCD >> Shift Right
« Reply #4 on: September 26, 2013, 09:34:29 AM »
Thanks!
  I've been racking my brain over this one!  Simply using the MATHBIN IBox made the proper shift for me, I wish I had simply asked sooner.

For more detail it seems when set up for motion profiling the V3630 word is split whereas

Bits 15-12 are the profile configuration in hex  (values 1-F)
Bits 11-0 are an BCD for the target velocity (values 0-9)
(documentation was not clear on these data types)

Simply parsing these values into two separate V memory registers and treating them as their native data types in the CMore panel then pushing them back into one value when needed seems to be working now.  Thanks for the assist.

Joe...

LWgreys

  • Hero Member
  • *****
  • Posts: 117
Re: MATHBCD >> Shift Right
« Reply #5 on: December 01, 2013, 02:01:02 PM »
"and make the bits modifiable on a CMore panel individually"

With the C-More display it easy!
Setup a Button or Switch that will turn ON or OFF the bit you want.
In setting up the bit for the switch or button select memory type "V" which will display a Bit box also. Put in the address 3630 and select the bit to work with.
No complex PLC ladder needed.
See image below.
« Last Edit: December 01, 2013, 04:24:02 PM by LWgreys »