Esempio n. 1
0
static void REF_MeasureRaw(SensorTimeType raw[REF_NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;

  LED_IR_On(); /* IR LED's on */
  WAIT1_Waitus(200); /*! \todo adjust time as needed */

  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(50); /* give some time to charge the capacitor */
  (void)RefCnt_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  do {
    /*! \todo Be aware that this might block for a long time, if discharging takes long. Consider using a timeout. */
    cnt = 0;
    for(i=0;i<REF_NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0  || 0x2000 <= RefCnt_GetCounterValue(timerHandle)) {
          raw[i] = RefCnt_GetCounterValue(timerHandle);
        }

      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=REF_NOF_SENSORS);
  LED_IR_Off();
}
Esempio n. 2
0
/*!
 * \brief Measures the time until the sensor discharges
 * \param raw Array to store the raw values.
 * \return ERR_OVERFLOW if there is a timeout, ERR_OK otherwise
 */
static void REF_MeasureRaw(SensorTimeType raw[REF_NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;
  RefCnt_TValueType timerVal;

  LED_IR_On(); /* IR LED's on */
  WAIT1_Waitus(200);
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(50); /* give at least 10 us to discharge the capacitor */
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  FRTOS1_taskENTER_CRITICAL();
  (void)RefCnt_ResetCounter(timerHandle); /* reset timer counter */
  do {
    cnt = 0;
    timerVal = RefCnt_GetCounterValue(timerHandle);
    for(i=0;i<REF_NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if ((SensorFctArray[i].GetVal()==0)){// || (timerVal > 0x2000)) {
          raw[i] = timerVal;
        }
      }
      else { /* have value */
        cnt++;
      }
    }
    if (timerVal > 0x3000){	//9375) {/*5ms*/
    	for(i=0;i<REF_NOF_SENSORS;i++) {
		  if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
			raw[i] = timerVal;
		  }
		}
    	break;
    }
  } while(cnt!=REF_NOF_SENSORS);
  FRTOS1_taskEXIT_CRITICAL();
  LED_IR_Off(); /* IR LED's off */
}
Esempio n. 3
0
static void REF_MeasureRaw(SensorTimeType raw[REF_NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;
  TMOUT1_CounterHandle timeout;

  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  if (ledON) {
    IR_on(TRUE); /* IR LED's on */
    WAIT1_Waitus(200);
  }
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(50); /* give at least 10 us to charge the capacitor */
  timeout = TMOUT1_GetCounter(REF_SENSOR_TIMEOUT_MS/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
  (void)RefCnt_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  do {
    cnt = 0;
    if (TMOUT1_CounterExpired(timeout)) {
      break; /* get out of while loop */
    }
    for(i=0;i<REF_NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0) {
          raw[i] = RefCnt_GetCounterValue(timerHandle);
        }
      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=REF_NOF_SENSORS);
  TMOUT1_LeaveCounter(timeout);
  if (ledON) {
    IR_on(FALSE); /* IR LED's off */
  }
  FRTOS1_xSemaphoreGive(mutexHandle);
}
Esempio n. 4
0
static void REF_MeasureRaw(SensorTimeType raw[REF_NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;

  LED_IR_On(); /* IR LED's on */
  WAIT1_Waitus(200); /*! \todo adjust time as needed */

  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(50); /* give some time to charge the capacitor */
  (void)RefCnt_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<REF_NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  int cntTimeOUt = 0;
  do {

    cnt = 0;

    for(i=0;i<REF_NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0) {
        	FRTOS1_taskENTER_CRITICAL();
        	raw[i] = RefCnt_GetCounterValue(timerHandle);
        	FRTOS1_taskEXIT_CRITICAL();
        }
        cntTimeOUt++;
        if(cntTimeOUt >= 50*REF_NOF_SENSORS){
      	  return;
        }
      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=REF_NOF_SENSORS);
  LED_IR_Off();
}