SENSING LIGHT.

One of the easiest ways to sense light electronically is to use a LDR (Light Dependent Resistor), as it's name suggests, the resistance of the device is proportional to the amount of light hitting it. As the light level increases the resistance of the device falls. One example of such a device is the ORP12 as used in Bugbot. The range of resistance covered by the ORP12 is approx. 50 Ohms at high light level to about 1 MOhm near dark levels. The problem then comes of converting this change in resistance to a binary number. One method would be to include the LDR as one leg of a potential divider circuit, the output of which would be a varying voltage proportional to the amount of light hitting the LDR. Then use an A2D (Analogue to Digital) converter to change the varying voltage to a varying binary number which is proportional to the amount of light hitting the LDR.

However as the PIC16F84 has no onboard A2D converters a different approach is used:
Switched Capacitance A2D conversion.

Below is a simulation circuit set up to demonstrate the operation of the Switched Capacitance method of A2D conversion.

In the simulation circuit R1 is used to represent the various resistance values of the LDR. For this example the values 50K to 600K Ohms, representing high and low light levels, are used. Vsqr1 and D1 emulate the open collector of C1's discharging circuit (operated by the micro controller). V1 is the +5 Volt power rail. When the switching waveform at P1 is high (logic '1') the capacitor C1 is charged via R1 (LDR). How quickly C1 charges depends on the resistance of R1. IC1a is a schmitt trigger a circuit that switches state when it's input rises above a preset value and switches back when the input falls below another preset value (this value is less then the previous one). In the case of the 7414 these values are preset at 1.7 and 0.9 Volts.
These points are know as the positive and the negative going thresholds. It then follows, that when the charge on C1 reaches the positive going threshold IC1a will switch, and as it's an inverting schmitt trigger it's output will go low (logic '0'). During the discharging cycle, IC1a will switch back (logic '1') when the voltage on C1 falls below the negative going threshold.

Note: In the real circuit, the width of the discharge would be much shorter than the width of the charging pulse.

So how does all this charging and discharging get converted to a binary number. Hopefully the following waveforms will help in understanding how it all works.

Remember that Vsqr1 is a square-wave generator that generates a 10Hz discharging signal. In other words C1 is discharged 10 times a second irrespective of what the LDR is doing. The charging and discharging cycles are clearly shown on the charts.

 

P1, P2 and P3 are the waveforms at Test points P1, P2 and P3 on the schematic above.

At the start of the cycle there is no charge on C1 and is below the negative going threshold thus the output of IC1a is High. The charging cycle then goes High, D1 prevents this High from charging C1, however C1 is now free to be charged from the supply voltage via R1. In this example the light level is low. Emulated on the simulation by increasing the value of R1 to 600KOhms. This high resistance slows the charging of C1. When the trigger level (Positive going threshold) is reached the output of IC1a goes low. Shortly after this point the discharge cycle begins and C1 is discharged via D1.

As there is virtually no resistance in the discharge path, C1 discharges almost instantly and as a result the output of IC1a goes High again. So the from the time that the charging cycle went high to the time the output of IC1a went low is proportional to the amount of light hitting the LDR.

 


Let's look at another example this time the value of R1 is dropped to 50KOhms to emulate a High light level at the LDR.

The process is exactly the same as above with the exception that R1 has a lower resistance. This means that C1 charges much faster, as can be seen on the waveform at P2. The trigger level is reached much sooner in the cycle and the resulting output from IC1a is a much shorter pulse. Once again the time from the charging cycle going High to the output of IC1a going low is proportional to the amount of light hitting the LDR.

Hopefully by now you will see that the width of the pulse at the output of IC1a (P3), is proportional to the amount of light hitting the LDR. For low levels of light the pulse is wide and at high light levels the pulse is much shorter.

The last step in the process is to measure the length of the pulse at the output of IC1a. This can be done by connecting the output of IC1a to one of the port pins on a micro-controller (In Bugbots case, the PIC16F84) and using software to measure the width of the pulse. Thus what we end up with is a varying binary number that is proportional to the amount of light hitting the LDR.

 

HOME