Allen Bradley SLC and M 1000 count down counter

weilerot

Member
Join Date
Nov 2004
Posts
19
I searched the threads and did not see an answer that applies to my question. The CTD for a SLC 500 and M 1000 counts down to -1 before the DN bit will set. The CTU counter does not act the same way. For example if I want to count down ten boxes before an event will happen, I have to go to a -1 before the event will happen. If I count up ten boxes then when the counter reaches ten the DN bit will set. Now I know that I can do a compare statement and get the desired results. I do not understand why the CTD behaves this way.

Thank,

Herb
 
either type of “counter” (CTU or CTD) obeys the following rule:



if the value in the ACCUMULATOR is GREATER THAN or EQUAL TO the value in the PRESET, then the DONE bit will have a status of ONE ... otherwise, the DONE bit will have a status of ZERO ...



note: we’re ignoring potential issues with an “overflow” or “underflow” condition here ...



so ... tell us more about your problem and we’ll try to help you understand ...



basic secret handshake: there is only ONE actual “counter” for C5:0 ... that “counter” is located in the processor’s data table ... the things that you are calling a “count up counter” and a “count down counter” are actually INSTRUCTIONS to the processor ... one of them (CTU) basically tells the processor to “add one to the accumulator” ... the other (CTD) basically tells the processor to “subtract one from the accumulator” ...



the part that confuses most people is that there is ONLY ONE DONE BIT for C5:0 ... specifically, there is NOT a DONE bit for CTU counter C5:0 - and ANOTHER separate DONE bit for CTD counter C5:0 ... more specifically, both of these “counter instructions” SHARE THE VERY SAME DONE BIT ...



once you’ve got that fact nailed down, then things usually start making more sense ... if this doesn’t answer your question, you might want to tell us what book you’re reading on the subject ... many of these documents (even official ones) have errors on this particular topic ...
 
Last edited:
Ron thank you for your reply. But I wrote a simple program with a CTD. I put 10 in the accumalator and pulsed it down. The DN bit did not set until the accum reached -1. This is not a real problem because I can use a compare statement when the CTD reaches zero. I just wanted to know why the CTD does this and the CTu does not. I did not know that the CTD and the CTU were one in the same. I thank you for that fact.

Herb
 
Herb,

Is it because the CTD needs to be able to count to 0, if you reset it at 0 then it would start counting again. That's the only reason I can think of.
Cheers
Peter
 
weilerot said:
I put 10 in the accumalator and pulsed it down. The DN bit did not set until the accum reached -1.
Look at this page from the instruction set reference manual. If the accumulator is greater than or equal to the preset then the DN bit will be set. The rule applies for ALL counters, it doesn't matter if the counter is being decremented by the CTD or incremented by the CTU.

A030308C.JPG




This is not a real problem because I can use a compare statement when the CTD reaches zero.
If you want the DN bit to clear when zero is reached then put 1 in as the preset. Then as soon as ACC < PRE, that is, ACC is less than 1, the DN bit will clear.
_______________________________________________________________

Lets look at this hypothetical program. The local airport restroom cleaning lady is a bit shy and just doesn't want to be walking in on the men doing there business, so an entry and exit turnstile are installed and a ML1K keeps track of how many men are in the restroom.
A030308e.JPG

As you can see, theere are 4 men in the restroom. The C5:0/DN bit is set and the RESTROOM_NOT_EMPTY light is on and the CLEANING_LADY_LIGHT is out. One exits. The counter decrements to 3. Another exits, the counter decrements to 2. One man enters, the counter increments to 3. Two leave, now the counter is at 1. The counter accumulator = the counter preset so the DN bit is still on. The RESTROOM_NOT_EMPTY light is still on as it should be.
A030308F.JPG


Finally the last man leaves, and the counter decrements to zero.

A030308G.JPG


Now the counter accumulator is less than the counter preset, and the DN bit finally clears. The RESTROOM_NOT_EMPTY light goes out, and the CLEANING_LADY_LIGHT goes on. The cleaning lady springs into action, blocks the door to the bathroom with her cart and speedily cleans the restroom, free from any emberassment from catching sight of some guy's unwaranted pride.
 
from Herb:

Thanks guys, I completely understand now.



well, good ... and that puts you a step ahead of the guys who write most of the official books ... let’s take another look at that screen shot posted by my distinguished colleague, Alaric ... (note: the part that he circled is OK ... but) ...



ctd_alaric.jpg




actually the operation of the Count Down Underflow Bit UN (bit 11) could more accurately be described as follows:



=================================================================



IS SET WHEN:

accumulated value wraps around to +32,767 (from -32,768) and continues counting down from there ...



specifically, the official text basically has the two values (and their signs) reversed ...



=================================================================



AND REMAINS SET UNTIL ONE OF THE FOLLOWING:

a RES instruction having the same address as the CTD instruction is enabled ... (that first part is OK) ... OR the count is equal to +32,767 and then wraps around to -32,768 when incremented with a CTU instruction ...



specifically, you cannot increment the value to be GREATER THAN +32,767 ... and if you increment the value to be EQUAL TO +32,767 then the UN bit still stays SET ...



=================================================================



notice that they came “closer” with the Instruction Set Reference Manual for the SLC500 and MicroLogix1000 ...



ctd_slc.JPG





case in point: we're all human - and we ALL make mistakes ... even the guys who write the official books ...


side note to Alaric: which book did you get your screen shot from? ... I can’t seem to find the same copy ... this one needs to go in my collection ...
 
Last edited:
Ron Beaufort said:
side note to Alaric: which book did you get your screen shot from? ... I can’t seem to find the same copy ... this one needs to go in my collection ...

It came from the MicroLogix 1000 users manual, Publication 1761-6.3 – July 1998, page 6-19

Good catch on the UN bit, I didn't even look at that.

 

Similar Topics

I am looking for the full version of the Software, thank you for your help
Replies
6
Views
373
HELP! I've been searching & searching for the software to run my SLC150 PLC for DOS 6.22 and for some reason, every link I have found for it -...
Replies
4
Views
1,152
Hi all, Client has a hard faulted SLC 5/05 Revision B CPU, and I'm wondering if a Rev C or D can be directly swapped. Thanks!
Replies
3
Views
1,124
Hello! We have a drum rotation machine controlled by a AB SLC 500. The drum rotation inputs comes from a encoder into a 1746-HSCE. We are using 2...
Replies
0
Views
1,134
Hello! We have a drum rotation machine controlled by a AB SLC 500. The drum rotation inputs comes from a encoder into a 1746-HSCE. We are using 2...
Replies
5
Views
2,246
Back
Top Bottom