Index: firmware/App/Drivers/ConductivityTeensy.h =================================================================== diff -u -rfea37ad4659d4162d43f3e343cd5b266c2757ea9 -r614a58c1d55d79e47329adb7e191d8cc9c681c72 --- firmware/App/Drivers/ConductivityTeensy.h (.../ConductivityTeensy.h) (revision fea37ad4659d4162d43f3e343cd5b266c2757ea9) +++ firmware/App/Drivers/ConductivityTeensy.h (.../ConductivityTeensy.h) (revision 614a58c1d55d79e47329adb7e191d8cc9c681c72) @@ -22,9 +22,9 @@ // ********** public definitions ********** -#define DOUBLE_COUNT 8 ///< Number of double values in Teensy EEPROM data -#define FLOAT_COUNT 16 ///< Number of float values in Teensy EEPROM data -#define MAX_COND_MST_PARAM_IDX 7 ///< Total number of parameters in measurement settings CONDUCTIVITY_MEASUREMENT_SETTINGS_T +#define DOUBLE_COUNT 8 ///< Number of double values in Teensy EEPROM data +#define FLOAT_COUNT 16 ///< Number of float values in Teensy EEPROM data +#define MAX_COND_MST_PARAM_IDX 7 ///< Total number of parameters in measurement settings CONDUCTIVITY_MEASUREMENT_SETTINGS_T /// Enumeration of conductivity sensors. typedef enum ConductivitySensors @@ -58,52 +58,53 @@ /// Enumeration of Teensy Commands. Also used as TX and TX states. typedef enum TeensyCmdIndex { - TEENSY_CMD_INIT_SENSOR = 0, ///< Maps to command "a" - TEENSY_CMD_GET_INIT_STATUS, ///< Maps to command "l" - TEENSY_CMD_UPDATE_EEPROM_DATA, ///< Maps to command "save" - TEENSY_CMD_GET_EEPROM_DATA, ///< Maps to command "e" - TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS, ///< Maps to command "cfg" - TEENSY_CMD_GET_MEASUREMENT_SETTINGS, ///< Maps to command "k" - TEENSY_CMD_START_MEASUREMENT, ///< Maps to command "m" - TEENSY_CMD_STOP_MEASUREMENT, ///< Maps to command "n" - TEENSY_CMD_GET_ALL_MEASUREMENTS, ///< Maps to command "g" - TEENSY_CMD_GET_SINGLE_MEASUREMENT, ///< Maps to command "h" - MAX_NUM_OF_TEENSY_CMDS ///< Total number of commands + TEENSY_CMD_INIT_SENSOR = 0, ///< Maps to command "a" + TEENSY_CMD_GET_INIT_STATUS, ///< Maps to command "l" + TEENSY_CMD_UPDATE_EEPROM_DATA, ///< Maps to command "save" + TEENSY_CMD_GET_EEPROM_DATA, ///< Maps to command "e" + TEENSY_CMD_UPDATE_MEASUREMENT_SETTINGS, ///< Maps to command "cfg" + TEENSY_CMD_GET_MEASUREMENT_SETTINGS, ///< Maps to command "k" + TEENSY_CMD_START_MEASUREMENT, ///< Maps to command "m" + TEENSY_CMD_STOP_MEASUREMENT, ///< Maps to command "n" + TEENSY_CMD_GET_ALL_MEASUREMENTS, ///< Maps to command "g" + TEENSY_CMD_GET_SINGLE_MEASUREMENT, ///< Maps to command "h" + TEENSY_CMD_SELECT_SENSOR, ///< Maps to command "u" + MAX_NUM_OF_TEENSY_CMDS ///< Total number of commands } TEENSY_CMD_INDEX_T; /// Enumeration of Initialization status of all the sensors connected to Teensy typedef enum Conductivity_Init_Status { - COND_INIT_STATUS_UNITIALIZED = 0, ///< The initialization process has not started. - COND_INIT_STATUS_IN_PROGRESS, ///< The initialization process has started. - COND_INIT_STATUS_INITIALIZED, ///< Initialization process completed and all the sensors were initialized successfully. - COND_INIT_STATUS_FAILED ///< Initialization process completed but one or more sensor was not initialized properly. + COND_INIT_STATUS_UNINITIALIZED = 0, ///< The initialization process has not started. + COND_INIT_STATUS_IN_PROGRESS, ///< The initialization process has started. + COND_INIT_STATUS_INITIALIZED, ///< Initialization process completed and all the sensors were initialized successfully. + COND_INIT_STATUS_FAILED ///< Initialization process completed but one or more sensor was not initialized properly. } COND_INIT_STATUS_T; /// Enumeration of Parse status of received byte data typedef enum Conductivity_Parse_Status { - COND_PARSE_NONE = 0, - COND_PARSE_ERROR_NULL_BUFFER, - COND_PARSE_ERROR_INVALID_LENGTH, - COND_PARSE_ERROR_INVALID_SENSOR_NUM, + COND_PARSE_NONE = 0, ///< None + COND_PARSE_ERROR_NULL_BUFFER, ///< buffer was empty on parsing + COND_PARSE_ERROR_INVALID_LENGTH, ///< invalid length of data in buffer, + COND_PARSE_ERROR_INVALID_SENSOR_NUM, ///< invalid sensor number from the buffer. COND_PARSE_SUCCESS, } COND_PARSE_STATUS; /// Enumeration of Conductivity Communication states. typedef enum Conductivity_Comm_States { - COND_COMM_STATE_IDLE = 0, - COND_COMM_STATE_TX, - COND_COMM_STATE_RX, - COND_COMM_STATE_FAILED, - NUM_OF_COND_COMM_STATES + COND_COMM_STATE_IDLE = 0, ///< Idle comm state, will q automated polling if nothing is q'd. + COND_COMM_STATE_TX, ///< TX comm state, sends commands to teensy. + COND_COMM_STATE_RX, ///< RX comm state, recv data from teensy. + COND_COMM_STATE_FAILED, ///< Failed comm state + NUM_OF_COND_COMM_STATES ///< Number of comm states. } COND_COMM_STATE_T; /// Enumeration of update EEPROM status typedef enum Conductivity_Update_Eeprom_Status { - COND_UPDATE_EEPROM_STATUS_UNITIALIZED = 0, ///< The initialization process has not started. + COND_UPDATE_EEPROM_STATUS_UNINITIALIZED = 0, ///< The initialization process has not started. COND_UPDATE_EEPROMSTATUS_IN_PROGRESS, ///< The initialization process has started. COND_UPDATE_EEPROM_STATUS_INITIALIZED, ///< Initialization process completed and all the sensors were initialized successfully. COND_UPDATE_EEPROM_STATUS_FAILED ///< Initialization process completed but one or more sensor was not initialized properly. @@ -120,60 +121,83 @@ COND_MST_STATUS_SUCCESS } COND_UPDATE_MST_STATUS_T; +/// Enumeration of Conductivity models +typedef enum Conductivity_Models +{ + STANDARD, ///< standard equation for conductivity + ALY_LINEAR, ///< Aly's high range model for conductivity + UPDATED_STANDARD, ///< Updated stand equation with a linear transformation. + NUM_OF_MODELS, ///< Number of models used for conductivity calculation. +} COND_MODELS_T; + /// Coefficients to be applied with raw impedance and rtd values to calculate conductivity and temperature. +/// Coefficients stored into the EEPROM of the sensors contain values for more than one model and each subsystem. typedef struct { - F64 A0; - F64 A1; - F64 B0; - F64 B1; - F64 B2; - F64 B3; + F64 beta; ///< Temperature scale factor, all models + F64 gamma; ///< Temperature offset factor, all models + F64 kHighDDUS; ///< Cell constant, high range ( DD ), Updated standard + F64 alphaHighDDUS; ///< Temperature correction factor, high range (DD), Updated Standard + F64 etaHighDDUS; ///< Resistance scale factor, high range (DD), Updated Standard + F64 zetaHighDDUS; ///< Resistance offset, high range (DD), Updated Standard + F64 kLowFPS; ///< Cell constant, low range ( IOFP ), Standard + F64 alphaLowFPS; ///< Temperature correction factor, low range (IOFP), Standard + F32 kHighDDS; ///< Cell constant, high range (DD), Standard + F32 alphaHighDDS; ///< Temperature correction factor, high range (DD), Standard + F32 kLowFPUS; ///< Cell constant, low range (IOFP), Updated Standard + F32 alphaLowFPUS; ///< Temperature correction factor, low range (IOFP), Updated Standard + F32 etaLowFPUS; ///< Resistance scale factor, low range (IOFP), Updated Standard + F32 zetaLowFPUS; ///< Resistance offset, low range (IOFP), Updated Standard + F32 beta0DD; ///< Beta 0 (DD), Aly Linear + F32 beta1DD; ///< Beta 1 (DD), Aly Linear + F32 beta2DD; ///< Beta 2 (DD), Aly Linear + F32 beta3DD; ///< Beta 3 (DD), Aly Linear + F32 beta0FP; ///< Beta 0 (IOFP), Aly Linear + F32 beta1FP; ///< Beta 1 (IOFP), Aly Linear + F32 beta2FP; ///< Beta 2 (IOFP), Aly Linear + F32 beta3FP; ///< Beta 3 (IOFP), Aly Linear } COND_COEFF_T; /// Structure to receive Sensor Measurement data from Teensy #pragma pack(push, 1) typedef struct { - U32 sensorNum; ///< Conductivity Sensor number i.e unit 1 to 6. - F32 impFreq; ///< Impedance Frequency - U32 impDataPoints; ///< Impedance Data Points. Hard coded to 1 - F32 impRzMag; ///< Value of medianMag - F32 impRzPhase; ///< Value of medianPhase - F32 rtdFreq; ///< RTD Frequency. Hard coded to 0.0 - U32 rtdDataPoints; ///< Impedance Data Points. Hard coded to 1 - F32 rtdRzMag; ///< Value of rtd_resistance - F32 rtdRzPhase; ///< RTD Rz Phase. Hard coded to 0.0 + U32 sensorNum; ///< Conductivity Sensor number i.e unit 1 to 6. + F32 impFreq; ///< Impedance Frequency + U32 impDataPoints; ///< Impedance Data Points. Hard coded to 1 + F32 impRzMag; ///< Value of medianMag + F32 impRzPhase; ///< Value of medianPhase + F32 rtdFreq; ///< RTD Frequency. Hard coded to 0.0 + U32 rtdDataPoints; ///< Impedance Data Points. Hard coded to 1 + F32 rtdRzMag; ///< Value of rtd_resistance + F32 rtdRzPhase; ///< RTD Rz Phase. Hard coded to 0.0 } COND_SENSOR_DATA_T; -#pragma pack(pop) -/// Structure to receive EEPROM data from Teensy. These are coefficient values to calculate conductivity and temperature. -#pragma pack(push, 1) +/// Structure to receive EEPROM data from Teensy. These are coefficient values to calculate conductivity and temperature.) typedef struct { - F64 doubleValue[DOUBLE_COUNT]; ///< Double Values stored in the EEPROM - F32 floatValue[FLOAT_COUNT]; ///< Float Values stored in the EEPROM + F64 doubleValue[DOUBLE_COUNT]; ///< Double Values stored in the EEPROM + F32 floatValue[FLOAT_COUNT]; ///< Float Values stored in the EEPROM } COND_EEPROM_DATA_T; -#pragma pack(pop) /// Structure to receive conductivity measurement settings from Teensy -#pragma pack(push, 1) typedef struct { - F32 SinFreq; ///< SinFreq : Frequency of excitation signal - F32 DacVoltPP; ///< DacVoltPP : DAC output voltage in mV peak to peak. Maximum value is 800mVpp. Peak to peak voltage - F32 BiasVolt; ///< BiasVolt : The excitation signal is DC+AC. This parameter decides the DC value in mV unit. 0.0mV means no DC bias. - U32 HstiaRtiaSel; ///< HstiaRtiaSel : Valid param values ( 0, 1, 2, 3, 4, 5, 6, 7 ) - U32 AdcPgaGain; ///< AdcPgaGain : Valid param values ( 1, 1.5, 2, 4, 9 ) i.e interpreted as ( 0, 1, 2, 3, 4 ) respectively in Teensy. - U32 DftNum; ///< DftNum : DFT number Valid param values ( 4096, 2048, 1024, 512, 256 ) i.e interpreted as ( 10, 9, 8, 7, 6 ) respectively in Teensy. - U32 ADCAvgNum; ///< ADCAvgNum : Valid param values ( 2, 4, 8, 16 )i.e interpreted as ( 0, 1, 2, 3 ) respectively in Teensy. + F32 SinFreq; ///< SinFreq : Frequency of excitation signal + F32 DacVoltPP; ///< DacVoltPP : DAC output voltage in mV peak to peak. Maximum value is 800mVpp. Peak to peak voltage + F32 BiasVolt; ///< BiasVolt : The excitation signal is DC+AC. This parameter decides the DC value in mV unit. 0.0mV means no DC bias. + U32 HstiaRtiaSel; ///< HstiaRtiaSel : Valid param values ( 0, 1, 2, 3, 4, 5, 6, 7 ) + U32 AdcPgaGain; ///< AdcPgaGain : Valid param values ( 1, 1.5, 2, 4, 9 ) i.e interpreted as ( 0, 1, 2, 3, 4 ) respectively in Teensy. + U32 DftNum; ///< DftNum : DFT number Valid param values ( 4096, 2048, 1024, 512, 256 ) i.e interpreted as ( 10, 9, 8, 7, 6 ) respectively in Teensy. + U32 ADCAvgNum; ///< ADCAvgNum : Valid param values ( 2, 4, 8, 16 )i.e interpreted as ( 0, 1, 2, 3 ) respectively in Teensy. } COND_MEASUREMENT_SETTINGS_T; #pragma pack(pop) /// Structure to store calculated Conductivity and Temperature for each sensor. typedef struct { F64 Conductivity; + F64 Resistance; F64 Temperature; } COND_CALCULATED_MEASUREMENTS_T; @@ -194,5 +218,6 @@ void addToConductivityCmdQ(TEENSY_CMD_INDEX_T teensyCmd); F32 getTeensyConductivityValue( CONDUCTIVITY_SENSORS_T sensorId ); F32 getTeensyConductivityTemperatureValue( CONDUCTIVITY_SENSORS_T sensorId ); +BOOL testSetTeenyConductivityModel( MESSAGE_T *message ); #endif /* _CONDUCTIVITY_TEENSY_H_ */