Camera Controller Project Report - EDA385
Camera Controller Project Report - EDA385
Abstract
This report is on an implementation of camera control hardware with
movement detecting capabilities. It describes the process in all steps from
design to nished product. Included are thoughts and comments on challenges, solutions and ideas for future improvement. The system is built
around a camera bought on ebay and a Nexys-3 platform from Digilent. The end result did not live up to the initial expectations because of
unforeseen challenges but a working prototype was delivered.
Contents
1
2
5
6
Introdution
Implementation
2.1 Camera . . . . . . . . . . .
2.1.1 Camera Setup . . .
2.1.2 Camera Interface . .
2.1.3 Camera Connection
2.2 Memory . . . . . . . . . . .
2.3 VGA Interface . . . . . . .
2.4 Movement Detector . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 4
. 4
. 6
. 7
. 7
. 8
. 10
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Challenges
3.1
3.2
3.3
3.4
3.5
3.6
3.7
.
.
.
.
.
.
.
12
12
12
12
13
13
14
14
Lessons Learned
14
User Manual
15
Contributions
15
Introdution
In this project a camera surveillance system with motion detection was developed. The implementation was based around a small camera module using on the
OmniVision 7670 CMOS VGA CameraChipTM , hereby referred to as OV7670,
together with a Xilinx Spartan-6 equipped Nexys-3 board from Digilent. While
the initial goal of motion tracking was not achieved, we managed to successfully
implement movement detection using a simple hysteresis based algorithm. The
reason for not implementing the full motion tracking was mainly time shortage
as a result of the camera conguration taking way more time than initially estimated. Both the camera and the VGA had timing constraints that could not
be met using software so the entire project was implemented in hardware, synthesized on the FPGA. The initial idea was to do motion tracking in software
and then accelerate it using hardware components but as time ran out it was
decided that it was simpler to just do detection in hardware rather than adding
a Microblaze core to the system. A simple overview of the system is shown in
gure 1 and an overview of the implemented hardware components is shown in
gure 2. All the components but the nal VGA controller were written by us.1
Implementation
2.1 Camera
2.1.1
Camera Setup
The setup of the cameras many options is done over SCCB (Serial Camera Control Bus), a proprietary bus developed by OmniVision for camera conguration.
The bus is similar to I2 C [1] with some subtle dierences, the most notable that
the data and clock ports are not open drain but regular CMOS logic I/O. Due
to diculties with implementing the bus specication, as can be seen in the
challenges section, only write capability was implemented. The registers and
their corresponding values that are used for camera initialization are shown in
table 3. More details on the specications in [2].
The purpose of the setup is to make the camera output RGB565 data at
a pixel clock rate that is the same as the camera input clock rate supplied
1 The
Used
# Slice Registers
# used as Flip Flops
# Slice LUTs
# used as logic
# using O6 output only
# using O5 output only
# using O5 and O6
# used as Memory
# used as Single Port RAM
# using O6 output only
# used exclusively as route-thrus
# with same-slice carry load
# occupied Slices
# MUXCYs used
# LUT Flip Flop pairs used
# with an unused Flip Flop
# with an unused LUT
# fully used LUT-FF pairs
# unique control sets
# slice register sites lost
# bonded IOBs
# LOCed IOBs
#IOB Flip Flops
# RAMB16BWERs
# BUFG/BUFGMUXs
# used as BUFGs
# OLOGIC2/OSERDES2s
# used as OLOGIC2s
Average Fanout of Non-Clock Nets
239
239
535
464
261
50
153
64
64
64
7
7
188
296
551
320
16
215
29
105
29
29
14
30
2
2
14
14
5.42
Available
Utilization
9,112
9,112
5,00%
5,00%
2,176
2,00%
2,278
4,556
8,00%
6,00%
551
551
551
58,00%
2,00%
39,00%
18,224
232
29
1,00%
12,00%
100,00%
32
16
93,00%
12,00%
248
5,00%
18,224
1,00%
Value
0x00
0x04
0x00
0x00
0x3A
0x35
0x11
0xF0
0x02
0xD0
Description
Internal Clock
Common Control 7
Common Control 3
Common Control 14
Test Pattern X
Test Pattern Y
DCW Control
Clock Divider
Clock Delay
Common Control 15
by the camera interface. Also some illegal default values are changed, again
see challenges section. The setup is managed by the cam_setup IP which in
turn uses a SccbInterf IP component for communication timing and driving
the I/O-pins. The cam_setup IP is a simple state machine where the cong
state consists of a case construct and a counter that counts up. Depending
on the counter value a dierent register is written. When the counter counts
past the last register associated value the state machine jumps to a done state
from which it never leaves. This works since the register values are only written
once, at system startup. The actual communication is handled by a SccbInterf
subcomponent. In SccbInterf everything needed for SCCB write operations is
implemented as state machine that shifts out data and clock on the respective
pins.
2.1.2
Camera Interface
2.1.3
Camera Connection
The camera was connected to the Nexys-3 board through the Pmod connectors.
The mapping can be seen in table 4. A simple connector was built and while
it provided basic functionality, it was later discovered that the long cables produced interference. This in turn added some noise to the picture. The connector
can be seen in gure 5. The camera itself can be seen in gure 6.
2.2 Memory
After a few iterations and tests it was the general consensus that the onboard
16MB of Cellular RAM was too slow to use as video memory. It would work,
but as speed was deemed more important the plan was scrapped. Therefore
a BRAM controller was implemented in VHDL, named mem. This IP contains
three memory banks
Bank 1 - for buering video from the camera and output to movement
detection
Because of the limited size of the BRAM, the picture was scaled to 160 by
120 pixels, more on that in the camera section. There was a need for three
banks because of the limited amount of read and write ports on the BRAM.
Limits in the synthesizing software produced unexplained errors until the port
issue was resolved. With this solution, there is support to add printouts to the
screen where the movement occurs. This is a bonus feature from solving the
challenges. However due to time constraints it has not been implemented yet.
The mem IP is implemented with three memory banks and three processes.
The cam process writes bank 1 and 3 continuously while bank 2 is only written
when the movement detector demands it, more on that in the movement detector section. The two other processes, det_rd_mem1 and vga outputs memory
7
Figure 7:
VGA Timing, unmodied original picture taken from
http://www.docstoc.com/docs/53768210/VGA-Timing-for-640x480-75-Hzrefresh-rate
from user. When SW1 is high the state machine is activated. It then awaits the
11
Figure 8: Example of SCCB Specication shortcoming. The only timing diagram that describes tri-state capable two wire communication is empty
complete reference frame before comparing pixels.
The movement detector can with some ne tuning detect if someone walks
past the camera. There is a lot of noise in the picture stream from the camera
and also the DSP is modifying the picture heavily. That is why the movement
detector sometimes indicates false positives or just doesn't detect movement at
all. The movement controller also needs to be tuned according to each camera,
since they seem to dier a bit. Might be because of external circumstances like
blocked lens, dierent lens focus or the interference between the cables in the
connector, as can be seen in gure 5.
Challenges
During this project there were some challenges and problems, some were solved
or worked around and some remained obstacles.
specication did refer to a timing diagram but the gure referred to was empty,
see gure 8. Another issue with the specication was the nomenclature. One
example of this is the fact that the ninth, and last, bit of each serial transmission
is called the don't care bit initially leading one to believe that it's value was
not important. Reading on in the specications does reveal however that the
so called don't care bit is thoroughly specied. After some work the write
functionality was implemented successfully and as only one camera initialization
was performed, at startup, and then never changed it was good enough for this
project.
13
Lessons Learned
Besides from the obvious like getting more comfortable with VHDL for synthesis
and working with the Xilinx tools and the Spartan-6 in general there were
some things that will be taken in consideration into future projects, especially
embedded systems projects.
14
User Manual
Contributions
The three authors worked closely on every part of the project but here are lists
on how the work was divided.
15
controllers
16
manual section
17
References
[1] I2 C on Wikipedia, http://en.wikipedia.org/wiki/I%C2%B2C 20131027
[2] OmniVision
Advanced
Information
Preliminary
http://www.voti.nl/docs/OV7670.pdf 20131027
Datasheet,
18