Monday, December 2, 2019

DIY USB 3.0 Camera: UVC Video Device Class VGA Camera Using Cypress FX3

This Project is going to next in the series of previous projects. Previously i interfaced inexpensive OV7670 VGA Camera to MCU.

In this post we will overcome the 10FPS limit of frame rate caused by slow Parallel port of PIC32MZ. This version of Camera will use 4.8Gbps Cypress FX3 USB 3.0  controller, with use of this controller comes 32bit 100Mhz GPIF interface, which make it possible to easily implement 30 FPS 640x480 live video transfer. 

Capability of Cypress FX3 is way higher than VGA 30FPS, but for this test project i will be limited the by the max resolution of OV7670. 




Hardware Connection

FX3 has Extremely flexible 32bit 100Mhz GPIF II interface for picking up data from external application processor/Data Producer. OV7670 Connected to GPIF II with 8bit prallel bus with Hsync and Vsyn line. GPIF is driver as slave with interface clock supplied from the camera pixel clock.

Here is how camera is connected to FX3


Signal CLK is pixel clock generated by camera
GPIF interface is Driven by a state machine , Here is the state machine which i used to latch data into DMA buffers. this state machine is from cypress FX3 application note AN75779 more details about can be found in the PDF document by cypress.


Test with VLC 



Firmware 

Firmware as usual can be found in my github account
https://github.com/circuitvalley/Cypress-FX3-USB3

54 comments:

  1. In Hardware Connection: - OV7670 has two clock PCLK and External clock. Here you mention only one clock connected GPIO16 of Fx3.

    ReplyDelete
  2. How to interface PIXCLK,SCL,SDA of OV7670 with FX3?

    ReplyDelete
    Replies
    1. External clock for the camera in my demo is supplied from signal generator.
      Camera need external clock , either have a external oscillator or use a signal gen.

      PCLK is output from camera and input to FX3. While XCLK is input to camera and not connected to FX3.

      Delete
  3. Please share pin connection(Hardware)

    ReplyDelete
  4. Whether SCL and SDA pins are used or not?

    ReplyDelete
    Replies
    1. Camera SDL and SDA pins are directly connected to FX3 SDL and SDA pins

      Delete
  5. Is it required to give power supply 3.3v and gnd to OV7670?

    ReplyDelete
  6. I have following error during build the project in EZ-USB Suite and I unable to create Image file


    11:22:21 **** Incremental Build of configuration Default for project Firmware ****

    make all

    Cannot run program "make": CreateProcess error=2, The system cannot find the file specified

    ReplyDelete
    Replies
    1. I guess compiler or tool chain is not properly installed.

      Delete
  7. May I know Which tool chain or compiler used for this work?

    ReplyDelete
    Replies
    1. You need to install, Cypress EZ USB Suite It will install every thing.

      Delete
  8. I build the project, generate the image file and I load into FX3 kit using USB control Center, but I unable to view the video streaming in VLC.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. May I know pin detail of GPIO_27 which is connected to OUTPUT1? in GPIF II designer

    ReplyDelete
    Replies
    1. That is for debugging, to probe with oscilloscope.

      Delete
    2. May I know Debugging signal? Is it debug FV or LV or PClK or Data signal?

      Delete
    3. To debug GPIO State machine, States with DR_GPIO drives this pin.

      Delete
  11. I unable to view the video streaming in VLC. May I know about PWDN Pin?

    ReplyDelete
  12. Is below hardware connection correct LV-> CLT_11, FV->CLT_12, data[0:7] -> DQ[0:7], pclk->pclk, i2c_sda->sda, i2c_sck -> sck. reset->CLT_5,pwdn->CLT-0.

    ReplyDelete
  13. May I know the frequency used for sensor(xclk), I used 50MHz. I unable to test with VLC.
    Could you support for that?

    ReplyDelete
  14. May I know the above state machine for ov7670 sensor?

    ReplyDelete
  15. For ov7670 timing diagram FV is low and LV is high then data are valid, but in above diagram FV and LV both are high then the data are valid. Is it matched with timing?

    ReplyDelete
  16. Camera VSYNC and HSYNC polarity is settable using a register. You can select how you want. I have sent register value in such a way that VSYNC and HSYNC both are active when data is available.

    On my other post about this camera interface to PIC32, timing diagrams are given
    https://www.circuitvalley.com/2019/06/opensource-diy-usb-webcam-ov7670-ov2640-pic32-USB-UVC-Video-device-class.html

    ReplyDelete
    Replies
    1. May I know register value for VSYNC and HSYNC

      Delete
    2. Register values available in source.

      Delete
  17. In sensor.h , why SADDR_HIGH required?

    ReplyDelete
    Replies
    1. SADDR_HIGH is macro to select between different I2C camera address.

      Delete
    2. for ov7670 has one camera address 0xBA only, here why SADDR_HIGH required? for multiple sensor SADDR required.

      Delete
  18. Is register configuration for VGA 30fps?

    ReplyDelete
    Replies
    1. Register values available in source are for 30FPS

      Delete
  19. I have following error, Could you support for this?

    Your input can't be opened:
    VLC is unable to open the MRL 'dshow://'. Check the log for details.

    ReplyDelete
    Replies
    1. Check if camera is outputting data,clock and other signal in correct order. and everything is connected properly

      Delete
  20. In my system have usb2.0 , Is FX3USB3 cable support to usb2.0 but it device,vendor id is detected FX3(04b4:00F8).

    ReplyDelete
    Replies
    1. Though USB 3.0 is backward compatible but i have not tested FW with USB2.0 , Device will be detected , what exact stream capability are implemented for USB 2.0 interface i need to look into code.
      whole point of FX3 is USB 3.0 , so try with USB 3.0

      Delete
  21. Is is possible to look your interface board? i.e. connection between FX3 and Sensor.

    ReplyDelete
    Replies
    1. Right now i do not have that board in my hands i will need to look for it. connections are exact as shown in the GPIF image above.

      Delete
  22. In uvc.c, UVC Probe Control Settings for a USB 3.0 connection max.video frame size 0x00, 0x6F, 0x09, 0x00. Could you explain this?

    ReplyDelete
    Replies
    1. can you please point out line number?

      Delete
    2. Line# 147 - 0x00, 0x6F, 0x09, 0x00, /* Max video frame size in bytes */

      Delete
    3. Its exactly what comments say , define how many maximum number of bytes are in one image frame. for VGA it should be larger than 640x480x2 .

      Delete
    4. above 0x00,0x6f,0x09,0x00 for 640x483x2 Why Height is 483?

      Delete
    5. If i remember correctly , Sensor output 3 extra lines for 640x480 resolution.

      Delete
  23. Could you explain the DBVAL(x) and WBVAL(x) line#3 and #4, Class specific uncompressed vs Frame Descriptor in cyfxuvcdscr.c

    ReplyDelete
    Replies
    1. DBVAL and WBVAL are just two macro to fill constant value into arrays with correct endianness.

      Delete
  24. Please make sure LV means Href and FV means Vsync.

    ReplyDelete
    Replies
    1. Yes LV is href , line sync
      FV is Vsync , frame sync

      Delete
  25. I tried with UART debug port and I got following log..
    Please help to solve this and I didn't get video streaming...

    UsbEventCB: SUSPEND encountered...
    Entering USB SuspÿY‹ j½‘•5Leaving Suspend Mode
    UsbEventCB: Detected HS USB Connection
    UsbEventCB: SUSPEND encountered...
    Entering USB Suspend Mÿ‹VVHøLeaving Suspend Mode
    Application Started
    DMA Reset Event: Frame timer overflow, time period = 400
    Application Stopped
    Application Started

    ReplyDelete
  26. I tired with USB 3.0 I didn't get video stream


    below log for USB 3.0

    UsbEventCB: Detected SS USB Connection
    UsbEventCB: SUSPEND encountered...
    Entering USB Suspend Mÿ‹VVHøLeaving Suspend Mode
    Application Started
    DMA Reset Event: Frame timer overflow, time period = 200
    Application Stopped
    Application Started

    ReplyDelete
    Replies
    1. It looks like FX3 is not getting frame sync signal from camera.
      if you have an oscilloscope, could you please check all vital camera signals.
      Like frame sync , line sync and pixel clock?

      Delete
  27. Please explain this How to calculate frame interval
    0x15, 0x16, 0x05, 0x00, /* Desired frame interval in the unit of 100ns: 30 fps */

    0x2A, 0x2C, 0x0A, 0x00, /* Desired frame interval in the unit of 100ns: 15 fps */

    ReplyDelete