How too:

solthiest

Member
Join Date
May 2008
Location
louisiana
Posts
6
I am trying to write a program where I have a normally open pushbutton that will turn on a motor when pushed, then when the same pushbutton is pressed the same motor will stop. And if pressed a third time the motor will again run. I am using RSLogix btw. Any help would be of most welcome.
 
Well I looked at the replys then I sat down infront of my PLC computer and I came up with this (bear with me I didn't scan it so I am going to try and write out what I did lol):

(NO) input to a counter (C5:0) with 3 presets
a (NO) contact latched threw the DN side of the counter to my < output
the same (NO) input (or pushbutton as in rung 1) and another counter (c5:1) with 4 presets
a (NO) contact from the C5:0/DN to a reset for C5:0
a (NO) contact from C5:1/DN to a reset for C5:1

this worked, well thnx for the help it sort of pointed me in the right direction.
 
Sounds convoluted. It might have worked, but it isn't the right way to do it, and since the aim of your assignement is to learn how to do it then I'll suggest a couple of simple solutions, but its up to you to understand why the solutions work and how to apply them.

The simplest way is

Button Oneshot* SS_bit
-----] [-------[OSR]-------------------( )--

SS_bit SS_bit Motor
-+-----] [-----+---+----]\[-----+------( )--
| | | |
| | | |
| | | |
| Motor | | Motor |
+----] [------+ +----]\[-----+



The first rung produces a single shot bit that is true for one scan only. The single shot bit toggles the state of the flip-flop logic in the second rung.

*If you are using a Micrologix 1100, 1200, or 1500 then use the ONS instruction instead of the OSR instruction.

If you want to use a counter then use the least significant bit of the counter accumulator and don't worry about the counter DN bit or what the counter preset is. Look at the binary value of the counter:
0 = 0000
1 = 0001
2 = 0010
3 = 0011
4 = 0100
5 = 0101

Did you notice that everytime the counter changes value the least significant bit of the counter changes state. It is 0 when the number is even, and 1 when the number is odd. The only thing to watch out for is that a counter is retentive. That is, if your turn your motor on, and then the power goes out, when the power comes back on your motor will too, and sometimes that is bad.


BUTTON
------] [-----------------+-----------------+-(CU)-
| CTU |
| Counter C5:0 +-(DN)-
| Preset 0 |
| Accumulator 0 |
+-----------------+

C5:0.ACC/0 MOTOR
----] [--------------------------------------( )-



There is no need to program a reset for the counter ever, EXCEPT if you want to use this method and you do not want the motor to restart after a power failure, in which case use the first scan bit to reset the counter.
 
Last edited:
Without a reset, what happens when the Counter.ACC = 32767 and the counter is triggered again?

I always thought it just stayed there and didn't rollover but, I don't remember ever testing this.
 
in short, rolls over and continues to toggle the bitI tried to search it, but Alaric and I had a conversation several years ago about it... when he told me that it would roll over, I decided to test it.... I think that was the last time I tested any thing he said :) I tried but could never prove him wrong on anything (YET) ;)
 
That is the beauty of 2s compliment numbers.

32767 = 0111 1111 1111 1111

When you add 1 to it you get

1000 0000 0000 0000

Which is -32768. Now add another 1 and you get

1000 0000 0000 0001

and so it goes all the way around until you get to

1111 1111 1111 1111

Which is -1. Add 1 to that and you'll generate a carry, and get

0000 0000 0000 0000

Since the counter instruction takes care of any overflow or carry you don't need to worry about the actual value of the counter ACC, just the state of ACC/0.

While using a counter for a flip flop is a neat trick, Its not how I prefer doing them, I usually use something like the first example because it is not retentive and you can easily include reset logic in the same rung with the flip flop logic.


Button Oneshot SS_bit
-----] [-------[OSR]-------------------( )--

RESET SS_bit SS_bit Motor
--]\[----+----] [-----+---+----]\[-----+------( )--
| | | |
| | | |
| | | |
| Motor | | Motor |
+---] [------+ +----]\[-----+


 
I appreciate the compliment Mark, but I make lots of mistakes.

Take the other day for example.... I came home from work and after a while my wife asks me "Well, did you notice?" I answered "Notice what?" ;)
 
Alaric said:
I appreciate the compliment Mark, but I make lots of mistakes.

Take the other day for example.... I came home from work and after a while my wife asks me "Well, did you notice?" I answered "Notice what?" ;)

How is the dog relating to sharing his quarters with you?

Dan Bentler
 

Similar Topics

Today I was working on my project for school and we were using a power supply with 24V and we accidentally had the current at 0.9A. We heard a pop...
Replies
9
Views
554
...and I agree. Context: TIA Portal/HMI = KTP1200 (12" screen) In the attached redacted image, the values in the white boxes are entered by the...
Replies
10
Views
723
Hi to everybody. I need to read the first 12 characters of the message that a barcode reader sends to the ascii card (1734-rs232 ascii) and I...
Replies
8
Views
730
Hi all, Can a machine be "too safe"? I originally wanted to ask a different question about best-practices when switching a machine from non-auto...
Replies
9
Views
960
It better to have too many instead of not enough right?
Replies
26
Views
2,899
Back
Top Bottom