Пример #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();
}
Пример #2
0
static void IR_on(bool on) {
  if (on) {
    LED_IR_On();
  } else {
    LED_IR_Off();
  }
}
Пример #3
0
static void REF_MeasureRaw(SensorTimeType raw[NOF_SENSORS]) {
  uint8_t cnt; /* number of sensor */
  uint8_t i;
  TMOUT1_CounterHandle timeout;

  FRTOS1_xSemaphoreTake(mutexHandle, portMAX_DELAY);
  if (ledON) {
    LED_IR_On(); /* IR LED's on */
    WAIT1_Waitus(200);
  }
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetOutput(); /* turn I/O line as output */
    SensorFctArray[i].SetVal(); /* put high */
    raw[i] = MAX_SENSOR_VALUE;
  }
  WAIT1_Waitus(20); /* give at least 10 us to charge the capacitor */
  timeout = TMOUT1_GetCounter(20/TMOUT1_TICK_PERIOD_MS); /* set up timeout counter */
  FRTOS1_vTaskSuspendAll();
  
  (void)TU1_ResetCounter(timerHandle); /* reset timer counter */
  for(i=0;i<NOF_SENSORS;i++) {
    SensorFctArray[i].SetInput(); /* turn I/O line as input */
  }
  do {
    cnt = 0;
    if (TMOUT1_CounterExpired(timeout)) {
      break; /* get out of wile loop */
    }
    for(i=0;i<NOF_SENSORS;i++) {
      if (raw[i]==MAX_SENSOR_VALUE) { /* not measured yet? */
        if (SensorFctArray[i].GetVal()==0) {
          raw[i] = TU1_GetCounterValue(timerHandle);
        }
      } else { /* have value */
        cnt++;
      }
    }
  } while(cnt!=NOF_SENSORS);
  TMOUT1_LeaveCounter(timeout);
  FRTOS1_xTaskResumeAll();
  if (ledON) {
    LED_IR_Off(); /* IR LED's off */
    WAIT1_Waitus(200);
  }
  FRTOS1_xSemaphoreGive(mutexHandle);
}
Пример #4
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 */
}
Пример #5
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();
}