Arnaud VALLEY / Mbed 2 deprecated Pinscape_Controller_V2_arnoz

Dependencies:   mbed FastIO FastPWM USBDevice

Committer:
mjr
Date:
Fri Nov 29 05:38:07 2019 +0000
Revision:
101:755f44622abc
Parent:
100:1ff35c07217c
Child:
104:6e06e0f4b476
Use continuous asynchronous frame transfers in image sensors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 100:1ff35c07217c 1 // Toshiba TCD1103 linear image sensors
mjr 100:1ff35c07217c 2 //
mjr 100:1ff35c07217c 3 // This sensor is similar to the original TSL1410R in both its electronic
mjr 100:1ff35c07217c 4 // interface and the theory of operation. The details of the electronics
mjr 100:1ff35c07217c 5 // are different enough that we can't reuse the same code at the hardware
mjr 100:1ff35c07217c 6 // interface level, but the principle of operation is similar: the sensor
mjr 100:1ff35c07217c 7 // provides a serial interface to a file of pixels transferred as analog
mjr 100:1ff35c07217c 8 // voltage levels representing the charge collected.
mjr 100:1ff35c07217c 9 //
mjr 100:1ff35c07217c 10 // As with the TSL1410R, we position the sensor so that the pixel row is
mjr 100:1ff35c07217c 11 // aligned with the plunger axis, with a backlight, and we detect the plunger
mjr 100:1ff35c07217c 12 // position by looking for an edge between a light area (where the backlight
mjr 100:1ff35c07217c 13 // is unobstructed) and a dark area (where the plunger rod is blocking the
mjr 100:1ff35c07217c 14 // backlight). The optical sensor area of the TSL1410R is large enough to
mjr 100:1ff35c07217c 15 // cover the entire plunger travel distance, so the physical setup for that
mjr 100:1ff35c07217c 16 // sensor is a simple matter of placing the sensor near the plunger, so that
mjr 100:1ff35c07217c 17 // the plunger casts a shadow on the sensor. The TCD1103, in contrast, has a
mjr 100:1ff35c07217c 18 // small optical sensor area, about 8mm long, so in this case we have to use
mjr 100:1ff35c07217c 19 // a lens to reduce the image of the plunger by about 10X (from the 80mm
mjr 100:1ff35c07217c 20 // plunger travel distance to the 8mm sensor size). This makes the physical
mjr 100:1ff35c07217c 21 // setup more complex, but it has the advantage of giving us a focused image,
mjr 100:1ff35c07217c 22 // allowing for better precision in detecting the edge. With the unfocused
mjr 100:1ff35c07217c 23 // image used in the TSL1410R setup, the shadow was blurry over about 1/50".
mjr 100:1ff35c07217c 24 // With a lens to focus the image, we could potentially get as good as
mjr 100:1ff35c07217c 25 // single-pixel resolution, which would give us about 1/500" resolution on
mjr 100:1ff35c07217c 26 // this 1500-pixel sensor.
mjr 100:1ff35c07217c 27 //
mjr 100:1ff35c07217c 28
mjr 100:1ff35c07217c 29 #include "edgeSensor.h"
mjr 100:1ff35c07217c 30 #include "TCD1103.h"
mjr 100:1ff35c07217c 31
mjr 100:1ff35c07217c 32 template <bool invertedLogicGates>
mjr 100:1ff35c07217c 33 class PlungerSensorImageInterfaceTCD1103: public PlungerSensorImageInterface
mjr 100:1ff35c07217c 34 {
mjr 100:1ff35c07217c 35 public:
mjr 100:1ff35c07217c 36 // Note that the TCD1103 has 1500 actual image pixels, but the serial
mjr 100:1ff35c07217c 37 // interface provides 32 dummy elements on the front end (before the
mjr 100:1ff35c07217c 38 // first image pixel) and 14 dummy elements on the back end (after the
mjr 100:1ff35c07217c 39 // last image pixel), for a total of 1546 serial outputs.
mjr 100:1ff35c07217c 40 PlungerSensorImageInterfaceTCD1103(PinName fm, PinName os, PinName icg, PinName sh)
mjr 100:1ff35c07217c 41 : PlungerSensorImageInterface(1546), sensor(fm, os, icg, sh)
mjr 100:1ff35c07217c 42 {
mjr 100:1ff35c07217c 43 }
mjr 100:1ff35c07217c 44
mjr 100:1ff35c07217c 45 // is the sensor ready?
mjr 100:1ff35c07217c 46 virtual bool ready() { return sensor.ready(); }
mjr 100:1ff35c07217c 47
mjr 101:755f44622abc 48 virtual void init() { }
mjr 100:1ff35c07217c 49
mjr 100:1ff35c07217c 50 // get the average sensor scan time
mjr 100:1ff35c07217c 51 virtual uint32_t getAvgScanTime() { return sensor.getAvgScanTime(); }
mjr 100:1ff35c07217c 52
mjr 101:755f44622abc 53 virtual void readPix(uint8_t* &pix, uint32_t &t)
mjr 100:1ff35c07217c 54 {
mjr 100:1ff35c07217c 55 // get the image array from the last capture
mjr 100:1ff35c07217c 56 sensor.getPix(pix, t);
mjr 100:1ff35c07217c 57 }
mjr 100:1ff35c07217c 58
mjr 101:755f44622abc 59 virtual void releasePix() { sensor.releasePix(); }
mjr 101:755f44622abc 60
mjr 101:755f44622abc 61 virtual void setMinIntTime(uint32_t us) { sensor.setMinIntTime(us); }
mjr 100:1ff35c07217c 62
mjr 100:1ff35c07217c 63 // the low-level interface to the TSL14xx sensor
mjr 100:1ff35c07217c 64 TCD1103<invertedLogicGates> sensor;
mjr 100:1ff35c07217c 65 };
mjr 100:1ff35c07217c 66
mjr 100:1ff35c07217c 67 template<bool invertedLogicGates>
mjr 100:1ff35c07217c 68 class PlungerSensorTCD1103: public PlungerSensorEdgePos
mjr 100:1ff35c07217c 69 {
mjr 100:1ff35c07217c 70 public:
mjr 100:1ff35c07217c 71 // Note that the TCD1103 has 1500 actual image pixels, but the serial
mjr 100:1ff35c07217c 72 // interface provides 32 dummy elements on the front end (before the
mjr 100:1ff35c07217c 73 // first image pixel) and 14 dummy elements on the back end (after the
mjr 100:1ff35c07217c 74 // last image pixel), for a total of 1546 serial outputs.
mjr 100:1ff35c07217c 75 PlungerSensorTCD1103(PinName fm, PinName os, PinName icg, PinName sh)
mjr 100:1ff35c07217c 76 : PlungerSensorEdgePos(sensor, 1546), sensor(fm, os, icg, sh)
mjr 100:1ff35c07217c 77 {
mjr 100:1ff35c07217c 78 }
mjr 100:1ff35c07217c 79
mjr 100:1ff35c07217c 80 protected:
mjr 100:1ff35c07217c 81 PlungerSensorImageInterfaceTCD1103<invertedLogicGates> sensor;
mjr 100:1ff35c07217c 82 };