Photo Detector
The photo detector experiment is an introductory application that unitizes a simple circuit to detect changes in the amount of light falling on a phototransistor. This circuit connects an input port to the 6522A VIA to the phototransistor circuit to allow the sense the presence or absence of light. The same basic concept can be used for many real time sensor applications. The experiment only senses the presence or absence of a fixed amount of light. Advanced applications would use a different circuit that includes a analog to digital converter to actually measure the amount of light hitting the sensor.
The phototransistor is connected to the 6522A Port B bit 0, which is pin 10 on the 6522A. Here is the schematic:
A photo transistor works the same as a normal transistor, except that the base current is controlled by the light hitting it. The more light, the more base current. Base current controls the amount of current flowing from collector to emitter.
In this circuit, the input to Port B, bit 0, senses the level of voltage at the collector of the photo transistor. With little light, the current flowing through the photo transistor is limited and the voltage rises to close to supply levels due to the influence of the current flowing through the 10K resistor. With sufficient light, the current flows through the phototransistor and the voltage on the collector drops to near ground.
The state of the phototransistor can be detected by reading the 6522A port B, bit 0. 6522A ports default to input mode so, no set up is necessary. To read port B, drop into the monitor by typing reset. If reset brings you to basic type "CALL -151" to get to the monitor. Then type "C0X0" return. X should be replaced by the slot number plus hexidecimal 8. For example: if the card is in slot 7, type "C0F0". The least significant bit of the byte displayed indicates the state of the photo-resistor. Repeat this read with the photo-resistor shielded from light and with a flashlight shinning on it.
Now return to basic by typing "control-B" followed by return. The port can also be read from BASIC by using the peek command. First you need to calculate the address of the port in decimal. Convert the hexidecimal address calculated in the previous section to decimal. Then subtract this number from 65536 and negate to find the number to be used in the peek command:
slot 7 example C0F0=49392 65536-49392=16144 negate and use -16144 in the peek command
type "PEEK (-16144)" several times with light striking the photo-transistor and with the photo-transistor in the dark
Here is a short integer basic program the reads the state of the input port and reports when it changes
10 A = PEEK (-16144) 15 PRINT "STARTING PORT B";A 20 B = PEEK (-16144) 30 IF A = B THEN 20 40 PRINT "PORT B CHANGED";B 50 A= B 60 GOTO 20 70 END
Other follow on experiments for the adventurous experimenter include replicating my old "Shutter Tester" project [1]