/* ** =================================================================== ** Method : AD1_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 AdcLdd1_OnMeasurementComplete(LDD_TUserData *UserDataPtr) { AdcLdd1_TResultData 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)AdcLdd1_GetCalibrationResultStatus(AdcLdd1_DeviceDataPtr); ModeFlg = STOP; /* Set the device to the stop mode */ AD1_OnCalibrationEnd(); /* If yes then invoke user event */ return; /* Return from interrupt */ } AdcLdd1_GetMeasuredValues(AdcLdd1_DeviceDataPtr, (LDD_TData *)&ResultData); AD1_OutV[SumChan] += ResultData; SumChan++; /* Increase counter of measured channels*/ if (SumChan == 4U) { /* 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 == 128U) { /* Is number of conversions on each channel equal to the number of conversions defined in the component? */ OutFlg = TRUE; /* Measured values are available */ AD1_OnEnd(); /* If yes then invoke user event */ ModeFlg = STOP; /* Set the device to the stop mode */ return; /* Return from interrupt */ } } SampleGroup[0].ChannelIdx = SumChan; /* Start measurement of next channel */ (void)AdcLdd1_CreateSampleGroup(AdcLdd1_DeviceDataPtr, (LDD_ADC_TSample *)SampleGroup, 1U); /* Configure sample group */ (void)AdcLdd1_StartSingleMeasurement(AdcLdd1_DeviceDataPtr); }
/* ** =================================================================== ** Method : AD1_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 AdcLdd1_OnMeasurementComplete(LDD_TUserData *UserDataPtr) { (void)UserDataPtr; /* Parameter is not used, suppress unused argument warning */ if (ModeFlg == STOP) { /* If the driver is in STOP mode */ return; /* Return from interrupt */ } if (ModeFlg == CALIBRATING) { /* If the driver is in CALIBRATING mode */ (void)AdcLdd1_GetCalibrationResultStatus(AdcLdd1_DeviceDataPtr); ModeFlg = STOP; /* Set the device to the stop mode */ AD1_OnCalibrationEnd(); /* If yes then invoke user event */ return; /* Return from interrupt */ } if (ModeFlg != SINGLE) { AdcLdd1_GetMeasuredValues(AdcLdd1_DeviceDataPtr, (LDD_TData *)&AD1_OutV); OutFlg = TRUE; /* Measured value is available */ AD1_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 = 0U; /* Restart measurement */ (void)AdcLdd1_CreateSampleGroup(AdcLdd1_DeviceDataPtr, (LDD_ADC_TSample *)SampleGroup, 1U); /* Configure sample group */ (void)AdcLdd1_StartSingleMeasurement(AdcLdd1_DeviceDataPtr); } else { AdcLdd1_GetMeasuredValues(AdcLdd1_DeviceDataPtr, (LDD_TData *)&AD1_OutV); OutFlg = TRUE; /* Measured value is available */ AD1_OnEnd(); /* If yes then invoke user event */ ModeFlg = STOP; /* Set the device to the stop mode */ } }
/* ** =================================================================== ** Method : AD1_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 AdcLdd1_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)AdcLdd1_GetCalibrationResultStatus(AdcLdd1_DeviceDataPtr); ModeFlg = STOP; /* Set the device to the stop mode */ AD1_OnCalibrationEnd(); /* If yes then invoke user event */ return; /* Return from interrupt */ } AdcLdd1_GetMeasuredValues(AdcLdd1_DeviceDataPtr, (LDD_TData *)&AD1_OutV); OutFlg = TRUE; /* Measured value is available */ AD1_OnEnd(); /* If yes then invoke user event */ ModeFlg = STOP; /* Set the device to the stop mode */ }
/* ** =================================================================== ** Method : AD1_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 PE_AD1_Calibrate(void) { if (ModeFlg != STOP) { /* Is the device in different mode than "stop"? */ return ERR_BUSY; /* If yes then error */ } (void)AdcLdd1_GetMeasurementCompleteStatus(AdcLdd1_DeviceDataPtr); /* Clear measurement complete status */ (void)AdcLdd1_StartCalibration(AdcLdd1_DeviceDataPtr); /* Start calibration */ while (!AdcLdd1_GetMeasurementCompleteStatus(AdcLdd1_DeviceDataPtr)) {}; /* Wait until calibration ends */ if (AdcLdd1_GetCalibrationResultStatus(AdcLdd1_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 */ }
/* ** =================================================================== ** Method : AD1_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 AD1_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)AdcLdd1_GetMeasurementCompleteStatus(AdcLdd1_DeviceDataPtr); /* Clear measurement complete status */ (void)AdcLdd1_StartCalibration(AdcLdd1_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 (!AdcLdd1_GetMeasurementCompleteStatus(AdcLdd1_DeviceDataPtr)) {}; /* Wait until calibration ends */ if (AdcLdd1_GetCalibrationResultStatus(AdcLdd1_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 */ }