Shop OBEX P1 Docs P2 Docs Learn Events
7 position switch, 2 inputs on Prop available. — Parallax Forums

7 position switch, 2 inputs on Prop available.

eagletalontimeagletalontim Posts: 1,399
edited 2013-08-25 16:20 in Accessories
This is a new one to me... I have a 7 position switch that has 7 different pins plus a common. The switch has a range of 10V to 16V DC that it switches and I need to pick this up via some kind of IC chip and somehow communicate the switch's position back to the Propeller. Could I get some advice or pointed in the right direction on this?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-22 22:30
    It's not clear what you're talking about. Does the switch select voltages in the 10-16V range and you want to measure this voltage or do you have one of 7 switch closures to the common pin ... connected to nothing at present ... and you want to use this to somehow generate a voltage.

    If it's the former, read the Propeller Application Note # 008 (here) on using two Propeller pins for an Analog to Digital Converter. You can also use one pin with a couple of resistors and a capacitor like what's done with the Stamps using the RCTIME statement. See the discussion here on the RCTIME statement.

    If it's the latter, you might use a PCA9554 8-bit I2C I/O Expander chip. It only needs 2 I/O pins for an I2C bus and you can piggyback it on the EEPROM I2C bus (pins 28 and 29). You'd connect the common pin to one PCA9554 I/O pin and the 7 other pins to the 7 other I/O pins of the PCA9554. You'd set one of the 7 output register bits to 0 and the other to 1, then read the 8th pin to see if it's 0 or 1. If it's a 0, you've identified which position the switch is in. If it's a 1, you shift the 7 bits and try again.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-23 04:27
    It is all the same voltage from each pin. The selector just moves that voltage to each pin as you move it. I was hoping to have 1 chip that could take care of this since I am limited on space.
  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-23 07:26
    The simplest solution would be a voltage divider for each switch pin and the PCA9554 that I mentioned. The voltage divider reduces the 10-16V signal to something like 2-3.3V. I'd suggest something like 39K and 10K in series to ground with the PCA9554 I/O pin attached to the junction of the two resistors. You'll need 7 pairs of resistors.
    Switch pin ------ 39K ----- 10K ----- Ground
                            |
                            |
                      To PCA9554
    
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-23 08:53
    Updated:
    As you are apparently using the switch for some real work (automotive 13v I guess) how it's connected can not be changed.
    just want to monitor its location. As common pin voltage vary a A/D solution is a little harder.
    Below I show how to do it with a 50cent IC (though a I2C version would not waste any Prop pins at all)

    You can mux clk and load pin on a 74(V)HC165 by a 1.5K resistor and a 2200pF cap.
    Keep clk pin high with at least 16-to-1 duty and only let it go low for longer time when you want to load the registers.

    1uS low and 15uS high are good values, and at least15uS low for Load followed with a 30uS high.
    As I have not tested it,
    you may have to use D1-D7 instead of D0-D6 for inputs as I'm not sure how the mux will affect the first rising edge.

    As the voltage is in the 10-16v range coming in to common and is not something you can change, use the C version of schematic below.
    Using 39K instead of 47K should also work and will give higher tolerance from 16-20v spikes (though the 100K inputs will filter short spikes anyway)
    615 x 290 - 8K
    1024 x 478 - 46K
    1024 x 509 - 65K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-08-23 09:26
    tonyp12 wrote:
    And if the voltage is really 10-16v coming in to common (don't why a switch would have a fixed voltage) ...
    I gather that the switch is used to turn on one of seven loads that require a nominal 12V supply. If so, there will be some current involved, and Mike's suggestion of a divider on each switch output will be required.

    OTOH, one could use old-time CMOS, powered from the higher voltage, and use voltage translation on the Prop side.

    -Phil
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-23 17:20
    tonyp12 wrote: »
    .....

    You can mux clk and load pin on a 74(V)HC165 by a 1.5K resistor and a 2200pF cap.
    Keep clk pin high with at least 16-to-1 duty and only let it go low for longer time when you want to load the registers.

    1uS low and 15uS high are good values, and at least15uS low for Load followed with a 30uS high.
    As I have not tested it,
    you may have to use D1-D7 instead of D0-D6 for inputs as I'm not sure how the mux will affect the first rising edge.

    You lost me here! Lol, I know enough about electronics to get what I need done, for the most part. Still learning though!
    Keep clk pin high with at least 16-to-1 duty and only let it go low for longer time when you want to load the registers.
    This is one thing I am not sure about what is going on here... How would I adjust the clock pin if it is connected to the clock of the prop? Would that not interfere with other time sensitive components?
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-23 18:26
    The Prop can create both the Clock Signal and Load Signal needed from just one Prop pin.
    The trick is a R/C filter.

    If the clock was 50/50 the signal after the R/C filter would be at 1/2 Vdd, no good.
    Now make the clock 94/6 (eg 15/1 uS) as you are doing it fast enough the signal after the R/C will be at 90-100% of Vdd and a IC input will never see a low state.

    When you need a low state, just make it long enough (15uS) and R/C will hit bottom, wait 30uS to charge up the cap fully again.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-24 18:03
    I found this in the SX forum :
    Get_165:
    Start:
    HIGH Load1
    
    ..........
    
      PULSOUT Load1, 10                             ' load switch inputs
      SHIFTIN SerData, Clock, MSBPRE, switches      ' shift them in
      RETURN
    

    So from what I understand, all I have to do set the "Load pin" to high, and when I want to read it, I could use the BS2_Functions (PWM_Set) then the X := BS2.SHIFTIN(5,6,BS2#MSBPRE,8) to receive the data from the chip? Sounds easy enough!
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-24 18:36
    If you can use 3 pins, no time restrictions on how to the flip the pins are needed.
    As you said you wanted to use 2 pins, serial-in would use up one, leaving you with 1 for Load and Clk
    With my schematic above you would do this.

    Clk low for 15us, Clk high for 30us, read ser-in,
    Clk low for 1uS, Clk high for 15uS, read ser-in,
    Clk low for 1uS, Clk high for 15uS, read ser-in,
    ..... for a total of 8 read ser-in. then repeat from start.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-24 18:42
    I am working on finding a 7 segment display driver for a common cathode display. Instead of 7 pins, I could use 3 or 4 I think. Still have not found anything that I can use that will connect directly to the prop or with an inline resistor....maybe I am missing something..... If I can eliminate those pins, I could free up more to use with this part of my project.
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-24 18:49
    Use a 74hc595 for the 7LED and combine it with the 74hc165 so clk pins are shared with both and also latch/load can be shared too.
    For a total of 4pins. (with NO complex timing required)

    Here I drive six 17seg LEDs multiplexed with just one wire using my above variable time length clock trick.
    http://forums.parallax.com/showthread.php/134106-Updated-17seg-LED-driver-for-PPDB-now-available.



    HC vs VHC vs HCT:
    HC is standard 3.3v and its inputs can only be up to 3.4v and a high state is at 70% of vdd
    VHC (or AHC) is more flexible with the voltage it runs at and it's input can be 5V though Vdd is 3.3v etc, a high state is at 70% of Vdd
    HCT runs at 5V but its good feature is that a high state is from 2v to 5v, a larger window so 3.3v signal will register even if it's Vdd is 5V
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-24 22:20
    So using a 74hc595 with the prop would require a resistor to be between it and the Prop since it needs 30% less than 3.3V? What exactly is the clock pin used for? I am not quite understanding the clock thing yet but I am sure something will click as soon as I read something I understand about it :)
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-25 07:13
    >So using a 74hc595 with the prop would require a resistor to be between it and the Prop since it needs 30% less than 3.3V?
    No, 70% (or shown as 0.7 Vdd) is when its inputs start registering as high, 70% to 100% is OK.
    If you are powering a VHC595 or HCT595 with 5v then you would have to put 3k resistors on its outputs that goes to the Prop.
    But a VHC at 5v its inputs like clk or latch would not see a 3.3v Prop signal, but a HCT would.

    Clk pushes the serial data ahead one step in it's daisy-chained registers.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-25 07:56
    The clock is like a "Data ready to be sent" pin? Turn the clock on, and the IC chip runs like normal, turn the clock pin off, and data can be either sent or read? I have been looking at code for other projects that use a clock pin and still don't quite get the clock thing :( I am trying though!
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-25 08:02
    >"Data ready to be sent"

    All Clk signals are either rising or falling edge.
    It's when a clk goes high when the single data bit on the other "data" pin is transferred to the 595 etc.
    And needs to go low and high again for the next bit to register.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-25 08:17
    Ohhhh, Ok, I kind of understand it now! I am going to order a few of these chips to tinker with. Hopefully when they come in, I can use them :) I am ordering all SM stuff since the final design is going to be soldered to a board that is quite small for all the stuff I am packing on it. Right now, I have just been soldering small jumper wires to the pins of the chips to test with them. Working so far....
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-25 08:29
    Get soic16 (or sometimes called so16) unless you also order a stencil.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-08-25 14:55
    So I still need the 2200pF cap and the 1.5K resistor if I am able to free up the additional pins? Trying to finish the shopping cart for my order and need to know if I need these components.
  • tonyp12tonyp12 Posts: 1,950
    edited 2013-08-25 16:20
    no need for cap and res, 4 prop pins can control 1-4 hc595 together with 1-4 hc165
    But you should get 0.1uF caps for decoupling on each IC
Sign In or Register to comment.