OV7670 FIFO camera wrong data

28 Oct 2017

The OV7670 module with FIFO gives me bad color data. In particular, I use it in RGB565 mode, the green is the channel where I get what looks like an error: it seems that the 4th bit of the 6-bit green color data is stuck in "1" position; it never changes throughout the image, even if I put a lens cap to have a dark image. I have tried many many registers settings, and even tried the YUV colorspace instead of RGB565. Here you are G,R,B channels separately. It is clear that the green channel is wrong; using ImageJ to plot the pixels, I can count a mere 4 shades of green (they should be 64).
Green channel: /media/uploads/rulla/imagesfereg.jpg Red channel: /media/uploads/rulla/imagesferer.jpg Blue Channel: /media/uploads/rulla/imagesfereb.jpg
Do you have an idea of what' s going wrong? It should be EVERYTHING ok, registers, timing, color data conversion. The camera configuration code is at: https://os.mbed.com/users/rulla/code/OV7670_ok/#f5f5d7c979cf , while the piece of code I use to convert data bytes to color is:
<<code>> bank0 = cam.ReadOneByte(); bank1 = cam.ReadOneByte(); r=((bank1 & 0x1f)) ; g= ((bank1&0xe0)>>5 ) |((bank0&0x7)<<3); b=((bank0 & 0xf8)>>3 ); <</code>>
Thank you all for your time!

28 Oct 2017

Perhaps bank0 and bank1 (and r, g, and b) need to be declared as unsigned chars? Maybe bank0 and bank1 are getting swapped or out-of-sequence?

Your red channel results looks like it has less resolution than the blue, too. Are the posted images supposed to be scaled to 6 or 8 bits? Do you want the r, g, and b values to have the same nominal scale (6 bits)? Do you want them in the upper or lower 6 bits of each byte?

Double check your channels with an image that has black and white patches plus a red 'R', green 'G', and blue 'B', etc.

P.S. your <<code>> tag needs to be on its own line.

28 Oct 2017

Yeah you' re right, red looks gross; but blue is ok, so I don' t think the problem' s something as big as a type mismatch... bank0 and bank1 are uint8_t. The Images I have posted are created from a .txt file with color values, fed into ImageJ "Import text image". The grey level scale is set by the program; nonetheless, blue and red nominal scale is 5bit, green is 6 bit. RGB565 data is 2 bytes; red is the first 5 bits, green shares 3bits from the first byte and 3 from the second byte, and blue is the last 5 bits of the second byte. But the real problem is the green. Thank you so much dear Fred.

28 Oct 2017

Oh, I forgot one detail. If you look at the Blue channel image I' ve posted, you see 2 balls which are lighter: they actually are Yellow. The other ball is Blue.