10-10-2012, 11:15 AM
Digital Project Digital Camera Interface
Digital Project Digital.pdf (Size: 512.5 KB / Downloads: 24)
Abstract
This document describes the development of a prototype of an interface between
a CMOS camera and a computer. This interface allows a user to get images
from the camera, to change some of the properties of the camera as brightness,
luminance, etc. In addition some image process is implemented allowing the
camera to track white objects and follow them with a servomotor. The interface
was implemented using the Atmel AVR ATmega16 microcontroller.
Introduction
Background
For the last four years I have been designing and building mobile robots based
in microcontrollers. In this course on Digital Project I wanted to do something
about robotics, but developing a robot would have been very expensive and
hard in the mechanical aspects. I decided to work with something related with
robotics but cheaper and in someway easier: the interface with a digital camera
that later I could add to one of my robots.
I own a the digital camera C3088[1]. This camera is used in the CMUcam[2]
interface to take images, process them and extract some interesting features that
can be used by a robot. My idea was to reproduce the similar characteristics
of the CMUcam using the C3088 camera. I wanted that my interface would be
able to get images from the camera, change the different settings of the camera
(luminance, brightness, etc.), and if possible make some processing of the image
(like detecting colors or lines), in a similar way as the CMUcam does.
Also I had the opportunity to use the AVR ATmega16[3] microcontoller and
learn about it. I decided to work with it despite it was the first time it was used
in the course.
Specifications
The aim of the project is the design and construction of an interface between
the CMOS camera c3088 and a computer, using the AVR microcontroller. The
information flows in two ways: on the one hand there are commands from the
computer to the camera to change different characteristics of it, on the other
images from the camera should be sent to the computer. The communication
between the computer and the AVR is through the serial port. The communication
between the camera and the microcontroller is: using the I2C protocol to access to the different registers of the camera; and using an 8 bit port to read
the images. In addition the camera will be connected to a TV with its analog
output for debugging purpose. In the next diagram of Figure 1.1 we can see the
main blocks of the design and how information flows.
The C3088 Camera
The C3088 is the camera used in the project and it is the main part of it, that
is the reason that a short explanation is made. It is a color camera module with
digital output. It uses a CMOS image sensor OV6620[4] from Omnivision[5].
It has a digital video port that supplies a continuous 8/16 bit-wide image data
stream. All the camera functions, such as exposure, gamma, gain, white balance,
windowing, can be changed through I2C interface by writing in some registers.
The video output can be expressed in different formats, and with different
type of channels (RGB, UVY). The format used in the project is the simplest
one: Zoom Video Port Format. In this format 8 bits represent the intensity (Y
channel) of one pixel , the other 8 bits represent the U and V channels, but
are not used. The information is sent continuously and is synchronized by the
HREF, VSYNC and PCLK signals as showed in the next graph in Figure 2.1.
The VSYNC signal indicates new frame, the HREF signal indicates when the
information is valid and makes the horizontal synchronization, and PCLK is the
clock signal (the data is valid in the rising edge). The period of PCLK can be
changed by writing in the registers of the camera. This will allow to read images
from the camera directly with the microcontroller without the use of additional
hardware.
The registers accessed by the I2C bus are 80 and as it was said above allow
to change different properties of the camera. In this project they are used to
change the period of PCLK, to read the size of the image, to make a mirror
of the image, and to reset the camera. It is important here to make a small
clarification about the I2C protocol in the camera. The datasheet of the C3088
camera says that the bus used is I2C, but nothing says about the registers and
the addresses that should be used. So it is necessary to read the datasheet of the
OV6620 chip. There you can find that the protocol used for the communication
is not I2C, it is SCCB[6]. If you read the specifications of this protocol you can
see that it is for some modes the same as I2C protocol.
Serial communications
The connection to the serial port of the computer is made using the integrated
circuit MAX232[8], because the TTL levels of the microcontroller are not compatible
with the computer. PD0 (RXD) and PD1 (TXD) are connected to the
MAX232 as it can be seen in the Figure 2.5 The TX and RX pins of the MAX232
with RS232 levels are connected to the computer through a DB9 connector. The
capacitors of the circuit are of 1uF.
C3088 Camera
The camera operation voltage is as the rest of the circuits 5V, and pins 20 and
22 that are VCC are connected to it. Pin 31 is GND and pins 21 and 15 are
AGND (analog ground) and all of them are connected to the common ground.
The pins PWDN and RST are connected to ground, so all the resets of the
camera are performed by software.
The bus Y0-Y7 of the camera is connected to the port A (PA0-PA7). PCLK
is connected to PD2, HREF to PD3 and VSYNC to PD4. The bus UV is not
connected because it is not used. SDA and SCL (I2C bus) from the camera
are connected to PC1 and PC0 in the microcontroller, because these pins are
connected to the TWI hardware that is used to implement the I2C protocol.
VTO pin that is the Video Analog Output is connected to the TV through a RCA connector. Pins FODD and EXCLK are unconnected. In Figure A.1 in
Appendix A all these connections can be found.
Comments
The election of which part was connected to which pin was easy. The JTAG
should be connected to pins PC2-PC5, because is required by the microcontroller.
The I2C bus was implemented using the help of the TWI hardware
of the microcontroller, so it should be connected to pins PCO and PC1. The
hardware serial port is in pin PD0 and PD1 so that is why these pins were used.
For the connection of Y bus of the camera one complete port should be chosen.
Ports C and D could not be chosen because they were used for other things.
Port A was chosen because the only peripheral that it has is the AD converter
and it is not required in this project. PCLK, HREF, VSYN, the servo, the LED
and the switch were connected to pins of port D. Port B remains completely
free. If in a future we want to use the UV bus to get color images from the
camera, it can be connected to the port B of the AVR. Pins PC6 and PC7 are
also free.
I2C Communication with the camera
The I2C[12] bus is a communication protocol developed by Philips. In this
protocol two pins are used, one is the clock and the other is the data. Also
this protocol has a Master-Slave architecture. In our case the master is the
AVR and the slave the C3088 camera. Registers of the camera can be read or
written by the AVR. In the writing operation the master put in the bus the
writing address of device, and after that put the address of the register it wants
to write, and finally the byte it wants to write in the register. The reading
operation is similar: first the master put in the bus the writing address of the
device it wants to write, after that the the register address to read from, and
then the device reading address. Finally the slave puts in the bus the data
requested.
The I2C communication was the most difficult part of the project, because
of two main reasons. First of all because I2C protocol is not implemented
hardware in the microcontoller used. Second because, as it was said in 2.1, the
C3088 camera implements the SCCB protocol that it is almost the same as I2C.
Main
The main function is implemented in MAIN.C and MAIN.H. This function
basically initiates the serial communications, the I2C bus to communicate with
the camera, and reset the camera by writing in one of its registers. After that it
sends a welcome message to the computer that is printed on the screen. Then
goes inside an infinite loop that look for commands sent from the computer and
acts according to the command received. This is done by the function readline
that reads from the serial port until a buffer is full or until a return character is
found. Then these characters read are compared with the different commands
implemented. If a command is found then the appropriate action is taken (like
read a register and print the result, get an image, move the servo, etc.). All the
actions taken are done using the functions explained in the above subsections.
After this the loop starts again. If the command is incorrect NCK is printed
and the loop starts again.