• AVR Freaks

Host interface to USB UVC compliant cameras using a PIC32 processor

Page: < 12 Showing page 2 of 2
Author
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/03/29 21:01:56 (permalink)
0

is the PIC32 capable of the task?

I recommend you to run it on other MCU with an external bus for RAM space extension.

If the PIC32 would be used just as a front end for USB webcam, ie. the PIC32 passes through video image data to other MCU / FPGA or a storage, it could work as you expected. However, the process of the video image, like you said, requires fair amount of RAM. When an image is fully decoded, 320x240 image occupies around 76.8K bytes, just for single color plane. The on-chip RAM of PIC32, at most 128KB, can't hold even two full images. Therefore, you have to divide the image into stripes, to process it on the on-chip RAM. This limitation significantly reduces the performance of the process.

You may add external RAM(s) at PMP (Parallel Master Port) for the image buffers. The data block is swapped using DMA over PMP between the internal and external. Even with this addition, the external RAM works as a storage, but the working RAM for process doesn't increase.

Tsuneo
#21
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/24 07:29:56 (permalink)
0
Hi all and Tsuneo in particular,
thanks in advance for all you wrote, it's very useful information. I'm working on a system that should record images from an usb camera with jpeg encoder onboard. I'm interested in large amount of data 640x480 at 30fps (compressed one frame should occupy 30-40KB). I want to record it in memory, sd class 10 via spi, I ask to the micro not only to record but also to trigger the event record with an adc channel, in particular when the voltage in an adc channel is above a certain threshold it should record for 20 seconds if not it goes in stand by. So I don't ask much to the mcu. I'm working at higher level so for now i'm interested in understanding the limits and how choose the correct components of the system in particular the mcu. One last question is about the driver of the usb camera, I saw in this thread that with long work is possible to solve the problems of an UVC compliant peripheral , making it work also by C programming, or you think it could be a better option to make run on the pic32 a RTOS (real time operating system) how I'm doing with an Atmel ARM9, but is quite more fast than the pic so I don't know if could work on the pic...
What you think of using in this system an mcu like pic24 or pic32 or is better an ARM9 (but is quite more expensive)?
thanks again to everyone
All the best
Bruno
post edited by icemanb - 2011/05/24 07:50:48
#22
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/24 09:52:58 (permalink)
0

I'm interested in large amount of data 640x480 at 30fps (compressed one frame should occupy 30-40KB).

I believe any camera doesn't put 30fps over full-speed bus. 10-20fps. High-speed host is required for 30fps. To confirm it, insert a full-speed (USB1.1) hub between the camera and PC, and measure possible fps on a PC.

Tsuneo
#23
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/25 01:00:25 (permalink)
0
Thanks Tsuneo for the answer,
I have a cmos sensor of the Pixart Corporation PAC7332 it has an USB 1.1 interface and he's throughput is 30 fps. I believe that thanks to the compressor onboard it can output the 30 fps... what you think about I wrote of the system?
Thanks
#24
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/25 03:44:29 (permalink)
0
Surely, the datasheet tells that "the JPEG compressed image data is transmitted by USB 1.1 isochronous pipe."
And "Frame Rate: Up to 30fps"

PAC7332 VGA PC Camera Single-Chip with Audio
http://www.pixart.com.tw/...V10_20100319092601.pdf

I have doubt that the camera would saturate full bandwidth of full-speed bus.
Can you post the descriptors of this camera?
Descriptors are read out using UVCView.exe

For your convenience, I attached UVCView.exe to this post.
The original UVCView is downloaded from MS as a part of WDK

Windows Driver Kit Version 7.1.0
http://www.microsoft.com/...43b5-b996-7633f2ec14ff

Tsuneo
#25
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/25 06:02:42 (permalink)
0
Thanks Tsuneo, I already have UVCView but you did a good thing posting it again cause it was hard to find... however I attached the descriptor.
If I can back to the main question regarding the system, also going down to 15-20fps you  think that the pic24 family or pic32 are capable to do that task: when one channel of the adc is above a fixed voltage threshold, through the DMA save the frames for 20 seconds in the memory via the spi? And if yes you think that (with hard work in C) it's possible to use the generic drivers of the UVC to make work with the usb camera or it would be better to make run a RTOS in the micro (but I don't know if the pic24-32 would succeed)?
Thanks a lot for the experience that you are posting to all readers, first of all me
#26
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/27 14:28:42 (permalink)
0
***I post it again cause I'm worried about the domain problem that microchip.com had***
                                                                  *-*
Thanks Tsuneo, I already have UVCView but you did a good thing posting it again cause it was hard to find... however I attached the descriptor.
If I can back to the main question regarding the system, also going down to 15-20fps you  think that the pic24 family or pic32 are capable to do that task: when one channel of the adc is above a fixed voltage threshold, through the DMA save the frames for 20 seconds in the memory via the spi? And if yes you think that (with hard work in C) it's possible to use the generic drivers of the UVC to make work with the usb camera or it would be better to make run a RTOS in the micro (but I don't know if the pic24-32 would succeed)?
Thanks a lot for the experience that you are posting to all readers, first of all me
#27
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/05/28 04:52:14 (permalink)
0

Thanks for the descriptors.
This camera has a vendor specific class instead of UVC (USB Video Class). I suppose this interface is a simplified UVC. A dedicated PC class driver runs it like a UVC. You'll take a USB traffic log on PC to know the sequence that the PC driver runs this camera. On an embedded host, you'll reproduce the sequence.

The interface has a couple of alternate interfaces, which have various EP max sizes. Among these alternates, the greatest one is 0x3FF (1023) bytes - full size of full-speed (FS) isoc. It saturates FS bandwidth. When this alternate is chosen, the audio interface is suppressed.

I believe PIC24 / 32 can run this camera. Also, these MCUs can save the data to a SD card. But I'm not sure if the speed performance is enough or not.

The speed class of SDHC card is guaranteed on SD bus access, but not on SPI. SPI access is slower than SD bus. PIC MCUs don't mount MCI (Multimedia Card Interface), just SPI. Here is the bottleneck.

Tsuneo
#28
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/06/30 03:00:28 (permalink)
0
Hi all and Tsuneo in particular,
I'm back... sorry but your experience is so precious for all us! I have only one more question. (Just to let you know I'm currently working with an Atmel with embedded Debian, Linux, so my question is beacause I don't have the pic but I should know in theory, just in theory, how will be the operation in a pic). In particular, and I come to the question, last time you told me that once I know the sequence
"On an embedded host, you'll reproduce the sequence. "
just in theory and also if you want a quick explanation of what this reproduce the sequence means. I should insert the register values that I read in the descriptor in Mplab? Sorry for my question but as I told I'm programming in C++ in Linux enviroment so I don't touch or see register i just write a code where i call the libraries...
thank you so much for explanations
All the best
Bruno
post edited by icemanb - 2011/06/30 03:05:37
#29
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/07/01 11:09:54 (permalink)
0

Both on PixArt web page and on PAC7332 datasheet, this camera is described as UVC (USB Video Class) compliant.

http://www.pixart.com.tw/product_data.asp?ToPage=1&productclassify_id=3&productclassify2_id=11

PAC7332
General Description
The PAC7332 is a single chip with an embedded VGA CMOS image sensor and USB 1.1 interface. It has JPEG image compression and image processing. .. It is fully compliant with USB Video Class 1.0 and USB Audio Class 1.0 standard.


However, the descriptor you've posted shows a composite device of a Vendor specific class and Audio class.

Is your camera an old revision? And current revision has moved to UVC?
OR
The web page is wrong?

I recommend you to make it sure by asking to PixArt.


If the current revision were UVC, you would get new camera for development.
Linux has native driver for UVC.

Tsuneo
#30
icemanb
New Member
  • Total Posts : 6
  • Reward points : 0
  • Joined: 2011/05/24 05:40:51
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/07/02 02:01:40 (permalink)
0
Ok Tsuneo thanks for the answer, but this is not a problem, the camera that I have is an old model but is currently working with linux so the question was not that. My question was about how programming the pic32 because I don't have it. The pic32 does not have linux native embedded and I don't wan't to install it, the question is how should be the programming...
when you told
"On an embedded host, you'll reproduce the sequence. "
what this means? In Mplab I write a program in C or C++ where I put the relative registers? Why are you talking about Linux if there is not on pic32?
A try to explain me in a better way, if I had an evaluation board of pic32 and an UVC compliant camera, what should be the steps to make the pic32 talk with the camera and save frames? Just in theory, I know that is quite complicated, but just to know the steps and the programs that I should use,
thanks
Bruno
post edited by icemanb - 2011/07/02 02:03:42
#31
RISC
Super Member
  • Total Posts : 5376
  • Reward points : 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2011/07/03 05:45:38 (permalink)
0
Hi,

BTW, the latest version of USB stack is 2.9.
You can download it here : http://www.microchip.com/MAL

regards
#32
nimarc
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2008/06/21 10:51:49
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/29 04:41:28 (permalink)
0
Hi Tsuneo,
     I been trying to work on same UVC class with PIC32 right now. I done lot of things and now I am gating Event also. I am not sure how I can process this Buffer further because all the time Data length I am gating is 0 and contain of data is always 0x00. I am not sure why this data length is 0 Please help me regarding this



regards


Nimish
#33
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/29 07:55:34 (permalink)
0

I done lot of things and now I am gating Event also. I am not sure how I can process this Buffer further because all the time Data length I am gating is 0 and contain of data is always 0x00.

Err..
Which one are you talking about?
a) Video payload packets over Video Streaming Isoc IN EP
or
b) The interrupt packet over Status Interrupt IN EP

Tsuneo
#34
nimarc
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2008/06/21 10:51:49
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/29 21:28:15 (permalink)
0
hi Tsuneo,
         I have done wollowing things


if(USBHostIsochronousBuffersCreate(cam_buf,USB_MAX_ISOCHRONOUS_DATA_BUFFERS,0x0200) == TRUE)
{
UART2PrintString("isochronous buffer created\n\r");
}
else
UART2PrintString("isochronous buffer failed\n\r");
this will be in USBHostGenericInit

then in main loop I called 
    

RetVal = USBHostReadIsochronous(1,0x82,cam_buf);

now after this function I am receiveing USB event
USBHostGenericEventHandler 
in usb event I done same thing as you told in your previous post but 
sprintf(dbg_buf, "Event End Point : 0x%02x dataCount = %d\n\r",
  ((HOST_TRANSFER_DATA *)data)->bEndpointAddress,dataCount);
UART2PrintString(dbg_buf);

but all the time this dataCount is zero as well as I tried buffer also this buffer also contain zero.

Please help me for understating is there any more USB web cam initialization I am missing.

If you can post your code that will be really helpful for me to understand more about UVC class


Regards

Nimish




#35
nimarc
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2008/06/21 10:51:49
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/30 03:17:47 (permalink)
0
Hi Tsuneo and all,
     Now good news is now I am gating data in event. :) 



Can you help me how i have to process this data, so that I can save the Image in BMP format, means I need to understand more about this Web cam Image frame.


Thanks in advance 


regards


Nimish
#36
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/30 04:18:53 (permalink)
0

To keep isoc streaming, v2012-02-15 version still requires a minor fix, discussed on this post.
http://www.microchip.com/forums/fb.ashx?m=520716

but all the time this dataCount is zero as well as I tried buffer also this buffer also contain zero.

Maybe, the isoc transactions start too early.

Here is a bus trace of Logitech C200 connected to a PC, at start of video streaming over Full-Speed bus.
Probe and Commit requests (not shown on this trace) before starting the video streaming. And then, Set_Interface request enables the video streaming interface.
Around 200 ms after Set_Interface, the PC host starts isoc transactions.
But still at this point, the camera returns just payload header packets without video data.
The camera puts real video frame around 800 ms later after Set_Interface.


[50.539,591] FS: Set Interface (0x06) 01 0B 06 00 01 00 00 00 


------ empty video payloads ------
[50.727,848] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8C 7B 6C 64 83 BD D3 70 83 66 02 
[50.728,848] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8C 7B 6C 64 83 3B 8F 71 83 67 02 
...
...
[51.309,970] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8C 5B 8A 03 85 E9 10 1B 85 AC 04 
[51.310,971] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8C 5B 8A 03 85 68 CC 1B 85 AD 04 

------ 1st video frame ------
[51.311,971] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8C DB F1 1B 85 DE 87 1C 85 AE 04 
[51.312,971] FS: Iosc (IN) Addr:05 Endp:1: 336 bytes
             0C 8C DB F1 1B 85 5E 43 1D 85 AF 04 FF D8 FF E0 
             00 21 41 56 49 31 00 01 01 01 00 78 00 78 00 00
             ...
[51.313,971] FS: Iosc (IN) Addr:05 Endp:1: 240 bytes
             0C 8C DB F1 1B 85 D9 FE 1D 85 B0 04 0A 28 00 A2 
             80 0A 4A 00 5A 28 00 A7 0A 00 91 6A 54 34 80 95 
             ...
...
...
[51.342,977] FS: Iosc (IN) Addr:05 Endp:1: 152 bytes
             0C 8C DB F1 1B 85 F8 3B 33 85 CD 04 90 8A F4 53 
             18 51 40 05 14 00 51 40 05 14 00 51 40 05 14 00 
             ...
[51.343,978] FS: Iosc (IN) Addr:05 Endp:1: 314 bytes
             0C 8E DB F1 1B 85 71 F7 33 85 CE 04 68 43 68 A0 
             61 4B 40 09 45 00 14 50 01 45 00 14 50 01 45 00 
             ...

------ 2nd video frame ------
[51.344,978] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8D 5B 59 34 85 F1 B2 34 85 CF 04 
[51.345,978] FS: Iosc (IN) Addr:05 Endp:1: 12 bytes
             0C 8D 5B 59 34 85 6D 6E 35 85 D0 04 
[51.346,978] FS: Iosc (IN) Addr:05 Endp:1: 588 bytes
             0C 8D 5B 59 34 85 EB 29 36 85 D1 04 FF D8 FF E0 
             00 21 41 56 49 31 00 01 01 01 00 78 00 78 00 00 
             ...
[51.347,979] FS: Iosc (IN) Addr:05 Endp:1: 136 bytes
             0C 8D 5B 59 34 85 66 E5 36 85 D2 04 50 02 D1 4C 
             41 49 48 02 8A 00 28 A0 05 A5 14 01 22 1A B3 19 
             ...


Tsuneo
#37
nimarc
Starting Member
  • Total Posts : 35
  • Reward points : 0
  • Joined: 2008/06/21 10:51:49
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/30 05:03:25 (permalink)
0
Hi Tsuneo,
               Thanks for replay. actually I am gatting data in event and end point is also correct..

But I am not sure how I can process this buffer. Can you help me to process this buffer so that I can put this buffer data in BMP file and send to computer for displaying

Nimish
#38
chinzei
Super Member
  • Total Posts : 2250
  • Reward points : 0
  • Joined: 2003/11/07 12:39:02
  • Location: Tokyo, Japan
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2012/03/30 08:45:01 (permalink)
0

Can you help me to process this buffer so that I can put this buffer data in BMP file and send to computer for displaying

Each isoc packet starts with 12 bytes payload header.
The format of payload header is described on this chapter of UVC spec on the USB.org
2.4.3.3 Video and Still Image Payload Headers (USB_Video_Class_1.1.pdf p31)
http://www.usb.org/develo...o_Class_1_1_090711.zip

Your firmware drops this payload header, and it takes the payload data. Some packets contain just a payload header, without any data, as shown in above trace.
Further process of video images depends on the compression method applied by the camera. But I recommend you to do this process on the PC side, because PIC doesn't have enough RAM  for this process.

Tsuneo

post edited by chinzei - 2012/03/30 08:48:49
#39
pablocael
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2013/07/03 18:37:53
  • Location: 0
  • Status: offline
Re:Host interface to USB UVC compliant cameras using a PIC32 processor 2013/07/04 10:27:48 (permalink)
0
Man, USB interfacing can be a hell.. Can any one tell me if it is possible to implement the same thing in PIC24FJ256DA206? 
 
What about frame rate.. what is the calculation? How does usb read spead relates to pic clock (e.g with external 16Mhz oscillator will I be able to read fast, wont I)...
 
And what a bout frame reading time.. If I have and usb frame of w * h pixels, each pixel with 3 bytes, how can I predict how many frame will I read based on the clock.. is it a simple division or there is much more about the overhead of usb protocol and stuff...
 
Thanks
#40
Page: < 12 Showing page 2 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5