0
\$\begingroup\$

I´m working on my OV7670 interface and I have some issues with the color / image settings. I use the color bar settings of the sensor to check my logic and the color bar looks good:

enter image description here

But I´m unsure if the order of the colors is correct because I have green / red swapped in the camera image. It doesn´t make any sense to me that the color bar from the camera has the correct order, but the camera image has green and red swapped.

enter image description here

And the camera image contains a black bar on the left side of the image (live image only) - check the photo. I have checked the data with a logic analyzer and it seems that the camera transmits some black pixels and the beginning of the frame (see the signals OV7670_D_Out and OV7670_HREF_Out which are the input signals from the camera):

enter image description here

I use the following settings for the image sensor (the first byte of an element is the register address and the second is the register value):

static uint8_t OV7670_Config[][2] =
{
    {0x11, 0x01},
    {0x0C, 0x00},
    {0x12, 0x04},
    {0x3E, 0x00},
    {0x40, 0xD0},
    {0x70, 0x3A},
    {0x71, 0x35},
    {0x72, 0x11},
    {0x73, 0xF0},
    {0xA2, 0x02},
};

Do I use the wrong configuration for the sensor or where does the black bar in the live image and the red / green swap in the live image come from?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Your color bar picture seems to match the standard. en.wikipedia.org/wiki/SMPTE_color_bars \$\endgroup\$ – Mattman944 Apr 5 at 19:49
  • \$\begingroup\$ @Mattman944 thank you. Doesn´t know that a standard for these color bars exist. \$\endgroup\$ – Kampi Apr 5 at 19:53
1
\$\begingroup\$

I had this exact same issue, color bar working but video output has pinkish and greenish colors mixed when streaming video. The solution was to basically set most of the configuration registers to values that I stole from another page, not all the configs were correct so I tweaked them a bit but it made the colors normal. Here Is the page that I took the configuration from:

https://lauri.xn--vsandi-pxa.com/hdl/zynq/zybo-ov7670-to-vga.html

Here is my code dealing with the configurations.

    case current_cmd_index is
        when 0 => current_command <= x"1280"; -- COM7   Reset
        when 1 => current_command <= x"0000"; -- DUMMY COMMAND for 3ms delay!
        when 2 => current_command <= x"1204"; -- COM7   Default size, RGB
        when 3 => current_command <= x"1100"; -- CLKRC  Prescaler - Fin/(1+1)
        when 4 => current_command <= x"0C00"; -- COM3   Lots of stuff, enable scaling, all others off
        when 5 => current_command <= x"3E00"; -- COM14  PCLK scaling off
        when 6 => current_command <= x"8C00"; -- RGB444 No RGB 444
        when 7 => current_command <= x"0400"; -- COM1   no CCIR601
        when 8 => current_command <= x"40f0"; -- COM15  Full 0-255 output, RGB 555
        when 9 => current_command <= x"3a04"; -- TSLB   Set UV ordering,  do not auto-reset window
        when 10 => current_command <= x"1438"; -- COM9  - AGC Celling
        when 11 => current_command <= x"4f40"; --x"4fb3"; -- MTX1  - colour conversion matrix
        when 12 => current_command <= x"5034"; --x"50b3"; -- MTX2  - colour conversion matrix
        when 13 => current_command <= x"510C"; --x"5100"; -- MTX3  - colour conversion matrix
        when 14 => current_command <= x"5217"; --x"523d"; -- MTX4  - colour conversion matrix
        when 15 => current_command <= x"5329"; --x"53a7"; -- MTX5  - colour conversion matrix
        when 16 => current_command <= x"5440"; --x"54e4"; -- MTX6  - colour conversion matrix
        when 17 => current_command <= x"581e"; --x"589e"; -- MTXS  - Matrix sign and auto contrast
        when 18 => current_command <= x"3dc8"; -- COM13 - Turn on GAMMA and UV Auto adjust
        when 19 => current_command <= x"1100"; -- CLKRC  Prescaler - Fin/(1+1)
        when 20 => current_command <= x"1711"; -- HSTART HREF start (high 8 bits)
        when 21 => current_command <= x"1861"; -- HSTOP  HREF stop (high 8 bits)
        when 22 => current_command <= x"3280"; -- HREF   Edge offset and low 3 bits of HSTART and HSTOP
        when 23 => current_command <= x"1903"; -- VSTART VSYNC start (high 8 bits)
        when 24 => current_command <= x"1A7b"; -- VSTOP  VSYNC stop (high 8 bits)
        when 25 => current_command <= x"030a"; -- VREF   VSYNC low two bits
        when 26 => current_command <= x"0e61"; -- COM5(0x0E) 0x61
        when 27 => current_command <= x"0f4b"; -- COM6(0x0F) 0x4B
        when 28 => current_command <= x"1602"; --
        when 29 => current_command <= x"1e27"; -- MVFP (0x1E) 0x07  -- FLIP AND MIRROR IMAGE 0x3x
        when 30 => current_command <= x"2102";
        when 31 => current_command <= x"2291";
        when 32 => current_command <= x"2907";
        when 33 => current_command <= x"330b";
        when 34 => current_command <= x"350b";
        when 35 => current_command <= x"371d";
        when 36 => current_command <= x"3871";
        when 37 => current_command <= x"3900";
        when 38 => current_command <= x"3c78"; -- COM12 (0x3C) 0x78
        when 39 => current_command <= x"4d40";
        when 40 => current_command <= x"4e20";
        when 41 => current_command <= x"6900"; -- GFIX (0x69) 0x00
        when 42 => current_command <= x"6b0a";  --Bypass PLL!
        when 43 => current_command <= x"7410";
        when 44 => current_command <= x"8d4f";
        when 45 => current_command <= x"8e00";
        when 46 => current_command <= x"8f00";
        when 47 => current_command <= x"9000";
        when 48 => current_command <= x"9100";
        when 49 => current_command <= x"9600";
        when 50 => current_command <= x"9a00";
        when 51 => current_command <= x"b084";
        when 52 => current_command <= x"b10c";
        when 53 => current_command <= x"b20e";
        when 54 => current_command <= x"b382";
        when 55 => current_command <= x"b80a";
        when others => current_command <= x"ffff";
    end case;

I am also getting the black bar and can't figure out how to get rid of it, probably need more registers set. A lot of these are undocumented so I have no idea what they're actually doing. Did you have any luck solving this in the meantime? And did you maybe record the end of a row to see if there is any data after the falling edge of Href?

Before After

\$\endgroup\$
1
  • \$\begingroup\$ Thank you. I will check it this weekend. \$\endgroup\$ – Kampi Jun 4 at 5:01
0
\$\begingroup\$

Color swap:

you read with one byte delay and the YUV decoder produces wrong results.

Black bar on the left:

The horizontal synch is correct but your controller starts reading zeros before the CMOS camera opens the rolling shutter.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ If the byte stream is off by one byte, why would the colorbar sent from camera be OK but image sent from camera not? \$\endgroup\$ – Justme Apr 5 at 20:24
  • \$\begingroup\$ I don´t have one byte delay in my reading. The design reads two bytes from the camera (one pixel), combine them to a 24-bit value (16 bit camera data, one zero byte and some reordering) for the video DMA and set a write enable signal for the internal FIFO (FIFO_WE_Out). \$\endgroup\$ – Kampi Apr 5 at 20:31
  • \$\begingroup\$ The byte stream that the camera outputs is ok. The microcontroller that captures those data might be not correctly configured. \$\endgroup\$ – Enrico Migliore Apr 5 at 20:32
  • \$\begingroup\$ It´s an FPGA that streams the data over a video DMA to a monitor, so the only configuration is done by the processor during the camera initialization. The configuration doesn´t change between the color bar and the live image. It is the same configuration in both cases. And I start the reading of the bytes when HREF is asserted by the camera, so the data are ready. \$\endgroup\$ – Kampi Apr 5 at 20:34
  • \$\begingroup\$ Is it an RGB565 or RGB888 display? \$\endgroup\$ – Enrico Migliore Apr 5 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.