7 position switch, 2 inputs on Prop available.
eagletalontim
Posts: 1,399
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
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.
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)
OTOH, one could use old-time CMOS, powered from the higher voltage, and use voltage translation on the Prop side.
-Phil
You lost me here! Lol, I know enough about electronics to get what I need done, for the most part. Still learning though!
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?
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.
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!
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.
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
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.
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.
But you should get 0.1uF caps for decoupling on each IC