Barcode reader with a TCD1304AP TOSHIBA CCD linear image sensor and NUCLEO-F103RB board.

Dependencies:   mbed zbar

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 charthttps://os.mbed.com/media/uploads/hudakz/barcodereader_diagram.png
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:

https://os.mbed.com/media/uploads/hudakz/barcodereader_timing.png




I used STM32CubeIDE to build the driver for the TCD1304AP sensor and then merged it with the Mbed OS 2 project.

STM32F103RB clock configuration
https://os.mbed.com/media/uploads/hudakz/barcodereader_clockconf.png


STM32F103RB pinout
https://os.mbed.com/media/uploads/hudakz/barcodereader_pinout.png


  • 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.

https://os.mbed.com/media/uploads/hudakz/barcodereader_clocking.png

Committer:
hudakz
Date:
Fri Jan 10 22:10:07 2020 +0000
Revision:
3:f2e67488f5ab
Parent:
0:cd0771c3346e
Barcode reader with a TCD1304AP TOSHIBA CCD linear image sensor and NUCLEO-F103RB board.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:cd0771c3346e 1 /* USER CODE BEGIN Header */
hudakz 0:cd0771c3346e 2 /**
hudakz 0:cd0771c3346e 3 ******************************************************************************
hudakz 0:cd0771c3346e 4 * @file : main.h
hudakz 0:cd0771c3346e 5 * @brief : Header for main.c file.
hudakz 0:cd0771c3346e 6 * This file contains the common defines of the application.
hudakz 0:cd0771c3346e 7 ******************************************************************************
hudakz 0:cd0771c3346e 8 * @attention
hudakz 0:cd0771c3346e 9 *
hudakz 0:cd0771c3346e 10 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
hudakz 0:cd0771c3346e 11 * All rights reserved.</center></h2>
hudakz 0:cd0771c3346e 12 *
hudakz 0:cd0771c3346e 13 * This software component is licensed by ST under BSD 3-Clause license,
hudakz 0:cd0771c3346e 14 * the "License"; You may not use this file except in compliance with the
hudakz 0:cd0771c3346e 15 * License. You may obtain a copy of the License at:
hudakz 0:cd0771c3346e 16 * opensource.org/licenses/BSD-3-Clause
hudakz 0:cd0771c3346e 17 *
hudakz 0:cd0771c3346e 18 ******************************************************************************
hudakz 0:cd0771c3346e 19 */
hudakz 0:cd0771c3346e 20 /* USER CODE END Header */
hudakz 0:cd0771c3346e 21
hudakz 0:cd0771c3346e 22 /* Define to prevent recursive inclusion -------------------------------------*/
hudakz 0:cd0771c3346e 23 #ifndef __MAIN_H
hudakz 0:cd0771c3346e 24 #define __MAIN_H
hudakz 0:cd0771c3346e 25
hudakz 0:cd0771c3346e 26 #ifdef __cplusplus
hudakz 0:cd0771c3346e 27 extern "C" {
hudakz 0:cd0771c3346e 28 #endif
hudakz 0:cd0771c3346e 29
hudakz 0:cd0771c3346e 30 /* Includes ------------------------------------------------------------------*/
hudakz 0:cd0771c3346e 31 #include "stm32f1xx_hal.h"
hudakz 0:cd0771c3346e 32
hudakz 0:cd0771c3346e 33 /* Private includes ----------------------------------------------------------*/
hudakz 0:cd0771c3346e 34 /* USER CODE BEGIN Includes */
hudakz 0:cd0771c3346e 35
hudakz 0:cd0771c3346e 36 /* USER CODE END Includes */
hudakz 0:cd0771c3346e 37
hudakz 0:cd0771c3346e 38 /* Exported types ------------------------------------------------------------*/
hudakz 0:cd0771c3346e 39 /* USER CODE BEGIN ET */
hudakz 0:cd0771c3346e 40
hudakz 0:cd0771c3346e 41 /* USER CODE END ET */
hudakz 0:cd0771c3346e 42
hudakz 0:cd0771c3346e 43 /* Exported constants --------------------------------------------------------*/
hudakz 0:cd0771c3346e 44 /* USER CODE BEGIN EC */
hudakz 0:cd0771c3346e 45
hudakz 0:cd0771c3346e 46 /* USER CODE END EC */
hudakz 0:cd0771c3346e 47
hudakz 0:cd0771c3346e 48 /* Exported macro ------------------------------------------------------------*/
hudakz 0:cd0771c3346e 49 /* USER CODE BEGIN EM */
hudakz 0:cd0771c3346e 50
hudakz 0:cd0771c3346e 51 /* USER CODE END EM */
hudakz 0:cd0771c3346e 52
hudakz 0:cd0771c3346e 53 void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
hudakz 0:cd0771c3346e 54
hudakz 0:cd0771c3346e 55 /* Exported functions prototypes ---------------------------------------------*/
hudakz 0:cd0771c3346e 56 void Error_Handler(void);
hudakz 0:cd0771c3346e 57
hudakz 0:cd0771c3346e 58 /* USER CODE BEGIN EFP */
hudakz 0:cd0771c3346e 59
hudakz 0:cd0771c3346e 60 /* USER CODE END EFP */
hudakz 0:cd0771c3346e 61
hudakz 0:cd0771c3346e 62 /* Private defines -----------------------------------------------------------*/
hudakz 0:cd0771c3346e 63 #define MASTER_CLOCK "TIM2 -> PA15"
hudakz 0:cd0771c3346e 64 #define SH_CLOCK "TIM3 -> PA6"
hudakz 0:cd0771c3346e 65 #define ICG_CLOCK "TIM3 -> PA7"
hudakz 0:cd0771c3346e 66 /* USER CODE BEGIN Private defines */
hudakz 0:cd0771c3346e 67
hudakz 0:cd0771c3346e 68 /* USER CODE END Private defines */
hudakz 0:cd0771c3346e 69
hudakz 0:cd0771c3346e 70 #ifdef __cplusplus
hudakz 0:cd0771c3346e 71 }
hudakz 0:cd0771c3346e 72 #endif
hudakz 0:cd0771c3346e 73
hudakz 0:cd0771c3346e 74 #endif /* __MAIN_H */
hudakz 0:cd0771c3346e 75
hudakz 0:cd0771c3346e 76 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
hudakz 0:cd0771c3346e 77