Help - Search - Members - Calendar
Full Version: Scan single bits
Forums.MrPLC.com > PLCs and Supporting Devices > Mitsubishi
LeDude
Hello geeks,

let's do some clustergeeking!


I don't know how to program this:

I am receiving a word aka 16bits.
So how do I scan which bits are set to 0 or 1, especially the combination of set bits?

A programming example would be appreciated.
I looked in the manual, but I couldn't find the right thing.

Thnak you guys.
Cheers




kaare_t
Any special (or standardized) combinations you are looking for (BCD or input matrix)?

You can also use a BMOV and move the int into an array of bools, or just compare the int value to another number.
LeDude
QUOTE (kaare_t @ Aug 6 2009, 02:27 PM) *
Any special (or standardized) combinations you are looking for (BCD or input matrix)?

You can also use a BMOV and move the int into an array of bools, or just compare the int value to another number.


OK,
let's say I receive 0010 (=2h)

With your BMOV you are saying I am comparing the Hex-Value with the set bits?
Basically

0010 is sent to the PLC, where I compare it this way: [= D1 H02]--------(Y1)

That's how I am doing it right now.

What I am looking for is actually a FNC for triggering an output, when I receive BCD:
I receive "0000 1001" and want to trigger e.g. output #9.

How do I do that?

Thanks a bunch
kaare_t
DINT_TO_BCD instruction (or INT_TO_BCD)?
Will that work correctly?
LeDude
QUOTE (kaare_t @ Aug 6 2009, 02:49 PM) *
DINT_TO_BCD instruction (or INT_TO_BCD)?
Will that work correctly?




I am already receiving binary.
Anyways, can you tell me the FNC-Number?
I can't fin anything under INT_TO_BCD.
PLCMentor.com
I must say that I think I like the int compare, or just using the bits. Simplicity is always a good thing.
LeDude
QUOTE (PLCMentor.com @ Aug 6 2009, 03:21 PM) *
I must say that I think I like the int compare, or just using the bits. Simplicity is always a good thing.


Agreed with simplicity, but how do I use the bits?
Please go ahead to wide my horizon :)
Sergei Troizky
It is still unclear WHAT you need to do, so cannot advice you HOW.
Clarify the task and specify your PLC model.
And what do you mean by Output #9 in Mitsubishi?
 
Crossbow
Convert the received BCD to binary, then use the DECO function to encode that number to a bit. DECO will take a number and turn on that bit number in the output. So if the incoming number was 4, bit 4 in the output sequence would turn on.

The functions kaare_t mentioned are IEC, so using GX IEC Developer.

You never mentioned which PLC or which software. More specific questions yield better answers.
panic mode
the question is still too fuzzy. based on what i understand from it, you want to check if certain combination of bits is received and if that is the case, turn on some bit (output for example).
there are different ways to do this but first - learn the hexadecimal numbers (it's only 0-F but they are perfectly suited for this kind of work):
you could evaluate bits using ladder for example. to check if you have all 16 bits in specific configuration you could do:


CODE
--||----------[MOV  D0 k4M0]

   M15  M14   M13   M12      M11   M10   M9     M8      M7    M6    M5    M4       M3    M2     M1    M0    Y0
--|/|---|/|---|/|---|/|------| |---| |---|/|---|/|-------|/|---|/|---| |---| |-------|/|---| |---|/|---| |---()


Note that BMOV is meant for blocks of registers (multiple registers), don't use it if you only need one or two 16-bit words (this is what MOV and DMOV are for).
This checks if the code received in D0 is 0000 1100 0011 0101b (or H0C35). If your PLC supports bit addressing of the D register, you don't need to use M bits, you could address D bits directly:

CODE
D0.F  D0.E   D0.D   D0.C         D0.B   D0.A  D0.9     D0.8      D0.7    D0.6   D0.5   D0.4      D0.3   D0.2   D0.1  D0.0      Y0
--|/|---|/|---|/|---|/|------------| |----| |-----|/|-----|/|---------|/|---|/|----| |----| |-------|/|---| |---|/|---| |------()


however, this will make for very messy code if you have more than few outputs to be controlled this way.

you could replace it by this:

CODE
[= D0 H0C35]-------(Y0)


now you can see where the hex comes in place - one hex digit defines four bits and if you know the 0-15 of binary/decimal/hex this is piece of cake.
note that this code is still only practical for very few comparisons - for more you need to have comments which becomes a burden when typing every time - specially is same comparison is used multiple times.
one way to do this is:
- initialize all expected "messages":
- compare receved word with register

this allows for very flexible system so codes can be changed on the fly - if needed. (why not from HMI, this way customer becomes responsible for maintenance for example.)
This is what "Program memory - Devices" is for but it can also be done in code (on first scan for example):

CODE
---| |----+------[MOV H03C5 D100]
          |
          +------[MOV H8750 D101]
          |
          +------[MOV H3A67 D102]
          |
          +------[MOV H233C D103]
          |
          +------[MOV H5569 D104]


then add comments to D100 and others ("pressure too high", "barcode scanned", "fault detected" etc.) and then when you do comparison in code, everyone can see what is this supposed to be (comments attached to D100 etc.):

CODE
[= D0 D100]------------(Y0)

[= D0 D101]------------(Y1)

[= D0 D102]----+-------(Y2)
[= D0 D103]----+
LeDude
Thanks, guys.

panic mode, you got me right.
I am checking it right now.

My FX3u supports bit addressing.
But where can I calculate the (to use your example) H0C35 out of 0000 1100 0011 0101b.

Thanks
panic mode
well, there is windows calculator. may not be the greatest but once you switch it to Scientific view, it becomes quite usefull.
then there is internet (google, wiki) which will produce conversion tables or tools similar to one below.
finally one can simply memorize it as 0-15 (0-F) table is short, simple and very handy (specially in this line of work):
LeDude
panic mode,
I am aware that there are tabs and google, Wiki etc.
I just thought the PLC has it already integrated.


panic mode
i see, did you try device batch monitor? it allows you to see content of memory locations in different presentations. for example pick any unused location (D or whatever) and set the value using one format and view in another.
LeDude
QUOTE (panic mode @ Aug 31 2009, 10:08 PM) *
i see, did you try device batch monitor? it allows you to see content of memory locations in different presentations. for example pick any unused location (D or whatever) and set the value using one format and view in another.



Yes,
I am using the Batch Monitor.
But what I am trying to avoid is to receive the bits and bytes and then write it in the program, I am actually trying to define it in the program first.


But either way it will work.
Thanks again :)
Crossbow
Now I'm confused what you are asking.

"But where can I calculate the (to use your example) H0C35 out of 0000 1100 0011 0101b"

You don't calculate anything. If you write H0C35, each character of hex sets 4 bits. So the 1100 is the same as hex C. Hexadecimal is nothing but shorthand for writing a bunch of ones and zeros. Try viewing the register value in hex, or in binary. The PLC can show you either method. It's all ones and zeros to the PLC. You're simply looking at it in different formats.

And maybe entry data monitor will be more useful than device batch, as you can specify the display format for each entry in the entry data monitor.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.