Shop OBEX P1 Docs P2 Docs Learn Events
Switch it on here, switch it off over there... — Parallax Forums

Switch it on here, switch it off over there...

TtailspinTtailspin Posts: 1,326
edited 2015-06-21 06:52 in Propeller 1
PUB Switch_Changed | CurrentSwitchState
'if any switch changes state for long enough,
'then turn SSR pin on if it's off,
'or off if it's already on.


I want to upgrade the vacuum system in my workshop.
I have three push on/push off switches(SPST), and would like to have as many as eight.
I would like to be able to activate the switches like three way switches on a flight of stairs or a hallway... In other words I would like to turn on the vacuum here, and be able to turn it off over there.

I can't seem to grasp such simple logic using Spin. It's not Spin, it's just me...
I tried a few things, but they seem 'Cludgy' and not very elegant.
How would you go about this, using a Propeller MCU and Spin?

Brother, can you spare a few lines of code to get me started?


-Tommy (can't figure it out) Tailspin

Comments

  • Mark_TMark_T Posts: 1,981
    edited 2015-06-13 01:58
    If they are push switches you just need to repond to any of them being pushed by changing the output state.

    If they are toggle switches you respond to any of them changing state by changing the output state.
  • idbruceidbruce Posts: 6,197
    edited 2015-06-13 04:13
    Tommy

    This is not that difficult, just run a loop which checks the input states of the switches (use software debounce for the switches).

    if INA 1, 2, 3, or 4, then change OUTA 5 state of relay.

    EDIT: Or you could simply control relay state with the Prop, and then control the vacuum system with three-ways and four-ways after the relay
    CON
    
      _CLKMODE                      = XTAL1 + PLL16X
      _XINFREQ                      = 5_000_000
    
      PB1 = 1
      PB2 = 2
      PB3 = 3
      PB4 = 4
    
      RELAY = 5  
     
    PUB Main
    
      DIRA[PB1]~
      DIRA[PB2]~
      DIRA[PB3]~
      DIRA[PB4]~
      DIRA[RELAY]~~
      
      OUTA[RELAY]~
    
      REPEAT
      
        IF INA[PB1] OR INA[PB2] OR INA[PB3] OR INA[PB4]
        
          WAITCNT(CNT + CLKFREQ \ 10)
    
          !OUTA[RELAY]
    
  • Don MDon M Posts: 1,652
    edited 2015-06-13 06:35
    My brother has a machine shop that has a vacuum system connected to many machines. I installed a garage door remote for him. He can take the remote to the different machines or buy additional remotes if necessary. Just an idea.
  • kwinnkwinn Posts: 8,697
    edited 2015-06-13 06:41
    You can have as many switches as you want and only need a single pin if you connect them in parallel. The only requirement is that the switches must be switched on then off to change the state of the vacuum system. I use push buttons to turn lights on and off from multiple locations, but regular switches will work as long as you turn them on and then off. See the attached diagram.

    On the propeller end each time the pin goes low and then high you change the state of the pin that controls the vacuum with a simple if statement.
    658 x 340 - 4K
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-13 15:58
    I have this system working already, Just no Micro controller for the cool factor..

    I have one 40A SSR and three "toggle" switches in parallel much like kwinn describes.


    Currently I must turn off the switch that turned the vacuum on, in other words, I have to turn it on here, and turn it off here.
    I would like to toggle the SSR pin from any switch at any time,

    PUB CheckSwitchStateChange
    CurrentSwitchState := ina[8..15]
    Check If CurrentSwitchState changes <<<(this is the line of code I am having trouble with)
    If any change, then toggle SSR pin..

    I am having a hard time getting the code right for "Check if CurrentSwitchState changes"... again, it's not spin, it's just me...


    -Tommy
  • SapphireSapphire Posts: 496
    edited 2015-06-13 17:12
    How about this:
    PUB CheckSwitchStateChange                   
      LastSwitchState := CurrentSwitchState        ' save last switch state
      CurrentSwitchState := ina[8..15]             ' get current switch state
    
      if LastSwitchState ^ CurrentSwitchState      ' any switch changed state  
        ToggleSSRpin                               ' toggle SSR pin
    
  • kwinnkwinn Posts: 8,697
    edited 2015-06-13 23:34
    Sapphire wrote: »
    How about this:
    PUB CheckSwitchStateChange                   
      LastSwitchState := CurrentSwitchState        ' save last switch state
      CurrentSwitchState := ina[8..15]             ' get current switch state
    
      if LastSwitchState ^ CurrentSwitchState      ' any switch changed state  
        ToggleSSRpin                               ' toggle SSR pin
    

    That should do it.
  • idbruceidbruce Posts: 6,197
    edited 2015-06-14 04:19
    At the risk of sounding stupid .... :)
    You can have as many switches as you want and only need a single pin if you connect them in parallel. The only requirement is that the switches must be switched on then off to change the state of the vacuum system.

    I am assuming this comment is intended for a common single pole toggle switch, with an on and off position, because I cannot see how this would apply to a momentary single pole switch, such as a pushbutton.

    Additionally, I cannot understand why "switch state" storage is necessary. Since the goal of the switches is to simply change the state of the relay pin, unless one of the switches is out of hearing range of the vacuum system, why not just change the state of the relay pin?

    I always thought this would inverse the current pin state: ..... !OUTA[RELAY]

    EDIT:
    unless one of the switches is out of hearing range

    Please disregard this comment due to irrelevancy :)
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-14 08:56
    XOR, of course, I knew it would be something simple, What is this symbol called? ( ^ ) it's a caret yes? well it's a very nice thing whatever they call it.
    Thanks Sapphire and all, that will indeed do what i need done..
    It is in my nature to over think everything, and paralyze the progress of entire projects, You guys are lifesavers.


    @idbruce,
    unless one of the switches is out of hearing range of the vacuum system, why not just change the state of the relay pin?
    Funny you should mention that, Because all of the switches are now out of hearing range of the vacuum...

    attachment.php?attachmentid=114474&d=1434296088

    Clogged filters and screaming ShopVacs are a thing of the past for me. YEAH!..

    Thanks again everybody.


    -Tommy(thinks he has it figured)Tailspin
    1024 x 1365 - 209K
  • SapphireSapphire Posts: 496
    edited 2015-06-14 09:55
    One more thing. Before you call CheckSwitchStateChange, you need to initialize the CurrentSwitchState variable by calling this method once at startup:
    PUB InitSwitchState                   
      CurrentSwitchState := ina[8..15]             ' get current switch state
    

    Otherwise, if any switches are ON when the program starts they will cause the SSR to toggle at startup.
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-15 21:20
    Thanks Sapphire, I will initialize as advised. :)

    Now I 'get' to debounce the switches,
    Some folks swear that Hardware debouncing is the best. Then again, some folks swear that Software debouncing is the best.
    As for me, I just try not to swear...:innocent:

    Two of the wire runs for the switches will be thirty feet, Three of the switches are only ten feet from the control panel.
    One is on the control panel, and one is a spare, because you just never know, seven switches might not be enough to turn on one Shop Vacuum...

    The switches are Toggle on/off type, But they are not all the same make and model.

    How will I go about debouncing all these switches?. Software? Hardware? Noware? Oh great, now i've paralyzed the project,..again...


    -Tommy
  • Heater.Heater. Posts: 21,230
    edited 2015-06-16 01:33
    Sapphire,

    As far as I gather you are reading 8 switches on 8 separate inputs and using exclusive OR to detect changes.

    You can debounce all 8 switches at the same time using XOR as well. The basic idea is to repeatedly read the inputs and use XOR to detect changes. If there is no change for some number of reads then you have a stable, debounced, switch reading.

    In pseudo code something like this:
    currentInput := read switch pins
    previousInput := currentInput
    count := 0
    
    Every 10ms do:
        currentInput := read switch pins
        change := currentInput XOR previousInput
        if change = zero
            increment count
            if count > 10
                CurrentSwitchState := currentInput
                count := 0
            endif
        endif
        previousInput := currentInput
    end
    
    That results in all switches having to be stable for one tenth of a second before the input is used as CurrentSwitchState. You can tweak the repetition rate and count limit to suit your system.

    I guess this is just a small modification of the code you already have.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-06-16 09:28
    Why not just connect the switches in series and put a resistor across each one? The resistors can all be the same value. That way, whenever a switch changes state, the overall resistance will change by about 12%. Even a BASIC Stamp could detect that using RCTIME.

    -Phil
  • kwinnkwinn Posts: 8,697
    edited 2015-06-16 09:51
    idbruce wrote: »
    At the risk of sounding stupid .... :)



    I am assuming this comment is intended for a common single pole toggle switch, with an on and off position, because I cannot see how this would apply to a momentary single pole switch, such as a pushbutton.

    Additionally, I cannot understand why "switch state" storage is necessary. Since the goal of the switches is to simply change the state of the relay pin, unless one of the switches is out of hearing range of the vacuum system, why not just change the state of the relay pin?.........................................

    Actually a single pole normally open push button is the ideal type of switch for what I suggested. Other types of switches can be used, but they must be returned to the open position position or they will disable the system. Switch state storage is also required for the switch debounce code.

    BTW, a microcontroller is not really required. A J-K flip flop would do as long as the switch signal is debounced.
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-16 10:20
    Thanks Heater, That is very helpful pseudo code, Though I don't think it is Sapphire that is confused.. It's just me. :)


    Phil, the Engineer's Mini-Notebook from Radio Shack has a circuit like you describe on page 20,



    I will try to list the Design Criteria more clearly, When i get home tonight. It's a big list!.



    -Tommy
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-16 10:28
    BTW, a microcontroller is not really required.
    I completely agree %100, but...
    The number one thing on the Design Criteria list would be:
    Extravagance, Luxury, and genuine envy from my Woodworking peers. :)


    I have to go to work now.


    -Tommy
  • kwinnkwinn Posts: 8,697
    edited 2015-06-16 19:25
    Ttailspin wrote: »
    I completely agree %100, but...
    The number one thing on the Design Criteria list would be:
    Extravagance, Luxury, and genuine envy from my Woodworking peers. :)


    I have to go to work now.


    -Tommy

    That comment was for the simple circuit I suggested in post 5. My very first circuit for controlling lights from multiple locations consisted of several doorbell push buttons, a 555 timer wired as a one shot, and a J-K FF. Put in a few of those, but when single chip micros dropped below $5.00 I switched over.

    For your application a microcontroller is definitely the way to go even if Extravagance, Luxury, and genuine envy from your Woodworking peers was not a requirement. Just think of all the other things you could automate with that propeller ;-)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-06-16 21:00
    kwinn wrote:
    Just think of all the other things you could automate with that propeller.
    F'instance: shut off the vacuum when the phone rings or someone is at the door. For extra credit, use video image recognition for the door that leaves the vacuum running if the person is wearing a tie or carrying leaflets.

    -Phil
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-17 22:58
    Sorry I took the quote out of context kwinn, I knew what you were talking about, I was just trying to be funny,(sometimes i'm not as funny as i think i am.)

    For sure I would like to use a Propeller for this project, I think it will be very luxurious and most extravagant. Of course, In my Trailer Park, luxury and extravagance is Relative..
    attachment.php?attachmentid=114499&d=1434606659


    Phil, Those are all great ideas, But they all assume you can actually hear this Vacuum running. Which you can't, unless you climb inside the box, Which you shouldn't, Unless you have hearing protection...
    attachment.php?attachmentid=114498&d=1434606044
    Note the Casters that came with the Vacuum remain uninstalled and are still safely quarantined in their original packaging..


    -Tommy
    1024 x 1365 - 203K
    1024 x 1365 - 304K
  • kwinnkwinn Posts: 8,697
    edited 2015-06-18 06:11
    Ttailspin wrote: »
    Sorry I took the quote out of context kwinn, I knew what you were talking about, I was just trying to be funny,(sometimes i'm not as funny as i think i am.)

    For sure I would like to use a Propeller for this project, I think it will be very luxurious and most extravagant. Of course, In my Trailer Park, luxury and extravagance is Relative......................


    -Tommy

    No apology required. I did get a laugh from the "Extravagance, Luxury, and genuine envy from my Woodworking peers", particularly the envy part.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2015-06-18 11:46
    Another way to handle multiple switches (with out microcontrollers) is to use two 3-way switches and one or more 4-way switches.

    4-way 120V switches are expensive however, so using low voltage switches and a relay would be a good option.

    A 3-way switch is nothing but a SPDT switch. A DPDT switch can be wired as a 4-way.

    Flipping any of these switches will toggle the load on/off. (NOTE - the circle represents the light or a relay, etc)

    If you need more switches, just insert another DPDT (4-way) switch in the circuit...

    attachment.php?attachmentid=114503

    As a practical matter, you need 3 conductor wire running between the switches - see link below...


    http://electrical101.com/4way-switches.html
    http://www.do-it-yourself-help.com/4_way_switch_diagram.html

    http://forums.parallax.com/showthread.php/161004-Capacitive-touch-sensor-SPDT-toggle-using-CD4027-Flip-Flop?p=1329376&viewfull=1#post1329376

    Another option would be to drive a relay with a CD4027 circuit with multiple momentary contact push button switches in parallel.
    Pushing any MOM button would latch the relay on/off.

    (This video has a push button and capacitive switch in parallel)

    http://www.electronicshub.org/jk-flip-flop-using-cd4027/
    758 x 309 - 28K
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-19 19:32
    Three and four way switches have been done, Over done in fact. It's time for change.
    It's time to grasp the future, A future with no /four way switches(or casters) making people lazy, Taking the easy way out, Don't get caught up in that...

    I am fully qualified(and have the tools) to install the 120V, 20A, eight switch, four wire 12AWG of permanently mounted, always in the way, spaghetti nightmare...
    None of that for me anymore, This is the future I will embrace...
    attachment.php?attachmentid=114516&d=1434763863
    Note the simulated steel braiding for super flexibility, and solid cast aluminum nearly watertight box connector ends,
    A solid steel body with integral spiral ribbing is used to hold the matching spiral ribbing of the high strength nylon switch holder securely.
    The future is here.

    Here is another picture of the future, It's already installed and ready for hard work at a moments notice...
    attachment.php?attachmentid=114517&d=1434764848
    Using any available magnet, I am able to mount the switch to any machine I am using, Saving steps and thus valuable time.

    In this next picture, I am using a more traditional switch holder as I know a switch will always be in this location...
    attachment.php?attachmentid=114518&d=1434765737
    I could post a video of the Shop Vac running, but all you would hear is (KPIG)(94 oink 9) on the shop radio.

    I like the idea of using some extra IC chips to help add to the fun, I do expect to make some custom circuit boards for this overly extravagant vacuum system.
    The XBEE radios will for sure need some custom boards.

    I think I would like to try an MCP23017 since I already have some laying about, one of those could watch the switches and run the indicator LED's too...


    All part of the fun I guess...

    -Tommy
    1024 x 1365 - 241K
    1024 x 1365 - 252K
    1024 x 1365 - 302K
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2015-06-20 07:15
    I suppose I missed the whole point - an "overly complex extravagant vacuum system".

    Thought you were looking for a straight forward, simple (and inexpensive) solution to control a vacuum.

    Guess you could add WiFly modules and wireless routers or mobile phone apps to the mix for even more fun..

    Personally, I'm a fan of the K.I.S.S. principle.

    Fewer fail points = less aggravation.
  • TtailspinTtailspin Posts: 1,326
    edited 2015-06-20 21:47
    "Thought you were looking for a straight forward, simple (and inexpensive) solution to control a vacuum." I do understand the K.I.S.S. principle, heh, i live in a trailer...
    The Shop Vac in the picture, comes with a big, fat, bright red switch, built right in, just give it a slap and it starts to screaming...
    Does not get much simpler that that, i suppose.

    This is all for fun and games, something to keep me off the streets at night, Maybe better myself in the meantime, And hey, is it really all that wrong to want a little Vacuum envy?. :)



    -Tommy(had it all figured out, but now he doesn't)Tailspin
  • kwinnkwinn Posts: 8,697
    edited 2015-06-21 06:52
    Congratulations, seems like you have the "Extravagance and Juxury" part well in hand, so the "genuine envy from my Woodworking peers" should be forthcoming.

    While I generally lean towards simplicity and moderation in all things (including moderation) there are times when one has to go all out on a project. Keep up the excessive Luxury and Extravagance.
Sign In or Register to comment.