[email protected] (Homer J Simpson) wrote in
My ohms law isnt totally gone .. but is it
R = 12v_source/30ma sinking capacity of stamp pin
or
R = 7v_needed to get rid of/30ma sinking capacity of stamp pin
and what about the zener ?
That would be what you would want if the stamp pin were acting as an
output, and you wanted to avoid burning it out. But that's not
what you're doing. Instead you're using it as an input. You don't
really care how much current flows, as long as the stamp can sense
the voltage correctly and nothing gets damaged.
There's a common trick for this. All you need is a largish resistor.
You don't actually need a zener or anything remotely as complex as
a 7805. I'll explain.
Logic inputs normally don't let any current flow (they're just
voltage-sensitive) but they have a pair of "protection diodes" on
the chip, going to the positive and negative (ground) rails, to
keep the input voltage from going out of bounds and damaging the
actual logic gate. The protection diodes aren't designed to take
very much current, but they can take some. So, let's say you simply
connect your stamp input to the 12v signal through a resistor, which
I will randomly choose a value for, of 100K. Some current will flow
through the resistor, into the input pin, through the protection
diode, and onto the +5v supply. How much current? Well, (12v - 5v)/100K,
or 0.07 milliamps. Not very much! (Actually, it will be a little
less, since the protection diode will have some voltage drop
associated with it.) 0.07 mA is small enough that it won't hurt
anything to have that much current going through the protection
diodes. So this ought to work fine.
Going into more detail, though, what values of resistor are OK?
There'll be a lower limit and an upper limit. If the resistor is
too small, then too much current will flow through the protection
diodes (which, remember, really aren't intended to carry very much
current) and burn them out, probably followed by burning out the
rest of the chip. If you look in the datasheet for the PIC on the
Stamp, in the "Electrical Characteristics" section it lists the
maximum "input clamp current". The particular PIC I just looked at
says it can handle 20mA there. (That's more than I thought!)
I'd be conservative and limit it to 2 mA, which works out to a resistor
value of (12v - 5v)/2mA = 3.5K. So any resistor larger than 3.5K
should be safe.
What's the upper bound? How large of a resistor can you use before something
stops working right? This is mostly determined by the capacitance of the
input pin, and its leakage current. The capacitance will bite us first
so I'll just calculate based on that. The datasheet says the IO pins
have at most 50 pF of capacitance. When the signal voltage changes, that
50 pF has to charge or discharge through the resistor. To a *very* rough
approximation, the time it takes for that to happen is R*C, the resistance
times the capacitance (if you work out all the units, you'll find that
ohms times farads equals seconds, so this makes sense). If you make the
resistor too large, then the input won't see changes quickly enough.
For the 100K resistor I mentioned earlier, R*C = 100K * 50p = 5 microseconds.
That's much faster than you need if you're just sensing a brake pedal.
In fact, you might want to hang an extra capacitor onto the input pin
(after the resistor) to slow down the input to (say) 5 millisconds, which
could also filter out small glitches and spikes on the line and help
to "debounce" the input a little.
I hope this explanation helps a little.