EEVblog Electronics Community Forum
Electronics => Projects, Designs, and Technical Stuff => Topic started by: Starlord on January 22, 2016, 01:39:28 pm
-
I have a project where I need to stick a potentiometer at the end of a Cat5 cable which will also be carrying power and an I2C bus. I've already discussed the I2C stuff here and done the calculations. I know it's not the best idea, but the cables are robust and cheap. The signal lines are twisted with ground returns. That leaves me four more wires, two of which need to supply 5V.
The potentiometer will be used for volume adjustment but won't be carrying audio signals. It will be read by a microcontroller and then the volume will be adjusted in software. This I assume should lead to lower potential for interference mucking with the audio, and if necessary I can digitally filter the input.
What I'd like to do is either connect two analog pins to the cable, twisting each with one 5V line, or connect one analog pin to two wires, each twisted with a 5V line.
Do you see any serious potential issues with doing this that couldn't be overcome with a little averaging of the analog input? Do you think a 10K pot will be fine, or should I use a 5K? Would 100K be fine as well? I assume more power draw (5K pot) = less potential for noise coupling from outside and the data being transferred in the twisted pairs running alongside the cable.
-
Please, draw a simple (freehand) schematics what you are thinking to do as it makes easier to figure out the intent.
-
I agree. A picture is worth 1000 words. Much of your verbal description is vulnerable to ambiguous interpretation. But I would use one of the cat pair to feed the voltage to the pot, and another pair to bring the resulting voltage back. Using a separate return "ground" removes the effect of the series resistance of the line. And I would lean in the direction of lower resistance pot. 5K seems good to me. That is only 1mA at 5V, so dissipation doesn't seem like a big deal unless this is a battery-operated, low-power circuit.
-
5V microcontroller analog pin -> 7ft CAt5e cable -> Potentiometer
Pin mapping on the cable currently is:
1st pair: IO, 5V
2nd pair: SDA, GND
3rd pair: SCL, GND
4th pair: IO, 5V
I need two 5V and two GND lines because it's only 24awg wire and there's a bunch of LEDs and stuff at the other end drawing significant power and I need to keep the voltage drop to a minimum.
But I would use one of the cat pair to feed the voltage to the pot, and another pair to bring the resulting voltage back. Using a separate return "ground" removes the effect of the series resistance of the line.
What do mean by remove the effect of the series resistance?
I can see how it would make sense to have separate lines supplying power and ground to the pot, but since I need SDA SCL, and two lines each dedicated to power and ground for the LEDs, I only have two lines left to work with.
I mean if I absolutely have to I could use a separate servo cable for the pot. But that would look really hack-ish and add to the cost of the whole thing which is already high. And I could do that regardless of whether the pot works with the Cat5 since the pins will be there on the board to plug the cable into.
-
Ehhhh....
Eww..
Please, just... don't.
For the sake of your own sanity, and for the sake of others.
Your I2C communications will be all but fully shat upon for even a small amount of ambient noise (~1V). An unfiltered Chinese power adapter will blot it out. Appliances and lights turning on and off will corrupt packets. Driveby radio communications will talk over it.
Likewise, nearby radios (from AM BCB to SW, though probably not into the VHF range) will be completely swamped any time your I2C is talking.
At the very least, use a shielded (as in braid) multiconductor cable, and shielded metallic (D-sub or circular) connectors. But much better, use a signaling standard suitable for transmission, like RS-422/485 (or -232 if slow is okay), which being differential can still use UTP cable.
Tim
-
Got a higher supply rail available at the MCU end? If so, you'd do best to put a regulated DC-DC converter at the remote end for the local 5V rail, and keep its -ve supply separate from the I2C ground at that end. You can easily halve the DC supply current through the cable if you go to 12V to feed the converter. As has been pointed out, I2C is *NOT* a good choice for this - even with I2C line drivers, and if you let the supply return current lift the I2C ground you haven't got a snowflake's chance in hell of it working.
For the remote pot, consider a 4-20ma current loop. e.g.:
(https://www.eevblog.com/forum/projects/need-potentiometer-at-end-of-7%27-cable-twisted-pair-w-i2c-potential-issues/?action=dlattach;attach=195720;image)
You get near enough to an Audio taper from a linear pot and if you add some filtering and a Zener clamp at the MCU end, its more or less bulletproof. Use the same supply as the feed to the DC-DC converter, and you'll only need 1 wire back or put it and the converter each on their own twisted pair. The 8V supply is a minimum to leave a little headroom for the LM317 at the 20mA end. You could go up to 12V or 24V with no problems.
LM317 model from yahoo attached. If you don't have one, make a "3rd party" folder under "lib\sym", drop the LM317.asy file in "lib\sym\3rd party" and the LM317.lib file in "lib\sub" and it should 'just work'.
-
Ehhhh....
Eww..
Please, just... don't.
For the sake of your own sanity, and for the sake of others.
Your I2C communications will be all but fully shat upon for even a small amount of ambient noise (~1V). An unfiltered Chinese power adapter will blot it out. Appliances and lights turning on and off will corrupt packets. Driveby radio communications will talk over it.
I've already had this conversation here. The I2C specification says twisted pair is fine so long as you use appropriately sized pullups (2K in my case) and twist each pair with ground, or twist one with 5V one with ground and have a small decoupling capacitor.
And are you seriously implying that turning on a light or having an unfiltered power adapter could cause the voltage in my data lines to change by as much as 1V? I mean maybe if I were using 100K resistors and the signal was high I could see it being overpowered.
Likewise, nearby radios (from AM BCB to SW, though probably not into the VHF range) will be completely swamped any time your I2C is talking.
If that's true, how is it normal networking traffic doesn't interfere with anything? Also, would using SPI make any difference here? Not that I could. The design is way past the stage where I could make that kind of change.
Also, I see a lot of people driving Neopixel/WS2812 LEDs with these networking cables. Wouldn't those interfere with radio as well?
If it helps, I'll be using fast mode+ which is 1MHz. That seems to be outside the normal band of AM radio and well below VHF.
At the very least, use a shielded (as in braid) multiconductor cable, and shielded metallic (D-sub or circular) connectors.
Been there, done that. Two different Chinese manufacturers nicked 50% of the cables and hid the damage beneath heat shrink. Cables cost me a fortune, the failing devices hurt my reputation, and I had to replace them and pay for shipping on top of it.
But much better, use a signaling standard suitable for transmission, like RS-422/485 (or -232 if slow is okay), which being differential can still use UTP cable.
There are chips designed to convert I2C to differential signals which after a quick glance at what RS-422 is seems to be what that's about. I considered using them, and perhaps in a future revision of the board I will consider going that route. The present design would allow for it without too much difficulty.
But I've been working on this for a year now and I'm almost out of money. I've gotta get something up and running in the next month if I hope to stay in business and there's a bunch of other stuff I need to do which takes priority over maybe interfering with someone's CB radio. If it makes you feel better I don't sell a lot of these boards and they're not something that is used more than 3-5 times a year for a few hours.
-
Juts put a 10Kohm potentiometer between the 5V and GND and connect the wiper to the wire. At the other end place a 100ohm resistor in series with the wire and place a 100nF capacitor to the ground from the other end of the resistor in order to provide some filtering**. Then feed the filtered signal into A/D-input of your processor. You may want to do some digital filtering (averaging) for the results you read from the A/D-converter in order to get cleaner signal.
Ps. If this works, you owe me a beer :)
** ie. 100nF capacitor between the A/D-input and the ground.
-
Radical thought! Why not put an I2C ADC at the pot end to read the pot?
-
The potentiometer will be used for volume adjustment but won't be carrying audio signals. It will be read by a microcontroller and then the volume will be adjusted in software.
...
Do you see any serious potential issues with doing this that couldn't be overcome with a little averaging of the analog input? Do you think a 10K pot will be fine, or should I use a 5K? Would 100K be fine as well? I assume more power draw (5K pot) = less potential for noise coupling from outside and the data being transferred in the twisted pairs running alongside the cable.
Should be fine.
Be sure to put a nice ceramic capacitor on the microcontroller's analog input pin (pin->ground) to help absorb any noise. 0.1uF should do it.
-
Radical thought! Why not put an I2C ADC at the pot end to read the pot?
:-+
-
Got a higher supply rail available at the MCU end? If so, you'd do best to put a regulated DC-DC converter at the remote end for the local 5V rail, and keep its -ve supply separate from the I2C ground at that end. You can easily halve the DC supply current through the cable if you go to 12V to feed the converter.
Yes I have a 12V supply. I considered this approach at one point but balked at the added cost of sticking switching regulators on each satellite module. This project is already getting ridiculous on the cost/profit ratio.
As has been pointed out, I2C is *NOT* a good choice for this - even with I2C line drivers, and if you let the supply return current lift the I2C ground you haven't got a snowflake's chance in hell of it working.
I've done the calculations. Forget ground lift for a moment. If the pullups are to 5V on the microcontroller side but the Vcc supply drops below I think it was 4.75V at any time then I would be outside the max voltage specs for the pins. That's why I have two power and two ground, and why I used Cat5 cable which has 24awg wire. The original plan was to use a flat flex cable, but there wasn't enough copper in that to keep the voltage drop low enough if I was drawing a worse case assumption of 1A.
So I know what my maximum voltage droop and ground lift might be. And they should be in spec.
And if something works, is is really a bad choice, if it reduces the cost of the design, and makes the cables much more reliable on my extremely limited budget? I mean yeah I'd be making my life easier on the engineering side if I weren't trying to walk such a fine line, and if I screw it up and the data transmission is unreliable, that's bad.
For the remote pot, consider a 4-20ma current loop. e.g.:
(https://www.eevblog.com/forum/projects/need-potentiometer-at-end-of-7%27-cable-twisted-pair-w-i2c-potential-issues/?action=dlattach;attach=195720;image)
You get near enough to an Audio taper from a linear pot and if you add some filtering and a Zener clamp at the MCU end, its more or less bulletproof. Use the same supply as the feed to the DC-DC converter, and you'll only need 1 wire back or put it and the converter each on their own twisted pair. The 8V supply is a minimum to leave a little headroom for the LM317 at the 20mA end. You could go up to 12V or 24V with no problems.
When you say a 4-20mA current loop, what do you mean by that? Are you suggesting I select a pot whose resistance is low enough that 4-20mA flows through it constantly? So a 1K pot? I don't understand your schematic. On first glance I'd say Vpot is connected to the wiper but what's with R1 and R3 and the diagram below them?
Furthermore why are you suggesting implementing an audio taper in hardware? I can implement that programmatically. And in doing so I can support both linear and logarithmic pots.
LM317 model from yahoo attached. If you don't have one, make a "3rd party" folder under "lib\sym", drop the LM317.asy file in "lib\sym\3rd party" and the LM317.lib file in "lib\sub" and it should 'just work'.
What is that application? LT Spice or something? I've never had time to learn that. Don't laugh! I've had very good success with my boards working even without simulating everything. :) I have occasionally used some online simulators to understand circuit behavior when implementing high pass filters or to determine what size resistors I should use for a level shifter that needed to operate at several MHz.
-
Radical thought! Why not put an I2C ADC at the pot end to read the pot?
Money.
If it doesn't work the way I want it to I can just tell my users who insist on sticking a pot at the end of the cable (most of them will not) to use a separate servo cable and then they can either buy that themselves or I can charge them extra for it. But adding another $3 to the cost of my board for a tiny fraction of people who insist on that volume pot isn't worth it.
-
Juts put a 10Kohm potentiometer between the 5V and GND and connect the wiper to the wire. At the other end place a 100ohm resistor in series with the wire and place a 100nF capacitor to the ground from the other end of the resistor in order to provide some filtering**. Then feed the filtered signal into A/D-input of your processor. You may want to do some digital filtering (averaging) for the results you read from the A/D-converter in order to get cleaner signal.
Ps. If this works, you owe me a beer :)
** ie. 100nF capacitor between the A/D-input and the ground.
What is the purpose of the 100 ohm resistor here? My gut says its to prevent ringing, but is ringing a concern for a signal that changes as slowly as one from a potentiometer?
And what's the 100nF there to filter out? Stuff it picks up by acting like an antenna I assume, but like, what frequencies will that particular size cap filter and why not a larger or smaller cap? Just wanna learn what I can about this stuff rather than just implement something not knowing why it works.
-
Juts put a 10Kohm potentiometer between the 5V and GND and connect the wiper to the wire. At the other end place a 100ohm resistor in series with the wire and place a 100nF capacitor to the ground from the other end of the resistor in order to provide some filtering**. Then feed the filtered signal into A/D-input of your processor. You may want to do some digital filtering (averaging) for the results you read from the A/D-converter in order to get cleaner signal.
Ps. If this works, you owe me a beer :)
** ie. 100nF capacitor between the A/D-input and the ground.
What is the purpose of the 100 ohm resistor here? My gut says its to prevent ringing, but is ringing a concern for a signal that changes as slowly as one from a potentiometer?
And what's the 100nF there to filter out? Stuff it picks up by acting like an antenna I assume, but like, what frequencies will that particular size cap filter and why not a larger or smaller cap? Just wanna learn what I can about this stuff rather than just implement something not knowing why it works.
The 100ohm is intended to provide rudimentary protection fro the controller's input from possible voltage spikes in the cable and provide slight filtering together with the 100nF capacitor. As I do not know the input impedance of your A/D-converter I selected 100ohm resistance. It can be increased to 1kohm or more in order to provide better protection and improve filtering if the A/D-converter input. You can also increase the 100nF to 1uF if needed. The component values are not too critical here.
-
R3 is the pot, 220R wired as a simple variable resistor. The stuff in the dashed box under R3 lets the LTSPICE simulator sweep its value in simulation time as it doesn't have an arbitrary variable resistor model. The current source Ipot3c (purple line) corresponds to pot rotation, 0A to 1A is 0% to 100%. Its arranged so that 0% rotation is the max resistance, for minimum output at Vpot for your ADC. V(in-out) (green line) is the voltage drop across the LM317 so you can check there is enough headroom for it to regulate the current.
However, its over-complex compared to a simple remote I2C ADC with the pot wired across its supply pins, which also frees up more wires in your cable for the supply and ground. Put it on a small option board soldered to the pot legs, with a fly lead to plug into a four pin header on your remote board and charge what the market will bear for the remote pot upgrade! If you think there's ever a need to have more remote pots, or buttons etc. you can extend the concept subject to I2C addresses being available. The software can poll for the I2C ADC's presence so it can be entirely plug&play.
-
Hm...
http://www.digikey.com/product-detail/en/MCP3021A5T-E%2FOT/MCP3021A5T-E%2FOTCT-ND/1979808 (http://www.digikey.com/product-detail/en/MCP3021A5T-E%2FOT/MCP3021A5T-E%2FOTCT-ND/1979808)
$0.89. Plus labor. So maybe $1.25 more per board.
Versus creating yet another PCB which will cost $20 min to manufacture, plus a $3 flat flex cable to go with it, plus a pot for $1. And then having to try to convince my customers that it's worth $35 so I can make a little profit...
Also, I'd have to put a connector that'll cost me $2 w/ labor on the the board the Cat5 goes to in order to provide a way to connect the thing to it. So, a $1 JST PH connector + a $1 chip vs a FFC connector that costs $2 with labor. Whether or not the end user decides to purchase the upgrade...
Ehh...
It's a neat idea being able to connect multiple pots though, I'll give you that. Unfortunately at the quantities I'll be manufacturing these it doesn't make a lot of sense since I can't get away with charging $10-$15 for the upgrade and not lose money.
Maybe I'll use the ADC chip. Or this one by TI since it can handle the higher I2C bus speeds:
http://www.ti.com/lit/ds/symlink/adc081c021.pdf (http://www.ti.com/lit/ds/symlink/adc081c021.pdf)
Only thing is that one's 8 bit, and not sure what that will do to my volume control with the audio tapering code. Ie, converting the value to float between 0 and 1 and then multiplying it by itself to approximate the log curve. Worried about hearing the volume suddenly step down on the low end. Guess I could interpolate the value over a period of time to smooth the transitions out. Hm...
Well, thanks for all the help guys!
-
I've already had this conversation here. The I2C specification says twisted pair is fine so long as you use appropriately sized pullups (2K in my case) and twist each pair with ground, or twist one with 5V one with ground and have a small decoupling capacitor.
For signal quality, it should survive just fine.
That means it'll function, in the average case.
That doesn't mean it's guaranteed to function in the worst case, or at all!
Appnotes rarely discuss EMC, for probably three reasons:
1. People hardly know anything about it;
2. It's a fairly complicated subject. Not at all intractable, but beyond the scope of the average graduate;
3. The authors themselves are just as likely, to be unaware of, or inexperienced with, the subject. Misinformation abounds.
So if you haven't seen much on the subject... it's not unusual, sadly.
And are you seriously implying that turning on a light or having an unfiltered power adapter could cause the voltage in my data lines to change by as much as 1V? I mean maybe if I were using 100K resistors and the signal was high I could see it being overpowered.
Yes! Absolutely!
A light switch doesn't seem like much, but a mechanical contact is extremely fast, having a rise time of fractional nanoseconds. Closed during the mains voltage peak, you get 160V (or more) of ringing, dancing around the power lines. It quickly permeates the building, and even at a modest distance from the wiring (within a room, say), can be several volts on a modest length of wire. The pulse is over in some tens of nanoseconds, so it's very easy to miss (and doesn't much disrupt limited-bandwidth radio transmissions), but if you have something susceptible (like digital logic inputs, which can respond in nanoseconds), it can be a big deal.
Note that the pull-up strength has almost no effect on signal quality or susceptiblity. At RF, the impedance of the cable is the important factor (~100 ohms, give or take wide peaks and valleys at characteristic frequencies).
The FCC recommends (but does not require) susceptibility testing at a level of 3V conducted, and 3V/m radiated. The IEC (to acquire a CE mark) requires this. Robust or special equipment may need to be tested for more.
Those are the levels on the outside. Very crudely speaking, you can expect about half that to appear on the signal lines. Maybe it'll be a lot less (1/10th, say), because most of the AC current is carried by the power and ground lines; maybe it'll be a lot more (10 times, say) due to resonance and poor grounding.
In any case, we're talking levels that are well within the ballpark of "fail", which isn't a very good place to be. Wouldn't it be much better to be, say, one or two orders of magnitude outside of that?
You can apply some filtering, but I2C is fundamentally limited on how much capacitance it can be loaded with, especially for "high speed". And the combination of open-collector loads, single ended digital pins, and high impedances, makes any kind of inductive filtering relatively ineffective. And you can't really shove it into a more robust standard like RS-422, because it's bidirectional and open collector. (Possibly a pair of CAN PHYs could be used, though?)
Likewise, nearby radios (from AM BCB to SW, though probably not into the VHF range) will be completely swamped any time your I2C is talking.
If that's true, how is it normal networking traffic doesn't interfere with anything?
You mean normal for CAT5, i.e., Ethernet?
Ethernet is a great signaling standard. It's very stable, robust, and tolerates situations that would nuke other interconnects (like mains ground loop voltages!). The key is, its signals are transformer coupled, and filtered with common mode chokes besides. So the common mode (emissions/susceptiblity side) footprint is very small, despite carrying near-RS485-level voltages. (RF emissions need to be in the < 1mV range, so we're talking ~60dB worth of balance on the twisted pair.)
RS-422 isn't quite as good, but properly implemented, can do a fine job. The receiver input common mode range is +/-7V, so it will completely ride through any commercial-level noise you throw at it, with just the bare ICs, no filtering. With a little filtering, and perhaps a reduced baud rate, it will tackle all but the worst industrial noise, too. Same goes for other robust "pair" type signals, like CAN and such. (But not most high speed pair types, like USB, HDMI, LVDS, etc. They have limited common mode range, and USB has quirks that preclude almost any kind of filtering.)
Provided with a DC-DC converter and optoisolators, a galvanically isolated RS-422/485 channel can perform just as well as Ethernet. If probably slower.
Also, would using SPI make any difference here? Not that I could. The design is way past the stage where I could make that kind of change.
Yes -- implemented correctly.
SPI is very easy to implement with RS-422 signaling. Just tack transmitters on the output pins, and receivers on the input pins. Match up the pairs through twisted pair cable (UTP is fine). Don't forget a few ground wires, by the way: ground reference is still required (again, it's not transformer coupled like Ethernet is!).
This takes up more than a few pins, but it can be used at reasonable speeds (RS-422 transmitters are available up to 30Mbaud) and distances (> 10m, anyway; though the standard does recommend a baud vs. distance tradeoff).
At this point, you might simply consider other means, like a pair of microcontrollers and asynchronous serial over RS-422. It's a bother but it saves wires.
Also, I see a lot of people driving Neopixel/WS2812 LEDs with these networking cables. Wouldn't those interfere with radio as well?
Just because other people are doing it, doesn't mean they're doing it right... it just means other people are doing what yet-other people are doing...
And likely, yes, they do, quite a lot. AM radio isn't much used by 'youngins', but that doesn't mean it's not interfering.
If it helps, I'll be using fast mode+ which is 1MHz. That seems to be outside the normal band of AM radio and well below VHF.
No, nooo, nononono! That's smack dab in the middle, and considerably below it, and considerably above!
Consider the data stream. It won't be toggling every single clock cycle. Often it will sit still for several bit times. A few of those repeating and you've got a lower frequency component (presumably, as low as 1/16th the clock rate, if the address field is all 0's or 1's, and the data field is opposite). (There are emergency services down there, e.g. international maritime around 500kHz.) Likewise, each one of those switching edges contributes high frequency harmonics, probably extending into the 10s of MHz. (How far depends on the fall time, which is specified as 20ns minimum, so harmonics will go up to perhaps 50MHz.)
In general, data covers a wide bandwidth of noise! So it's that much more important to keep it from leaking out of wires and such.
Been there, done that. Two different Chinese manufacturers nicked 50% of the cables and hid the damage beneath heat shrink. Cables cost me a fortune, the failing devices hurt my reputation, and I had to replace them and pay for shipping on top of it.
Yuck. Definitely put that into the contract -- dependent on approval of items, do a full proper inspection, all that good stuff.
In any case, you'll have that problem with any cheaply made cable. And CAT5 is often solid core, which will flex even worse than stranded, lightly-nicked. I suppose you're more comfortable with that, then...
Is the price really so critical that you can't get a local builder to do it? I've seen quotes for basic cables from US companies, they're not terrifically bad. Quantity pricing factors heavily, though.
Tim
-
That leaves me four more wires, two of which need to supply 5V.
Two spare wires? Two wires is perfect for I2C.
Your I2C communications will be all but fully shat upon for even a small amount of ambient noise (~1V). An unfiltered Chinese power adapter will blot it out. Appliances and lights turning on and off will corrupt packets. Driveby radio communications will talk over it.
Likewise, nearby radios (from AM BCB to SW, though probably not into the VHF range) will be completely swamped any time your I2C is talking.
You can apply some filtering, but I2C is fundamentally limited on how much capacitance it can be loaded with, especially for "high speed".
Question: Why does it need to be high speed? A volume control could be read once per second, no problem. Add some capacitance, clock it at 20Hz (or whatever). Problem solved?
-
In any case, you'll have that problem with any cheaply made cable. And CAT5 is often solid core, which will flex even worse than stranded, lightly-nicked. I suppose you're more comfortable with that, then...
I said the Cat5 were cheap, not cheaply made.
I paid $10 for each of the cables I had assembled in China.
The Cat5 cables I can get for $3 each from Digikey:
http://www.digikey.com/product-detail/en/DK-1511-007%2FBL/AE10488-ND/2268280 (http://www.digikey.com/product-detail/en/DK-1511-007%2FBL/AE10488-ND/2268280)
7 strand 24 AWG. No reason to expect it will break.
Is the price really so critical that you can't get a local builder to do it? I've seen quotes for basic cables from US companies, they're not terrifically bad. Quantity pricing factors heavily, though.
Let me put it this way. This design was supposed to take three to five months to finish. It's taken a year. If I'm lucky I'll finish by the end of the month and I can order a set of prototype which will take three weeks to manufacture. If I'm lucky those prototypes will work, and it will only take a couple weeks to write the code. Because if I'm lucky I have enough cash to last me through the end of March.
I don't even know where I'm gonna get the money to manufacture the boards if the prototypes do work. I'm hoping people will decide to pre-order a bunch once they see it in action. I know my customers so it's a fair bet they will. But still. Money is most definitely tight.
I've got several other projects in the works too of course. I'm not putting all my eggs in one basket. Nor is this my first time at the rodeo. Let's just say the last three years have been... interesting.
Anyway, thanks for all the information!
-
Question to OP: Why does it need to be high speed? A volume control that could be read once per second with no problems.
Because it's not just a volume control. There's also an IO expander for some switches and a couple LED drivers. That's why my original question was about an analog signal alongside an I2C bus. The pot itself was just going to be connected to an analog pin. It may still be. I haven't decided.
-
There is a simple reliable way to do this using cheap and versatile CAT5:
(1) Forget about I2C and its idiosyncrasies. If not a mission-critical device, just wire the pot and just send the output of the pot back to the MCU and read the filtered value with an A2D input of a MCU or just use the pot as a analog pot and send the audio signal back, just make sure to use separate power, digital and signal ground connections. Simple and likely to be just what you need.
Use 8-bit SR's if you want super noise immunity(for example CMOS CD4021BE CD4094BE SR's with 15V Vdd) to control the LED's and send the switch states back to the host. No fancy in/out expander chips required. This technique only needs clock and data to turn on/off LED's and read switch states and just use the pot as a analog vol. ctrl.
(2)Use a cheap PICC MCU at the remote end of the 7' cable to handle the switches and lights and read any pot you want with it's 10-bit A2D. Send the MCU >7.6V and use a 78L05 to give the remote 5V MCU stable power. Use unfiltered >7.6V to drive LEDs through BJT's or MOSFETs to eliminate 5V MCU supply fluctuations to ensure stable A2D measurement of the pot. If the remote LED's are slaved to the main unit, a simple SR chip can control the LED's instead.
Only in the most mission-critical device will need to send data to/back to the main unit using a schmidt-trigger input stage or comparator(LM393/LM339) and then output to an IRQ RBIE or INTE pin to receive data on a falling edge start bit. If anything than the most mission-critical applications, the schimdt-trigger input stage might not be needed at all since all transmissions would be error checked as described below and repeated.
Very high data rates are possible for this 2-way communication just using two twisted pairs terminated by resistors at the remote and receiving end.
Format data sent back like RS232 except using a custom long word, no. of bits suitable to handle the data size. Use a start bit followed by the data stream. Each bit would correspond to a switch or LED setting followed by 10-bits for the pot setting. Send data stream as one long stream transmission, but all the bits are first sent normal and then the stream inverted. Receiving MCU compares the two sequential bit sets to ensure 100% noise immunity. Use one wire for Clk and one wire for Data out for xmit and Data-in receive.
Format data to control LEDs without using the remote MCU the same way, but only a few bits will be required to set states of the LED's and as a request to send signal for the start of the long data stream output going back to the host MCU. The remote MCU needn't even be involved in turning on-off LEDs by just feeding the control stream to one or more 8-bit SR chips (74HCT164 for example to drive at least 8 LED's without any other decoding). The SR can directly drive the LEDs using a small limiting resistor.
-
Hm... I just realized that if I don't run a seperate 5V and GND supply to the pot then I'm likely to have serious problems. We were discusion ground lift and voltage drop earlier and I mentioned how I'd calculated what they would be in the worst case. Well the digital stuff should be able to tolerate some noise, but if the voltage is varying by 0.2V peak to peak, that's 4% of my 5V supply. That's a lot of variation in the volume level. With decent digital filtering I could correct for it but potentially at the cost of the volume not responding instantly to input. |O
Perhaps for the sake of my sanity I should just require the user to run a long servo cable for the pot if they want one at the end of the cable. I really can't afford to spend another month rethinking and redesigning this.
I may implement that suggestion to add a filtering capacitor and series resistor though. How would I calculate the best value resistor to use assuming I know the pin's impedance or whatever it was? I know the 100 ohms was just a guess.
-
If you simply use separate grounds for the LED's and Sw's and for the pot's analog ground you won't have these two circuits interfering with each other at all. Certainly the digital ground may rise .2V (at the remote end of the 7' cable) for example, but the analog signal and its ground level would not be affected. If you use CAT5, you have plenty of wires to resolve this groundloop problem!
-
Yes, but the pot is a voltage divider and I only have one pair free to assign as I wish. I could give it it's own ground, but the 5V level would still be bouncing around with the digital circuits drawing lots of power intermittently, wouldn't it? I mean, it would cut the difference in half, but...
-
That is when you stick a current source at the far end controlled by the pot. Only two wires needed (or one if you can run it off the far end 5V supply) and as long as the wire insulation is good, the receiver gets exactly the same current, no matter how the voltage is bouncing around.
-
Question to OP: Why does it need to be high speed? A volume control that could be read once per second with no problems.
Because it's not just a volume control. There's also an IO expander for some switches and a couple LED drivers. That's why my original question was about an analog signal alongside an I2C bus. The pot itself was just going to be connected to an analog pin. It may still be. I haven't decided.
You could have two separate I2C buses. One just for this.
(And .... if this is likely to fail at high speed then won't the IO expander fail too?)
-
Yes, but the pot is a voltage divider and I only have one pair free to assign as I wish. I could give it it's own ground, but the 5V level would still be bouncing around with the digital circuits drawing lots of power intermittently, wouldn't it? I mean, it would cut the difference in half, but...
How about a rotary encoder? That only needs two signal wires and adding capacitance is no problem (it's even a good idea, for all the reasons stated earlier).
-
The original plan was to use a rotary encoder. The issue with that though is that an encoder won't remember its position, so every time you power the board up the volume would have to default to max. I can't store the volume in EEPROM because there's a limited number of write cycles, and I can't store it on the SD card because I can't halt the audio to do a write operation.
Then again, while the EEPROM is only good for 100K write cycles, if I were to say, write to it 250ms after the last volume adjustment and the user adjusted the volume 10 times a day every day (an absurd notion) then it would take some 27 years for the EEPROM to fail.
But there's something to be said for a volume knob that stops when you reach max volume to you know it's at max volume. Also users may want o use their own pots.
-
Perhaps we are all over-thinking this. If this is just a volume control, lets scale the solution to the actual design and operational requirements.
If there is a ground-current-induced offset, can it simply be eliminated by firmware?
If there is induced noise in the return analog signal, can it simply be filtered in hardware (capacitor) or software (averaging)?
-
Then again, while the EEPROM is only good for 100K write cycles, if I were to say, write to it 250ms after the last volume adjustment and the user adjusted the volume 10 times a day every day (an absurd notion) then it would take some 27 years for the EEPROM to fail.
Yep. It's really a non-issue. The 100k is usually very conservative. People have gone over a million (http://tronixstuff.com/2011/05/11/discovering-arduinos-internal-eeprom-lifespan/), no problem.
Will they still be using your gadget 27 years from now?
If you're really paranoid you can implement a simple wear-levelling algorithm. eg. Write a 16-bit counter along with your volume level. Increment the counter with every write. When the counter reaches 0xffff you move on to the next location in EEPROM and write the values there.
At power-up you simply step over any location with a counter of 0xffff until you find your data
When you reach the end of your reserved area of EEPROM (eg. 32 entries) you wipe the area to zero and start over. If you have the whole of EEPROM to play with you should be OK for several millennia (the flash memory holding your program will probably self-erase before then).