Shift register suggestions
ke4pjw
Posts: 1,261
Hey folks,
I am working on a project that needs to read a set of dip switches. I am running low on available pins on the propeller and am looking at using a PISO shift register. I was thinking of going with the CD4014BE. It appears to be widely available but is of the 5 volt variety. Is this a good choice, or is there something better suited?
Regards,
Terry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry
I am working on a project that needs to read a set of dip switches. I am running low on available pins on the propeller and am looking at using a PISO shift register. I was thinking of going with the CD4014BE. It appears to be widely available but is of the 5 volt variety. Is this a good choice, or is there something better suited?
Regards,
Terry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
Robert
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Are only one switch on at at any time?
Some type of Multiplexing/charlieplixing could also work.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry
You know that DIP switches need access ports in the enclosure, they take up room and I/O. Unless they are things that need to be configured "in the field" by almost anyone, I favor the USB serial to laptop approach or if the unit has a display then use that with 3 to 4 buttons maybe. Anything but DIP switches.
So I2C bus expanders are a solution to your requirement but changing the requirement may be the solution.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
pub in165(ld, clk, do) | tmp165 '' Read inputs from 74x165 '' -- ld : shift/load pin (output) '' -- clk : clock (output) '' -- do : data out (input) outa[noparse][[/noparse]ld]~~ ' default to shift mode dira[noparse][[/noparse]ld]~~ outa[noparse][[/noparse]clk]~ ' clock is 0-1-0 dira[noparse][[/noparse]clk]~~ dira[noparse][[/noparse]do]~ ' make do an input outa[noparse][[/noparse]ld]~ ' load present inputs outa[noparse][[/noparse]ld]~~ tmp165~ ' clear workspace repeat 8 tmp165 := (tmp165 << 1) | ina[noparse][[/noparse]do] ' get new bit, MSBFIRST ' tmp165 := (tmp165 >> 1) | (ina[noparse][[/noparse]do] << 7) ' get new bit, LSBFIRST outa[noparse][[/noparse]clk]~~ ' blip clock outa[noparse][[/noparse]clk]~ return tmp165[noparse][[/noparse]Edit] I just noticed that you have 16 inputs; I only have eight inputs to check. You can easily expand this to 16-bits and daisy-chain the x165s to read them all with one method call and the same three pins.
The shift/load and clock pins are common to both chips. The downstream 165's DO pin (9) connects to the upstream 165's SERIAL IN pin (10). The upstream 165 DO pin connects to the Propeller.
pub in165x16(ld, clk, do) | tmp165 '' Read inputs from two 74x165s '' -- ld : shift/load pin (output) '' -- clk : clock (output) '' -- do : data out (input) outa[noparse][[/noparse]ld]~~ ' default to shift mode dira[noparse][[/noparse]ld]~~ outa[noparse][[/noparse]clk]~ ' clock is 0-1-0 dira[noparse][[/noparse]clk]~~ dira[noparse][[/noparse]do]~ ' make do an input outa[noparse][[/noparse]ld]~ ' load present inputs outa[noparse][[/noparse]ld]~~ tmp165~ ' clear workspace repeat 16 tmp165 := (tmp165 << 1) | ina[noparse][[/noparse]do] ' get new bit, MSBFIRST ' tmp165 := (tmp165 >> 1) | (ina[noparse][[/noparse]do] << 15) ' get new bit, LSBFIRST outa[noparse][[/noparse]clk]~~ ' blip clock outa[noparse][[/noparse]clk]~ return tmp165▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 2/23/2010 7:30:10 PM GMT
obex.parallax.com/objects/381/
- they are $0.78 each in a DIP16. You can cascade them for days.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Signature space for rent!
Send $1 to CannibalRobotics.com.
What's the difference/pros/cons with 74HC597 ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Pin 9 - 1 ' Set to PISO
Pin 10 - 1 ' Populate registers with parallel data
Pin 10 - 0 '
Repeat 8 times
{
Pin 10 - 1 ' Shift data from LSB to Pin 3
Pin 10 - 0 '
Read bit from Pin 3
}
Is there something wrong with my understand of this?
Thanks in advance for your help!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry
Cascade Q8 from the previous stage into SERIAL INPUT etc.
So change your clock from high/low to low/high to guarantee an edge and also remember to read the data before clocking for the next one as P8 appears at Q8 straight after parallel load.
BTW, take note of taking pin 9 low to change to serial mode.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
Post Edited (Peter Jakacki) : 2/27/2010 5:05:08 AM GMT
I am pulling my hair out [noparse]:)[/noparse] I *MUST* be something stupid that I can't see. I have checked the wiring again and again.
Thanks guys!
--Terry
ld := 19 clk := 18 do := 17 channel := $0000 '' -- ld : shift/load pin (output) - Pin 9 of CD4014 '' -- clk : clock (output) - Pin 10 of CD4014 '' -- do : data out (input) - Pin 3 of CD4014 outa[noparse][[/noparse]ld]~ dira[noparse][[/noparse]ld]~~ outa[noparse][[/noparse]clk]~ dira[noparse][[/noparse]clk]~~ dira[noparse][[/noparse]do]~ outa[noparse][[/noparse]ld]~~ waitcnt(1000 + cnt) channel := (channel << 1) | ina[noparse][[/noparse]do] outa[noparse][[/noparse]ld]~ waitcnt(1000 + cnt) repeat 7 outa[noparse][[/noparse]clk]~~ waitcnt(1000 + cnt) channel := (channel << 1) | ina[noparse][[/noparse]do] outa[noparse][[/noparse]clk]~ waitcnt(1000 + cnt) Debug.start(31, 30, 0, 57600) waitcnt(clkfreq*2 + cnt) Debug.tx(Debug#CLS) Debug.Bin(channel, 31)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry
If you comment your code as to what it is doing you will see it doesn't conform to the description I gave. Look at these simple steps
1. LD high ' parallel mode 2. CLK low 3. CLK high ' now parallel data is latched 4. LD low ' back to serial mode ' remember not to clock before reading the 1st bit as it is already present!!!! 5. Repeat 8 times shift channel left Or input data with channel CLK low CLK high ' clock this way to guarantee a low to high (ESPECIALLY THE 1ST TIME)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
ld := 19 clk := 18 do := 17 channel := $0000 '' -- ld : shift/load pin (output) '' -- clk : clock (output) '' -- do : data out (input) outa[noparse][[/noparse]ld]~ ' Set shift/load low dira[noparse][[/noparse]ld]~~ ' Set shift/load pin for output on Prop outa[noparse][[/noparse]clk]~ ' Set clock low dira[noparse][[/noparse]clk]~~ ' Set click pin for output on Prop dira[noparse][[/noparse]do]~ ' Set data out pin for input on Prop waitcnt(1000 + cnt) outa[noparse][[/noparse]ld]~~ ' Set shift/load high (parallel mode) waitcnt(1000 + cnt) outa[noparse][[/noparse]clk]~~ ' Set clock high waitcnt(1000 + cnt) outa[noparse][[/noparse]ld]~ ' Set shift/load low (serial mode) waitcnt(1000 + cnt) repeat 8 channel := (channel << 1) | ina[noparse][[/noparse]do] ' Shift bits in channel and populate with new bit outa[noparse][[/noparse]clk]~ ' Set clock low waitcnt(1000 + cnt) outa[noparse][[/noparse]clk]~~ ' Set clock high waitcnt(1000 + cnt)▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-- Terry
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM