This post from 2015 introduced the very first firmware for driving the tcd1304dg. For an up-to-date version and a more well structured presentation go to tcd1304.wordpress
CCD’s are just like women, demanding but wonderful creatures. And as with women timing is everything with CCD’s.
Here are the timing requirements for the TCD1304:
This, together with the timing diagram in the previous post, is about as much information the datasheet provides. However, these application notes from Toshiba explain the different pulses a little better, and the datasheets for similar chips – namely the TCD1254 and TCD1103 – are also instructive.
Even though I felt smarter after reading I still had a nagging suspicion it would be a small nightmare to fulfill the timing criteria of the chip.
However, having the Cortex-M4 timers, it proved quite manageable, and after waking up one night remembering an ARM timing register called something-Polarity and only a few trial runs, I finally had this:
The blue line is the SH pulse and the red is the ICG pulse. On two other GPIOs not shown here are the master clock, running at 1.4 MHz, and the ADC clock at 350 kHz. And the MCU itself is doing nothing 🙂
From here it went quickly to this:
It’s my first 1D-selfie! The red line is the ICG-pulse running with a period of 40 ms and the blue is the output from the CCD. The SH is not shown but here it runs with a period of only 400 µs.
Apparently the SH and ICG need only fulfill the requirements when both trigger, and SH does indeed control the integration time. The datasheet finally makes more sense to me (though I still find it confusing that ICG period is called the readout time, when clearly all reading is done 10.6 ms after each ICG pulse).
Here’s a plot of the CCD master clock (running at 1.4 MHz) with the output signal at every 4th clock cycle:
I was hoping to see exactly during which of the four clock cycles the CCD would feed me the output, but I don’t really feel smarter;
As with women there are still many things I don’t quite understand about CCD’s.
Next up is setting up two other pieces of the M4’s peripherals: I need the DMA controller to pick up all those delicious pixelreadings from the ADC.
In the meantime you can enjoy yourself with the source code for driving the TCD1304 with the STM32F401RE Nucleo board. I included a few bits of explanation if you want to play yourself or simply learn more.