fossasia / pslab-python

Python Library for PSLab Desktop: https://pslab.io
GNU General Public License v3.0
1.62k stars 227 forks source link

Add support for TCD1304 linear CCD #211

Closed bessman closed 1 year ago

bessman commented 2 years ago

This code uses a new firmware feature which is not available in PSLab v5; trigger on non-sampled channel. However, it may be possible to get this to work with the v5 hardware.

There is significant cross-talk between adjacent analog inputs for high frequency signals. This is normally a bad thing, but in this case it should be possible to use it to our advantage. Connect the sensor to the PSLab as follows:

fM -> SQ1 SH -> SQ2 ICG -> SQ3 -> CH2 OS -> CH1

Then, run this code:

from pslab.external.tcd1304 import TCD1304

tcd = TCD1304
tcd.start_clocks()
x, y = tcd.read(analogin="CH1", trigger="CH1")

The idea is to start sampling when the ICG clock line goes high, since that is when the TCD1304 starts putting its pixel values on its analog output. Notice that we are both sampling and triggering on CH1, even though the ICG line is connected to CH2. This is because the fast rise-time of the ICG PWM-signal has a very high frequency content, which will manifest as a noise spike in CH1 due to the cross talk issue mentioned above. This noise spike will cross the trigger threshold and cause the oscilloscope to start sampling.