ELM Home Page

February 4, 2011

Fundamentals and Experiments of Line Scan Camera


Line Camera

Line scan camera is a kind of digital camera. It is not that found easy because the line scan camera is embedded in the various machines as a constituent component. This project develop the line scan camera and evaluate it.

CCD line sensor is the most impotant device of the line scan camera. I have obtained it at the electric town over ten years ago. However building a line scan camera in portable size was too hard project because the electronic components needed for the project, high performance microcontrollers and large storage devices, ware not available for personal projects. Therefore the line sensor had been kept in the junk bin expecting to realize the project. In other words, I had aborted and forgotten it :-)

After about ten years, the project gradually gained practicality by progress in semiconductor technologies and falling the price of devices and development envilonment. Now the 32-bit microcontrollers and large memory cards are used in electronics handiworks even for simple projects for beginners. So I tried the project again with the latest technology.

The Line Scan Camera

Fundamentals

Fig 1. Area Camera and Line Camera
Fig.1

The line scan camera is the digital camera that using a line sensor (1-D CCD) for the image detector. Generic camera captures the object as a plane by using an area sensor (2-D CCD) but the line scan camera captures the object as a line like shown in Figure 2.

Also the line scan camera is to get a 2-D image at the end however it can capture only a line at a time. To create a 2-D image with the line scan camera, the object is captured in line-by-line with moving the camera or object. The image of the object is created on the memory from the captured lines.

The slit camera is a similar one of the film camera. It takes the object through a thin slit (1-D window) with winding the film and create 2-D image on the film like line scan camera.

Features and Applications

The line scan camera has some features listed below.

The line scan camera is used for some kind of machines because of its features. You will find that the line sensor is an impotant device as well as area sensor.

Hardware

Functions

Fig 2. Functional Block Diagram
Block Diagram

Figure 2 shows the block diagram of the build line scan camera. The line image converted into electric signal by line sensor is digitized and fed to the control part as numeric data. The data is displayed into the display panel and recorded to the storage media. The line rate is from 500 to 2000 lines per second because of the specs of the CCD is limited to this range.

The electric part is divided into three boards and each is tied with FPC cables. I am always not making PCB because the PCB is very expensive, troublesome to design and difficult to fix errors after manufacture. The point-to-point construction on the protoboard is the best way for one-time prototyping.

Optics and Case

Photo 2. Case
case

Photo 2 shows the built case for the line scan camera. It is made from a Takachi SW-85B plastic case. This project has a optics that requires certain accuracy so that each componet should be machined and assembled in accordance with well drawn plan. This is a draft of the case design applied to the project. The analog board that carries the line sensor is attached with floating screw to adjust the infinite distance.

The type of lens mount used in this project is C-mount. It is one of the standard lens mount for industrial cameras but it is a little hard to obtain. I used a C-CS conversion adapter to implement the female C-mount to the camera body. To fix the camera on the tripod, a UNC nut is bonded on the bottom of the case. The inside of the case is painted with conductive paint for electromagnetic shield.

Analog Board

Photo 3. Analog Board
PCB
Circuit Diagram | Wave forms

Photo 3 shows the built analog board that most impotant block of the line scan camera. It has a CCD line sensor and analog processing circuit. The CCD line sensor to be used is a TCD132D monochrome CCD from Toshiba. The CCD is also sensitive at infrared rays so that an IRCF is needed on the window to match the spectal response to human eyes. The CCD line sensor is driven by clock signals from the control board. The video signal from the CCD line sensor is pre-conditioned by a variable gain amplifier (AD8830) and digitaized it by an A-D converter (ADC1173). The 8-bit digital data from the A-D converter is fed to the control board. Pixel rate is varied from 0.5 MHz to 2 MHz but the A-D converter is driven in twice rate due to the lower limit of the sampling frequency of the A-D converter. The data is acquired in every two samples by controller.

Control Board

Photo 4. Control Board
PCB
Circuit Diagram

The controller board includes an MCU, PLD and power supply (Photo 4). An NXP LPC2368 is used as MCU. It integrates an ARM7TDMI core runnning at 72MHz, 512K bytes flash, 32K+16K+8K bytes SRAM and powerful peripherals. The MicroSD card can be controlled in 4-bit native mode by integrated SD controller. The LPCxxxx ARM microcontroller famiry is widely used for recent electronics handiwork projects by its aggressive marketing.

A PLD (LC4256V) is used to drive the CCD line sensor. A timing genetator for the CCD line sensor and a data FIFO to receive the fast pixel data are configured in the PLD. The power supply circuit generates a logic supply (3.3 volts) and analog supply (12 volts).

Display Board

Photo 5. Display Board
PCB
Circuit Diagram

The display board is mounted at back end of the camera (Photo 5). It works as a control panel of the camera. The devices on the board is: OLED display, switches and a MicroSD card socket. The SD card is inserted/removed on cover is opened.

Software

Data Acquisition

The pixel rate from the A-D converter becomes upto 2.1M pixels/sec. First of all, the pixel data must be captured into the data buffer of the MCU. Because data receiving process at 2.1M cycles/sec is too fast for software data transfer, the pixel data is stored into the data FIFO configured on the PLD. The data FIFO generates an interrupt (DRDY#) to the MCU on half of FIFO is filled and then MCU pops the half of FIFO at once. The size of FIFO is 16 bytes so that the cycle rate becomes 1/8 of the pixel rate. This is not too fast for the interrupt process but still it must be processed at the highest priority. This project uses FIQ feature (low latency interrupt by banked register) of ARM7TDMI core. (Unfortunately FIQ feature has been removed at Cortex-M3 core)

On the CPU responds the FIQ, some registers switch to the banked registers of the FIQ state and the FIQ routine can be entered/leaved without context switching. Generally the FIQ routine is written in assembler to maximize the performance. According to the scope view of the response timing of the FIQ service, it reads the 8-byte data within 0.8μ seconds at no load and extended upto 2μ seconds due to bus contention under DMA in use (writing data to the MicroSD). This is acceptable delay for this project.

Number of pixels output per a line is 1094 and 1024 effective pixels out of them are captured into the memory. An interrupt signal (SYNC#) is output at start of each line to synchronize to the first pixel.

Recording Image Data

The captured image data can be recorded to the MicroSD card in generic BMP file in 8-bit grayscale, 1024 pixels in width and the height is as long as captured. The file is named \DCIM\LCAM\Ynnnn.BMP(nnnn is serial number). This is the same way as generic digital still cameras.

There are some technical hurdles to write data to the SD cards by cheap microcontrollers because incoming data at constant rate must be written to a file with limited delay. The maximum data rate in this project becomes 2MB/sec maximum. Fortunately LPC2368 has an MCI (SD/MMC native mode interface) and it achieves 8MB/sec for file read, 6MB/sec for file write. However these are average value to read/write a large file. In fact there are dead-times that the data transfer temporary stops due to internal process of SD card and file system. To avoid loss of write data due to buffer overrun, a data buffer to store incoming data during the dead-time is required. But microcontroller system with a limited size of memory may not able to allocate sufficient size of data buffer.

Let's estimate the permissive delay time per a write transaction. In this project, all of internal 32KB SRAM is allocated for the data buffer and program works on the 16KB ethernet RAM. The data buffer works as ring buffer that divided in two. Each block is written to the file at a time on it filled with incoming data. Therefore write request of 16KB occures every 8msec and each process must be finished by next. This requirement could be satisfied by following software techniques.

The most significant delay during a file write process is due to cluster allocation. It often troubles us in real-time system. This appears more or less in most file system and cannot be estimated correctly. The dead-time due to cluster allocation can reach upto some seconds depends on the situation. This project applied cluster pre-allocation (expands the file with f_lseek function prior to start to record) to avoid accessing to the FAT while a file write process.

Each write data is aligned to the cluster boundary to finish the write process with only a write transaction to the card. Image file on the SD card are forced aligned to the AU boundary of the SD card on the file creation. This avoids a large internal delay of unknown reason that tend to occure at start of the file write process.

Although these effort on the file system to minimize the dead-time, still SD card has some degree of internal processing delay. We should choose an SD card that has more ability on write speed. I have compared some MicroSD cards across the manufacture brands. As the result, these MicroSD cards manufactured by Toshiba (only made in Japan) displayed the shortest write delay time and steady performance.

Monitoring Image Data

Photo 3. Display Mode
disp1

Because captured video signal is 1-D image, it cannot be monitored as 2-D image like generic digital still camera. To solve this problem, there are two different monitoring modes.

One is the scope view that displays video signal in Y-t mode like oscilloscope (Figure 3a). Y-axis represents the luminance and X-axis represents the pixel position in the line. This mode is for adjustment of exposure and focus. The lower scope is absolute of differential of video signal to adjust focus (Figure 3b). When image comes into focus, high frequency component of the video signal increases and differential values also increase and the focus can be found. This is the fundamentals of contrast detect A/F applied to the compact digital still cameras.

And the other is waterfall view that rolls up the lines from bottom of the screen. This mode is for adjustment of line rate. The aspect ratio of captured 2-D image is varied by line rate and moving speed of the object. The waterfall view displays the captured 2-D image but it displays on vertical lines if the object is not moving. Thus the object or camera must be moving at the actual speed to capture to adjust the line rate.

How to Use

The basic use for the built line scan camera is like slit camera. However it is easy by far than slit camera because the pixel size that corresponds to slit size is very small (14μm) compared to the slit camera. As the effect most images will able to be captured successfully if only focus and exposure are adjusted properly.

Fixing Camera

First of all, the camera should be fixed on the rigid mount to passing the object at right angles with line sensor. For example, to capture an object moving horizontally or panorama image by horizontal pan, the camera is fixed to get the line sensor vertical. It should be set exactly right angle or the captured image will be distorted like rectangle into parallelogram.

Adjusting Focus

The line scan camera is controlled with a 5-position joystick (up, down, left, right and center). Display mode (scope and watafall) is alternated by right click. First, input level (upper scope) is adjusted by iris ring and gain control (up/down click). The gain control can also be auto-adjusted by left ckick. Next, adjust focus by focus ring to maximize the differential values (lower scope).

Adjusting Line Rate

Line rate is adjusted at waterfall view. It is adjusted to display the image at correct aspect ratio. The line rate can also be calculated by moving speed of the object, distance to the object and focal length of the lens. It should not that be always accurate because it is digital image that can be corrected by post-processing. Of course the resolution will be lost if the line rate is too slow and the image is expanded much. There is no wrong effect at too high line rate except for low sensitivity. The line rate affects exposure time (sensitivity) of each line so that the input level may be needed to ajust after any changes to the line rate.

Captureing Images

Center button is to start/stop the recording. On start of recording by button down, cluster pre-allocation is done about 0.5 second and suspended until release of the button. The recording is started on button release and stopped on any button down or reached end of the file where pre-allocated. The pre-allocation size is configured for 100,000 lines (about 100MB) but it can be changed according as the object size. The created image files are post-processed on the PC to apply correction of orientation, aspect ratio and gamma.

Resources

Sign