Electronic – OV7670 frames are 640×308 not 640×480

buffercameraccdstm32f10x

There is a lot of helpful information on the internet about getting the OV7670 camera up and running but the following problem has me a bit stumped.

I am using a Maple r5 Board (STM32F103RBT6) to grab an image from this model of OV7670 with AL422 buffer on a PCB.

I've uploaded the circuit schematic for this device from ebay and my code here.

My code grabs one frame from the OV7670, stores to AL422 and then relays it back to the PC with UART over USB connection (very slowly!). As you can see below, the image is initially unaligned, then I only get 640 by about 300 pixels, then the image repeats. I am just reading the grayscale Y channel. From the angle of the camera, it looks like the right hand of the image is repeated to the left.

grayscale image from ov7670
I have the camera focused on my oscilloscope because that image is rapidly changing to test if the repeats are subsequent frames or the same image. The pixels are identical which I think means the read pointer is wrapping around the buffer outputting the same data. I tried reading out further rows from the buffer and I get the same shortened frame repeated over and over.

UPDATE:
I checked the product sheet for the AL422B. This buffer can hold 393,216 bytes. With two bytes for a pixel (one for color, one for grayscale) this means only 393,216/2 = 640×307 pixels can be stored! I think this explains what is happening here! Now my question is, are there any settings for the OV7670 to output only the grayscale channel so I can store one whole frame!

PS: I am new here so please let me know how to ask questions more effectively.

Best Answer

For reference if others find this: The COM7 register was set to Bayer RAW (bits[2:0]=001). This causes the camera to output 640 by 480 bytes which can fit on the AL422B. However the Bayer interpolation needs to be done externally to get full rgb color picture. Alternatively the gains on r,g,b channels can be fiddled to get something close to a grayscale image which is what I desired.

Related Topic