4/18/2013

GP2D12 distance sensor 1N5819




During 250 ms, sensor is configured as a light sensor (powered), C1 charges through D1 up to SENSOR+ voltage. Low drop regulator U1 generates a 5V regulated supply. Q1 is blocked by D2 (D2 maintains base to a voltage higher or equal to its emitter voltage), so GP2D12 is not powered. Q3 is non-conducting too, preventing current flow through D3/R5/Q2. So the only significant current diverted from C1 charging is through R1 (less than 2 mA), and at the end of this phase C1 is fully charged.

During the following 50 ms, sensor is configured as a touch sensor (passive). SENSOR+ is now only pulled up to +5V through 10Kohm (inside RCX), insufficient to block Q1. Q1 and Q3 are then conducting, and GP2D12 is powered. Q2, mounted as an emitter follower, buffers GP2D12 output and its value is available to RCX through D3 and R5.



Sample code to read sensor:

    SetSensor(SENSOR_1,SENSOR_LIGHT);
    
    Wait(25);
    
    SetSensor(SENSOR_1,SENSOR_TOUCH);
    
    Wait(5);
    
    SetSensorMode(SENSOR_1,SENSOR_MODE_RAW);
    
    distance=SENSOR_1;
    
    SetSensor(SENSOR_1,SENSOR_LIGHT); //Enable C1 charge as soon as possible



Component selection

    D1 prevents destroying the sensor in case of reverse connexion. I didn't use the full bridge rectifier used in Lego sensor that enables sensors to work when connected backwards (number of needed diodes jumps from 3 to 8 !). I considered that someone able to build this sensor is also able to connect it in the right way... For those who want it, here is the diagram with full bridge rectifier.
    I used 1 Amp. Shottky diode 1N5819 for D1, inexpensive and readily available. Its low forward drop foltage is less than 0.1V for the current that flow through it, this enables to charge C1 to the highest voltage possible.
    C1 stores energy that will be used during measure phase, it must provide 5V at the end of this stage. Assuming typical values for GP2D12 (I=35mA, conversion time=50ms) and an initial 7.5V across C1, its value is C = I * dT / dV = 35 * 50 / (7.5-5) = 700 µF. Small margin with 1000 µF...
    U1 is a low drop out 5V regulator in TO92 case. I used a Telcom/Microchip TC55RP5000, but other regulators will probably work, such as STMicroelectronics L4931-50. Standard regulators such as 78L05 will NOT work because they require more than 7V at input to get a 5V output. Take care with some low drop regulators such as LM2931 that require more than 25 mA when powered at 1V. With RCX current limitation, this hog eats all energy. (I was caught with this one...)
    Q1 switches power on and off for GP2D12. At 35 mA current, I originally used a plain-vanilla BC548. My sensor began to work with it, but exhibited strange behavior. Looking to GP2D12 power supply I then discovered 2V dips ! I then looked at GP2D12 consumption and discovered that it was pulsed (220mA pulses 1/8th of time, supperposed to a 8mA constant current. See oscilloscope captures here). At such a current, BC548 has a low gain, and since I couldn't lower base resistor R1 (main current drain during capacitor charge) I used a high performance Zetex transistor, ZTX718 that offers high gain at high current (other similar devices can work!).
    C2 stabilizes U1 and helps absorb peaks of current. A low ESR version would be better (see "grass" on 5V output when GP2D12 works).

No comments:

Post a Comment