Lab 11: CMOS Camera: OV7670 COEN-4720 Embedded Systems Cristinel Ababei Dept. of Electrical and Computer Engineering, Marquette University 1. Objective The objective of this lab is to use the OV7670 camera module to capture video frames that are displayed on the LCD display of the LandTiger 2.0 board. 2. Camera Module Based on the OV7670 CameraChip with OmiPixel Technology We use a low price (<$10, including shipping!) camera VGA OV7670 Camera Module Lens [1]. The OV7670 is a low cost image sensor + DSP that can operate at a maximum of 30 fps and 640x480 ("VGA") resolution, equivalent to 0.3 Megapixels. The captured image can be pre-processed by the DSP before sending it out. This preprocessing can be configured via the Serial Camera Control Bus (SCCB). For details about this camera, please read the rather incomplete and confusing datasheet available at [2]. Its main specs include: High sensitivity for low-light operation; Photosensitive Array: 640 x 480 Low operating voltage for embedded application; Voltage: 2.5V to 3.0V; Low power (60 mW @ 15 fps and less than 20 μA sleep mode current) Operating Temperature: -30 to 70 deg C Standard SCCB interface, also compatible with I2C interface Raw RGB, RGB (GRB4:2:2, RGB565/555/444),YUV(4:2:2), and YCbCr(4:2:2) output format Support VGA, CIF and from CIF to 40 x 30 format; No output FIFO registers at all to hold pixel data; The camera module has a 9x2 header with the pin diagram shown below. VDD GND SDIOC SDIOD VSYNC HREF PCLK XCLK D7 D6 D5 D4 D3 D2 D1 D0 RESET PWDN 1 The definition of these pins is as follows. Pin Type Description VDD** Supply Power supply GND Supply Ground level SDIOC Input SCCB clock SDIOD Input/Output SCCB data VSYNC Output Vertical synchronization HREF Output Horizontal synchronization PCLK Output Pixel clock XCLK Input System clock D0-D7 Output Video parallel output RESET Input Reset (Active low) PWDN Input Power down (Active high) Because this is a rather old camera, there is lots of information related to its usage out there. For example, instances of this camera utilization is shared online at [3], to name a few. However, the camera module does have some limitations. The primary limitation is the rather difficult programming of the numerous camera registers. This difficulty is amplified by the conflicting information available out there about what the value of these registers should be; OmniVision’s documentation is rather lacking organization and clarity. Camera Module Versions It has to be noted that there are commonly two types of this camera module: 1) the one that we use – the cheaper one – but without a FIFO buffer on the module itself, and 2) one that has also a FIFO buffer on the module (its cost is about $25 though). This FIFO is basically a “AL422 3M-Bits FIFO Field Memory” chip soldered on the back of the module’s PCB. In this case the camera module’s connections are a bit different and therefore the camera programming is different too (and easier/simpler). Here is one example of a place where this is available [4]. Moreover, there are actually two different flavors of this type (see the discussion at http://wiki.beyondlogic.org/index.php?title=OV7670_Camera_Module_with_AL422_FIFO_Theory_of_ Operation) Specialized Camera Interfaces It has also to be noted that there are microcontrollers out there that actually have dedicated peripherals/devices for interfacing with camera modules such as the OV7670. Also, companies would provide design examples of how to utilize such peripherals. There are also some dedicated development boards that have camera modules included. Unfortunately, the LPC1768 MCU is not one of them. Two such examples include: 2 1. LPC4300 has a SPGIO that is digitally configurable interface. In the application note from [5], this SGPIO is used to emulate an 8-bit parallel interface to communicate with the camera module. A design example was demonstrated using the Keil MCB4300 board. 2. The state configurable timer (SCT) available on the LPC1800 and LPC4300 is a powerful digital configurable interface, which is used in [6] to work with an NXP camera module (based on OV7670) attached to the Keil MCB1800 board. 3. The STM32F4 microcontroller comes with a Digital CaMera Interface (DCMI) and a Direct Memory Access (DMA) controller; and one can use these two to capture the frames without the intervention of the processor [7]. 3. Example 1: Interfacing the Camera Module to the LandTiger 2.0 board All the required source files for this example are located under example1/ folder that comes with the archive of files provided for this lab. Create a new project, and add all the provided files to your project. We “talk” to the camera module using I2C (studied in a previous lab) to write/read camera registers. Frames are read one by one in a brute-force manner. Pixels of a given frame are displayed on the LCD display on the fly while the frame is being scanned. Currently the camera module is configured to work with QCIF (176x144) format in order to eliminate timing issues. However, the image size in the case of the camera instance I use is only 155x145; not sure why. Read the provided source files, which have lots of comments – this will help you understand the whole design. You will have to attach the camera module to the board. Create the connections illustrated in Figure 1 below. Also, connect the UART0 from the board to your host PC where you should have opened a Putty (or alike) terminal; check the provided source code for info on the baud rate. Build the project and download to target. Observe operation and comment. 3 Figure 1 Connections between LandTiger board and Camera module. Figure 2 Camera module providing 155x145 frames. 4 4. Lab Assignment Read thoroughly the provided source code as well as the datasheet of the camera module. Then, think about how to make it run at 320x240 image size. Make necessary changes to the code and present results to the TA as well in the lab report (photographs of your board in operation mode). Describe in detail the rationale of your changes; explain why you made those changes, the expected results, and the actual obtained results. You may use any technique you would like. Demo your new and improvement camera system to your TA. Upload a copy of your code (entire uVision project) to D2L. 5. References [1] http://www.amazon.com/sunkee-OV7670-640X480-CompatibleInterface/dp/B00AZWVZKW/ref=sr_1_1?s=electronics&ie=UTF8&qid=1379557438&sr=11&keywords=CMOS+OV7670+Camera [2] Datasheet of OV7670 (2006 version). http://www.eleparts.co.kr/data/design/product_file/Board/OV7670_CMOS.pdf [3] --Jorge Aparicio's blog on Electronics, Robotics and more: Hacking the OV7670 camera module, 2012. http://embeddedprogrammer.blogspot.com/2012/07/hacking-ov7670-camera-module-sccb-cheat.html --OV7670+FIFO camera control with an AVR ATmega1284. https://github.com/arndtjenssen/ov7670 --desaster's blog: OV7670-FIFO + MSP430 Launchpad http://www.rpg.fi/desaster/blog/2012/10/20/ov7670-fifo-msp430-launchpad [4] Camera module + FIFO. http://www.emartee.com/product/42043/OV7670%20AL422%20FIFO%20Camera%20Module%20CF76 70C%20V2 http://www.suntekstore.com/goods-14004307640x480_cmos_camera_module_ov7670_vga_yuv_snr_46_db_with_high_quality_lens.html [5] SGPIO camera module design using LPC4300 http://www.lpcware.com/content/nxpfile/an11343-sgpio-camera-module-design-using-lpc4300 [6] SCT camera interface design with LPC1800 and LPC4300 http://www.lpcware.com/content/nxpfile/an11365-sct-camera-interface-design-lpc1800-and-lpc4300 [7] Jorge Aparicio's blog on Electronics, Robotics and more: Hacking the OV7670 camera module, 2012. http://embeddedprogrammer.blogspot.com/2012/07/hacking-ov7670-camera-module-sccb-cheat.html 5