Index: firmware/App/Drivers/InternalADC.c =================================================================== diff -u -rf068446fdb7889d320ddb6ffbd58f347ce0501e7 -r0dec8744af40d0c87a6d7cd1923920c1c2bd1d2f --- firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision f068446fdb7889d320ddb6ffbd58f347ce0501e7) +++ firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 0dec8744af40d0c87a6d7cd1923920c1c2bd1d2f) @@ -1,72 +1,79 @@ -/************************************************************************** - * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN - * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. - * - * @file InternalADC.c - * - * @date 08-Nov-2019 - * @author S. Nash - * - * @brief Driver for the internal ADC peripheral. - * - **************************************************************************/ +/************************************************************************** +* +* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file InternalADC.c +* +* @author (last) Quang Nguyen +* @date (last) 21-Jul-2020 +* +* @author (original) Sean +* @date (original) 04-Feb-2020 +* +***************************************************************************/ #include "adc.h" #include "InternalADC.h" +/** + * @addtogroup InternalADC + * @{ + */ + // ********** private definitions ********** -#define MAX_ADC_CHANNELS 24 // ADC supports up to 24 channels -#define SIZE_OF_ROLLING_AVG 16 // samples in rolling average calculations -#define ROLLING_AVG_SHIFT_DIVIDER 4 // rolling average shift divider +#define MAX_ADC_CHANNELS 24 ///< DG internal ADC supports up to 24 channels. +#define SIZE_OF_ROLLING_AVG 16 ///< Number of DG internal ADC samples in rolling average calculations for each channel. +#define ROLLING_AVG_SHIFT_DIVIDER 4 ///< Rolling average shift divider for DG internal ADC readings. +/// ADC channel # to ADC channel ID (enumeration) look-up table. const INT_ADC_CHANNEL_T adcChannelNum2ChannelId[ MAX_ADC_CHANNELS ] = { - INT_ADC_DIAL_IN_PUMP_SPEED, // 0 - INT_ADC_NOT_USED, // 1 - INT_ADC_NOT_USED, // 2 - INT_ADC_NOT_USED, // 3 + INT_ADC_RO_PUMP_INLET_PRESSURE, // 0 + INT_ADC_RO_PUMP_OUTLET_PRESSURE, // 1 + INT_ADC_DRAIN_PUMP_OUTLET_PRESSURE, // 2 + INT_ADC_DRAIN_PUMP_INLET_PRESSURE, // 3 INT_ADC_NOT_USED, // 4 - INT_ADC_NOT_USED, // 5 - INT_ADC_NOT_USED, // 6 - INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT, // 7 - INT_ADC_NOT_USED, // 8 - INT_ADC_NOT_USED, // 9 - INT_ADC_NOT_USED, // 10 - INT_ADC_NOT_USED, // 11 - INT_ADC_NOT_USED, // 12 - INT_ADC_NOT_USED, // 13 - INT_ADC_NOT_USED, // 14 - INT_ADC_NOT_USED, // 15 - INT_ADC_BLOOD_PUMP_SPEED, // 16 - INT_ADC_BLOOD_PUMP_MOTOR_CURRENT, // 17 - INT_ADC_DIAL_OUT_PUMP_SPEED, // 18 - INT_ADC_DIAL_OUT_PUMP_MOTOR_CURRENT,// 19 - INT_ADC_NOT_USED, // 20 - INT_ADC_NOT_USED, // 21 + INT_ADC_FPGA_1_8_VOLTS, // 5 + INT_ADC_FPGA_1_VOLT, // 6 + INT_ADC_SENSORS_3_3_VOLTS, // 7 + INT_ADC_PROCESSOR_1_8_VOLTS, // 8 + INT_ADC_SENSORS_6_VOLTS, // 9 + INT_ADC_SENSORS_5_VOLTS, // 10 + INT_ADC_LOGIC_5_VOLTS, // 11 + INT_ADC_3_3_VOLTS, // 12 + INT_ADC_CONCENTRATE_PUMP_1, // 13 + INT_ADC_CONCENTRATE_PUMP_2, // 14 + INT_ADC_PROCESSOR_1_2_VOLTS, // 15 + INT_ADC_REFERENCE_VOLTAGE, // 16 + INT_ADC_PRIMARY_HEATER_24_VOLTS, // 17 + INT_ADC_TRIMMER_HEATER_24_VOLTS, // 18 + INT_ADC_REF_IN1, // 19 + INT_ADC_REF_IN2, // 20 + INT_ADC_BOARD_THERMISTOR, // 21 INT_ADC_NOT_USED, // 22 INT_ADC_NOT_USED // 23 }; // ********** private data ********** -static adcData_t adcRawReadings[ NUM_OF_INT_ADC_CHANNELS ]; // buffer holds latest adc channel readings -static U32 adcRawReadingsCount = 0; // readings count for raw readings buffer +static adcData_t adcRawReadings[ NUM_OF_INT_ADC_CHANNELS ]; ///< buffer holds latest adc channel readings. +static U32 adcRawReadingsCount = 0; ///< readings count for raw readings buffer. -static U16 adcReadings[ NUM_OF_INT_ADC_CHANNELS ][ SIZE_OF_ROLLING_AVG ]; // holds samples for each channel for a rolling average -static U32 adcReadingsIdx[ NUM_OF_INT_ADC_CHANNELS ]; // index for next reading in each rolling average array -static U32 adcReadingsTotals[ NUM_OF_INT_ADC_CHANNELS ]; // rolling total for each channel - used to calc average -static U32 adcReadingsAvgs[ NUM_OF_INT_ADC_CHANNELS ]; // rolling average for each channel +static U16 adcReadings[ NUM_OF_INT_ADC_CHANNELS ][ SIZE_OF_ROLLING_AVG ]; ///< buffer holds samples for each channel for a rolling average. +static U32 adcReadingsIdx[ NUM_OF_INT_ADC_CHANNELS ]; ///< index for next reading in each rolling average buffer. +static U32 adcReadingsTotals[ NUM_OF_INT_ADC_CHANNELS ]; ///< rolling sum for each ADC channel - used to calc average. +static U32 adcReadingsAvgs[ NUM_OF_INT_ADC_CHANNELS ]; ///< rolling average for each ADC channel. // ********** private function prototypes ********** -/************************************************************************* +/*********************************************************************//** * @brief initInternalADC * The initInternalADC function initializes the InternalADC module. * @details @@ -98,8 +105,8 @@ adcEnableNotification( adcREG1, adcGROUP1 ); } -/************************************************************************* - * @brief adcNotification +/*********************************************************************//** + * @brief * The adcNotification function handles an ADC conversion complete interrupt. \n * All channel readings in the FIFO are retrieved. * @details @@ -117,7 +124,7 @@ } } -/************************************************************************* +/*********************************************************************//** * @brief execInternalADC * The execInternalADC function processes the last set of raw ADC channel \n * readings and kicks off the next conversion of ADC channels. @@ -148,14 +155,14 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_DATA_OVERRUN, adcRawReadingsCount ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_DATA_OVERRUN, adcRawReadingsCount ) } // start an adc channel group conversion adcStartConversion( adcREG1, adcGROUP1 ); } -/************************************************************************* +/*********************************************************************//** * @brief getIntADCReading * The getIntADCReading function gets the latest average reading for a given \n * channel. @@ -175,9 +182,10 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_INVALID_CHANNEL_REQUESTED, channel ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INT_ADC_INVALID_CHANNEL_REQUESTED, channel ) } return result; } +/**@}*/