check in
Completed

TCD1304_Teensy 4.0

STDTCD1304_Teensy 4.0

tag

7
0
0
0
Mode:Full

License

GPL 3.0

Creation time:2025-02-16 18:36:00Update time:2025-03-13 01:25:46

Description

Code Without Filtering

This version of the code is designed to control a TCD1304 CCD sensor using an Teensy 4.0 (Theremino compatible). It performs the following tasks:

  • Hardware Setup:
    Defines the sensor control pins (SH, MCLK, ICG, and the analog input OS) and initializes the buffer for storing samples.

  • Precise Timing:
    Uses the DWT (Data Watchpoint and Trace unit) cycle counter to achieve precise microsecond delays, which are crucial for generating accurate sensor pulses.

  • Sensor Clock Generation:
    Configures PWM outputs on two pins (MCLK_PIN1 and MCLK_PIN2) to generate the sensor clock with a 50% duty cycle.

  • ADC Sampling:
    Uses an IntervalTimer to periodically trigger an ADC sampling callback. In the callback, the sensor’s analog output is read via analogRead and stored in a circular buffer. Different debug modes can simulate alternative data patterns.

  • Exposure Control:
    The function RestartAdc() manages the sensor’s exposure by generating a SH pulse at the start and a combination of ICG and SH pulses at the end of the exposure period. The delays in these pulses are set based on experimental values (e.g., 50 µs for SH at exposure start, and 80 µs for ICG at exposure end).

  • Data Transmission:
    Once sampling is complete, the code sends the buffered data over the serial port.


Code With Filtering

This modified version builds upon the original implementation and introduces noise reduction via an IIR filter (exponential moving average). Key additions include:

  • IIR Filter Implementation:
    A simple function (applyFilter()) is added, which computes an exponential moving average using a constant factor (alpha). For example, with alpha set to 0.1, the new filtered value is 10% of the current ADC reading plus 90% of the previous filtered value. This filter helps to suppress high-frequency noise from the sensor.

  • Integration in ADC Callback:
    In the ADC sampling callback, the code applies the filter to the raw ADC value if the sensor type is set to TCD1304 (SensorType == 0) and the debug mode is set to the default (DebugType == 0). The filtered value is then stored in the buffer instead of the raw reading.

  • All Other Functionality Remains Unchanged:
    The overall sensor control, timing for exposure (including SH and ICG pulses), and data transmission via serial remain the same as in the version without filtering.

 

Firmware available for download here: https://protheustrio.cz/teensy/Teensy_TCD.zip

Design Drawing

The preview image was not generated, please save it again in the editor.

BOM

Bom empty

Attachments

OrderFile nameDownload times
No data
Clone
Add to Album
0
0
Share
Report

Project Members

Comment

All Comments(1)
Sort by time|Sort by popularity
Followers0|Likes0
Related projects
Empty

Bottom Navigation