larwe wrote:
On Sep 25, 1:06 am, "Michael J. Mahon" <mjma...@aol.com> wrote:
The servo PWM pulses vary from about 1 ms. to about 2 ms., so you'd need
measure the duration of each pulse (just filtering would probably slow
down response too much) and convert that timing variation into a
resistance variation of a few ohms to about 150kOhms (an FET would be
I don't think a controllable resistance is necessary, IIRC the Apple's
analog joy/pot inputs work by measuring the time taken to charge a cap
from 0 to Vih from a V supplied by using the pot as a voltage divider
from Vcc. So a simple voltage source would work just as well.
The pot is a variable series resistor to +5v, and the timing is set
by the RC time constant, so paddle reading really is linear with the
resistance of the pot.
A voltage source won't work at all, since it is either below the
trigger voltage or above it, with no intermediate states.
A current source will work, but a linearly varying current produces
a reciprocal variation in time to charge to Vih, and therefore a
reciprocal change in paddle reading.
It would be very handy just to use the PWM pulses to charge the timing
capacitor at (nearly) constant current, but that would also cause a
linear change in conductance, or a reciprocal change in resistance,
which would make for highly nonlinear paddle readings.
There's also a need to provide at least a minimal charging current so
that the timer is satisfied in about 255 paddle counts, otherwise the
timer may still be running when it is next triggered, leading to an
inaccurate count.
It also takes a fair amount of charging current to get a count of 0,
though I suppose just getting a low value would be acceptable.
Perhaps linearizing the response by making the PWM output nonlinear
is the easiest approach, since the microcontroller could do the
approximate reciprocal pretty easily (though this would place greater
resolution demands on the PWM output).
DACs are quite rare on small micros (not unheard of but rare) - an
R-2R ladder would work, but one more usually gets "DAC" output from
these devices by PWMing.
As I pressed "send", I realized that I probably should have been more
explicit about the nature of the DAC. You are absolutely correct.
A straight R-2R would require too many pins, since the paddle needs
8-bit resolution. PWM is definitely the preferred implementation.
The PWM frequency of the microcontroller would be high enough that the
filtering time constant could be quite short, allowing for very fast
"joystick" response. (Unlike the servo PWM, which has a small duty
cycle and about a 50Hz repetition frequency--much too low to permit
both adequate smoothing and quick response.)
This would be a good project for a little 8-pin microcontroller--two
input pins and two output pins. It would be fine to sample the input
(servo) pulse widths alternately to simplify the code.
It's conceptually simple but not just a matter of taking off the shelf
parts and wiring them together; definitely a weekend's worth of
tinkering and coding.
As is anything worth doing... ;-)
I would find that a lot more fun than playing any computer game!
But that's also why I suggested that the OP's issue might be best
addressed by simply lengthening the joystick cable. ;-)