Sign in to follow this  
Followers 0
ngo4life

How to scan Input words bit by bit

11 posts in this topic

Hi all, I have 5 input words that i use. How can i create a loop to scan 16 bits of the first input word then go back and scan the next input word bit by bit and so on until 5 words are scanned. Base on the condition of these bits the program will do something. How can i set indirect addressing for IO instead of DM area Please help

Share this post


Link to post
Share on other sites
Well if you know how to use indirect adressing on the DM words, I would suggest to move your IO to DM words using a simple XFER box, then use indirect adressing on the DM. That's what I would do. Good luck

Share this post


Link to post
Share on other sites
Assuming that you are using a CJ / CS / CP1H / CP1L PLC, you can perform indirect addressing using IR / DR (Index Register / Data Register) methods. How do you want to process the data once you have scanned the bits (ie what are you looking for?) a bit pattern? a count of how many bits are on?

Share this post


Link to post
Share on other sites
Could you show me an example. I am using CQM1 CPU41

Share this post


Link to post
Share on other sites
Not sure if what you are looking for, but the attached example is a start to doing what you want to do. It does not use true indirect addressing utilising *,IR etc, but works to a certain extent. I just mocked this up, there is no limit checking etc, you will need to adapt to suit your application, as you could advance it to look at words 1, 2, 3 etc if the need be. As I said, just whipped this up, there may be a better way, but it is friday....... wheres the beerchug? testcq.cxp

Share this post


Link to post
Share on other sites
Hi ngo4live, a kind of indirect addressing is offered by the instructions COLL(81) and DIST(80). You could use the instruction COLL to copy different words to a "work word" . But maybe just program some LINE or COLM-instructions, and indirect addressing is no more needed? The instruction COLM(--) distributes the Bits, like you described. LINE and COLM are expanded instructions, you have to assign it and download the expansion instruction table into the CPU. For COLM(--) see W228-E1-8 chapter 5-19-16. Harald Edited by Harald_Brueck

Share this post


Link to post
Share on other sites
Yep Harald that's the best: this is an test I wrote some time ago for a PWM application on standard CJ1 ouputs: COLM instruction dimmertest.cxp Dimmer3.cxp Edited by beegee

Share this post


Link to post
Share on other sites
Here is my two cents. I think I would just create the individual ladders for this logic. But then again, I like to keep things simple. Yes I understand it is 75 rungs of code, but at least it will be maintainable/understandable by most anyone that sees the code. Unless I misunderstand the application, it appears to me the LINE instruction (which I did not know about, Thank you Harald!) seems to do the reverse of the desired results. I took a quick look at scottmurphy's code (not a GOOD look) and I am afraid most support personnel would be totally baffled by the logic. But that might not be a bad thing from a programmer standpoint. Like I said, just my two cents. And we all know that does not go far these days!

Share this post


Link to post
Share on other sites
I am all for gtsuport's concept of ladder logic. Why are you trying to make something hard out of something simple? If you are worired about speed, the loop will take microseconds longer. If you're concerned about job security, you just made something entirely unintelligible.

Share this post


Link to post
Share on other sites
depends what you want to do with it.... I have a version where I have to transpose a matrix of 32 bits by 32 bits.... that would make 1024 lines (with possible typos)

Share this post


Link to post
Share on other sites
I agree, and would do the same for the logic, sometimes, if it is not commented, it can be hard for the original programmer to follow that code also! Not defending my code, I was bored and thought it would be a good test for a friday afternoon, however, do understand it, you also need a knowledge of the instructions, and where and when to use them! I did not comment it that well either, just enough to give an idea on what was going on. There is a pretty extensive instruction set available, so it makes sense to take use of them when the need arises, some of them can bu re-produced using indirect addressing etc, the benefit of using the available instructions over indirect, is that there is documentation available for the instructions, this is not always the case with someone elses code. At the end of the day, IMO, if a program is well structured and commented, then it should be reasonably easy to follow.....interpreting the process is another story.....

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