Exemplo n.º 1
0
void Stonyman::getPixelList( short *img, unsigned char rowlist[], unsigned char collist[], unsigned char numPixels )
{
  short *pimg = img; // pointer to output image array
  int val;
  //russ: unused
  //unsigned char chigh,clow;
  unsigned char i;
  unsigned char row,col,lastRow,lastCol;

  setPointerValue(Stonyman::REG_ROWSEL,rowlist[0]);
  setPointerValue(Stonyman::REG_COLSEL,0);

  lastRow = rowlist[0];
  lastCol = 0;

  // Loop through all rows
  for (i=0; i<numPixels; ++i)
  {
    // If row has changed, update row and col registers
    if (rowlist[i] != lastRow) {
	setPointer(Stonyman::REG_ROWSEL);
	incValue(rowlist[i] - lastRow);
	lastRow = rowlist[i];
        setPointerValue(Stonyman::REG_COLSEL,collist[i]);
    } else {  // If not, just update col register
	setPointer(Stonyman::REG_COLSEL);
	incValue(collist[i] - lastCol);
	lastCol = collist[i];
    }

      // settling delay
      delayMicroseconds(1);

      // pulse amplifier if needed
      if (flagUseAmplifier)
      {
        pulseInphi(2); // TODO russ: necessary value unclear/unknown
      }

      // get data value
      delayMicroseconds(1);

      val = analogRead(pinANALOG1);

      // AHHH: shorten casts!
      *pimg = (short)val; // store pixel
      pimg++; // advance pointer
  }
}
Exemplo n.º 2
0
// russ: dual read!
void Stonyman::getDualImages( short *img1, short *img2, unsigned char rowstart, unsigned char numrows,
                              unsigned char rowskip, unsigned char colstart, unsigned char numcols,
                              unsigned char colskip ) //, char ADCType, char anain )
{
  short *pimg1 = img1; // pointer to output image array
  short *pimg2 = img2; // pointer to output image array
  int val1, val2;
  //russ: unused
  //unsigned char chigh,clow;
  unsigned char row,col;

  // Go to first row
  setPointerValue(Stonyman::REG_ROWSEL,rowstart);

  // Loop through all rows
  for (row=0; row<numrows; ++row)
  {
    // Go to first column
    setPointerValue(Stonyman::REG_COLSEL,colstart);

    // Loop through all columns
    for (col=0; col<numcols; ++col)
    {
      // settling delay
      delayMicroseconds(1);

      // pulse amplifier if needed
      if (flagUseAmplifier)
      {
        pulseInphi(2); // TODO russ: necessary value unclear/unknown
      }

      // get data value
      delayMicroseconds(1);

      val1 = analogRead(pinANALOG1);
      val2 = analogRead(pinANALOG2);

      // AHHH: shorten casts!
      *pimg1 = (short)val1; // store pixel
      *pimg2 = (short)val2; // store pixel
      pimg1++; // advance pointer
      pimg2++; // advance pointer
      incValue(colskip); // go to next column
    }
    setPointer(Stonyman::REG_ROWSEL);
    incValue(rowskip); // go to next row
  }
}
Exemplo n.º 3
0
// chipToMatlab
// This function dumps the entire contents of a Stonyman or
// Hawksbill chip to the Serial monitor in a form that may be copied
// into Matlab. The image is written be stored in matrix Img.
void Stonyman::chipToMatlab()
{
  unsigned char row,col,rows,cols;
  unsigned short val;
  // russ: unused
  //unsigned char chigh,clow;

  rows=cols=112;

  Serial.println("Img = [");
  setPointerValue(Stonyman::REG_ROWSEL,0); // set row = 0
  for (row=0; row<rows; ++row)
  {
    setPointerValue(Stonyman::REG_COLSEL,0); // set column = 0
    for (col=0; col<cols; ++col)
    {
      // settling delay
      delayMicroseconds(1);
      // pulse amplifier if needed
      if (flagUseAmplifier)
      {
        pulseInphi(2);
      }

      // get data value
      delayMicroseconds(1);

      val = analogRead(pinANALOG1);

      // increment column
      incValue(1);
      Serial.print(val);
      Serial.print(" ");
    }
    setPointer(Stonyman::REG_ROWSEL); // point to row
    incValue(1); // increment row
    Serial.println(" ");
  }
  Serial.println("];");
}
Exemplo n.º 4
0
void ArduEyeSMHClass::chipToMatlab(char whichchip,char ADCType, char anain) 
{
  unsigned char row,col,rows,cols;
  unsigned short val;
  unsigned char chigh,clow;

  
  if(ADCType==SMH1_ADCTYPE_ONBOARD)	//if onboard ADC
     setAnalogInput(anain);		//set analog input
  else
  {
    setADCInput(anain,1); // enable chip
    ADC_SS_PORT |= ADC_SS; // make sure SS is high
  }


  if (whichchip==1) {
	  rows=cols=136;	//hawksbill
  }	else {
	  rows=cols=112;	//stonyman
  }	
  
  Serial.println("Img = [");
  setPointerValue(SMH_SYS_ROWSEL,0); // set row = 0
  for (row=0; row<rows; ++row) {
    setPointerValue(SMH_SYS_COLSEL,0); // set column = 0
    for (col=0; col<cols; ++col) {
      // settling delay
      delayMicroseconds(1);
      // pulse amplifier if needed
	    if (useAmp) 
            pulseInphi(2);
      
      // get data value
      delayMicroseconds(1);
      
      // get pixel from ADC
      switch (ADCType) {
        case SMH1_ADCTYPE_ONBOARD:
           val = analogRead(anain); // acquire pixel
	    break;
        case SMH1_ADCTYPE_MCP3001: // Micrchip 10 bit
           ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<5;
           val += (clow&0xF8)>>3;
           ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        case SMH1_ADCTYPE_MCP3201: // Microchip 12 bit
	     ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<7;
           val += (clow&0xFE)>>1;
	     ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        default:
           val = 555;
          break;
      }

      // increment column
      incValue(1);
      Serial.print(val);
      Serial.print(" ");
    }
    setPointer(SMH_SYS_ROWSEL); // point to row
    incValue(1); // increment row
    Serial.println(" ");
  }
  Serial.println("];");
  if(ADCType!=SMH1_ADCTYPE_ONBOARD)
    setADCInput(anain,0); // disable chip

}
Exemplo n.º 5
0
void ArduEyeSMHClass::findMax(unsigned char rowstart, unsigned char numrows, unsigned char rowskip, unsigned char colstart, unsigned char numcols,unsigned char colskip, char ADCType,char anain,unsigned char *max_row, unsigned char *max_col)
{
  unsigned short maxval=5000,minval=0,val;
  unsigned char row,col,bestrow,bestcol;
  unsigned char chigh,clow;

  
  if(ADCType==SMH1_ADCTYPE_ONBOARD)	//if using onboard ADC
     setAnalogInput(anain);	//set Arduino analog input
  else
  {
    setADCInput(anain,1); // enable chip
    ADC_SS_PORT |= ADC_SS; // make sure SS is high
  }

  // Go to first row
  setPointerValue(SMH_SYS_ROWSEL,rowstart);

  // Loop through all rows
  for (row=0; row<numrows; ++row) {

    // Go to first column
    setPointerValue(SMH_SYS_COLSEL,colstart);

    // Loop through all columns
    for (col=0; col<numcols; ++col) {

      // settling delay
      delayMicroseconds(1);

      // pulse amplifier if needed
	if (useAmp) 
        pulseInphi(2);
      
      // get data value
      delayMicroseconds(1);
      
      // get pixel from ADC
      switch (ADCType) {
        case SMH1_ADCTYPE_ONBOARD:	//onboard Arduino ADC
           val = analogRead(anain); // acquire pixel
	    break;
        case SMH1_ADCTYPE_MCP3001: // Micrchip 10 bit
           ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<5;
           val += (clow&0xF8)>>3;
           ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        case SMH1_ADCTYPE_MCP3201: // Microchip 12 bit
	     ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<7;
           val += (clow&0xFE)>>1;
	     ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        default:
           val = 555;
          break;
      }

	if(useAmp)	//amplifier is inverted
	{
		if (val>minval) 	//find max val (bright)
		{
       	 bestrow=row;
       	 bestcol=col;
      	 minval=val;
      	}
	}
	else		//unamplified
	{
      	if (val<maxval) 	//find min val (bright)
		{
        	 bestrow=row;
        	 bestcol=col;
        	 maxval=val;
      	}
	}

      incValue(colskip); // go to next column
    }
    setPointer(SMH_SYS_ROWSEL);
    incValue(rowskip); // go to next row
  }

  if(ADCType!=SMH1_ADCTYPE_ONBOARD)
   setADCInput(anain,0); // disable chip

  // Optionally we can comment out these next three items
  //Serial.print("bestrow = "); Serial.println((short)bestrow);
  //Serial.print("bestcol = "); Serial.println((short)bestcol);
  //Serial.print("maxval = "); Serial.println((short)maxval);

  *max_row = bestrow;
  *max_col = bestcol;
}
Exemplo n.º 6
0
void ArduEyeSMHClass::getImageColSum(short *img, unsigned char rowstart, unsigned char numrows, unsigned char rowskip, unsigned char colstart, unsigned char numcols, unsigned char colskip, char ADCType,char anain) 
{
  short *pimg = img; // pointer to output image array
  short val,total=0;
  unsigned char chigh,clow;
  unsigned char row,col;
  
  if(ADCType==SMH1_ADCTYPE_ONBOARD)	//if using onboard ADC
     setAnalogInput(anain);		//set analog input to Arduino
  else if(ADCType==SMH1_ADCTYPE_MCP3201_2)
  { 
     setAnalogInput(anain);
     ADC_SS_PORT |= ADC_SS; // make sure SS is high
  }
  else	//if using external ADC
  {
    setADCInput(anain,1); // enable chip
    ADC_SS_PORT |= ADC_SS; // make sure SS is high
  }

  // Go to first col
  setPointerValue(SMH_SYS_COLSEL,colstart);
 
  // Loop through all cols
  for (col=0; col<numcols; ++col) {
    
    // Go to first row
    setPointerValue(SMH_SYS_ROWSEL,rowstart);
  
    total=0;
    
    // Loop through all rows
    for (row=0; row<numrows; ++row) {
      
      // settling delay
      delayMicroseconds(1);

      // pulse amplifier if needed
	if (useAmp) 
        pulseInphi(2);
      
      // get data value
      delayMicroseconds(1);
      
      // get pixel value from ADC
      switch (ADCType) 
      {
        case SMH1_ADCTYPE_ONBOARD:	//onboard Arduino ADC
           val = analogRead(anain); // acquire pixel
	    break;
        case SMH1_ADCTYPE_MCP3001:  // Micrchip 10 bit
           ADC_SS_PORT &= ~ADC_SS;  // turn SS low to start conversion
           chigh=SPI.transfer(0);   // get high byte
           clow=SPI.transfer(0);    // get low byte
           val = ((short)(chigh&0x1F))<<5;
           val += (clow&0xF8)>>3;
           ADC_SS_PORT |= ADC_SS;   // SS high to stop
          break;
        case SMH1_ADCTYPE_MCP3201:  // Microchip 12 bit
        case SMH1_ADCTYPE_MCP3201_2:
	     ADC_SS_PORT &= ~ADC_SS;  // turn SS low to start conversion
           chigh=SPI.transfer(0);   // get high byte
           clow=SPI.transfer(0);    // get low byte
           val = ((short)(chigh&0x1F))<<7;
           val += (clow&0xFE)>>1;
	     ADC_SS_PORT |= ADC_SS;   // SS high to stop
          break;
        default:
           val = 555;
          break;
      }
      
      total+=val;	//sum value along column
      incValue(rowskip); // go to next row
    }
	
    *pimg = total>>4; // store pixel
    pimg++; // advance pointer

    setPointer(SMH_SYS_COLSEL);
    incValue(colskip); // go to next col
  }

  if((ADCType!=SMH1_ADCTYPE_ONBOARD)&&(ADCType!=SMH1_ADCTYPE_MCP3201_2))
   setADCInput(anain,0); // disable chip

}
Exemplo n.º 7
0
void ArduEyeSMHClass::sectionToMatlab(unsigned char rowstart, unsigned char numrows, unsigned char rowskip, unsigned char colstart, unsigned char numcols, unsigned char colskip, char ADCType, unsigned char anain) 
{
  short val;
  unsigned char row,col;
  unsigned char clow,chigh;

  if(ADCType==SMH1_ADCTYPE_ONBOARD)	//if onboard ADC
     setAnalogInput(anain);
  else
  {
    setADCInput(anain,1); // enable chip
    ADC_SS_PORT |= ADC_SS; // make sure SS is high
  }

  Serial.println("Img = [");
  setPointerValue(SMH_SYS_ROWSEL,rowstart);

  for (row=0; row<numrows; row++) {

    setPointerValue(SMH_SYS_COLSEL,colstart);

    for (col=0; col<numcols; col++) {
      // settling delay
      delayMicroseconds(1);

      // pulse amplifier if needed
      if (useAmp) 
        pulseInphi(2);
      
	delayMicroseconds(1);

      // get pixel from ADC
      switch (ADCType) {
        case SMH1_ADCTYPE_ONBOARD:
           val = analogRead(anain); // acquire pixel
	    break;
        case SMH1_ADCTYPE_MCP3001: // Micrchip 10 bit
           ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<5;
           val += (clow&0xF8)>>3;
           ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        case SMH1_ADCTYPE_MCP3201: // Microchip 12 bit
	     ADC_SS_PORT &= ~ADC_SS; // turn SS low to start conversion
           chigh=SPI.transfer(0); // get high byte
           clow=SPI.transfer(0); // get low byte
           val = ((short)(chigh&0x1F))<<7;
           val += (clow&0xFE)>>1;
	     ADC_SS_PORT |= ADC_SS; // SS high to stop
          break;
        default:
           val = 555;
          break;
      }

      incValue(colskip);
      Serial.print(val);
      Serial.print(" ");
    }
    setPointer(SMH_SYS_ROWSEL);
    incValue(rowskip); // go to next row
    Serial.println(" ");
  }
  Serial.println("];");

  if(ADCType!=SMH1_ADCTYPE_ONBOARD)
    setADCInput(anain,0); // disable chip

}