Barcode reader with a TCD1304AP TOSHIBA CCD linear image sensor and NUCLEO-F103RB board.
Barcode Reader
Barcodes represent data by varying the widths of spaces and bars. These barcodes, now commonly referred to as linear or one-dimensional (1D), can be scanned by barcode readers. In this project a TCD1304AP TOSHIBA CCD linear image sensor is used to scan barcodes. The obtained light intensity stream is passed to the ZBar library streamlined for embedded use.
Flow chart |
TCD1304AP Driver
The TCD1304AP requires three clock signals (see below the Timing chart). It can operate with or without a built-in electronic shutter. In this project the electronic shutter is used to control the integration (exposure) time:
I used STM32CubeIDE to build the driver for the TCD1304AP sensor and then merged it with the Mbed OS 2 project.
STM32F103RB clock configuration
STM32F103RB pinout
- The signal for TCD1304AP's master clock (fiM) is generated by STM32F103's TIM1 timer and it is output at pin PA_8.
- The Shift Gate clock signal (SH) is produced by timer TIM2 and it's available at pin PA_15.
- The Integration Clear Gate pulses (ICG) are generated by timer TIM3 at pin PA_6.
The TCD1304AP's master clock runs at 1.714MHz. Pixel data is available at its output (OS) after each four pulses. To keep up with such speed DMA (Direct Memmory Access) is used to move the voltage data produced by the ADC (Analog to Digital Convertor) into the STM32F103's SRAM. The ADC is clocked with a 12MHz signal and runs in continuous mode.
Revision 3:f2e67488f5ab, committed 2020-01-10
- Comitter:
- hudakz
- Date:
- Fri Jan 10 22:10:07 2020 +0000
- Parent:
- 2:415e979c52cf
- Commit message:
- Barcode reader with a TCD1304AP TOSHIBA CCD linear image sensor and NUCLEO-F103RB board.
Changed in this revision
diff -r 415e979c52cf -r f2e67488f5ab main.cpp --- a/main.cpp Fri Jan 10 21:03:00 2020 +0000 +++ b/main.cpp Fri Jan 10 22:10:07 2020 +0000 @@ -2,12 +2,12 @@ * Barcode reader * * Target: NUCLEO-F103RB - * Sensor: TCD1304AP(DG) - Toshiba CCD linear image sensor + * Sensor: TCD1304AP(DG) - TOSHIBA CCD linear image sensor * * Author: Zoltan Hudak * Date: 2020-01 * - * Depends on the ZBar library <http://zbar.sourceforge.net/> + * Depends on the ZBar library <http://zbar.sourceforge.net> * */ #include "main.h" @@ -169,8 +169,8 @@ scanner->flush(); scanner->new_scan(); - int black = 0; - int i; + uint16_t black = 0; + int i; for (i = MARGIN_LEFT; i < DATA_LEN - MARGIN_RIGHT; i++) { if (adcData[i] > black) @@ -178,7 +178,7 @@ } for (i = MARGIN_LEFT; i < DATA_LEN - MARGIN_RIGHT; i++) { - scanner->scan_y(adcData[i] - black); + scanner->scan_y(black - adcData[i]); } #endif printf("Scan done.\r\n");
diff -r 415e979c52cf -r f2e67488f5ab mbed_app.json --- a/mbed_app.json Fri Jan 10 21:03:00 2020 +0000 +++ b/mbed_app.json Fri Jan 10 22:10:07 2020 +0000 @@ -1,7 +1,6 @@ { "target_overrides": { "*": { - "target.clock_source": "USE_PLL_HSE_XTAL", "target.default_lib": "small" } }
diff -r 415e979c52cf -r f2e67488f5ab zbar.lib --- a/zbar.lib Fri Jan 10 21:03:00 2020 +0000 +++ b/zbar.lib Fri Jan 10 22:10:07 2020 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/hudakz/code/zbar/#e33621169e44 +https://os.mbed.com/users/hudakz/code/zbar/#4f5c042a2d34