Sign in to follow this  
Followers 0
Div_by_zero

need help with a little output sequencing program

9 posts in this topic

OK, this is going to be *extremely* basic for most of you, sorry for the noobishness. I have one input (let's call it the triggering input) and 4 outputs (AB Micro 800, FYI). Outputs are 1,2,3,4 let's say. When I catch the rising edge of the triggering input, I need to cycle to the next output. Let me now add that each output can be enabled or disabled via its own switch (which actually makes 5 total inputs…) If all 4 outputs are enabled via their switch and the triggering input goes high repeatedly, the sequence is 1,2,3,4,1,2,3,4… Let's say (for example) output 3 is disabled. The sequence would be 1,2,4,1,2,4… What would be the best, most concise way to code the indexing and skipping aspect of the logic? Edited by Div_by_zero

Share this post


Link to post
Share on other sites
Hi, Might not be the most efficient but a counter as being a sequence number mould do. If you do it with ladder, you will probably loose 1 CPU cycle going from 4 to 1. Writting a function seems the most efficient to me but would work on arrays to be short... Say, if you call the function on the trigger RE : output[count] :=0; //unlatch actual output watchDog:=0; //used to avoid endless loop REPEAT IF count<3 then count :=count+1;//increase up to 3 ELSE count:=0 //or back to zero END_IF; loopWatch:=loopWatch+1; //loop counter if all condition switches are off (might happen) output[count] :=condition[count];//output equals its associated condition; UNTIL (output[count] or (watchDog>=4)) // until an output has been set, or none END_REPEAT; Chek the syntaxe, I just wrote this like that, it's the idea, not the solution. count should be persistant to 'survive' from one function call to another. That is if you copy your switches into an array and outputs from another one. Hope it helped. Edited by drx

Share this post


Link to post
Share on other sites
Thanks. I guess I would add that code (or something very similar) as a "structured text" entity? edit: yes, this is obviously structured text. The syntax (as you alluded to) is off. It's giving me a hard time over the ":=". I am also confused as to what the bracketed program entities do, how they work? Edited by Div_by_zero

Share this post


Link to post
Share on other sites
there are MANY ways to do this. language is not important, use one you know. here is an example that uses bit shift. on powerup, bit_shift register is initialized (only LSB is set). on trigger, bit_shift is ... shifted. AB has instruction for it but i tend to use more efficient substitute (in this case an ADD instruction). because: 1 = 1 (starting value) 1+1 = 2 2+2 = 4 4+4 = 8 8+8 =16 (greater than 8 so we re-initialize to 1) rest is just mapping bit_shift register bits to outputs. an alternative is to use count for example.

Share this post


Link to post
Share on other sites
Hi Panic, Thanks for the examples! The indexing will work fine (The *exact* way that would have to be coded on the Micro 810 is slightly different than what you have there as it's a slightly less powerful device). I don't see any provision to skip a disabled loader position though. If one or more of the (4) outputs is disabled via 4 separate swathes wired to the inputs, it must be skipped in the sequence.

Share this post


Link to post
Share on other sites
true again, how about this one:

Share this post


Link to post
Share on other sites
Awesome, thanks again. What PLC are you using, and is that Logix 500? I know exactly what you mean about connected components. I simply cannot begin to imagine how on earth it takes 2 gigabytes worth of compilation to make that program. It's like what are they doing in there?!?! Not to ask a stupid question, but how did you get it to say "COUNT" highlighted in green in your code? Edited by Div_by_zero

Share this post


Link to post
Share on other sites
Hi, The ladder would do, the one thing is, as I said in my first message, if loosing 1 cpu cycle is allowed or not. Say you get into the ladder routine beeing on Position 3, with enable4=OFF and enable1=ON : you would expect ouput1 to be ON when leaving the routine as it is obviously the next one on the "activation list" But when you'll reach the end of the routine, output3 and output4 will be OFF as they should, but output1 will be OFF : It will take to wait until next CPU cycle to be calculated correctly. It's just a detail, it might not be important for your application, if so, the ladder should do the job just the same, and for sure, can be a bit more comprehensive than a structured text algorithme. But this one guarantees you loop-checked everything from next to previous, and in the conditions above, you will reach the end of routine with output1 =ON as it should. As for the code I wrote, it's just an general algo, I'm sorry if the syntaxe is not exactly correct like it should, but I write code in many langages and come to mix them sometimes. Good luck.

Share this post


Link to post
Share on other sites
hi drx, you are right of course, for example i provided, described case (and it is not the only one), would set an output one scan time later. div_by_zero didn't ask for this so i left it out. i felt it is more important to provide an easy to understand example. but this has nothing to do with ladder. to make it happen every time in a same scan, one just need to separate mapping to outputs and use loop for example to determine next output. in fact loop is really not needed, it is enough to run check second time before setting outputs.

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