QHYCCD

PoleMaster Low Level USB Protocol and HEX

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
PoleMaster Low Level USB Protocol and HEX
« on: February 15, 2017, 12:09:01 PM »
1.0.Vend Request Command
This section shows the value of PoleMaster Vender Read and Write and you can use it in libusb_control_transfer().
Following is libusb_control_transfer() description. For more detail, please visit http://libusb.org/.

int libusb_control_transfer(
                             libusb_device_handle *    dev_handle,
                             uint8_t    bmRequestType,
                             uint8_t    bRequest,
                             uint16_t    wValue,
                             uint16_t    wIndex,   
                             unsigned char *    data,
                             uint16_t    wLength,
                             unsigned int    timeout
                            )

Details:

a. dev_handle
In libusb document, you can find a explaination.
"a handle for the device to communicate with"
The link is http://libusb.org/static/api-1.0/group__syncio.html#gadb11f7a761bd12fc77a07f4568d56f38

b.bmRequestType and bRequest(Vender Request)
Indicate write if bmRequestType is 0x40 and bRequest is 0xD1
Indicate read  if bmRequestType is 0xC0 and bRequest is 0xD2

c.wValue and wIndex
not used,you can set any value if you want

d.data



VendRequest 0xD1 is to write the command into the CMOS camera
The data contains the data and command you want to send to the camera. The data structure is :
byte0 byte1 ..........byte15

byte0 is the command TYPE


Command Type
0xA0   CMOS INIT
0xA1   Set Chip Speed
0xA2   Set Resolution
0xA3   Set Exposure
0xA4   Set Gain
0xA5   Set USBTraffic
0xA6   Start Capture


VendRequest 0XD2 is to read some byte back from camera.

The data structure is :
byte0 byte1....byte4byte5~byte8byte9~byte12byte13byte14byte15byte16


Byte0  usb speed uint is Mhz
Byte1~4     reserved
Byte5~8     exposure time(Byte5 is MSB, Byte8 is LSB) uint is us.
Byte9~12   reserved
Byte13~15 Gain Byte13 is Dgain, Byte14 is Again1, Byte15 is Again2
Byte16       USB Traffic Value

e. wLength
set to 16 when write.
set to 32 when read.

f.timeout
In libusb document, you can find a explaination.
"timeout (in millseconds) that this function should wait before giving up due to no response being received. For an unlimited timeout, use value 0."
The link is http://libusb.org/static/api-1.0/group__syncio.html#gadb11f7a761bd12fc77a07f4568d56f38

« Last Edit: February 16, 2017, 09:54:50 PM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: PoleMaster Low Level USB Protocol and HEX
« Reply #1 on: February 15, 2017, 12:17:11 PM »
The details of the camera control Command


1.1.CMOS Initialization
You can make a cmos initialization use following data formate.
byte0 0xa0
byte1~byte15 not used

C++ example:
#define QHYCCD_bmREQUEST_WRITE 0x40
...
uint8_t buf[64] = {0};
buf[0] = 0xA0;//command type
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE,
 0xD1, 0x0000, 0x0000, buf, 16, 1000);

...


Explaination:
For more details, please refer to 1.0.
libusb_control_transfer(
      camHandle,//dev_handle: a handle we opened.
      QHYCCD_bmREQUEST_WRITE,//bmRequestType: we want send a write command,
                             //so set to 0x40
      0xD1,                  //bRequest: we want send a write command,
                             //so set to 0xD1
      0x0000,                //wValue: not used
      0x0000,                //wIndex: not used
      buf,                                 //buffer to be send.
                             //note: we want initialize the cmos,
                             //so the byte0 is 0xA0         
      16,                    //buf length is 16
      1000                             //timeout value
);



1.2.Chip Speed Setting
You can set Chip speed to 12Mhz,24Mhz or 48Mhz,To set the USB speed,
please use Vender Write.Following is the buf format.
byte0  0XA1
byte1  value of cmos speed setting
byte2~byte15


value
0=12Mhz
1=24Mhz
2=48Mhz

(for 48MHz and small USB traffic setting the camera can get 30fps maxium frame rate if there is no frame lost happen,for 24MHz it is 15fps and for 12MHz it is 7.5fps)

C++ example:
//this will set chip speed to 12Mhz
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
buf[0] = 0xA1;//command type
buf[1] = 0;//set chip speed to 12Mhz
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...



1.3.Resolution Setting(1280*960)
byte0 0xA2
byte1~byte15   not used


C++ example:
//this set resolution to 1280*960
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
buf[0] = 0xA2;//command type
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...


1.4.Exposure Setting
We use four Bytes uinsigned int type store the Exposure time whitch is precision in the microsecond range.
You can set exposure time use byte1 to byte4 and the byte1 is MSB,byte4 is LSB.

byte0 0xA3
byte1 exposure time MSB
byte2 exposure time...
byte3 exposure time...
byte4 exposure time LSB

byte5~byte15 not used

C++ example:
//this set exposure time to 50ms
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
uint32_t ExpTime = 50000;//50000us = 50ms
buf[0] = 0xa3; //command type
buf[1] = (uint8_t)((ExpTime & ~0x00ffffff) >> 24);
buf[2] = (uint8_t)((ExpTime & ~0xff00ffff) >> 16);
buf[3] = (uint8_t)((ExpTime & ~0xffff00ff) >> 8);
buf[4] = (uint8_t)(ExpTime & ~0xffffff00);
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...



1.5.Gain Setting
byte0 0xA4
byte1 Dgain
byte2 Again1
byte3 Again2
byte4~byte15 not used

a.Digital Gain(Dgain)
The format dgain is xxx.yyyyy. the decimal vale is

So the Digital Gain minimum value is 0.00000, the maximum is 7.90000.

b. Analog Gain
The Analog Gain = Again1*Again2. So the maximum possible analog gain to be set to 10x,the minimum is 1X.

Stage 1(Again1)
valueMeaning
0=1X
1=2X
2=4X
3=8X

Stage 2(Again2)
10 1X
11 1.25X

C++ example:
//This set the Digital gain to 4.5X and analog gain to 10x
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
buf[0] = 0xA4;//command type//Dgain
buf[1] = 0x90;//(100.10000),set digital to 4.5X

//set analog gain to 10X
//again1*again2 = 8*1.25 = 10
//Again1
buf[2] = 0x11;//set analog gain 1 to 8X
//Again2
buf[3] = 0x11;//set analog gain 2 to 1.25X
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...

1.6.USB Traffic Setting
We can use this set the usb traffic from 0 to 100.
byte0 0XA5
byte1 value of USB traffic setting
byte2~byte15 not used

C++ example:
//This set the usb traffic to 100.
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
buf[0] = 0xa5;//command typebuf[1] = 100;//usb traffic to 100
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...


1.7.Start Capture
After perform this, the CMOS chip will continuously output the image data
byte0 0xA6
byte1~byte15  not used

C++ example:
//Start capture
...
#define QHYCCD_bmREQUEST_WRITE 0x40
...
//Start capturebuf[0] = 0xA6;//command type
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_WRITE, 0xD1, 0x0000, 0x0000, buf, 16, 1000);
...

« Last Edit: February 16, 2017, 08:38:39 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: PoleMaster Low Level USB Protocol and HEX
« Reply #2 on: February 15, 2017, 12:19:27 PM »
1.8.Read CMOS Status
You can access CMOS Status had been set by using vender read command. Forrowing is the buf format:
ByteMeaning0usb speed uint is Mhz1~4reserved5~8exposure time(Byte5 is MSB, Byte8 is LSB) uint is us.9~12reserved13~15Byte13 is Dgain, Byte14 is Again1, Byte15 is Again216USB Traffic Value

C++ example:
//read camera status
...
#define QHYCCD_bmREQUEST_READ  0x40
...
//read camera status
libusb_control_transfer(camHandle, QHYCCD_bmREQUEST_READ , 0xD2, 0x0000, 0x0000, buf, 32, 1000);
uint32_t exptime = 0;
exptime = (uint32_t)buf[5] << 24 | (uint32_t)buf[6] << 16 | (uint32_t)buf[7] << 8 | (uint32_t)buf[8];
cout << "get exptime:"    << exptime    << "us" << endl;
cout << "get usb speed: " << (uint32_t)buf[0]  << endl;
cout << "get Dgain: "     << (uint32_t)buf[13] << endl;
cout << "get Again1: "    << (uint32_t)buf[14] << endl;
cout << "get Again2: "    << (uint32_t)buf[15] << endl;
cout << "get traffic: "   << (uint32_t)buf[16] << endl;
...




Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: PoleMaster Low Level USB Protocol and HEX
« Reply #3 on: February 15, 2017, 12:19:48 PM »
2.Get Raw Data
To get Raw Data,you can use usb bulk in endpoint 0x82.The header length is five bytes,
first four is the check bytes(AA11CCEE) and the last one is the pad.
......A FrameHEADER(AA11CCEEXX)A Frame(1280*960 bytes)HEADER(AA11CCEEXX)A Frame......

Note: You must get the image data from usb as soon as possible.
  If not, the newer image data maybe cover the older image data. Because the fx2(usb chip) just only has a 4k small buffer and the cmos chip continuously output the image data to the buffer after start capture. so if not take the data form the buffer in time. The buffer will be filled up and the newer data will cover the older data. This will cause the older data is missing.
 

Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: PoleMaster Low Level USB Protocol and HEX
« Reply #4 on: February 15, 2017, 12:20:01 PM »
3.C++ Example To Using Libusb Access PoloMaster
« Last Edit: February 15, 2017, 12:29:11 PM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: PoleMaster Low Level USB Protocol and HEX
« Reply #5 on: February 15, 2017, 12:20:32 PM »
HEX file is here

Warn: This hex should match the instrument in this topic but it is not fully compatible with QHYCCD Low Level (1)  White paper. We will update this HEX soon to match the white paper.
« Last Edit: February 27, 2017, 10:03:24 AM by QiuHY »
Qiu Hongyun

Re: PoleMaster Low Level USB Protocol and HEX
« Reply #6 on: October 13, 2017, 06:27:55 AM »
update the hex file . the one is the newest .