Ejemplo n.º 1
0
/*
** ===================================================================
**     Method      :  AD2_OnMeasurementComplete (component ADC)
**
**     Description :
**         The method services the conversion complete interrupt of the 
**         selected peripheral(s) and eventually invokes the beans 
**         event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void AdcLdd2_OnMeasurementComplete(LDD_TUserData *UserDataPtr)
{
  (void)UserDataPtr;                   /* Parameter is not used, suppress unused argument warning */
  if (ModeFlg == CALIBRATING) {        /* If the driver is in CALIBRATING mode */
    (void)AdcLdd2_GetCalibrationResultStatus(AdcLdd2_DeviceDataPtr);
    ModeFlg = STOP;                    /* Set the device to the stop mode */
    AD2_OnCalibrationEnd();            /* If yes then invoke user event */
    return;                            /* Return from interrupt */
  }
  AdcLdd2_GetMeasuredValues(AdcLdd2_DeviceDataPtr, (LDD_TData *)&AD2_OutV);
  OutFlg = TRUE;                       /* Measured value is available */
  AD2_OnEnd();                         /* If yes then invoke user event */
  ModeFlg = STOP;                      /* Set the device to the stop mode */
}
Ejemplo n.º 2
0
/*
** ===================================================================
**     Method      :  M1_ANALOG_Calibrate (component ADC)
**     Description :
**         This method starts self calibration process. Calibration is
**         typically used to remove the effects of the gain and offset
**         from a specific reading.
**     Parameters  :
**         NAME            - DESCRIPTION
**         WaitForResult   - Wait for a result of
**                           calibration. If the <interrupt service> is
**                           disabled, the WaitForResult parameter is
**                           ignored and the method waits for
**                           calibration result every time.
**     Returns     :
**         ---             - Error code
**                           ERR_OK - OK
**                           ERR_BUSY - A conversion is already running
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
**                           ERR_FAILED - Calibration hasn't been
**                           finished correctly
** ===================================================================
*/
byte M1_ANALOG_Calibrate(bool WaitForResult)
{
  if (ModeFlg != STOP) {               /* Is the device in different mode than "stop"? */
    return ERR_BUSY;                   /* If yes then error */
  }
  ModeFlg = CALIBRATING;               /* Set state of device to the calibration mode */
  (void)AdcLdd2_GetMeasurementCompleteStatus(AdcLdd2_DeviceDataPtr); /* Clear measurement complete status */
  (void)AdcLdd2_StartCalibration(AdcLdd2_DeviceDataPtr); /* Start calibration */
  if (!WaitForResult) {                /* If doesn't wait for result */
    return ERR_OK;                     /* then return ERR_OK, but user have to check the result of calibration e.g. by GetCalibrationStatus method */
  }
  while (!AdcLdd2_GetMeasurementCompleteStatus(AdcLdd2_DeviceDataPtr)) {}; /* Wait until calibration ends */
  if (AdcLdd2_GetCalibrationResultStatus(AdcLdd2_DeviceDataPtr) != ERR_OK) { /* If calibration failed flag is set */
    ModeFlg = STOP;                    /* Set the device to the stop mode */
    return ERR_FAILED;                 /* Return ERR_FAILED error code */
  }
  return ERR_OK;                       /* ADC device is now calibrated */
}
Ejemplo n.º 3
0
/*
** ===================================================================
**     Method      :  M1_ANALOG_OnMeasurementComplete (component ADC)
**
**     Description :
**         The method services the conversion complete interrupt of the 
**         selected peripheral(s) and eventually invokes the beans 
**         event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void AdcLdd2_OnMeasurementComplete(LDD_TUserData *UserDataPtr)
{
  word ResultData;                     /* Temporary result data */
    
  (void)UserDataPtr;                   /* Parameter is not used, suppress unused argument warning */
  if (ModeFlg == CALIBRATING) {        /* If the driver is in CALIBRATING mode */
    (void)AdcLdd2_GetCalibrationResultStatus(AdcLdd2_DeviceDataPtr);
    ModeFlg = STOP;                    /* Set the device to the stop mode */
    M1_ANALOG_OnCalibrationEnd();      /* If yes then invoke user event */
    return;                            /* Return from interrupt */
  }
  AdcLdd2_GetMeasuredValues(AdcLdd2_DeviceDataPtr, (LDD_TData *)&ResultData);
  M1_ANALOG_SumV[SumChan] += ResultData;
  SumChan++;                           /* Increase counter of measured channels*/
  if (SumChan == 2U) {                 /* Is number of measured channels equal to the number of channels used in the component? */
    SumChan = 0U;                      /* If yes then set the counter of measured channels to 0 */
    SumCnt++;                          /* Increase counter of conversions*/
    if (SumCnt == 8U) {                /* Is number of conversions on each channel equal to the number of conversions defined in the component? */
      OutFlg = TRUE;                   /* Measured values are available */
      M1_ANALOG_OutV[0] = (word)M1_ANALOG_SumV[0]; /* Save measured value to the output buffer */
      M1_ANALOG_OutV[1] = (word)M1_ANALOG_SumV[1]; /* Save measured value to the output buffer */
      if (ModeFlg != MEASURE) {        /* Is the device in other then measure state? */
        M1_ANALOG_SumV[0] = 0U;        /* Set mesured values to 0 */
        M1_ANALOG_SumV[1] = 0U;        /* Set mesured values to 0 */
        SumCnt = 0U;                   /* Set counter of conversions to 0 */
      }
      M1_ANALOG_OnEnd();               /* If yes then invoke user event */
      if (ModeFlg == MEASURE) {        /* Is the device in the measure state? */
        ModeFlg = STOP;                /* Set the device to the stop mode */
        return;                        /* Return from interrupt */
      }
    }
  }
  SampleGroup[0].ChannelIdx = SumChan; /* Start measurement of next channel */
  (void)AdcLdd2_CreateSampleGroup(AdcLdd2_DeviceDataPtr, (LDD_ADC_TSample *)SampleGroup, 1U); /* Configure sample group */
  (void)AdcLdd2_StartSingleMeasurement(AdcLdd2_DeviceDataPtr);
}