QHYCCD

QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« on: February 23, 2017, 08:56:37 AM »
In order to get the QHYCCD used in any CPU and OS system. QHYCCD is making a low level usb protocol standard. This standard will repackage all the camera control / IO to the same simple protocol.This protocol does not need any SDKs.

Under linux,mac/os, you can use libusb to control the camera. Under android you can use the android.hardware.usb API to control the camera. And in windows. Since the camera system is installed. It depends the camera model:

QHY5II,QHY5III,QHYCOLDMOS: CYUSB DRIVER
QHY8L/8PRO/10/12  QHY9,QHY11,QHY6,QHY5,QHY21/22/23,QHY27/28/29,QHY A series:  WINUSB DRIVER



If the HEX/IMG file match the standard of this white paper. We will mark it as "Compatible with QHYCCD LOW LEVEL (1) USB PROTOCOL"

« Last Edit: February 23, 2017, 10:10:25 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #1 on: February 23, 2017, 09:04:01 AM »
Name

QHYCCD Low Level (1) USB Protocol

Low level 0 means the original USB protocol that we have never open to public before. (Only some of the old camera may release to public many years before)

Low level 1 means the QHYCCD repackaged command sets for a standard, similar and simple interface. In order to use on other system like linux,macos,android etc, we released the HEX file or IMG file of the firmware. This is an addtional command sets and it exist together with the low level (0) USB protocol.

« Last Edit: February 23, 2017, 09:05:43 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #2 on: February 23, 2017, 09:11:25 AM »
Level (1) Protocol Instruction

QHYCCD Low level 1 usb protocol has two basic vend request. 

VendRequest 0xd1
VendRequest 0xd2

0xd1 direction is OUT.  Host computer will send 16bytes data in this vendrequest to the camera
0xd2 direction is IN. Host computer will read 64bytes data of camera current status information in this vendrequest from camera

There is no use for index and value of this two vend request, set them to 0x0000  0x0000



we may add other vendrequest command other than this two in future in order to achieve more complex command
« Last Edit: February 23, 2017, 09:13:43 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #3 on: February 23, 2017, 09:17:08 AM »
3. VendRequest 0XD1 Instruction

0xD1 will transfer 16byte data from computer to camera. In these 16byte data, the first byte (byte0) is the Camera Control Command (CCC).  The following data is called Camera Control Parameter (CCP)


Data Structure is
Byte0                        Camera Control Command(CCC)
Byte1......Byte15        Camera Control Parameter(CCP1...15)


« Last Edit: February 23, 2017, 09:29:39 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #4 on: February 23, 2017, 09:23:08 AM »
CCC=0XA0
Camera initialize. After send this command the camera will enter into a definitized working status.

CCP1       Continuous streaming mode or Single frame mode    0=streaming    1=single
CCP2...3  Camera Binning in X direction (CCP2=MSB, CCP3=LSB)
CCP4...5  Camera Binning in Y direction   (CCP4=MSB, CCP5=LSB)


*1. After entering the streaming mode, some camera will start video streaming immdiately. some camera may need video start command. After entering the single frame mode, all camera need be sent the start capture command to run one frame.

*2.Please refer the camera document for the pixel binning of one camera model.


Sample Code
Code: [Select]
void CCC_A0(unsigned char mode, int binx,int biny){


unsigned char data[16];
data[0]=0xa0;
data[1]=mode;
data[2]=MSB(binx);
data[3]=LSB(binx);
data[4]=MSB(biny);
data[5]=LSB(biny);

QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);



}

« Last Edit: March 13, 2017, 11:36:36 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #5 on: February 23, 2017, 09:25:07 AM »
CCC=0XA1   

set the camera readout speed. Different camera may have different readout speed setting to optimize the noise. Or to match the computer transfer speed.


CCP1  read out speed value. See the camera document for this setting.

Code: [Select]
void CCC_A1(void){
unsigned char data[16];
data[0]=0xa0;
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:37:13 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #6 on: February 23, 2017, 09:29:16 AM »
CCC=0XA2   
select the camera resolution or ROI

CCP1  select resolution mode
CCP2..3  ROI X size  (CCP2=MSB  CCP3=LSB)
CCP4..5  ROI X start position
CCP6..7  ROI Y size   ( CCP6=MSB   CCP7=LSB)
CCP8..9  ROI Y position

*1. Some of the camera does not support any ROI. It only support some specially resolution mode, then use the CCP1 to set these resolution mode. If it been set to zero, it means the following byte of the ROI XSIZE, ROI XSTART,ROI YSIZE, ROI YSTART active.

*2. Some of the camera hardware only support one direction ROI, for example, in Y direction. In this condition the ROI XSIZE and ROI XSTART will be ignored. You can also set them to zero.

Code: [Select]
void CCC_A2(unsigned char mode, int XSTART,int XSIZE, int YSTART,int YSIZE){
unsigned char data[16];
data[0]=0xa2;
data[1]=mode;
data[2]=MSB(XSIZE);
data[3]=LSB(XSIZE);
data[4]=MSB(XSTART);
data[5]=LSB(XSTART);
data[6]=MSB(YSIZE);
data[7]=LSB(YSIZE);
data[8]=MSB(YSTART);
data[9]=LSB(YSTART);
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:37:46 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #7 on: February 23, 2017, 09:31:12 AM »
CCC=0XA3
set exposure time

CCP1..4   32BIT exposure time,unit is micro second   CCP1=MSB  CCP4=LSB


Code: [Select]
void CCC_A3(unsigned int exposureTime)
unsigned char data[16];
data[0]=0xa3;
data[1]=(exposureTime &~0x00FFFFFF)>>24;
data[2]=(exposureTime &~0xFF00FFFF)>>16;
data[3]=(exposureTime &~0xFFFF00FF)>>8;
data[4]=(exposureTime &~0xFFFFFF00);
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:38:17 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #8 on: February 23, 2017, 09:33:43 AM »
CCC=0XA4
set camera gain

CCP1..2      Analog Gain R
CCP3..4      Digital Gain R
CCP5..6      Analog Gain G
CCP7..8      Digitial Gain G
CCP9..10    Analog Gain B
CCP11.12   Digital Gain B

*1.Some camera may have analog gain but no digital gain. Some camera has digital gain but no analog gain. Some camera has both of them
*2.For monochrome camera, the camera will only use the "R" value as actual value. So you can set R,G,B to a same value, or only set the R value.


Code: [Select]
void CCC_A4(int againR,int againG,int againB,int dgainR,int dgainG,int dgainB)
{
unsigned char data[16];
data[0]=0xa4;
data[1]=MSB(againR);
data[2]=LSB(againR);
data[3]=MSB(dgainR);
data[4]=LSB(dgainR);

data[5]=MSB(againG);
data[6]=LSB(againG);
data[7]=MSB(dgainG);
data[8]=LSB(dgainG);

data[9] =MSB(againB);
data[10]=LSB(againB);
data[12]=LSB(dgainB);
data[11]=MSB(dgainB);


QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:38:43 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #9 on: February 23, 2017, 09:39:14 AM »
CCC=0XA5
set USB bandwidth limit value

CCP1  value


Many of the cmos camera working in the cmos continuous video streaming. The CMOS sensor can not pause the output to wait the host. So that if there is no big buffer in the camera side, when host cpu is busy and can not read the data on time. The buffer in camera will be full and then the later coming data can not enter the buffer and it will be lost. In this condition you can increase this value to reduce the usb bandwidth.

This value will be add some null pixel read in each line. So the line period will increase and the average USB data bandwidth will be limited.

Warn: In some camera, it may reduce the performance, for example, it will increase the ampilfer glow that generated during readout period.


Code: [Select]
void CCC_A5(unsigned char traffic){
unsigned char data[16];
data[0]=0xa5;
data[1]=traffic;
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:39:03 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #10 on: February 23, 2017, 09:43:57 AM »
CCC=0XA6
Start or stop the capture

CCP1 0X00: start video streaming in video streaming mode or start one frame capture in single capture mode
          0x11: force stop the exposure and read the sensor (data will still transfer back to computer)
          0x22: enter sleep mode(in sleep mode sensor will not work to save power, but the register value will be keep)
          0x44: wake up the sensor
          0x66: reset CMOS/CCD
          0XFF: stop streaming in video streaming mode or force stop exposure but not return any data in single frame mode.


*1. Not all camera will not send back the data when use CCP1=0XFF.   Please see the camera document for details.



Code: [Select]
void CCC_A6(unsigned char command){
unsigned char data[16];
data[0]=0xa6;
data[1]=command;
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:39:33 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #11 on: February 23, 2017, 09:45:12 AM »
CCC=0XA7
set image bit depth

CCP1=0    8BIT
CCP1=1  16BIT


*1: if the sensor is 10bit/12bit/14bit. When set to 16bit, it is MSB aligned.


Code: [Select]
void CCC_A7(unsigned char value){
unsigned char data[16];
data[0]=0xa7;
data[1]=value;
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:40:00 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #12 on: February 23, 2017, 09:46:23 AM »
CCC=0XA8
set camera offset

CCP1..2  OFFSET1 R
CCP3..4  OFFSET1 G
CCP5..6  OFFSET1 B

CCP7..8      OFFSET2 R
CCP9..10    OFFSET2 G
CCP11..12  OFFSET2 B

Most camera has only one offset (OFFSET1). Some camera may have two offset (like analog offset and digital offset)



Code: [Select]
void CCC_A8(int offset1R,int offset1G,int offset1B){
unsigned char data[16];
data[0]=0xa8;
data[1]=MSB(offset1R);
data[2]=LSB(offset1R);
data[3]=MSB(offset1G);
data[4]=LSB(offset1G);
data[5]=MSB(offset1B);
data[6]=LSB(offset1B);
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:40:24 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #13 on: February 23, 2017, 09:49:54 AM »
CCC=0XA9
on camera DDR buffer or SDRAM buffer control

CCP1  0X00=BYPASS DDR
          0XFF=ENABLE DDR



Code: [Select]
void CCC_A9(unsigned char value){
//ENABLE DDR
unsigned char data[16];
data[0]=0xa9;
data[1]=value;
QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}
« Last Edit: March 13, 2017, 11:40:53 AM by QiuHY »
Qiu Hongyun

QiuHY

  • *****
  • 5000
    • View Profile
    • Email
Re: QHYCCD LOW LEVEL (1) USB PROTOCOL WHITE PAPER
« Reply #14 on: February 23, 2017, 09:51:12 AM »
CCC=0XAA
Send CFW Control Command via 4PIN QHYCFW socket

The 4PIN QHYCFW socket includes an industry standard RS232 communication port (RXD,TXD, +-10V level) and a +12V powersupply for the QHYCFW. You can connect the QHYCFW1 and QHYCFW2 with the 4PIN TO 6PIN cable.

The QHYCFW control is via RS232 communication protocol. Please refer the http://www.qhyccd.com/ManualCFW2S4.1.html  for QHYCFW2 control.

For QHYCFW1 control. The command is still the ASCII '0','1','2'.......'A','B','C','D','E','F' for the 16 positions. But the return value is ASCII '-' to indicate the color wheel arrives the target position.

CCP1                RS232 command length
CPP2..CCP15     RS232 command


For example, Go to the Position 3  ( The command should be '2' because all position is from zero)

CCP1=1
CCP2=32    (32 is the ASCII '2') 


The eight bytes CFW buffer will be clear to all zero and after the color wheel run to target, the first byte will become 32(ASCII '2').

For example, send "VRS" command to the QHYCFW2 to get the version

CCP1=3
CCP2='V'
CCP3='R'
CCP4='S'


The version will be return via the eight byte CFW buffer in 0XD2

Code: [Select]
void CCC_AA(unsigned char length,char *buf){

unsigned char data[16];
data[0]=0xaa;
data[1]=length;
for(int i=0;i<length;i++){
  data[2+i]=buf[i];
}

QHYCCDVendRequestWrite(g_hCam,0xd1,0x00,0x00,16,data);
}




After the command sent to the QHYCFW. QHYCFW will response and send back some information back the the camera. In the 0XD2 command there is 8bytes buffer to store it. You can use 0xD2 command to get to know these information.

Please note each time after you send the command to QHYCFW, The eight bytes buffer will be clear to all zero at first ,then after the command been executed , it will be fill to the data of results.




How to identity if there is QHYCFW connected on the camera:

For QHYCFW2. You can send "MXP" command

CCP1=3
CCP2='M'
CCP3='X'
CCP4='P'

and then check the 8byte CFW buffer from 0XD2 command

if the first byte is not zero, it shows there is CFW connected with the camera.
« Last Edit: March 19, 2017, 07:07:44 AM by QiuHY »
Qiu Hongyun