Sign in to follow this  
Followers 0
LeDude

Scan single bits

16 posts in this topic

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
DINT_TO_BCD instruction (or INT_TO_BCD)? Will that work correctly?

Share this post


Link to post
Share on other sites
I am already receiving binary. Anyways, can you tell me the FNC-Number? I can't fin anything under INT_TO_BCD.

Share this post


Link to post
Share on other sites
I must say that I think I like the int compare, or just using the bits. Simplicity is always a good thing.

Share this post


Link to post
Share on other sites
Agreed with simplicity, but how do I use the bits? Please go ahead to wide my horizon :)

Share this post


Link to post
Share on other sites
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?   Edited by Sergei Troizky

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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: --||----------[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: 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: [= 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): ---| |----+------[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.): [= D0 D100]------------(Y0) [= D0 D101]------------(Y1) [= D0 D102]----+-------(Y2) [= D0 D103]----+

Share this post


Link to post
Share on other sites
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 Edited by LeDude

Share this post


Link to post
Share on other sites
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):

Share this post


Link to post
Share on other sites
panic mode, I am aware that there are tabs and google, Wiki etc. I just thought the PLC has it already integrated.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0