Interfacing CMOS Camera With ATMega

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

INTERFACING C328 CMOS CAMERA WITH AN ATMEGA32L

MICROCONTROLLER

Er. Shrijandra Nath Kayastha

Department of Electronics and Communication Engineering,


Khwopa Engineering College, Libali, Bhaktapur

Abstract
A small low power VGA camera module C328 can perform as a JPEG compressed still camera and can be
attached to a microcontroller, PC, wireless or PDA host, etc. This paper introduces the C328 CMOS camera
interface with a low power CMOS 8 bit ATMega32L microcontroller based on AVR enhanced RISC
architecture. The ATMega32L executes powerful instruction in single clock cycle and achieves throughputs
approaching 1MIPS per MHz that allows designing the system with optimum power consumption versus
processing speed. The camera module C328 was serially interfaced with microcontroller, and the lowest
resolution JPEG image (80x64) compression mode was made for the analysis of packet of image data in hex
format. It was specifically designed for the cost effective embedded vision system that can be used in robot,
security, monitoring etc.
Keywords: Camera, Embedded system, Microcontroller, Hex format

1. Introduction 80x64 of image was taken within the limit of 2Kbyte


As in the modern world, the vision system is main of internal SRAM of ATMega32L.
concern. People are concerned about the security
of their homes and property through CCTV camera. For the simulation and debugging, the VMLAB was
The robotic systems are becoming smaller, lower used since it provides a true virtual microcontroller
power, and cheaper enabling their application in design lab in which the hardware and software are
areas previously impossible, and this is also true of co-simulation, making unnecessary in-circuit
the vision system. Traditionally, these systems emulator.
comprise a camera with complex hardware system
to interface and require powerful computer and large VMLAB uses WinAVR as a compiler for compiling
memory for the image processing. Recent the code [6]. WinAVR is a suite of executable, open
developments of low cost CMOS color camera source software development tools for the Atmel
modules and high speed microcontrollers make it AVR series of RISC microprocessors hosted on the
possible to build a simpler and cost effective system. Windows platform. It includes the GNU GCC
The well known camera C328 which consists of compiler for C and C++ [8]. A simple parallel port
Omnivision image sensor OV7640 and OV528 PonyProg programmer was used for programming
JPEG image compressor chip. The compression chip the AVR that also provides the facility of setting
includes a serial interface suitable for a direct the fuse bits of the microcontroller.
connection to a microcontroller’s UART. By issuing
the appropriate commands, a snap-shot as JPEG- 2. Camera Sensors Interfacing
compression byte streams of the lowest resolution The C328 uses Omni Vision OV7640/8 VGA
Camera Chips with an 8-bit YCbCr interface and
*Corresponding author: Er. Shrijandra Nath Kayastha
Department of Electronics and Communication Engineering, compressor chip. The OV528 Serial Bridge is a
Khwopa Engineering College, Libali, Bhaktapur. controller chip that can transfer image data from
Contact: 977-9841726299
Email: er.shrijandra@gmail.com
Camera Chips to external device [5]. The OV528
(Received: 2011 Nov 11 Accepted: 2011 Nov 23)
JScE Vol. 1, Falgun 2068 Shrijandra N. Kayastha 38
takes 8-bit YCbCr 422 progressive video data from to synchronize properly between the camera and
an OV7640CameraChip [2]. The camera interface microcontroller [1] and low byte of fuse bits
synchronizes with input video data and performs CKSEL3…0 are configured as (1111) through
down-sampling, clamping and windowing functions PonyProg (setting CKSEL3...0 as unchecked) [7] in
with desired resolution, as well as color conversion order to use external crystal [4].
that are requested by the user through serial bus
host commands. The JPEG CODEC with variable 2.1 Package Size
quality settings can achieve higher compression The default size is 64 bytes and the maximum size
ratio & better image quality for various image is 512 bytes [2].
resolutions which are shown in Fig 2(a-b). A serial
type program memory is built-in for C328, which ID Data Image Data Verify
provides user-friendly commands to interface (2 bytes) size (Package size- code
external control units. This command was issued (2 bytes) 6) bytes (2 bytes)
by the host to change the size of data package which
was used to transmit JPEG image data from the ID -> Package ID; starts from zero for
C328-7640 to the host [2]. This command was an image
issued before sending Snapshot Command or Get Data Size -> Size of image data in the package
Picture command to C328-7640. It was noted that Verify Code -> Error detection code, equals to the
the size of the last package varies for different lower byte of sum of the whole
image. package data except the verify
code field. The higher byte of this
The C328 needs 3.3V to power up which was code is always zero.
designed using LM317 voltage regulator. Since, the
camera operating voltage is 3.3V, the microcontroller Number of packets= image size/ (data size-6)
ATMega32L was selected to operate in low voltage Image size= HH LL of AA 0A 01 LL HH ZZ
of 3.3V, and this removed the use of voltage logic Data size= HH LL of packet size (00 00, LL HH,
level converter between microcontroller and camera. Image Data, Verify Code)
The C328 camera module responds to serial
commands and each command of the C328 is equal The SYNC command AA 0D 00 00 00 00(@
to 6 bytes. Exact value of external crystal was used 14400bps) was sent until receiving ACK command
AA 0E 0D XX 00 00 from C328-7640 (usually an
ACK command is received after sending 40 times
of SYNC command) [2]. Note: The value of XX
can be 00 or 01 or 10 or 11.Similarly, the host should
acknowledge the camera by sending the ACK
command AA 0E 0D 00 00 00, so in this way the
camera was synchronized with the host
(microcontroller). Now, the microcontroller set up
the configuration of camera, and the snap shot
command was sent to get picture. Since the camera
goes to sleep mode after receiving the command
AA 09, the microcontroller should send SYNC
command AA 0D to wake up C328 camera until
ACK command is received from camera.
2.2 JPEG Snapshot Picture
By default package size is 64 bytes, so there was
Fig.1. System Block Diagram of Camera and
no need to set packet size.
C328 camera module
JScE Vol. 1, Falgun 2068 Shrijandra N. Kayastha 39
The camera has to be initialized and setup in the The software Hex Editor Free Serial Monitor was
configuration that the user defines. Here, the camera used to view the data from camera that was sent or
was set in the following configuration: received from the Serial Port [9]. The sample data

a) Sample Picture of Microcontroller (80 x 64) b) Sample Picture (320 x 240)


Fig.2. Snap shot picture taken from C328 CMOS camera

· Initial Cmd: Color Type = 07h = JPEG, JPEG of above picture from camera for 80x64 resolutions
Resolution = 01h = 80x64 was as follows:
· Get Picture Cmd: Picture Type = 01h = JPEG
· Snapshot Cmd: Snapshot Type = 00h = 3. Packet information
Compressed After initializing the camera JPEG snap shot picture
· Package Size Cmd: Leave as it is for Default command AA 04 01 00 00 00 was sent and the
= 64 bytes camera acknowledged by the command AA 0E 04
· Data Cmd: Data Type = 01h = Snapshot Picture

Fig.3. Snap shot of HEX data format (Left) and ASCII format (Right) of Microcontroller.jpg (80x64) in Hex
Editor Software, showing starting JPEG format FF D8.

JScE Vol. 1, Falgun 2068 Shrijandra N. Kayastha 40


04 00 00 along with the packet size information by Last Packet:
AA 0A 01 C4 02 00. 0C 00 0C 00 00 28 A2 8A 00 28 A2 8A 00 FF D9
00 98 00
Here the size of image data is store in the format
HH LL of AA 0A 01 LL HH ZZ, i.e. image size is Here, the packet ID 0C 00 0C 00 informs the 13th
02 C4 means 708 bytes of image data are sent from packet with 12 bytes of image data and 98 00 is the
the camera to calculate the number of packets. The end of packets. So, It was programmed to remove
default packet size 64 bytes was used and the packet ID (e.g. 0C 00), data size (e.g. 0C 00) and
number of packets= image size/ (data size-6) verify code (e.g. 98 00) and store image data in an
=ceil[708/(64-6)]=12 [3]. Now, the camera was array of size (58*12 + 12= 708, i.e. 02 C4) for all
ready to send the number of packets of image data the packets which gives the image of the snapshot.
and to receive the first packet data the command Actually there are 13 packets, i.e. 12 packets of 58
AA 0E 00 00 00 00 was sent, where 00 means initial bytes and 1 packet of 12 bytes. The image data
packet and the camera will send image data: stored in the memory of microcontroller was in the
following format which can be transfer to PC to
First packet: view the complete picture. The whole image was
00 00 3A 00 FF D8 FF E0 00 11 4A 46 49 46 00 01 stored in the memory of microcontroller but of small
02 03 04 05 06 07 08 09 0A FF DB 00 43 00 10 0C resolution, so to store the picture of high resolution
0C 0E 0C 0A 10 0E 0E 0E 12 12 10 14 18 28 1A the memory card can be used. Image Data in the
18 16 16 18 32 24 26 1E 28 3A 34 3E 3C 3A 34 10 memory of Microcontroller:
00
FF D8 FF E0 00 11 4A 46 49 46 00 01 02 03 04 05
Here, 00 means first packet with the packet 06 07 08 09 0A FF DB 00 43 00 10 0C 0C 0E 0C
containing 3A or 58 bytes of image data and 3A is 1 0A 10 0E 0E 0E 12 12 10 14 18 28 1A 18 16 16 18
byte i.e. 8 bits and AVR microcontroller can transfer 32 ……………………. 8A 00 28 A2 8A 00 28 A2
or receive 1 byte (e.g. AA) at a time. Similarly, to 8A 00 28 A2 8A 00 FF D9 00
receive the second packet of image data, the
command AA 0E 00 00 01 00 was sent. Where, FF D8 and FF D9 are the start and end of
JPEG format respectively [10]. This, can be verify
Second Packet: when we view any JPEG picture by HEX editor
01 00 3A 00 38 38 40 48 5C 4E 40 44 58 46 38 38 software that shows the HEX data format of JPEG
50 6E 52 58 60 62 68 68 68 3E 4E 72 7A 70 64 78 along with their ASCII form [9].
5C 66 68 64 FF DB 00 43 01 12 12 12 16 16 16 30
1A 1A 30 64 42 38 42 64 64 64 64 64 64 64 29 00 4. Conclusion
The C328 is a highly integrated camera module
Third Packet:
featured on-board JPEG compression engine and
02 00 3A 00 64 64 64 64 64 64 64 64 64 64 64 64
RS232 serial interface. The goal of this project is to
64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64
implement a simple embedded vision system
64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 FF
consuming low power to replace fairly complicated,
C4 00 1F 00 00 01 05 01 01 01 01 01 01 00 F6 00
expensive system that is out of reach for many
developers who have moderate camera interfacing
Fourth Packet:
requirements for storing in MMC card, security
03 00 3A 00 00 00 00 00 00 00 00 01 02 03 04 05
system, uploading image using GPRS modem,
06 07 08 09 0A 0B FF C4 00 B5 10 00 02 01 03 03
robotics etc. The feasibility was demonstrated by
02 04 03 05 05 04 04 00 00 01 7D 01 02 03 00 04
taking the JPEG still image of low resolution and
11 05 12 21 31 41 06 13 51 61 07 22 71 14 E7 00
storing the image data in memory of microcontroller
which can be easily used for the further
Similarly, 5th to 12th packet was received.
JScE Vol. 1, Falgun 2068 Shrijandra N. Kayastha 41
requirements. However, only the lowest resolution [5] OV7640 (2003) “Single Chip VGA (640x480) CMOS
Color Image Sensor” Version 1.3, CA USA: Omnivision
of image was stored in microcontroller due to its
Technologies, INC. www.ovt.com/cc7640.html
small size (2K Byte) of internal SRAM and for the
higher resolution one can extend memory or [6] VMLAB (2007) “A Virtual Prototyping IDE for AVR”
interface MMC card to store large number of Version 3.12, SPAIN: Advance Microcontroller Tools Ltd.
http://www.amctools.com/vmlab.htm
pictures at high resolution.
[7] Lanconelli, C., (2000) “PonyProg2000, Serial Device
References Programmer” Version 2.06, Italy. http://www.lancos.com/
[1] Bitti, A.R. (2006) “The Witness Camera” UK: Circuit prog.html
Cellar.
[8] WinAVR (2007) “GNU GCC Compiler for C and C++”
[2] C328-7640 (2005)” User Manual for CMOS VGA camera USA: Free Software Foundation, Inc. http://
module” Version 3, CH: COMedia Ltd. winavr.sourceforge.net/

[9] Hex Editor Neo (2010) “Free Serial Port Monitor” Version
[3] Gaddam, S., (2007) “Intelligent Machine Design
4.81, UK: HDD Software Ltd. http://
Lab”USA: University of Florida.
www.hhdsoftware.com/serial-monitor
[4] ATMega32L (2006) “Datasheet of Atmel 8-bit AVR RISC-
based Microcontroller” USA: Atmel corporation. [10] JPEG (2009) “Joint Photographic Experts Group, JPEG
www.atmel.com/avr Homepage” UK: ISO/ISE Joint Technical Committee.
http://www.jpeg.org/jpeg/index.html

JScE Vol. 1, Falgun 2068 Shrijandra N. Kayastha 42

You might also like