PDA

View Full Version : Sending bits to prop with mechanical switches, easiest cheapest way?



rwgast_logicdesign
04-13-2012, 03:57 AM
Ok so you got 8, 16, 32 switches maybe. You want to send the state of these switches to the prop, whats the best way. Obviously you could use eight data pins but thats not elegant or intuitive at all. Id like to send the bytes via i2c or 1 wire bus. I thought ok you could use a cheapy 8 bit micro and connect to its 8 pins then send the data off to the prop, but that seems like over kill. Basically I just wanna hit some push buttons or flip some switches into a binary pattern then hit a send button and off to the prop the byte goes to be stored in memory or sd or whatever.... Id like to do this as cheap as possible and maybe even without an IC, maybe just passive and transistors, but if the IC route is cheaper so be it...

Phil Pilgrim (PhiPi)
04-13-2012, 04:04 AM
Take a look at the 74HC165 parallel-in serial-out shift register.

-Phil

Mike Green
04-13-2012, 04:07 AM
You could use a parallel to serial shift register like the 74HC165. That would use 3 I/O pins and you can cascade several of these in series for multiples of 8 bits.

You could use an I2C I/O expander. The PCA9554 provides 8 I/O bits while the PCA9555 provides 16 I/O bits. In both cases, the I2C bus could be the same 2 I/O pins as are used for the boot EEPROM. In both cases, the I2C address is selectable, so you could have up to 8 such devices on the same I2C bus.

jmg
04-13-2012, 04:10 AM
Obviously you could use eight data pins but thats not elegant or intuitive at all.

?? - Simplicity has its own elegance.
If the pins are not doing anything else this can work fine.

The cheapest is likely to use a series of HC4051's, ( ~ 13c? ) as that allows you to use just one load resistor.
4 of these will scan 32 contacts, using 7 pins, and 9 can scan 64 contacts using 7 pins.

Peter Jakacki
04-13-2012, 05:20 AM
I like all the solutions offered so far but jmg is right, unless the Prop's pins are needed elsewhere it doesn't make sense to not use them because that would counter-intuitive. My approach though would be not to use dip switches at all as they are so 80's but then there may be some really special requirement you have. Would you like to enlighten us on how you intend to use them and also why you need to make it "cheap"? BTW, dip switches are not a cheap way to go.

cavelamb
04-13-2012, 06:09 AM
Prop chips, even one off, are cheap enough that you could dedicate one to reading switches.

But a 74HC165 parallel-in serial-out shift register or a handfull multiplexer chips like 74HC152 added
to your host Prop would do. Multiplexers take a few address bits and select a single input based on the address.
So the software to read switches through one is fairly straight forward.
Set the address of the switch you want to read (for a single mux chip that means 3 output pins) and read the
input that the mux output is wired to. '152 is not expandable, so it works well up to 8 inputs.

So it would have to have it's OUTPUT fed into one of another '152's INPUT (as an expander) and another
address line (or 3) for THAT chip to select one of 8 mux chips. Now we are looking at 8 x 8 or 64 maximum
switch (or just bit) inputs).

It's a lot faster since you can address any desired switch without having to shift in all the ones befor that one.


http://html.alldatasheet.com/html-pdf/63830/HITACHI/HD74HC152/501/2/HD74HC152.html91649 (http://html.alldatasheet.com/html-pdf/63830/HITACHI/HD74HC152/501/2/HD74HC152.html)

Duane Degn
04-13-2012, 06:48 AM
You could use a pair of these (http://www.sparkfun.com/products/10064)and enter a byte of data as hex.

Don't forget the knob (http://www.sparkfun.com/products/10263).

rwgast_logicdesign
04-14-2012, 01:35 AM
Thank you guys for all the suggestions lot of approaches!! I really want to do this i2c though to hook up on the eeprom line so no pins are used. I mean why not... why waste any pins on something that doesnt really require very much bus speed at all. I mean im aleady looking into copying the GG solution to get a keyboard on the i2c bus, it has no reason not to be! i2c can handel what 128 devices... might as well use em ;).

But in reality this is going to hopefully be commercial project, that is why im concerned about price, every penny counts id rather splurge on things that will benefit the whole system rather than things that are not speed critical. Im still learning about hardware, reading tons of books listening to pod casts all day I love it I really want to get into this industry I could do this stuff 16 hours a day. Money and having to read are the only things slowing me down :)!

Ok so this is going to be used as an education tool. Im going to sell it has a kit, and Im going to document how it works along with how to build it. Im no electronics guru but the goal of my project is to teach people how computer and machine code work so as long as I understand how it works and can explain what I built thats enough to satisfy what Im trying to do. Here is the project
http://forums.parallax.com/showthread.php?139417-The-binary-programmable-Interface-based-on-a-prop-quot-70s-wire-wrap-micro-throw-back-quot-.&p=1090687#post1090687

N (http://forums.parallax.com/showthread.php?139417-The-binary-programmable-Interface-based-on-a-prop-quot-70s-wire-wrap-micro-throw-back-quot-.&p=1090687#post1090687)ow im going to look into the PCA chip figure out how it works and what its cost is, hell maybe I can get a sample. My idea is to drop a TI MSP430 dip between the prop and the buttons. The things are a buck they have built in flash and will communicate with i2c or anything else for that matter. My problem with that is this is an educational thing and Im trying to keep it simple, ya throwing a micro at a problem is a simple cheap solution and cost effective. But is it fun for the kit builder, will it teach them anything to solider on a micro that i explain i programmed to do this... no. This is my worry about the PCA chip too. Now this kit is suppose to be low level enough so kids/hobbyist understand whats going on and how hardware and bits acually make a computer do what it does, but not so level its just to overwhelming like it would be for most beginners like myself to wire wrap a z80 schematic.

So based on trying to keep the board cheap, and trying to teach CS not just kit soldering what would you suggest? The 74s may be the way to go... idk whatever you guys think would meet my goal im going to have to go book up on it too probably, unless its a push button and pull down resistor connected to each pin!! Im still not even real sure how the whole thing will work I mean if i send PASM opcodes with switches i guess ill need 32 switches, but im hoping to do an intel 8088 emulator or something and keep it 8 bit. Its prop based once you learn the basics of ASM you can always hook up a kb and monitor and write some PASM. I will probably use 7 segment led's to show register values out put program data. This is a no kb or monitor deal.

Would going with some kind of transistor/passive solution be to complex and exspensive? I wanted to go that way really but maybe thats like hitting the z800 schematic wall. And if there is a way to do it with those kinds of components and keep the prop pin count down by half the bits at least id need some part names and a lil explanation of what to do with them. This is what im sayin though i could add a micro and its all software, and for the consumer its just soldering a programmed micro,,,

mindrobots
04-14-2012, 02:18 AM
It's an ambitious and admirable project and I think anything teaching computers is a great venture and I don't want to throw cold water on it but in reading your goals, a number of things jump out at me.

1) are there really that many people now days that want to know how a computer and machine level code really work?
2) As far as a target processor for learning these basics, I would think you would want a very simple architecture with a simple instruction execution cycle and a flat memory space. Either an 8080 type model or a 6502 or 6800. When you get into the 8088/8086, you get into memory banks and all kinds of nasty sophisticated hardware architecture - much more than the basics. The Propeller itself has a unique architecture with complications added from the multi-cog structure and the dedicated and shared memory spaces. There are either no registers are nothing but registers in the COG memory space. It's a very sophisticated processor for a beginner to grasp the machine level operations....the expert are still learning and squeezing tricks out of it.
3) If someone is really interested in the basics and how the machine works at the bit level and byte, there is an absolutely WONDERFUL book called CODE by Charles Petzold that literally goes from information encoding systems (Morse, Braille, etc.), and then how binary fits into this and then once you have binary, how you begin to manipulate bits and how the logic gates work and how they are combined into adders and ones and twos compliment math and clocking and memory addressing and latching and instructions fetching and decoding and.......well, you get the picture. I read this on a trip to Atlanta last spring and literally couldn't put it down. Maybe an "Experimenters Kit" or "lab Environment" to compliment this book? You could implement it in hardware (switches and logic chips) and software (logic simulators, adders, etc.) and folks could learn and play at a very basic level....at some point, you could load up the 8080 emulator in a COG and they could program and debug an 8080.

Propeller PASM is difficult to teach to beginners (there are a number of threads proving this fact). If you have programmed some processor in some assembler before, it is much easier, if you have programmed the Propeller in SPIN, it is much easier but if you are really a beginner, coding in PASM is not going to come to most people. I think to understand the various layers of hardware and software abstraction from where most programmers are today down to the machine level requires a foundation to be built up like the Petzold book does (or like us old timers did back in the dark ages).

Just my thoughts, I'm sure there are others out there!

frank freedman
04-14-2012, 02:37 AM
Ok so you got 8, 16, 32 switches maybe. You want to send the state of these switches to the prop, whats the best way. Obviously you could use eight data pins but thats not elegant or intuitive at all. Id like to send the bytes via i2c or 1 wire bus. I thought ok you could use a cheapy 8 bit micro and connect to its 8 pins then send the data off to the prop, but that seems like over kill. Basically I just wanna hit some push buttons or flip some switches into a binary pattern then hit a send button and off to the prop the byte goes to be stored in memory or sd or whatever.... Id like to do this as cheap as possible and maybe even without an IC, maybe just passive and transistors, but if the IC route is cheaper so be it...

You could also do this with a cheap PIC chip to act as an I/O controller. Maybe Dr. A or Heater could consider using something like this to create an authentic looking IMSAI or ALTAIR MITS front panel for their CP/M machines. How cool would that be ??

Just thinkin' out loud.....

FF

jmg
04-14-2012, 02:52 AM
So based on trying to keep the board cheap, and trying to teach CS not just kit soldering what would you suggest?

If you want it cheap, switch-entry is certainly not cheap, or very friendly. Those 8 (min) toggle switches will cost MORE than your controller!

It was ONLY done this way, way back when, because there were no PCs in every home/office.

There are shiploads of good small uC simulators, here is just one example :
http://www.edsim51.com/

Even Real-Silicon, connected to a PC-Debug is remarkably cheap - even 32 bit ones can be found for under $20

This one is $4.35, even from Digikey ?! (can anyone do better ? )
http://www.ti.com/lit/wp/slay017/slay017.pdf

So you are probably much better off taking some very-low-cost PC-connected platform, like that LAUNCHPAD DEV BRD FOR MSP430G2XX, and expanding that with application/education examples.

mindrobots
04-14-2012, 03:02 AM
@jmg, thanks for the pointer to edsim51, that looks like a lot of fun!

Peter Jakacki
04-14-2012, 08:11 AM
@jmg: Your post reminded me to take a look at the MSP430 range again. I used them many many years when they were still very new and enjoyed working with them especially in assembler, very reminiscent of the old TMS9900. I took another look at Digikey and the current lineup and I was surprised with how cheap many of the low end parts are. I found a 14-pin TTSOP device (MSP430G2001IPW14) for 39 cents in quantities of 100. Now that is cheap for a 16-bit micro! It would be very easy to use one of these for every group of 8-way dip switches to connect them to the I2C bus.

StephenMoore
04-16-2012, 12:51 AM
The Dallas-Maxim DS2408 is a one wire solution for 8 switch input. You can put as many as you like on one Prop pin (or BS2px pin) and communicate at up to 9600baud. They are cheap (~2$). They are also software programmable for outputs as well. I used one on a relay output board I made and it works great on the standard Parallax 3 pin header (gnd, pwr, pin). The Spin objects are in the OBEX too.

sm

tonyp12
04-16-2012, 02:24 AM
up to 80 buttons, though its tiny footprint is major obstacle.
http://www.ti.com/lit/ds/symlink/tca8418.pdf

Peter Jakacki
04-16-2012, 02:34 AM
For dumb I2C I/O there is the venerable PCF8574 which can be had for $1 or less and because you can use the EEPROM I2C lines it doesn't even require any extra pins. Most projects I do I bring out P28,29 onto a 4-pin header with VCC and GND as it is a easy and cheap way (mere cents) to add that little extra interface later on and it doesn't require dedicated pins. The I2C lines are also used for other devices such as SD cards and SPI chips where SCL becomes SCK and SDA becomes SDO to the device. There are never any conflicts because SPI devices require a chip select just as I2C device require a chip select too in the form of a I2C start condition and device address but the start condition (pull SDA low while SCL is high) is never used or needed in SPI transfers which commonly use "clock on low to high" transitions where we control the data line and keep it stable while the clock is high.

BTW, on my designs my 4-pin Prop plug connection is actually a 4x2 footprint with I2C and VCC lines plus one special funtion. A normal PropPlug can still plug in to the first row of 4 pins. This is also a way I can plug in special interfaces and also perform firmware upgrades in the field with a dedicated stamp sized module which puts the Prop into reset and loads it's EEPROM directly. The same footprint takes my tiny USB to serial module (1.1" x 0.45") which can even be soldered into place as a permanent microUSB interface.

JonnyMac
04-16-2012, 02:59 AM
I really want to do this i2c though to hook up on the eeprom line so no pins are used.

I've used the MCP23017 in a few projects -- very easy to use if you're not worried about super-fast access (if it's monitoring mechanical switches that is not an issue). Bonus is that it's a bidirectional device.

Don M
04-16-2012, 03:22 AM
If you are looking for an even smpler way you could use a resistor "ladder" and then use an A2D function on the Prop to measure the resistance and use a look up table to define the switches based on measured value. Plus it only needs one pin. Just a thought.

StephenMoore
04-16-2012, 04:14 AM
up to 80 buttons, though its tiny footprint is major obstacle.
http://www.ti.com/lit/ds/symlink/tca8418.pdf

wow. That is tiny.

Does anybody have any practical tips for handling these little BGA guys?

I was looking at some GaN power MOSFETS and ran into the same miniature BGA like solder connections that required very special step heat and flux removal. Our home brew techniques which more resemble stone axe and club than tight tolerance science need to keep pace with technology.

Peter Jakacki
04-16-2012, 05:19 AM
First off that chip is totally unsuitable as it is a keypad scanner in that it has a row and column matrix which is suitable for a single switch at a time being closed. There is no way to use this with dip switches where you would have multiple closures at any one time as the scanning matrix would cross-connect and some would appear to be closed that aren't.

As for BGA I stay away from it because I can. I don't mind working with any other SMD stuff but unless you are setup for BGA and can guarantee alignment and controlled reflow I think it would be too much of a headache. Besides densely packed BGA really requires a multilayer PCB and they are much more expensive, especially when you are prototyping. The BGA package cannot be probed or patched either. Great for high-volume, too much trouble and expense for anything less IMO.

StephenMoore
04-16-2012, 05:35 AM
What does IMO mean?

Peter Jakacki
04-16-2012, 05:43 AM
AFAIK it means "In my opinion". :)

Phil Pilgrim (PhiPi)
04-16-2012, 06:01 AM
"IMO Chivo" used to be a commercial sour-cream-and-chives topping for baked potatoes. 'Haven't seen it on the shelves in years, though.

-Phil

pedward
04-16-2012, 09:04 AM
I 2nd the R2R dac method, simple and creative.

Peter Jakacki
04-16-2012, 09:13 AM
I didn't hasten to comment on the R2R method but since it is being seconded....

The R2R method is very limited by resolution and tolerances and although it could work fine for maybe 4 switches it is a different story when it comes to 8 switches and 256 levels (or more) to resolve with precision. Yes, resistors are "simpler" than a chip but a chip is far easier to implement and will take a smaller footprint. If these were individual push-buttons rather than dip switches it would be possible to string them together with a single resistor of the same value per switch which would be fairly easy to resolve with sufficient precision.

pedward
04-16-2012, 08:34 PM
I will agree that exceeding 8 bits probably isn't a good idea, however you are dismissing a valid idea.

This method has been used commercially for the last 20+ years, with more than 4 bits. The propeller, with a sigma delta ADC, will have no trouble resolving the values with a 9bit software ADC. It might even work reliably with an 8bit ADC, yielding precisely the same value as the dip switch.

Ford has used this technique since the 80's for multiplexing the cruise control buttons on the steering wheel.

Duane C. Johnson
04-16-2012, 09:17 PM
I'm not sure about how to use the R2R resister networks?

The switches, presumably single NO contacts, won't work by themselves. R2R networks have the bit inputs driven both hi and low.
However, with the switch this is not the case. As I see it, you would need a CMOS buffer, or at least a low value pullup resistor.

Am I wrong?

Duane J

pedward
04-16-2012, 09:31 PM
R2R ladders are basically a bunch of 10k resistors between outputs, with the intersection connected to a switch. There is a 20k resistor as the last out on the ladder. In schematic form it resembles a ladder and is easy to build.

Phil Pilgrim (PhiPi)
04-16-2012, 09:34 PM
You're right, Duane, the R2R approach would require SPDT switches. But even then, you would have an impossible time reading 8 switches with a sigma-delta ADC accurately without precalibratiing it. I don't see this as a reliable alternative. Two banks of four SPDT switches would be more realistic.

-Phil

pedward
04-16-2012, 09:47 PM
It *can* be done with an R2R ladder chip (http://www.bitechnologies.com/pdfs/resistorladder.pdf) a 74HCT244 Octal driver, an 8 pole DIP switch, and some pullups.

At that point you may as well trade for a shift register, but it's still worthwhile discussing "old" techniques, for fear of people getting their brain boxed into certain ways of thinking.

Peter Jakacki
04-16-2012, 11:48 PM
Hey pedward ...... :) ....... now your simple idea is getting more complicated, I think it's way before that point that we would trade for a shift register mate! :) (friendly aussie banter)

The cruise control you mentioned though might be built using momentary action switches in which case it is easy to implement a resistor ladder (not R2R) as only one button will be operated at a time. I've used this technique in vending machines many years ago to cut down on the wiring loom for the selection buttons so that each switch is connected to it's neighbor with a resistor plus a common. This resistor string is at maximum value when no switches are pressed and decreases depending upon which tap is connected to ground.

Sometimes I think our digressions, even though we enjoy them, must certainly confuse the OP. Oh well, it's a forum. By all means pedward, don't stop with alternatives, we all love a skeet shoot :)

pedward
04-17-2012, 02:32 AM
Hey pedward ...... :) ....... now your simple idea is getting more complicated, I think it's way before that point that we would trade for a shift register mate! :) (friendly aussie banter)

The cruise control you mentioned though might be built using momentary action switches in which case it is easy to implement a resistor ladder (not R2R) as only one button will be operated at a time. I've used this technique in vending machines many years ago to cut down on the wiring loom for the selection buttons so that each switch is connected to it's neighbor with a resistor plus a common. This resistor string is at maximum value when no switches are pressed and decreases depending upon which tap is connected to ground.

Sometimes I think our digressions, even though we enjoy them, must certainly confuse the OP. Oh well, it's a forum. By all means pedward, don't stop with alternatives, we all love a skeet shoot :)

You're right on the implementation. There are a variety of specially picked values, and each button is a momentary tap. This was the concept I was originally thinking of when I suggested it.

Duane C. Johnson
04-17-2012, 03:50 AM
Ok, just to be complete:

Similar to the series connected resister string with grounding switches the complementary arrangement is:
The parallel resister arrangement with grounding switches,
In this case the resisters are linearly increased in value. 1R 2R 3R 4R ....
Both of these methods can't distinguish multiple switch closures.

And of course, there is the binary resister network method using single contact grounding switches. 1R 2R 4R 8R 16R ....
This can distinguish multiple switched. However, these resister networks are not very common.

Duane J

Peter Jakacki
04-17-2012, 07:07 AM
There is no need to use binary values, just the one value like this. (Oops, I think this is what you meant when you said (1R 2R 3R....)
91770

Duane C. Johnson
04-17-2012, 01:21 PM
Not exactly.

I wanted to complete the circuit design matrix.
The linear circuits can't distinguish between multiple switches, the binary circuits can.

91774

Duane J