Posted: 02:06am 29 Mar 2014 |
Copy link to clipboard |
 Print this post |
|
here we are, the mark 2 version. this time i've adopted a circuit first written about by Bob Pease back in 2000, in a column titled "What's All This Current Limiter Stuff, Anyhow?". it removes the V+/V- drop of the LM334 to outside of the current loop, using an external PNP transistor. in this configuration the set current is no longer given by I=68mV/R, but instead I=64mV/R. this is due to the V- pin current not going through the load (so i am led to believe).
i've switched to a 140uA current, and use strings of 680r and 2k7 resistors. the 180r + 470r resistors in the circuit, plus the switch resistance (in my keypad this around 20 ohms) combine to make up the bottom '680r' resistor.
even when a key is not pressed there is still a current flow, corresponding to a non-existent key "20". this serves as a calibration point for the software. there are no fixed voltages specified in the code, just a ratio, with everything self-calibrating whenever no key is pressed. the design should be more than happy working down to the minimum Vcc of 2.3 volts.
here is the circuit:
and here is some test code:
SetPin 4, AIN
maxvolts = Pin(4)
SetTick 10, keyISR
Do
Do
Loop Until ready
Print Str$(inkey,2), Str$(keyvolts,6,3), Str$(maxvolts,6,3)
ready = 0
Loop
keyISR:
keyvolts = Pin(4)
inkey = Cint( keyvolts * 20 / maxvolts )
If inkey > 18 Then maxvolts = (0.995 * maxvolts) + (0.005 * keyvolts)
ready = 1
IReturn
note the line starting "If inkey > 18...", which implements the self-calibration when no key is pressed. the 0.995 and 0.005 have been chosen to allow for a relatively slow drift over a number of seconds, ignoring any rapid transients.
the only problem i have noticed is that if you hold your hand closely round the flex to the keypad, some jitter is present on the voltage fed back to the micromite. probably not an issue in a completed and boxed up project, but someone might like to have a closer look at this with a scope and see if it can be easily filtered out. going to a higher current may help, but then the current draw is now always present (even with no key pressed), so it is desirable to keep it as low as possible in case of battery operation.
enjoy,
rob :-) |