Creating a register array to sequence

rsdoran

Lifetime Supporting Member
Join Date
Apr 2002
Location
Birmingham, AL
Posts
7,371
I am now working with products from Horner...[url]www.heapg.com[/URL] Specifically the OCS and RCS units using CScape software. This vendor has been supplying GE Fanuc with 3rd party devices for years. The CScape software uses terminology and functions similar to GE Fanuc.

The software does NOT have a sequencer function(like AB's SEQ or GE's Drum), does have a SHL (shift left) and SHR (shift right) but they shift one or more bits all at once...and once used will not shift again.

I am trying to develop a sequencer...ie use an array of bits, lets say 16 bits in Register 5 (%r5). What I want is to be able to use the bit level address of this register to turn on outputs or start an action within the plc...ie
Code:
     R5.1                           Out1
|---|    |-------------------------(     )--|
I want to shift and add bit to this register at same time thus FILLING the register..ie
00000000
00000001
00000011
00000111
etc

To give a better view of what I am doing I have a plc tester/trainer built to work with in my shop. This unit has 8 inputs, 6 outputs wired to lights and an HMI that has 12 keys that can be used in ladder code.

A question here prompted me to look at ways to do sequencing, the post was about starting 6 fan motors with a 5 second delay using one PB. I have taken that task a step further by attempting to turn off the 6 outputs in sequence with the timer delay.

I have created a working solution that I think may be sloppy and uses to much code/rungs. I used one of the HMI keys to act as a PB to start a timer which turns on each output after 5 seconds. This requires a line for the initial start sequence that has a timer, I dont latch output 1 yet because of the sequence.

This option requires the use of 2 lines of codes per output, one for the SHL and other to latch output..NOTE I am not using SET/RESET...just latching with branch and XIC that is output. SET/RESET might make it easier but I attempt to avoid using them.

Since 6 outputs are involved and the original start ckt we are at 13 to 14 rungs. Because I used features of the scan to latch the ckts...an XIC of the bit used to turn on the output in series with the output XIO I could just use SHR's to turn OFF the outputs when the bits are true. There are details to work out but overall I am at 20 rungs.

Is this acceptable...I dont think it is...or am I worrying to much about details? Are there ways to create a sequencer with a few functions that could eliminate all these rungs? I know this can be done with multiple timers but that also seemed sloppy to me.

This is NOT a project, just me looking for ways to familiarize myself with NEW software that is PART of my new job. I guess I have gotten use to having sequncer functions built into the software and now want to find a way to create one.

BTW...the SHL and SHR move bits according to the input and count(s). That means if I move a bit once that SHR/SHL is done, I have to setup new SHR/SHL to move bit again. This software also does no allow functions to be branched....ie the need for an SHL/SHR for each output.

Appreciate any ideas.
 
Easy

To shift a bit left just add the register to itself.
The carry represents the bit just shifted out.
To add a new bit add a 1 after added the register to itself.

Note, this can be extended to many words or dword of bits as long as one keeps track of the carry add adds it into the next word.
 
OK, it's about time to FINALLY post the sequencing logic I use on 99% of my projects. Of course I'm quite busy, so I can only give a quick overview which hopefully you can understand by studying and/or actually trying it.

This is VERY generic, so it can be used on nearly ANY brand (I haven't found one I can't use it on... yet). There are many other (and more efficient) ways to create a sequencer, but you can't always use them across brands. As long as you have set and reset instructions available, this works.

I know 'some' people don't like set and reset, but notice how they are always paired together. This comes from the fact that I developed this on old Omron C-series PLCs, which required set and reset to be in the same instruction (the KEEP instruction). Actually, this logic WON'T work unless you KEEP them paired!

Here's the ladder:

|
| STEP 1 IN CYCLE
|----] [------------------------( S )
|
| COMPLETE IN CYCLE
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+
|
| STEP 5 STEP 5 DONE COMPLETE
|----] [-------] [--------------( S )
|
| IN CYCLE COMPLETE
|----]/[---+--------------------( R )
| |
| RESET |
|----] [---+
|
| STEP 4 STEP 4 DONE STEP 5
|----] [-------] [--------------( S )
|
| COMPLETE STEP 5
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+
|
| STEP 3 STEP 3 DONE STEP 4
|----] [-------] [--------------( S )
|
| STEP 5 STEP 4
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+
|
| STEP 2 STEP 2 DONE STEP 3
|----] [-------] [--------------( S )
|
| STEP 4 STEP 3
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+
|
| STEP 1 STEP 1 DONE STEP 2
|----] [-------] [--------------( S )
|
| STEP 3 STEP 2
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+
|
| START IN CYCLE STEP 1
|----] [-------]/[--------------( S )
|
| STEP 2 STEP 1
|----] [---+--------------------( R )
| |
| RESET |
|----] [---+


And here's the (probably lousy) explanation...
The START bit begins the sequence, as long as it's not already running (note the NOT IN CYCLE). This SETS the STEP 1 latch. On the following scan, IN CYCLE gets set, inhibiting START from having any effect. The program now sits in STEP 1, waiting for STEP 1 to finish.

When STEP 1 DONE turns on, this latches STEP 2, and immediately UN-latches STEP 1. It's critical that you understand that part! At no time will you have STEP 1 and STEP 2 both on elsewhere in the scan. Similar to how a bit shift works, but you don't need bit shift instructions. Now we're sitting in STEP 2, waiting for STEP 2 to finish.

When STEP 2 DONE turns on, this latches STEP 3, and immediately UN-latches STEP 2. Now we're sitting in STEP 3.

This repeats for as many steps as you have in the sequence, moving from step to step, BACKWARDS (or UPWARDS) though the ladder.

Eventually you're sitting in the last step (STEP 5 in my example), waiting for that step to finish. When that step finishes, the COMPLETE latch turns on which, in essence, is just another step. Notice though, that on the following scan, COMPLETE will UN-latch the IN CYCLE latch, which in turn, UN-latches the COMPLETE latch.

Since COMPLETE turns on for one-scan, I use this to notify other sections of the program that the sequence is complete.

RESET is just there as a way to clear (reset) the sequence.

I'll let you digest this part, then come back with questions. Once you fully understand how this functions, I'll add complexity to it... :D

beerchug

-Eric

P.S. I think it was Paul who 'broke' your website by posting his mug there yesterday!... :p
 
Drum Sequencer

A bit-pattern sequence is NOT how I would go about doing cascaded converyor control.

But, just for the intellectual exersize, one method to build your own drum sequencer is to use an indirect move (IMV) instruction of CScape.

For example, you could set up a series of registers with the following values:
Code:
%R100   101
%R101     0    (0000)
%R102     1    (0001)
%R103     3    (0011)
%R104     7    (0111)
%R105    15    (1111)
%R106    14    (1110)
%R107    12    (1100)
%R108     8    (1000)
%R109     0    (0000)

And in ladder set up a "STEP" register (%R099) which will have values 0 to 8, and populate a bit pattern in %R200:

+-----+ +-----+
| ADD | | IMV |
--------| |----------------| |--------
%R099--|In1 | @R100--|IN |
| Q|--%R100 | Q|--@R200
101--| | 1--|N |
+-----+ +-----+



When you are on step 3, %R099 will be programmed to equal 3 (below), thus %R100 will equal 104, and so %R200 will have the bit pattern 0111.

This is nice because your output code is simple:

%R200.00 MOTOR_1
------| |-------------------( )

%R200.01 MOTOR_2
------| |-------------------( )

etc.


If you need to change the order of how the motors start, all you need to do is change the values in %R101 to %R109


For controlling step numbers, there are several good ways. The simplest is to just move a new value in when you are on the step and whatever transition conditions are appropriate (The following uses Erik's example for the transition from step 2):

+-----+ STEP_2_DONE +-----+
---------| EQU |----+-------| |---------| MOV |
%R099--|IN1 | | 3--|IN1 |
2--|IN2 | | | Q|--%R099
+-----+ | +-----+
|
| RESET +-----+
+-------| |---------| MOV |
0--|IN1 |
| Q|--%R099
+-----+




But there's more than one way to control the Step number. If you don't have individual "STEP_1_DONE", "STEP_2_DONE", etc., transitions, but perhaps just a single timer, your logic could look like this:

TIMER_DONE +-----+
------| |-------------| ADD |
%R099--|IN1 |
| Q|--%R099
1--|IN2 |
+-----+



Anyway, you get the idea.
 
Last edited:
I appreciate what y'all have offered, I will add all this to my collection.

Actually to do what I wanted I found an instruction that was so obvious that I wanted to "smack" myself along side the head.

CScape has a ROTATE (ROR) function that allows you to use a word or double word register, using either I can create setpoints...ie fill in half the register with 1's and other half with 0's, this allows me to have 8 bits per register that I can turn on/off in sequence using a timer or any condition(s) that may be needed. Using a double word I can shift 16 bits.

The key to this was that SHL & SHR (shift bit functions) only triggered once so one had to be created for each shift. With the ROR or ROL I could trigger them with a timer pulse and it shift every 5 seconds (or as needed).

I got to work this morning and after about 30 minutes of messing with the other functions I tried the ROR and had a working soulution in a few minutes, maybe 30 minutes later I had 11 lines of code that did what I wanted...sequenced on in order when PB was pushed and sequenced off when another PB was pushed. IT would also stop and reverse sequence anywhere in between during either sequence. I didnt add a STOP but that part would be simple.

What I have is 1 timer, 1 ROR, 1 ROL, 2 rungs to latch in direction then 6 rungs to latch the outputs which makes a clean looking 11 rungs of code that should be easy to understand.

Thanks alot, now I am off to see the wizard to see if he can give me a database.

Thanks also for the comments about the site, its partially my fault but is related to aspects of the domain host. I am going to move the site and hopefully restore the database in the process in the next few days. I still have the database but need a wizard to do magic to get it back to that dimension it needs to be in.

P.S. Think Paul's finger had anything to do with it?
 
I am always impressed with how you folks can explain things so clearly...even I can follow along! Ron, when you get time I hope that you will post your solution, too. And we all eagerly await the return of that "other" forum. I think that we are misinterperting the potential effects that Pauls' questionable finger photo may have had on its' demise...I think it was the Chinese astronaut's craft that did it. :D
Have a nice quiet weekend everyone, I'm off to Keenland for the Fall Race meet w/ my daughter...she did a video add about the racecourse for her senior project at UK, and they thanked her by giving her a 8 seat box for this weekend!!!now what was that horse I liked for the Fourth race.......
David
beerchug beerchug beerchug beerchug beerchug
 
I had to fit a picture together so some of it may seem out of kilter. Ignore the branches on the output rungs that have F keys, they are there for testing. NOTE: F keys are buttons on the HMI part of this type plc.

ITs amazing, posting this picture I see inconsistences I didnt see earlier...any of you students notice it?

bitrotate.jpg
 
Last edited:
Ok here is one more idea, just to cover the topic.
( sorry everyone, I guess I made a mess although it was not my intention.
I guess I'm getting tires and I hope moderator will fix this...)
 
Last edited:

Similar Topics

I am trying to create a cash register. I have 9 buttons. This diagram shows how it is set up. 2 5 8 1 4 7 0 3 6 2= Whopper combo 1= Whopper Dbl...
Replies
5
Views
1,993
The idea here is to provide for a brief rapid influx of message codes while preventing sequentially repeating the same message. i.e. if two...
Replies
22
Views
426
Hello everyone, In a factory where we installed Citect 7.20 the computer began to show the first signs of end of life. They never considered...
Replies
0
Views
57
Hi everyone, I'm a last year student at the university in Ghent, and for my thesis i need to write a TwinCAT program that writes data to a .daq...
Replies
0
Views
118
When I go to create a new module in Studio 5000 I can't enter any information for the IP Address or change any other fields. Is there any fix to...
Replies
1
Views
238
Back
Top Bottom