The Beeb Bodybuilding Course Part 119 By Mike Cook The charge of the Light Brigade I always intended that these articles be a spring board for you own investigations. Sometimes this involves a complete project leaving you to enhance the driving software, other times I look at some fundamental sensor or technique. This month I would like to investigate a new sensor that has recently appeared on the market, one that will no doubt be used in many projects in the months to come. I was quite excited when I came across the TSL 214 integrated opto sensor in a new copy of a trade components catalogue. This is an integrated circuit containing a row of 64 light sensors, or in other words a linear array of sensors. Now linear sensor arrays are not new, but, what was new was the affordable price and the simplicity of operation. Also, conventional linear sensors have their sensing elements, or pixels, quite close together. In this device they are spread out over a distance of 8 mm, an altogether much more useful distance. This has all sorts of potential applications for measuring the position of something sliding in front of it, in short a linear displacement sensor. I could also see how you could make a bar code reader or even an imaging device. So I thought before I embarked on any specific project I would investigate the properties of this remarkable device. The conventional way of measuring light is by a photo resistive effect, this is where light falling on some material alters its resistivity. By measuring this you can get a measure of the light. There are also similar photo voltaic effects. The point about both of them is that the sensitivity is fixed by the type of material used and the physical area of the device. Now the TSL 214 uses a charged coupled sensor or CCD technique, the same technique that is used in many camcorders. This technique can be thought of as a charge bucket. Light comes along and each photon creates a charge in the sensor, the more light, the more charge is gathered. Then this charge is read out in the form of a voltage. The point is that the voltage you get out is proportional not only to the amount of light shining on the sensor but also to the time you spent gathering the charge. Therefore the sensitivity is controlled by how often you read out the sensor's charge. It's the same technique that allows modern camcorders to offer a number of shutter speeds, they just alter the length of time between gathering the charge packets. With regard to the TSL 214 this means that we can control the sensitivity by how often it is read. There are limits however, we must read out the pixels at a rate between 500KHz and 10KHz but this gives a wide range in sensitivity. In fact we can have the light gathering for as long as we like, it's only the readout that has a lower limit on the speed. Like all silicon sensors the peak sensitivity is in the invisible Infra red at about 750 nm but it is still quite sensitive in the visible part of the spectrum, although for blue light it has dropped to 10% of its peak sensitivity. Let's have a look inside this device, figure I shows a block diagram of its function. Conventional CCD sensors use a bucket brigade analogue shift register to output the charge. This device is somewhat unconventional in that it uses individual selector switches to connect each pixel in turn to the output amplifier, this improves the performance. The device also generates a dark current reference, that is the amount of charge you would see if there were no light, and subtracts it from the light current through a differential amplifier. This simplifies the processing you have to do on the output. In addition when all 64 pixels have been read out a clock pulse is generated. This is useful if you want to connect two or more devices together to form a long sensor. The device comes in a standard size IC and the pinout is shown in figure II. It looks very different from a standard IC however, because the top is made from transparent plastic. Consequently you can see all the gold connectors and the silver bar that holds the sensors. If you have a strong magnifying glass, at least times ten, or a microscope, you can see the individual squares that form the sensitive cells. They are square and are separated by a blank piece of silicon of about half the size of the sensitive areas. You will note that there are two connections for each of the power rails, they must both be connected. Also note that down one side there is only one connector, this means that if you plug it in upside down you can't damage the device. Now over to figure III. This shows what sorts of waveforms we need to feed into this device and they are basically very simple. We kick things off with pulse on the serial input line, this is followed by 64 pulses on the clock line during which the light output is read. Finally the device generates a serial output pulse, this is so we can connect it into the serial input of another device. The device will not read out any more pixels until we get another serial input clock, note that after the last pixel is read out the clock input can continue or be at a low level. However, the time between serial output pulses determines the overall integration time and hence the sensitivity. Now I started to design a counter circuit that would generate the correct number of pulses, but, when I had finished I realised that we could do most of the work in software. The VIA on the User Port has a counter that will invert the state of bit 7 every time it times out. This can be set to run continuously and is an ideal source for the clock pulse. Also the top speed of the signal is 500KHz - exactly the top speed we need. Thus by changing the timer value you can change the sensor's sensitivity. The problem now was to synchronise the serial input pulse and the reading of the data to the clock pulses. Therefore I decided to connect bit 7 to the CB1 input because CB1 could be made to detect the edge of the pulse and use CB2 as an output to generate the serial input pulse. This left 7 bits of the User Port free. I was tempted to put a full 8 bit analogue to digital converter here but three things stopped me. First of all most applications involving positioning a sensor don't need one. Secondly it would slow the clock rate down and finally the data sheet says the device only has a 4 bit resolution. However the output is an analogue voltage so you need a comparator to make it into a digital form. The LM339 chip has four comparators in it so I decided to use all of them to make a very small flash converter. This will indicate five different light levels using the four comparators, the full circuit is shown in figure IV. Of course the flash converter does not give the output in a binary form but this can be converted in software using a look up table. The two variable resistors can be adjusted to give the desired spread of output values in response to different light levels. As we need to gather the data from the sensor quickly this needs to be done in machine code and with the interrupts off. I have written software to do this which is on the subscription disc. Basically it reads the array four times into a buffer, this allows any overcharging of the sensors to settle down, and allows the reading to reach a true level. Then the levels are displayed on the screen using direct memory access for speed. This is then repeated until the space bar is pressed. The display is then frozen and the buffer is analysed. The analysis is quite simple, the number of pixels in each level and how far from each end the first pixel change occurs. You can also alter the sensitivity of the sensor, this simply takes in a number and uses it as the lower 8 bits of the timer. In other words it simply alters the clock frequency. We can't use the full speed of the timer as the software takes some time to gather, convert and store the data between clock pulses. Therefore the program adds a constant to the sensitivity reading you enter. This is different for the 8 bit and 32 bit machines. If you have an ARM3 chip then perhaps you can run even faster. Notice that when using the more sensitive settings the response time is slower because you are gathering light for longer. One thing the software does not do at the moment is to automatically adjust the sensitivity. You can do this quite simply by looking at the number of pixels at the top and bottom level and adjusting the sensitivity parameter until there are pixels in both levels. The construction is quite straightforward and all the components are available as Body Build pack No. 86, this includes veroboard and layout diagram. You will also need some form of connection to the User Port. This is best done using Body Build packs 1 and 2 which are a board with screw connectors. However, a lower cost option is Body Build pack No.0. This consists of a piece of ribbon cable on a single socket and a screw connector connection block. You will find that this device is quite sensitive to light, even on the lowest sensitivity you can get a full output with a normal room light. If you try and cover up part of the row of sensors make sure you are using something with a sharp edge and that is truly opaque like a steel rule. If you want to reduce the sensitivity even more you can use filters fitted in front of the sensor. I am sure you will think of lots of uses for this sensor, if not then keep on reading and I am sure that I will.