Shop OBEX P1 Docs P2 Docs Learn Events
door limit switch — Parallax Forums

door limit switch

coldspringscoldsprings Posts: 14
edited 2010-10-25 17:45 in BASIC Stamp
is there a way to have a program run on the BS2 and have a limit switch act as an interupt? I need to install a limit switch on a door for a machine run by the BS2 and I'm not sure how to go about having a "Go" button scanned and a "kill" button scanned at the same time.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-13 08:28
    It all depends on how the BS2 is controlling the machine. Typically, you have some kind of main control loop in your program and you'd have a test for the limit switch in the main loop. If the limit switch is on, the main loop would exit to something that would activate a brake or braking mode.

    In the case of a "kill" switch, you really want some kind of external hardware involved. A "kill" switch should be able to override the BS2. Often that's done with some kind of relay that cuts power to the motor and may activate a brake or may short the motor windings to cause braking. Typically this relay must be activated to enable the motor so, when power fails, the motor is "kill"ed.

    The BS2 doesn't have an interrupt. You could reset the BS2, but that's indistinguishable from turning the power off and then on. The BS2p does have what's called "polling" which can force execution of one program when an I/O pin is activated, but there's no way to return to the previous point of execution. That may be ok in your situation. Have a look at the POLLIN, POLLRUN, and POLLMODE statements in the Stamp Manual.
  • coldspringscoldsprings Posts: 14
    edited 2010-10-13 12:56
    thank you Mr. Green, the poll statements would have suited my requirements perfectly, alas I am running on the BS2, oh well. I think I will get a NC relay and connect it to the BS2 power supply to reset the program.
  • coldspringscoldsprings Posts: 14
    edited 2010-10-14 04:01
    I was thinking more about it last night, is there a way to test out of the main loop and then set a test in a secondary loop? Or is it setup to where the program can do nothing else but scan 1 button input at a time?
    I'm trying to make the two button setup work because when the door is opened, there is a blinking light to indicate that the door is open, and if I wire it into the emergency stop button (which is a NC pushbutton) it will reset the stamp to the beginning of the program but will not have the blinking light.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-10-14 06:57
    You can put whatever tests you want in your main loop or your secondary loops. These tests are all IF / THEN statements that then GOTO somewhere.
  • ercoerco Posts: 20,256
    edited 2010-10-14 08:42
    Many different ways to wire up a kill switch on an automatic door, most of them are hardware, external to the Stamp. Do you really need a Stamp? Please fully describe your application; you might only need a DPDT relay, in which case you can save your Stamp for something more fun.
  • coldspringscoldsprings Posts: 14
    edited 2010-10-14 11:34
    the machine is a cleaning machine, it controls a vat with an ac motor, 2 ac blower fans for drying, 1 ac exhuast fan, and 1 dc controlled pnuematic valve for a air syphon system, as well as a go button, door limit switch and E stop button.

    when the machine is idle the GO button has a solid green light, when you press GO the green light extinguishes and then the red light on the E STOP button lights up. The vat motor, alcohol pump, and exhuast fan kick on when GO is pressed and the stamp pauses for 25 sec. The next part of the program shuts off the pump, leaves the exhuast and vat motor on, and also activates the blower fans for 3.5 min.

    If you try to start the cycle when the door is open the GO light flashes three times and pauses for 5 sec. to indicate the door is open, it also won't start the cycle. I would like to program the limit switch on the door to also do this in mid program in case some knuckle head wants to open the door while the machine is running.

    The stamp controls all of the AC componants via solid state relays, it also directly controls the pump and the lights through the Dout's. I've been able to slightly accomplish the safety on the door in two ways.

    the first. The program runs as planned lights and all. When the door is opened at anytime the program goes to a cuation sub and then to the main loop when the door is closed and locked. The only problem is I can't get the program to procede past the vat, pump, and exhuast fan running, it's stuck in an infinite loop.

    the second. The program and lights work as planned all the way through the program from start to finish. The problem is if you open the door in between the stamp pauses, it will react to the limit switch after it finishes that particular pause.

    I'll try to post my code in a little bit.
  • ercoerco Posts: 20,256
    edited 2010-10-14 21:38
    Hey coldsprings: It sure sounds like you need a Stamp! :) You might even be able to use a BS1 and save some cash. If you're building the Stamp in, consider it. The BS1 Project board is nice, has 8 I/Os. and costs $30: http://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/119/Default.aspx?txtSearch=stamp+1
  • ercoerco Posts: 20,256
    edited 2010-10-14 21:46
    Regarding the pauses, you don't want to do a pure 25 second pause if you need an immediate reaction like a door being opened. You want to execute a loop something like this:

    for b0=1 to 50
    if (door is open) then abort
    pause 500
    next
    ...
    ...
    ...



    abort:

    That keeps your program looping for about 25 seconds (50 loops of one-half second each) and jumps to label 'abort' if the door is opened.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-10-15 06:18
    When the door is opened at anytime the program should go to a STOP
    condition and stay STOP until the door is closed and the user pushes the START BUTTON to re START the machine

    When you close the door again you may not be out of the way far enough when the machine re start on it own that is not good for the user

    Could you PLEASE explain why the door needs to be open-en and depending on why there maybe a better way to write your code just an :idea:

    I understand most of what you have here but two thing I am not clear on why and what you have here


    when the machine is idle the GO button has a solid green light, when you press GO the green light extinguishes and then the red light on the E STOP button lights up. The vat motor, alcohol pump, and exhaust fan kick on when GO is pressed and the [What happen here and why] [stamp pauses for 25 sec.]<
    What happen fron> here to here< dose it run for so many minutes
    >The next part of the program shuts off the pump, leaves the exhaust and vat motor on, and also activates the blower fans for 3.5 min.



    I seen some machine do this in some way or another and I can see some bad thing could happen with this setup

    This is just my though on what I have seen
    I have also work on production machine before and if I where doing a project like this I would write the code in a way that user had to restart the machine
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-10-21 17:58
    I run this type of Industrial Program with Stamps all the time.
    The secret in making it work is to wait just a little bit at a time, over and over and over.
    You always have to keep looking at your Emergency stuff and whatever needs to be done at the time.
    I use a bunch of mini loops each time the machine function changes.
    The Stamp may be slow, but it is way faster then this type of machine, and can do lots of looping between switch presses.

    I check switches, execuite output processes, and monitor everything that needs to be monitored.
    I stay away from For/Next loops. If you need to leave the main loop, you can get caught up in the For/Next Nested Loop Limit problems.

    As for the Emergency Stop, it has to Operate in any failuire mode.
    The door switch also needs to interupt motion, and any processes that could cause harm to persons or equipment.
    It needs stop motion wheather the Stamp is running or not.
    An E-Stop switch is designed to operate even if its contacts are welded shut from overcurrent.
    It has no spring mounted contacs like other types of push button switches.

    I will post some code tomorrow morning, and a sample of my E-Stop circuit.
    I will have more time and have access to mt CAD program at the office.
    Too much going on tonight.
    It will better show what I am talking about.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-10-22 06:16
    Alan Bradford

    Could you post a working code that used in the past so I can get an idea of how you did it

    Thanks SAM
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-10-22 07:18
    I have attached a schematic of my BS2 Emergency Stop Circuit.

    The E-Stop Switche(s) must be closed.
    When the Power On Push Button is pressed, DC Input (P0) lets the Stamp know that Power wants to turn on.

    The Stamp will then turn on output P5 and allow the Power On Relay to Enregize.
    This way if the Stamp is not running or some condition the Stamp is monitoring is not met, the system cannot turn on.
    The Stamp cannot turn on the System, only 'Allow' it to turn on.
    Only by pushing the Power On Button can the system turn on.
    Anything can shut it off.
    The CR1 contacts act as a latch to the on circuit.
    The Drive Fault Contacts are in series with the latch.
    If you have a device thea takes a few seconds to power up before removing a fault condition, then this is where to put the Fault Contacts.
    When you push the Power On, you need to hold it a few seconds to clear the fault, then the circuit latches on.

    When the E-Stop is pressed, CR1 drops out, the Stamp senses this (P0), and turns off the Power Enable Output.
    The BS2 also Flashes Output P10 E-Stop Lamp indicating the machine is in E-Stop Mode.
    The Power On lamp Should be On when the System is Energized and ther E-Stop LAmp should be on (or flashing) when in Emergency Stop Mode.

    On the software side:
    I have attached a sample program, and some of the code is here:
    This is from a Plasma Cutting Machine.
    The Stamp is the interface between the Main CNC, and the Plasma Torch.

    CNC_Run:
    '
    LOW Cut_Sense 'Arc On Signal to the CNC
    '
    IF Cut_Control = 1 THEN Plasma_Stop
    IF Process_Off = 1 THEN Plasma_Stop
    IF Machine_Motion = 1 THEN Plasma_Stop
    IF E_Stop_Sense = 1 THEN E_Stop
    IF Drive_Fault = 1 THEN E_Stop
    IF CNC_THD = 0 THEN CNC_THD_On
    IF CNC_THD = 1 THEN CNC_THD_Off
    '
    GOTO CNC_Run
    '
    CNC_THD_Off:
    '
    HIGH THD
    GOTO CNC_Run
    '
    CNC_THD_On:
    '
    LOW THD
    GOTO CNC_Run
    '
    At this part of the program we are on and monitoring all the switches for Action.

    Turning on Cut Sense (Low is On), we are telling the Main CNC to start moving the machine.
    We then look at all the switches and inputs that are used at this point.

    I use If-Then for looking at the inputs.
    If something needs attention, we go off and do it then come right back and continue looking at the inputs.

    The if one of the major inputs is active, like Plasma_Stop, or E-Stop, then we go to that part of the code, and have no need top return. This is why For-Next loops dont work so good. If you dont come back, you dont have to worry about clearing the nest.

    When you go do something and it ios more than 2-3 lines of code, then you must add the Stop, Emergency-Stop, and other checks in the new loop.

    In our case we dont care if something happens in 1 millisecond or 500 miliseconds.
    If timing is critical below .01 seconds, then you may want to use a Propeller (with an interupt) or a PLC.

    For long time delays use an external timer chip and look at the time.
    Do not use a Pause Delay of more than 1.
    This is what I call waiting in little bits...

    For a 2 Second Pause:

    2_Second_Pause:
    '
    X=X+1
    IF Cut_Control = 1 THEN Plasma_Stop 'Look at your Monitored Inputs
    IF Process_Off = 1 THEN Plasma_Stop 'Do stuff whilre waiting
    IF Machine_Motion = 1 THEN Plasma_Stop
    '
    Pause 1 'Wait as little bit, then check the delay
    '
    If X < 1000 then 2_Second_Pause

    X = 0

    (Go on to other Stuff)

    You will have to modify the X < 1000 to get close to your desired time as the code executed will also effect the total delay time

    Hope this helps and dosen't confuse you more.
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-10-22 09:44
    Here is the Program saved as a text file.
    It was a .BS2
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-10-22 13:07
    Alan Bradford

    Thank you for posting that code it help in the fact of other way to write code routine with out using DO LOOP as well

    One thing I learn from your code is that you can reload your program or I am I wrong in thinking that way

    I know this maybe asking to much BUT could you post the Set up code Thanks

    I am going to steal any thing by ask you to do this

    At the last job that I was at I was ask about writing a program for a machine that the controller kept having all kinds of problem but that problem was finally fixed >>> Controller Cable / Switch Box

    I might be going to another job doing the same kinda thing Facilities Maintenance

    I have not seen code for input and outputs set up this way

    Reset_PLC:
    '
    ' Turn Off All Outputs and Reinit the Program
    '
    '*****Set I/O's*****
    '
    ' Inputs
    '
    INPUT E_Stop_Sense 'Senses the State of the E-Stop Button
    INPUT Cut_Control 'Edge Cut On Signal
    INPUT CNC_THD 'Edge Torch Height Disable Signal
    INPUT Plasma_Start_PB 'Manual Plasma Start Push Button
    INPUT Process_Off 'Plasma Stop Push Button
    INPUT Machine_Motion 'Machine Motion from Plasma/THC
    INPUT CNC_Manual 'Selects CNC or Manual Mode
    INPUT Drive_Fault 'Servo Drives Powered UP and Enabled
    '
    ' Outputs
    '
    OUTPUT Power_Enable 'Allows the System to Power UP
    OUTPUT E_Stop_Lamp 'E-Stop Lamp
    OUTPUT Plasma_Start 'Plasma Start Signal to the Command THC
    OUTPUT THD 'Torch Height Disable Signal
    OUTPUT Plasma_Lamp 'Plasma On Lamp
    OUTPUT Cut_Sense 'Plasma Motion Signal to the CNC
    OUTPUT Drives_Disabled 'Lets CNC know the Drives are Enabled and no faults.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-10-22 13:40
    coldsprings

    I am sorry if you think that I high jack this post
    I did not mean to
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-10-25 16:37
    Sorry I have been out of touch for a few days.
    Ill post the complete program when I get to the ffice tomorrow.
  • wiresalotwiresalot Posts: 40
    edited 2010-10-25 16:45
    An E-stop Is not to be in the programing of a PLC,

    EMERGENCY STOP LOOP -
    All control equipment shall be provided with a direct hard wired (independent of PLC's / Programmable / Electronic controls) Emergency Stop Loop. The ESTOP loop shall be wired such that interruption of any of a series string of NORMALLY CLOSED contacts shall drop out a master seal in relay. Upon resetting the activating device(s), a momentary NORMALLY OPEN operator is required to be used to seal the loop back in.

    You can however use the PLC to monitor the E-stop circuit.

    wiresalot
  • Alan BradfordAlan Bradford Posts: 172
    edited 2010-10-25 17:45
    The PLC (or in this case Stamp2) is a NC contact in the E-Stop String.
    It can drop the E-Stop circuit. but cannot start it.
    I put it the PLC in the circuit so the machine could not be turned on if the PLC was not on and running properly.
    It is another NC set of contacts that must be satisfyed for the power to turn on.

    We are using Safety Relays now and redesigning our Power on Circuit to conform to the stricter Canadian Safety Rules.
    We have a control voltage that stays on all the time to run the Stamp and safety relays.
    This way we can monitor the faults and Flash the E-stop Indicators to let the operator know the machine is in E-stop.
Sign In or Register to comment.