Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rb26c5dd805f0c95856456fd16c8fc9c56659f76e -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision b26c5dd805f0c95856456fd16c8fc9c56659f76e) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -7,8 +7,8 @@ * * @file BalancingChamber.c * -* @author (last) Jashwant Gantyada -* @date (last) 10-Apr-2026 +* @author (last) Vinayakam Mani +* @date (last) 14-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 28-Jan-2025 @@ -542,12 +542,12 @@ if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp - setHeaterTargetTemperature( D45_HEAT, getD4AverageTemperature() ); + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); } else { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp - setHeaterTargetTemperature( D45_HEAT, getD99AverageTemperature() ); + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D99_TEMP ) ); } // Check fresh dialysate pressure in range or BC switch only flag set or BC pressure alarms are disabled @@ -847,12 +847,12 @@ if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp - setHeaterTargetTemperature( D45_HEAT, getD4AverageTemperature() ); + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); } else { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp - setHeaterTargetTemperature( D45_HEAT, getD99AverageTemperature() ); + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D99_TEMP ) ); } // Check fresh dialysate pressure in range Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rd210786d6c7d75bb0b4d9e18efc40a01d85123fe -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision d210786d6c7d75bb0b4d9e18efc40a01d85123fe) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -26,10 +26,12 @@ #include "Messaging.h" #include "ModeGenDialysate.h" #include "OperationModes.h" +#include "PIControllers.h" #include "PressureSensor.h" #include "PersistentAlarm.h" #include "Pressure.h" #include "TaskGeneral.h" +#include "TemperatureSensors.h" #include "Timers.h" #include "Valves.h" @@ -43,11 +45,15 @@ #define DRY_BICART_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. // Dry Bicart Fill -#define DRY_BICART_FILL_DURATION_MIN_MS (2 * MS_PER_SECOND) ///< Minimum fill duration to be met to end the fill cycle. +#define DRY_BICART_FILL_DURATION_MIN_MS ( 2 * MS_PER_SECOND ) ///< Minimum fill duration to be met to end the fill cycle. #define DRY_BICART_FILL_COMPLETE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to reset the request flag after fill complete #define DRY_BICART_FILL_DURATION_DIFF_MS 750 ///< Fill duration difference between last and current fill cycle. -#define DRY_BICART_FILL_COMPLETE_PRESSURE 15.0F ///< Maximum pressure reached to indicate the dry bicart fill being completed. -#define DRY_BICART_FILL_INITIATE_PRESSURE 5.0F ///< Minimum pressure required to initiate the dry bicart fill process. +#define PRESSURE_OFFSET 2 ///< Dry bicart pressure offset +#define DRY_BICART_FILL_COMPLETE_PRESSURE ( 10.0F + PRESSURE_OFFSET ) ///< Maximum pressure reached to indicate the dry bicart fill being completed. +#define DRY_BICART_FILL_INITIATE_PRESSURE 3.0F ///< Minimum pressure required to initiate the dry bicart fill process. +#define DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE 6.0F ///< Maximum pressure allowed at bicart fill during supply process/state +#define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE 3.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state + #define DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT 10 ///< Default max fill cycle allowed for dry bicart fill/mix with water. #define DRY_BICART_MAX_FILL_CYCLE_CNT 30 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. // Dry Bicart Fill Vent @@ -58,7 +64,7 @@ // Bicarb chamber fill/Supply #define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill. #define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. -#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. +#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1.1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. // Dry Bicart Drain #define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. @@ -69,6 +75,36 @@ #define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< Zero conductivity threshold #define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) +// drybicarb mixing +#define BICARB_VOL_CONTROL_P_COEFFICIENT 0.00008484 ///< Bicarb proportional gain (kp) +#define BICARB_VOL_CONTROL_I_COEFFICIENT 0.00033936 ///< Bicarb integral gain. (ki) +#define MIN_BICARB_VOLUME_ML 0.868686869 ///< Minimum bicarb volume in mL +#define MAX_BICARB_VOLUME_ML 1.8 ///< Maximum bicarb volume in mL + +#define ACID_VOL_CONTROL_P_COEFFICIENT (0.00000997/2) ///< Acid proportional gain (kp) +#define ACID_VOL_CONTROL_I_COEFFICIENT (0.00003988/2) ///< Acid integral gain. (ki) +#define MIN_ACID_VOLUME_ML 0.3 ///< Minimum acid volume in mL +#define MAX_ACID_VOLUME_ML 1.0 ///< Maximum acid volume in mL/min. + +#define DRY_BICARB_TARGET_CONDUCTIVITY 2714.0F ///< Target bicarb conductivity +#define DRY_BICARB_DELTA_CONDUCTIVITY 500.0F ///< Delta bicarb conductivity + +#define DRY_ACID_BICARB_TARGET_CONDUCTIVITY 13734.87F ///< Target acid bicarb mix conductivity +#define DRY_ACID_BICARB_DELTA_CONDUCTIVITY 700.0F ///< Delta acid bicarb mix conductivity + +#define ACID_TYPE_1K_2_5_CA 11192.55F ///< standard acid conductivity for 1K +#define ACID_TYPE_2K_2_5_CA 11313.62F ///< standard acid conductivity for 2K +#define ACID_TYPE_3K_2_5_CA 11435.68F ///< standard acid conductivity for 3K + +#define MIN_BICARB_CONDUCTIVITY 2000 ///< Minimum Bicarb conductivity limit +#define MAX_BICARB_CONDUCTIVITY 4000 ///< Maximum Bicarb conductivity limit + +#define MIX_NO_FEED_FORWARD 0.0F ///< Feedforward term for dialysate closed loop control + +#define MIXING_CONTROL_INTERVAL_MS ( 15 * MS_PER_SECOND ) ///< Dialysate mixing control interval in ms +#define MIXING_CONTROL_INTERVAL ( MIXING_CONTROL_INTERVAL_MS /\ + TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mixing is controlled. + /// Payload record structure for dry bicart fill request typedef struct { @@ -85,6 +121,31 @@ NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation } DRY_BICART_OPERATION_T; +/// Enumeration of dialysate Mixing id. +typedef enum DialysateMixingID +{ + BICARB_MIX_ID = 0, ///< Bicarb mixing id + DIALYSATE_MIX_ID_FIRST = BICARB_MIX_ID, ///< First dialysate mixing in list + ACID_MIX_ID, ///< Acid mix id + NUM_OF_DIALYSATE_MIXING_ID ///< Number of dialysate mix ids +} DIALYSATE_MIXING_ID_T; + +/// Enumeration of dialysate Mixing states. +typedef enum DialysateMixing_States +{ + DIALYSATE_MIXING_OPEN_LOOP_STATE = 0, ///< Dialysate open loop state + DIALYSATE_MIXING_RAMP_UP_STATE, ///< Dialysate mixing ramp up state + DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE, ///< Dialysate mixing control to target state + NUM_OF_DIALYSATE_MIXING_STATES ///< Number of dialysate mixing states +} DIALYSATE_MIXING_STATE_T; + +/// Dialysate Mixing state machine data structure +typedef struct +{ + U32 controlTimerCounter; ///< Timer counter to perform control on dialysate mixing. + DIALYSATE_MIXING_STATE_T dialysateMixingState; ///< Current state of dialysate mixing controller state machine. +} DIALYSATE_MIXING_DATA_T; + // ********** private data ********** static DRY_BICART_FILL_EXEC_STATE_T dryBiCartFillExecState; ///< Current state of dry bicart fill executive state machine. @@ -96,6 +157,9 @@ static U32 lastFillDurationInMS; ///< Previous time duration to fill the bicart fill. static U32 currentFillDurationInMS; ///< Current time duration to fill the bicart fill. static OVERRIDE_U32_T biCartMaxFillCycleCount; ///< Maximum number of drybicart fill cycle ( overrideable) +static OVERRIDE_F32_T dryBiCartUpperCartPressure; ///< Upper cart pressure +static OVERRIDE_F32_T dryBiCartLowerCartPressure; ///< Lower cart pressure + // initiate the fill/supply/drain static OVERRIDE_U32_T dryBiCartFillRequested; ///< Start/stop dry bicart fill. static OVERRIDE_U32_T bicarbChamberFillRequested; ///< Start/stop bicarb chamber fill. @@ -117,6 +181,29 @@ static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request +// drybicart mixing +static OVERRIDE_F32_T dryBiCartAcidMixVolume; ///< Acid concentrate volume in ml ( overrideable). +static OVERRIDE_F32_T dryBiCartBicarbMixVolume; ///< Bicarb concentrate volume in ml ( overrideable). + +static OVERRIDE_F32_T dryBiCartAcidMixVolumeKpGain; ///< Acid kp gain. +static OVERRIDE_F32_T dryBiCartAcidMixVolumeKiGain; ///< Acid ki gain. + +static OVERRIDE_F32_T dryBiCartBicarbMixVolumeKpGain; ///< Bicarb kp gain +static OVERRIDE_F32_T dryBiCartBicarbMixVolumeKiGain; ///< Acid ki gain. + +static DIALYSATE_MIXING_DATA_T dialysateMix[ NUM_OF_DIALYSATE_MIXING_ID ]; ///< Array of dialysate mixing data structure. + +static OVERRIDE_F32_T dryBiCartBicarbTargetConductivity; ///< Target bicarb conductivity +static OVERRIDE_F32_T dryBiCartBicarbDeltaConductivity; ///< Target delta conductivity + +static OVERRIDE_F32_T dryBiCartDialysateTargetConductivity; ///< Acid bicarb mix conductivity +static OVERRIDE_F32_T dryBiCartDialysateDeltaConductivity; ///< Acid bicarb delta conductivity + +static OVERRIDE_F32_T dryBiCartMixControlInterval; ///< Mix control interval + +static PI_CONTROLLER_SIGNALS_DATA bicarbControlSignals; ///< Bicarb closed loop control signal data +static PI_CONTROLLER_SIGNALS_DATA acidControlSignals; ///< Acid closed loop control signal data + // ********** private function prototypes ********** static void updateDrybicartOperation(void); @@ -142,6 +229,26 @@ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ); + +// dosing control loop +static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ); +static DIALYSATE_MIXING_STATE_T handleDialysateMixRampToTargetState( DIALYSATE_MIXING_ID_T mixId ); +static DIALYSATE_MIXING_STATE_T handleDialysateMixControlToTargetState( DIALYSATE_MIXING_ID_T mixId ); + +static void setBicarbMixVol( F32 targetValue ); +static void setAcidMixVol( F32 targetValue ); +static F32 getBicarbDeltaConductivity( void ); +static F32 getBicarbTargetConductivity( void ); +static F32 getAcidBicarbDeltaConductivity( void ); +static F32 getAcidBicarbTargetConductivity( void ); +static F32 getBicarbKpGainCoefficient( void ); +static F32 getBicarbKiGainCoefficient( void ); +static F32 getAcidKpGainCoefficient( void ); +static F32 getAcidKiGainCoefficient( void ); +static F32 getDryBicartLowerCartPressure( void ); +static F32 getDryBicartUpperCartPressure( void ); +static F32 getDryBicartMixControlInterval( void ); + // publish the status static void publishDryBicartData( void ); static U32 getDryBicartFillDataPublishInterval( void ); @@ -156,52 +263,133 @@ *************************************************************************/ void initDryBiCart( void ) { - dryBiCartFillExecState = DRY_BICART_START_STATE; - bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; - dryBiCartDrainExecState = DRY_BICART_DRAIN_START_STATE; - dryBicartStartRequest = DRY_BICART_IDLE; + DIALYSATE_MIXING_ID_T mixId; - dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; - dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; - dryBiCartDataPublishInterval.ovInitData = 0; - dryBiCartDataPublishInterval.override = OVERRIDE_RESET; + dryBiCartFillExecState = DRY_BICART_START_STATE; + bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; + dryBiCartDrainExecState = DRY_BICART_DRAIN_START_STATE; + dryBicartStartRequest = DRY_BICART_IDLE; - biCartMaxFillCycleCount.data = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; - biCartMaxFillCycleCount.ovData = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; - biCartMaxFillCycleCount.ovInitData = 0; - biCartMaxFillCycleCount.override = OVERRIDE_RESET; + for ( mixId = DIALYSATE_MIX_ID_FIRST; mixId < NUM_OF_DIALYSATE_MIXING_ID; mixId++ ) + { + dialysateMix[ mixId ].dialysateMixingState = DIALYSATE_MIXING_OPEN_LOOP_STATE; + dialysateMix[ mixId ].controlTimerCounter = 0; + } - dryBiCartFillRequested.data = FALSE; - dryBiCartFillRequested.ovData = FALSE; - dryBiCartFillRequested.ovInitData = FALSE; - dryBiCartFillRequested.override = OVERRIDE_RESET; + dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; + dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; + dryBiCartDataPublishInterval.ovInitData = 0; + dryBiCartDataPublishInterval.override = OVERRIDE_RESET; - dryBiCartDrainRequested.data = FALSE; - dryBiCartDrainRequested.ovData = FALSE; - dryBiCartDrainRequested.ovInitData = FALSE; - dryBiCartDrainRequested.override = OVERRIDE_RESET; + biCartMaxFillCycleCount.data = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; + biCartMaxFillCycleCount.ovData = DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT; + biCartMaxFillCycleCount.ovInitData = 0; + biCartMaxFillCycleCount.override = OVERRIDE_RESET; - bicarbChamberFillRequested.data = FALSE; - bicarbChamberFillRequested.ovData = FALSE; - bicarbChamberFillRequested.ovInitData = FALSE; - bicarbChamberFillRequested.override = OVERRIDE_RESET; + dryBiCartFillRequested.data = FALSE; + dryBiCartFillRequested.ovData = FALSE; + dryBiCartFillRequested.ovInitData = FALSE; + dryBiCartFillRequested.override = OVERRIDE_RESET; - dryBiCartType.data = FALSE; - dryBiCartType.ovData = FALSE; - dryBiCartType.ovInitData = 0; - dryBiCartType.override = OVERRIDE_RESET; + dryBiCartDrainRequested.data = FALSE; + dryBiCartDrainRequested.ovData = FALSE; + dryBiCartDrainRequested.ovInitData = FALSE; + dryBiCartDrainRequested.override = OVERRIDE_RESET; - dryBiCartFillStartTime = 0; - lastFillDurationInMS = 0; - currentFillDurationInMS = 0; - dryBiCartDataPublicationTimerCounter = 0; - biCartFillCycleCounter = 0; - dryBiCarbSupplyStartTime = 0; - dryBiCarbSypplyVentStartTime = 0; - dryBiCartDrainStartTime = 0; - dryBiCartDrainLastCondSampleTime = 0; - dryBiCartDrainCondStableCount = 0; - dryBiCartDrainTimePeriod = 0; + bicarbChamberFillRequested.data = FALSE; + bicarbChamberFillRequested.ovData = FALSE; + bicarbChamberFillRequested.ovInitData = FALSE; + bicarbChamberFillRequested.override = OVERRIDE_RESET; + + dryBiCartType.data = FALSE; + dryBiCartType.ovData = FALSE; + dryBiCartType.ovInitData = 0; + dryBiCartType.override = OVERRIDE_RESET; + + dryBiCartAcidMixVolume.data = DEFAULT_ACID_VOLUME_ML; + dryBiCartAcidMixVolume.ovData = DEFAULT_ACID_VOLUME_ML; + dryBiCartAcidMixVolume.ovInitData = 0.0F; + dryBiCartAcidMixVolume.override = OVERRIDE_RESET; + + dryBiCartBicarbMixVolume.data = DEFAULT_BICARB_VOLUME_ML; + dryBiCartBicarbMixVolume.ovData = DEFAULT_BICARB_VOLUME_ML; + dryBiCartBicarbMixVolume.ovInitData = 0.0F; + dryBiCartBicarbMixVolume.override = OVERRIDE_RESET; + + dryBiCartAcidMixVolumeKpGain.data = ACID_VOL_CONTROL_P_COEFFICIENT; + dryBiCartAcidMixVolumeKpGain.ovData = ACID_VOL_CONTROL_P_COEFFICIENT; + dryBiCartAcidMixVolumeKpGain.ovInitData = 0.0F; + dryBiCartAcidMixVolumeKpGain.override = OVERRIDE_RESET; + + dryBiCartAcidMixVolumeKiGain.data = ACID_VOL_CONTROL_I_COEFFICIENT; + dryBiCartAcidMixVolumeKiGain.ovData = ACID_VOL_CONTROL_I_COEFFICIENT; + dryBiCartAcidMixVolumeKiGain.ovInitData = 0.0F; + dryBiCartAcidMixVolumeKiGain.override = OVERRIDE_RESET; + + dryBiCartBicarbMixVolumeKpGain.data = BICARB_VOL_CONTROL_P_COEFFICIENT; + dryBiCartBicarbMixVolumeKpGain.ovData = BICARB_VOL_CONTROL_P_COEFFICIENT; + dryBiCartBicarbMixVolumeKpGain.ovInitData = 0.0F; + dryBiCartBicarbMixVolumeKpGain.override = OVERRIDE_RESET; + + dryBiCartBicarbMixVolumeKiGain.data = BICARB_VOL_CONTROL_I_COEFFICIENT; + dryBiCartBicarbMixVolumeKiGain.ovData = BICARB_VOL_CONTROL_I_COEFFICIENT; + dryBiCartBicarbMixVolumeKiGain.ovInitData = 0.0F; + dryBiCartBicarbMixVolumeKiGain.override = OVERRIDE_RESET; + + dryBiCartBicarbTargetConductivity.data = DRY_BICARB_TARGET_CONDUCTIVITY; + dryBiCartBicarbTargetConductivity.ovData = DRY_BICARB_TARGET_CONDUCTIVITY; + dryBiCartBicarbTargetConductivity.ovInitData = 0.0F; + dryBiCartBicarbTargetConductivity.override = OVERRIDE_RESET; + + dryBiCartBicarbDeltaConductivity.data = DRY_BICARB_DELTA_CONDUCTIVITY; + dryBiCartBicarbDeltaConductivity.ovData = DRY_BICARB_DELTA_CONDUCTIVITY; + dryBiCartBicarbDeltaConductivity.ovInitData = 0.0F; + dryBiCartBicarbDeltaConductivity.override = OVERRIDE_RESET; + + dryBiCartDialysateTargetConductivity.data = DRY_ACID_BICARB_TARGET_CONDUCTIVITY; + dryBiCartDialysateTargetConductivity.ovData = DRY_ACID_BICARB_TARGET_CONDUCTIVITY; + dryBiCartDialysateTargetConductivity.ovInitData = 0.0F; + dryBiCartDialysateTargetConductivity.override = OVERRIDE_RESET; + + dryBiCartDialysateDeltaConductivity.data = DRY_ACID_BICARB_DELTA_CONDUCTIVITY; + dryBiCartDialysateDeltaConductivity.ovData = DRY_ACID_BICARB_DELTA_CONDUCTIVITY; + dryBiCartDialysateDeltaConductivity.ovInitData = 0.0F; + dryBiCartDialysateDeltaConductivity.override = OVERRIDE_RESET; + + dryBiCartUpperCartPressure.data = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE; + dryBiCartUpperCartPressure.ovData = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE; + dryBiCartUpperCartPressure.ovInitData = 0.0F; + dryBiCartUpperCartPressure.override = OVERRIDE_RESET; + + dryBiCartLowerCartPressure.data = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE; + dryBiCartLowerCartPressure.ovData = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE; + dryBiCartLowerCartPressure.ovInitData = 0.0F; + dryBiCartLowerCartPressure.override = OVERRIDE_RESET; + + dryBiCartMixControlInterval.data = MIXING_CONTROL_INTERVAL; + dryBiCartMixControlInterval.ovData = MIXING_CONTROL_INTERVAL; + dryBiCartMixControlInterval.ovInitData = 0.0F; + dryBiCartMixControlInterval.override = OVERRIDE_RESET; + + dryBiCartFillStartTime = 0; + lastFillDurationInMS = 0; + currentFillDurationInMS = 0; + dryBiCartDataPublicationTimerCounter = 0; + biCartFillCycleCounter = 0; + dryBiCarbSupplyStartTime = 0; + dryBiCarbSypplyVentStartTime = 0; + dryBiCartDrainStartTime = 0; + dryBiCartDrainLastCondSampleTime = 0; + dryBiCartDrainCondStableCount = 0; + dryBiCartDrainTimePeriod = 0; + + initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ + getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ + MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); + + initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ + getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ + MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); } /*********************************************************************//** @@ -219,6 +407,43 @@ /*********************************************************************//** * @brief + * The execDialysateCompositionMixingController function executes the dialysate mixing controller. + * @details \b Inputs: dialysateDosingState + * @details \b Outputs: dialysateDosingState + * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid dialysate dosing + * state machine found. + * @return none + *************************************************************************/ +void execDialysateCompositionMixingController( void ) +{ + DIALYSATE_MIXING_ID_T mixId; + + for ( mixId = DIALYSATE_MIX_ID_FIRST; mixId < NUM_OF_DIALYSATE_MIXING_ID; mixId++ ) + { + switch ( dialysateMix[ mixId ].dialysateMixingState ) + { + case DIALYSATE_MIXING_OPEN_LOOP_STATE: + dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixOpenLoopState( mixId ); + break; + + case DIALYSATE_MIXING_RAMP_UP_STATE: + dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixRampToTargetState( mixId ); + break; + + case DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE: + dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixControlToTargetState( mixId ); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYSATE_MIX_EXEC_INVALID_STATE, mixId ) + dialysateMix[ mixId ].dialysateMixingState = DIALYSATE_MIXING_OPEN_LOOP_STATE; + break; + } + } +} + +/*********************************************************************//** + * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge fill, * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time * @details \b Inputs: dryBicartStartRequest @@ -227,8 +452,21 @@ *************************************************************************/ void execDryBicart( void ) { + //( TRUE == getBicarbChamberFillRequested() ) + //supply dryBicartStartRequest = DRY_BICART_SUPPLY ; + //( TRUE == getBicartFillRequested() ) + //fill dryBicartStartRequest = DRY_BICART_INITIAL_FILL; + //( TRUE == getBicartDrainRequested() ) + //drain dryBicartStartRequest = DRY_BICART_DRAIN; + //else idle dryBicartStartRequest = DRY_BICART_IDLE; updateDrybicartOperation(); + if( getCurrentBalancingChamberExecState() > BAL_CHAMBER_STATE_IDLE ) + { + // closed loop bicarb and acid dosing controller + execDialysateCompositionMixingController(); + } + // top level state machine selection DRY_BICART_OPERATION_T dryBicartState = dryBicartStartRequest; U32 dryBicartSubstate; @@ -237,27 +475,25 @@ { case DRY_BICART_IDLE: // run as idle state - dryBicartSubstate = 0x0; break; case DRY_BICART_INITIAL_FILL: // Dry bicart fill exec - dryBicartSubstate = execDryBicartFillMode(); + execDryBicartFillMode(); break; case DRY_BICART_SUPPLY: // Fill Bicarb chamber F exec - dryBicartSubstate = execBicarbChamberFillMode(); + execBicarbChamberFillMode(); break; case DRY_BICART_DRAIN: // Dry bicart drain exec - dryBicartSubstate = execDryBicartDrainMode(); + execDryBicartDrainMode(); break; default: // software fault, - dryBicartSubstate = 0x0; dryBicartStartRequest = DRY_BICART_IDLE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DRY_BICART_FILL_INVALID_EXEC_STATE, dryBicartStartRequest ); break; @@ -279,6 +515,8 @@ *************************************************************************/ U32 execDryBicartFillMode( void ) { + hydChamberWaterInletControl(); + // execute drybicart fill state machine switch ( dryBiCartFillExecState ) { @@ -330,6 +568,7 @@ *************************************************************************/ U32 execBicarbChamberFillMode( void ) { + // TODO in pregen mode call hydChamberWaterInletControl(); // execute bicarb chamber fill state machine switch ( bicarbChamberFillExecState ) { @@ -413,6 +652,34 @@ /*********************************************************************//** * @brief + * TThe getBicarbMixVol function gets the bicarb mix volume provided by the controller + * @details \b Inputs: dryBiCartBicarbMixVolume + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +F32 getBicarbMixVol( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolume ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAcidMixVol function gets acid mix volume provided by the controller + * @details \b Inputs: dryBiCartAcidMixVolume + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +F32 getAcidMixVol( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartAcidMixVolume ); + + return result; +} + +/*********************************************************************//** + * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested @@ -555,6 +822,311 @@ /*********************************************************************//** * @brief + * The setAcidMixVol function sets acid mix volume provided by the controller + * flag value to be True. + * @details \b Inputs: none + * @details \b Outputs: dryBiCartAcidMixVolume + * @param targetValue acid mix volume + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static void setAcidMixVol( F32 targetValue ) +{ + dryBiCartAcidMixVolume.data = targetValue; +} + +/*********************************************************************//** + * @brief + * The setBicarbMixVol function sets bicarb Mix volume provided by the controller + * @details \b Inputs: none + * @details \b Outputs: dryBiCartBicarbMixVolume + * @param targetValue bicarb Mix volume + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static void setBicarbMixVol( F32 targetValue ) +{ + dryBiCartBicarbMixVolume.data = targetValue; +} + +/*********************************************************************//** + * @brief + * The getBicarbDeltaConductivity function gets the delta target conductivity + * @details \b Inputs: dryBiCartBicarbDeltaConductivity + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getBicarbDeltaConductivity( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartBicarbDeltaConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicarbTargetConductivity function gets the target conductivity + * @details \b Inputs: dryBiCartBicarbTargetConductivity + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getBicarbTargetConductivity( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartBicarbTargetConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAcidBicarbDeltaConductivity function gets the acid bicarb delta target conductivity + * @details \b Inputs: dryBiCartAcidBicarbMixDeltaConductivity + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getAcidBicarbDeltaConductivity( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartDialysateDeltaConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAcidBicarbTargetConductivity function gets the acid bicarb delta target conductivity + * @details \b Inputs: dryBiCartAcidBicarbMixTargetConductivity + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getAcidBicarbTargetConductivity( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartDialysateTargetConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicarbKpGainCoefficient function gets the Kp Gain for closed loop + * bicarb mix volume control + * @details \b Inputs: dryBiCartBicarbMixVolumeKpGain + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getBicarbKpGainCoefficient( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolumeKpGain ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicarbKiGainCoefficient function gets the Kp Gain for closed loop + * bicarb mix volume control + * @details \b Inputs: dryBiCartBicarbMixVolumeKiGain + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getBicarbKiGainCoefficient( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolumeKiGain ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAcidKpGainCoefficient function gets the Kp Gain for closed loop + * acid mix volume control + * @details \b Inputs: dryBiCartAcidMixVolumeKpGain + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getAcidKpGainCoefficient( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartAcidMixVolumeKpGain ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getAcidKiGainCoefficient function gets the Ki Gain for closed loop + * acid mix volume control + * @details \b Inputs: dryBiCartAcidMixVolumeKiGain + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getAcidKiGainCoefficient( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartAcidMixVolumeKiGain ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getDryBicartUpperCartPressure function gets the bicart upper threshold pressure + * @details \b Inputs: dryBiCartUpperCartPressure + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getDryBicartUpperCartPressure( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartUpperCartPressure ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getDryBicartLowerCartPressure function gets the bicart lower threshold pressure + * @details \b Inputs: dryBiCartLowerCartPressure + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getDryBicartLowerCartPressure( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartLowerCartPressure ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getDryBicartMixControlInterval function gets the bicart mix control interval + * @details \b Inputs: dryBiCartMixControlInterval + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +static F32 getDryBicartMixControlInterval( void ) +{ + F32 result = getF32OverrideValue( &dryBiCartMixControlInterval ); + + return result; +} + +/*********************************************************************//** + * @brief + * The handleDialysateOpenLoopState function handles the dialysate open loop state of + * the dialysate mix controller state machine. + * @details \b Inputs: D17_COND, D29_COND + * @details \b Outputs: none + * @param mixId dialysate mix id to run the dialysate mix + * @return next state for the controller state machine + *************************************************************************/ +static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ) +{ + DIALYSATE_MIXING_STATE_T result; + + if ( BICARB_MIX_ID == mixId ) + { + result = DIALYSATE_MIXING_OPEN_LOOP_STATE; + F32 measuredBicarbConductivity = getFilteredConductivity( D17_COND ); + // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop + if ( measuredBicarbConductivity >= ( getBicarbTargetConductivity() - getBicarbDeltaConductivity() ) ) + { + result = DIALYSATE_MIXING_RAMP_UP_STATE; + } + } + else if ( ACID_MIX_ID == mixId ) + { + result = DIALYSATE_MIXING_OPEN_LOOP_STATE; + F32 measuredAcidBicarbMixConductivity = getFilteredConductivity( D27_COND ); + + // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop + if ( measuredAcidBicarbMixConductivity >= ( getAcidBicarbTargetConductivity() - getAcidBicarbDeltaConductivity() ) ) + { + result = DIALYSATE_MIXING_RAMP_UP_STATE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The handleDialysatePumpRampToTargetState function handles the dialysate ramp to target state of + * the dialysate mix controller state machine. + * @details \b Inputs: none + * @details \b Outputs: none + * @param mixId mix id to + * @return next state for the controller state machine + *************************************************************************/ +static DIALYSATE_MIXING_STATE_T handleDialysateMixRampToTargetState( DIALYSATE_MIXING_ID_T mixId ) +{ + DIALYSATE_MIXING_STATE_T state = DIALYSATE_MIXING_RAMP_UP_STATE; + + if ( BICARB_MIX_ID == mixId ) + { + resetPIController( PI_CONTROLLER_ID_BICARB_VOL, DEFAULT_BICARB_VOLUME_ML, MIX_NO_FEED_FORWARD ); + + state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; + } + else if ( ACID_MIX_ID == mixId ) + { + resetPIController( PI_CONTROLLER_ID_ACID_VOL, DEFAULT_ACID_VOLUME_ML, MIX_NO_FEED_FORWARD ); + + state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleDialysatePumpControlToTargetState function handles the control to + * target state of the dialysate mix controller state machine.. + * @details \b Inputs: D17_COND, D29_COND, controlTimerCounter + * @details \b Outputs:none + * @return next state of the controller state machine + *************************************************************************/ +static DIALYSATE_MIXING_STATE_T handleDialysateMixControlToTargetState( DIALYSATE_MIXING_ID_T mixId ) +{ + DIALYSATE_MIXING_STATE_T state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; + + // control at set minimum interval or interval is expired and balance chamber fill is complete + if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getDryBicartMixControlInterval() ) ) + { + dialysateMix[ mixId ].controlTimerCounter = 0; + + // Control based on the measured and target conductivity + if ( BICARB_MIX_ID == mixId ) + { + PI_CONTROLLER_SIGNALS_DATA debugBicarbControl; + F32 measuredBicarbConductivity; + + measuredBicarbConductivity = getFilteredConductivity( D17_COND ); + F32 bicarbMixVol = runPIController( PI_CONTROLLER_ID_BICARB_VOL, getBicarbTargetConductivity(), measuredBicarbConductivity ); + //Set bicarb dosing vol + setBicarbMixVol( bicarbMixVol ); + + debugBicarbControl = getDebugPIControllerSignals( PI_CONTROLLER_ID_BICARB_VOL ); + + memcpy( (void*)&bicarbControlSignals, (void*)&debugBicarbControl, sizeof(PI_CONTROLLER_SIGNALS_DATA) ); + } + // ACID Mix + else if ( ACID_MIX_ID == mixId ) + { + F32 measuredAcidBicarbMixConductivity; + PI_CONTROLLER_SIGNALS_DATA debugAcidControl; + + measuredAcidBicarbMixConductivity = getFilteredConductivity( D27_COND ); + + F32 acidMixVol = runPIController( PI_CONTROLLER_ID_ACID_VOL, getAcidBicarbTargetConductivity(), measuredAcidBicarbMixConductivity ); + //Set acid dosing vol + setAcidMixVol( acidMixVol ); + + debugAcidControl = getDebugPIControllerSignals( PI_CONTROLLER_ID_ACID_VOL ); + + memcpy( (void*)&acidControlSignals, (void*)&debugAcidControl, sizeof(PI_CONTROLLER_SIGNALS_DATA) ); + } + } + + return state; +} + +/*********************************************************************//** + * @brief * The updateDrybicartOperation function initiates the water fill, bicarbonate supply or bicarbonate drain * operation * @details \b Inputs: none @@ -602,8 +1174,8 @@ //if(FP_MODE_GENP == getCurrentFPOperationMode()) { // TODO: pre gen should start the D12 pump and D14 valve - setValveState( D14_VALV, VALVE_STATE_OPEN ); - setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); + //setValveState( D14_VALV, VALVE_STATE_OPEN ); + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM_B1_9_B2_0, TRUE ); state = DRY_BICART_FILL_WATER_START_STATE; } @@ -798,6 +1370,9 @@ // TODO: implement the broadcast message for fill complete if ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_COMPLETE_TIME_MS ) ) { + currentFillDurationInMS = 0; + lastFillDurationInMS = 0; + biCartFillCycleCounter = 0; // Go idle dryBiCartFillRequested.data = FALSE; // for this request override also cleared @@ -875,7 +1450,7 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + if ( d66Pressure >= getDryBicartUpperCartPressure() ) { // Close water inlet valve as D66 pressure reaches 15 PSI. setValveState( D65_VALV, VALVE_STATE_CLOSED ); @@ -896,13 +1471,13 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCheckLevelState( void ) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_CHECK_LEVEL_STATE; - LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); // TODO: Confirm D80 open on chamber low or end of balancing chamber switching? // TODO: Enable the below code once level sensor is working //if ( LEVEL_STATE_LOW == bicarbChamberLevel ) - //{ - if ( getBalancingChamberFillinProgressStatus() == FALSE ) + { + // if ( getBalancingChamberFillinProgressStatus() == FALSE ) { // Open the Bicarb chamber inlet valve setValveState( D80_VALV, VALVE_STATE_OPEN ); @@ -912,7 +1487,8 @@ state = BICARB_CHAMBER_FILL_STATE; } - //} + } + // TODO: alarm return state; } @@ -929,7 +1505,7 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_FILL_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); // Once level reached, close the valve if ( LEVEL_STATE_HIGH == bicarbChamberLevel ) @@ -938,11 +1514,15 @@ state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; } // Open water inlet valve to fill the bicart - else if ( d66Pressure <= DRY_BICART_FILL_INITIATE_PRESSURE ) + else if ( d66Pressure <= getDryBicartLowerCartPressure() ) { setValveState( D65_VALV, VALVE_STATE_OPEN ); state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; } + else + { + state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; + } return state; } @@ -959,10 +1539,10 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); // Once level reached, close the valve - if ( ( LEVEL_STATE_HIGH == bicarbChamberLevel ) || + if ( ( LEVEL_STATE_HIGH == bicarbChamberLevel ) || ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); @@ -971,12 +1551,14 @@ dryBiCarbSypplyVentStartTime = getMSTimerCount(); state = BICARB_SUPPLY_VENT_START_STATE; } - + /*else if ( d66Pressure <= getDryBicartLowerCartPressure() ) + { + setValveState( D65_VALV, VALVE_STATE_OPEN ); } // Close water inlet valve as fill is complete. - if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + else if ( d66Pressure >= getDryBicartUpperCartPressure() ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); - } + }*/ return state; } @@ -992,18 +1574,64 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; + float setpoint; + U32 startTime; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + F32 tmpD66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + setpoint = d66Pressure - 1.0; + + if ( ( d66Pressure > DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE ) ) { + setValveState( D64_VALV, VALVE_STATE_OPEN ); + state = BICARB_SUPPLY_VENT_END_STATE; + } + + //if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, 10 ) ) +#if 0 + while ( tmpD66Pressure >= getDryBicartLowerCartPressure() && tmpD66Pressure >= setpoint ) { + //setpoint = d66Pressure - 1.0; + + // Venting loop: stay open until target PSI is reached + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); + startTime = getMSTimerCount(); + while ( TRUE != didTimeout( startTime, 12 ) ) + { + } + // close the vallve + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); + startTime = getMSTimerCount(); + while ( TRUE != didTimeout( startTime, 100 ) ) + { + } + tmpD66Pressure = getFilteredPressure( D66_PRES ); + //sleep + } +#endif + else if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + { //Vent bicart after 1 sec setValveState( D85_VALV, VALVE_STATE_OPEN ); } - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) + else if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) { - //Vent chamber F after 3 sec + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + //Vent chamber F after 200 ms setValveState( D64_VALV, VALVE_STATE_OPEN ); dryBiCarbSypplyVentStartTime = getMSTimerCount(); + //state = BICARB_SUPPLY_VENT_END_STATE; + } + + // D66 pressure drops or time out + else if ( ( d66Pressure <= DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE ) /*|| + ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) )*/ ) + { + setValveState( D64_VALV, VALVE_STATE_OPEN ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCarbSypplyVentStartTime = getMSTimerCount(); state = BICARB_SUPPLY_VENT_END_STATE; } @@ -1022,12 +1650,12 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_END_STATE; - // close bicart vent and chamber f vent after 3 sec - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) + // close bicart vent and chamber f vent after 1 sec + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_CLOSED); - + //setValveState( D64_VALV, VALVE_STATE_CLOSED); + bicarbChamberFillRequested.data = FALSE; // for this request override also cleared bicarbChamberFillRequested.ovData = FALSE; @@ -1236,10 +1864,26 @@ data.bicarbChamberFillRequest = getU32OverrideValue( &bicarbChamberFillRequested ); data.dryBiCartDrainRequest = getU32OverrideValue( &dryBiCartDrainRequested ); data.dryBiCartLastFillTime = lastFillDurationInMS; - data.dryBiCartCurrentFillTime = currentFillDurationInMS; + data.dryBiCartCurrentFillTime = currentFillDurationInMS; data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); data.dryBiCartDrainTimePeriod = dryBiCartDrainTimePeriod; - + + // TODO: remove after feature testing + memcpy( &data.dryBiCartBicarbDosingControl, &bicarbControlSignals, sizeof( PI_CONTROLLER_SIGNALS_DATA ) ); + // TODO: remove after feature testing + memcpy( &data.dryBiCartAcidDosingControl , &acidControlSignals , sizeof( PI_CONTROLLER_SIGNALS_DATA ) ); + + data.dryBiCartAcidMixVolume = getAcidMixVol(); + data.dryBiCartBicarbMixVolume = getBicarbMixVol(); + + // TODO: remove after feature testing + data.dryBiCartBicarbDosingKPgain = getBicarbKpGainCoefficient(); + // TODO: remove after feature testing + data.dryBiCartBicarbDosingKIgain = getBicarbKiGainCoefficient(); + + data.dryBiCartAcidDosingKPgain = getAcidKpGainCoefficient(); + data.dryBiCartAcidDosingKIgain = getAcidKiGainCoefficient(); + broadcastData( MSG_ID_DD_DRY_BICART_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DRY_BICART_DATA_T ) ); dryBiCartDataPublicationTimerCounter = 0; @@ -1352,4 +1996,225 @@ return result; } +/*********************************************************************//** + * @brief + * The testDryBiCartAcidMixVolumeOverride function sets the override value + * of the acid concentrate dosing volume. + * @details Inputs: dryBiCartAcidMixVolume + * @details Outputs: dryBiCartAcidMixVolume + * @param message Override message from Dialin which includes the override + * value to override the acid concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartAcidMixVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartAcidMixVolume ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartBicarbMixVolumeOverride function sets the override value + * of the bicarb concentrate dosing volume. + * @details Inputs: dryBiCartBicarbMixVolume + * @details Outputs: dryBiCartBicarbMixVolume + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartBicarbMixVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartBicarbMixVolume ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartBicarbMixVolControlKpGainOverride function sets the override value + * of the Kp gain coefficient for closed loop bicarb dosing volume control + * @details Inputs: dryBiCartBicarbMixVolumeKpGain + * @details Outputs: dryBiCartBicarbMixVolumeKpGain + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume kp gain. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartBicarbMixVolControlKpGainOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartBicarbMixVolumeKpGain ); + + initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ + getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ + MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartBicarbMixVolControlKiGainOverride function sets the override value + * of the Ki gain coefficient for closed loop bicarb concentrate dosing volume control + * @details Inputs: dryBiCartBicarbMixVolumeKiGain + * @details Outputs: dryBiCartBicarbMixVolumeKiGain + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume ki gain. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartBicarbMixVolControlKiGainOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartBicarbMixVolumeKiGain ); + + initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ + getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ + MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartAcidMoxVolControlKpGainOverride function sets the override value + * of the Kp gain coefficient for closed loop acid concentrate dosing volume control + * @details Inputs: dryBiCartAcidMixVolumeKpGain + * @details Outputs: dryBiCartAcidMixVolumeKpGain + * @param message Override message from Dialin which includes the override + * value to override the acid concentrate dosing volume kp gain. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartAcidMixVolControlKpGainOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartAcidMixVolumeKpGain ); + + initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ + getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ + MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartAcidMixVolControlKiGainOverride function sets the override value + * of the Ki gain coefficient for closed loop acid concentrate dosing volume control + * @details Inputs: dryBiCartAcidMixVolumeKiGain + * @details Outputs: dryBiCartAcidMixVolumeKiGain + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume ki gain. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartAcidMixVolControlKiGainOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartAcidMixVolumeKiGain ); + + initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ + getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ + MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartTargetConductivityOverride function sets the override value + * of target conductivity for closed loop control + * @details Inputs: dryBiCartTargetConductivity + * @details Outputs: dryBiCartTargetConductivity + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate target conductivity. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartTargetConductivityOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartBicarbTargetConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartDeltaConductivityOverride function sets the override value + * of delta target conductivity for closed loop control + * @details Inputs: dryBiCartDeltaConductivity + * @details Outputs: dryBiCartDeltaConductivity + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate delta target conductivity. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartDeltaConductivityOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartBicarbDeltaConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartAcidBicarbTargetConductivityOverride function sets the override value + * of acid bicarb mix target conductivity for closed loop control + * @details Inputs: dryBiCartAcidBicarbMixTargetConductivity + * @details Outputs: dryBiCartAcidBicarbMixTargetConductivity + * @param message Override message from Dialin which includes the override + * value to override the acid bicarb mix target conductivity. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartAcidBicarbTargetConductivityOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartDialysateTargetConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartAcidBicarbDeltaConductivityOverride function sets the override value + * of delta target conductivity for acid bicarb mix closed loop control + * @details Inputs: dryBiCartDeltaConductivity + * + * @details Outputs: dryBiCartDeltaConductivity + * @param message Override message from Dialin which includes the override + * value to override the acid bicarb mix target delta conductivity. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartAcidBicarbDeltaConductivityOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartDialysateDeltaConductivity ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartUpperCartPressureOverride function sets the override value + * of bicart upper cart pressure + * @details Inputs: dryBiCartUpperCartPressure + * @details Outputs: dryBiCartUpperCartPressure + * @param message Override message from Dialin which includes the override + * value to override the bicart upper cart pressure + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartUpperCartPressureOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartUpperCartPressure ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testDryBiCartLowerCartPressureOverride function sets the override value + * of Lowercart pressure + * @details Inputs: dryBiCartLowerCartPressure + * @details Outputs: dryBiCartLowerCartPressure + * @param message Override message from Dialin which includes the override + * value to override the bicart lower pressure. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDryBiCartLowerCartPressureOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &dryBiCartLowerCartPressure ); + + return result; +} + /**@}*/ Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -rccebe8df730dba8ad2d11e244a60788002a73b3b -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision ccebe8df730dba8ad2d11e244a60788002a73b3b) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -8,7 +8,7 @@ * @file Conductivity.c * * @author (last) Michael Garthwaite -* @date (last) 06-Mar-2026 +* @date (last) 15-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 13-Sep-2024 @@ -35,8 +35,8 @@ #define COND_SENSOR_REPORT_PERIOD ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Broadcast conductivity values message every second. #define COND_SENSOR_UPDATE_INTERVAL ( 700 / TASK_PRIORITY_INTERVAL ) ///< Time in task intervals for new sensor data #define DATA_PUBLISH_COUNTER_START_COUNT 40 ///< Data publish counter start count. -#define CONDUCTIVITY_SAMPLE_FILTER_MS ( 30 ) ///< Filter conductivity data for given time -#define CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS ( 30 ) ///< Filter conductivity temperature data for given time +#define CONDUCTIVITY_SAMPLE_FILTER_MS ( 50 ) ///< Filter conductivity data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) +#define CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS ( 50 ) ///< Filter conductivity temperature data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) #define SIZE_OF_COND_ROLLING_AVG ( CONDUCTIVITY_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity moving average sample count. #define SIZE_OF_COND_TEMP_ROLLING_AVG ( CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity temprature moving average sample count. #define RO_RR_MOVING_AVG_NUM_OF_SAMPLES 30 ///< RO rejection ratio moving average number of samples. @@ -63,9 +63,11 @@ // ********** private data ********** -static FILTER_CONDUCTIVITY_READINGS_T filteredConductivityReadings[NUM_OF_CONDUCTIVITY_SENSORS]; ///< Filtered conductivity reading for conductivity sensors. +static U08 condPrevReadCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Previous read count for conductivity per sensor +static U08 condTempPrevReadCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Previous read count for temperature per sensor. +static FILTER_CONDUCTIVITY_READINGS_T filteredConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Filtered conductivity reading for conductivity sensors. static OVERRIDE_F32_T filteredcurrentConductivityReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor conductivity readings (overrideable). -static FILTER_CONDUCTIVITY_TEMPERATURE_READINGS_T filteredConductivityTemperatureReadings[NUM_OF_CONDUCTIVITY_SENSORS]; ///< Filtered temperature reading for conductivity sensors. +static FILTER_CONDUCTIVITY_TEMPERATURE_READINGS_T filteredConductivityTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Filtered temperature reading for conductivity sensors. static OVERRIDE_F32_T filteredcurrentTemperatureReadings[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< filtered current conductivity sensor temperature readings (overrideable). static U32 ddConductivityPublishTimerCounter; ///< DD Conductivity data publication counter. static OVERRIDE_U32_T ddConductivityDataPublishInterval; ///< DD Conductivity sensors publish time interval override. @@ -107,11 +109,8 @@ { CONDUCTIVITY_SENSORS_T sensor; -#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ initConductivityTeensy(); -#else initConductivitySensors(); -#endif ddConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; fpConductivityPublishTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; @@ -152,6 +151,9 @@ filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsIdx = 0; filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsTotal = 0.0F; filteredConductivityTemperatureReadings[ sensor ].conductivityTempReadingsCount = 0; + + condPrevReadCount[ sensor ] = 0; + condTempPrevReadCount[ sensor ] = 0; } ddConductivityDataPublishInterval.data = COND_SENSOR_REPORT_PERIOD; @@ -182,19 +184,8 @@ void execConductivity( void ) { //read conductivity sensors raw value -#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ execConductivityTeensy(); -#else - readConductivitySensors(); -#endif - //control conductivity sensor - // TODO : need more clarity on why and when to execute following control. -#if 0 - handleConductivitySensorsReset(); - handleConductivitySensorsInitProcedure(); - execConductivitySensorWrite(); - execConductivitySensorRead(); -#endif + execConductivitySensors(); filterConductivitySensors(); calcRORejectionRatio(); // TODO: should this be called here or inside filter function @@ -260,34 +251,49 @@ static void filterConductivitySensorReadings( void ) { CONDUCTIVITY_SENSORS_T sensor; - F32 rawCond = 0.0F; + F32 calculatedConductivity = 0.0F; + BOOL freshData = FALSE; for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { -#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ - if (sensor != D74_COND ) + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) { - rawCond = getTeensyConductivityValue( sensor ); + if ( sensor != D74_COND ) + { + calculatedConductivity = getTeensyConductivityValue( sensor ); + freshData = TRUE; + } + else + { + calculatedConductivity = getConductivity( sensor ); + freshData = TRUE; + } } else { - rawCond = getConductivityValue( sensor ); + // Check FPGA read counts for freshness rather than wait on fix time. + if ( condPrevReadCount[ sensor ] != getConductivityReadCount( sensor ) ) + { + calculatedConductivity = getConductivity( sensor ); + condPrevReadCount[ sensor ] = getConductivityReadCount( sensor ); + freshData = TRUE; + } } -#else - rawCond = getConductivityValue( sensor ); -#endif - // TODO - calibrate - - if ( filteredConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_COND_ROLLING_AVG ) + // Apply sample to filter if we know it's fresh, v2/v3 only. V1's will always update filter regardless of freshness. + if ( TRUE == freshData ) { - filteredConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ]; + // TODO - calibrate + if ( filteredConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_COND_ROLLING_AVG ) + { + filteredConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ]; + } + filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ] = calculatedConductivity; + filteredConductivityReadings[ sensor ].conductivityReadingsTotal += calculatedConductivity; + filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); + filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); + filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; } - filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ] = rawCond; - filteredConductivityReadings[ sensor ].conductivityReadingsTotal += rawCond; - filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); - filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); - filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; } } @@ -332,34 +338,49 @@ static void filterConductivitySensorTemperatureReadings( void ) { CONDUCTIVITY_SENSORS_T sensor; - F32 rawTemp = 0.0F; + F32 calculatedTemperature = 0.0F; + BOOL freshData = FALSE; for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { -#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ - if (sensor != D74_COND ) + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) { - rawTemp = getTeensyConductivityTemperatureValue( sensor ); + if ( sensor != D74_COND ) + { + calculatedTemperature = getTeensyConductivityTemperatureValue( sensor ); + freshData = TRUE; + } + else + { + calculatedTemperature = getConductivityTemperature( sensor ); + freshData = TRUE; + } } else { - rawTemp = getConductivityTemperatureValue( sensor ); + // Check FPGA read counts for freshness rather than wait on fix time. + if ( condTempPrevReadCount[ sensor ] != getConductivityTemperatureReadCount( sensor ) ) + { + calculatedTemperature = getConductivityTemperature( sensor ); + condTempPrevReadCount[ sensor ] = getConductivityTemperatureReadCount( sensor ); + freshData = TRUE; + } } -#else - rawTemp = getConductivityTemperatureValue( sensor ); -#endif - // TODO - calibrate - - if ( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount >= SIZE_OF_COND_TEMP_ROLLING_AVG ) + // Apply sample to filter if we know it's fresh, v2/v3 only. V1's will always update filter regardless of freshness. + if ( TRUE == freshData ) { - filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal -= filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ]; + // TODO - calibrate + if ( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount >= SIZE_OF_COND_TEMP_ROLLING_AVG ) + { + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal -= filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ]; + } + filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ] = calculatedTemperature; + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal += calculatedTemperature; + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx = INC_WRAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx, 0, SIZE_OF_COND_TEMP_ROLLING_AVG - 1 ); + filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount = INC_CAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount, SIZE_OF_COND_TEMP_ROLLING_AVG ); + filteredcurrentTemperatureReadings[sensor].data = filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal / (F32)filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount; } - filteredConductivityTemperatureReadings[sensor].conductivityTempReadings[ filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx ] = rawTemp; - filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal += rawTemp; - filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx = INC_WRAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsIdx, 0, SIZE_OF_COND_TEMP_ROLLING_AVG - 1 ); - filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount = INC_CAP( filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount, SIZE_OF_COND_TEMP_ROLLING_AVG ); - filteredcurrentTemperatureReadings[sensor].data = filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsTotal / (F32)filteredConductivityTemperatureReadings[sensor].conductivityTempReadingsCount; } } @@ -703,4 +724,77 @@ return result; } +/*********************************************************************//** + * @brief + * The testConductivitySensorReadingsOverride function overrides the value of the + * specified conductivity sensor with a given value and determines which driver + * override. + * @details \b Inputs: testConfig + * @details \b Outputs: none + * @param message Override message from Dialin which includes an sensor + * ID and override value of the conductivity sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConductivitySensorReadingsOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + + if ( payload.index != D74_COND ) + { + result = testTeensyConductivitySensorReadingsOverride( message ); + } + else + { + result = testConductivitySensorReadingsOverride( message ); + } + } + else + { + result = testConductivitySensorConductivityReadingsOverride( message ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testConductivitySensorTemperatureOverride function overrides the value of the + * specified conductivity sensor with a given value and determines which driver + * override. + * @details \b Inputs: testConfig + * @details \b Outputs: none + * @param message Override message from Dialin which includes an sensor + * ID and override value of the conductivity sensor. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testConductivitySensorTemperatureOverride( MESSAGE_T *message ) +{ + BOOL result = FALSE; + TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; + OVERRIDE_TYPE_T ovType = getOverrideArrayPayloadFromMessage( message, &payload ); + + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_2_0_HW ) != TRUE ) + { + + if ( payload.index != D74_COND ) + { + result = testTeensyConductivitySensorTemperatureReadingsOverride( message ); + } + else + { + result = testConductivitySensorTemperatureReadingsOverride( message ); + } + } + else + { + result = testConductivitySensorTemperatureReadingsOverride( message ); + } + + return result; +} /**@}*/ Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r9b2aa25492c9286b9c1d5b0f4ce9e3676d9ade84 -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 9b2aa25492c9286b9c1d5b0f4ce9e3676d9ade84) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -7,8 +7,8 @@ * * @file AlarmMgmtSWFaults.h * -* @author (last) Raghu Kallala -* @date (last) 23-Feb-2026 +* @author (last) Vinayakam Mani +* @date (last) 14-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 07-Aug-2024 @@ -120,7 +120,7 @@ SW_FAULT_ID_TEMPERATURE_SENSORS_EXEC_INVALID_STATE = 89, SW_FAULT_ID_PI_CTRL_INVALID_CONTROLLER = 90, SW_FAULT_ID_PI_CTRL_INVALID_SIGNAL = 91, - SW_FAULT_ID_PI_CTRL_INVALID_STEP_LIMIT = 92, + SW_FAULT_ID_AVAILABALE_1 = 92, SW_FAULT_ID_DIALYSATE_PUMP_INVALID_RPM_SELECTED = 93, SW_FAULT_ID_DIALYSATE_PUMP_EXEC_INVALID_STATE = 94, SW_FAULT_ID_DIALYSATE_PUMP_INVALID_PUMP_ID = 95, @@ -153,8 +153,10 @@ SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE = 122, SW_FAULT_ID_DRY_BICART_DRAIN_INVALID_EXEC_STATE = 123, SW_FAULT_ID_INVALID_RINSE_PUMP = 124, - SW_FAULT_ID_PI_CTRL_INVALID_FEED_FORWARD_LIMIT = 125, - SW_FAULT_ID_DIALYSATE_MIX_EXEC_INVALID_STATE = 126, + SW_FAULT_ID_CONDUCTIVITY_SENSOR_CAL_CHECK = 125, + SW_FAULT_ID_PI_CTRL_INVALID_FEED_FORWARD_LIMIT = 126, + SW_FAULT_ID_INVALID_TEMPERATURE_SENSOR_SELECTED3 = 127, + SW_FAULT_ID_DIALYSATE_MIX_EXEC_INVALID_STATE = 128, NUM_OF_SW_FAULT_IDS } DD_SW_FAULT_ID_T; Index: firmware/App/Services/FpgaDD.c =================================================================== diff -u -rc9c9b1bade37555a0f226b9cc24529410325e3ed -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision c9c9b1bade37555a0f226b9cc24529410325e3ed) +++ firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -8,8 +8,8 @@ * * @file FpgaDD.c * -* @author (last) Jashwant Gantyada -* @date (last) 17-Mar-2026 +* @author (last) Michael Garthwaite +* @date (last) 15-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 26-Aug-2024 @@ -61,7 +61,8 @@ #define FPGA_EXPECTED_ID 0x06 ///< FPGA expected ID for Beta 2 systems. //TODO: Remove once Beta 1.9 is obsolete -#define FPGA_BETA_1_9_EXPECTED_ID 0X04 ///< FPGA expected ID for Beta 1 and 1.9 systems. +#define FPGA_BETA_1_9_EXPECTED_ID 0x08 ///< FPGA expected ID for Beta 1.9 systems. +#define FPGA_BETA_1_0_EXPECTED_ID 0x04 ///< FPGA expected ID for Beta 1.0 systems. #define MAX_COMM_ERROR_RETRIES 5 ///< Maximum number of communication error retries @@ -401,59 +402,59 @@ U32 fpgaD11PumpHallSense; ///< Reg 690. Concentrate pump D11_Pump hall sensor pulse width U32 fpgaD10PumpHallSense; ///< Reg 694. Concentrate pump D10_Pump hall sensor pulse width U32 fpgaD76PumpHallSense; ///< Reg 698. Concentrate pump D76_Pump hall sensor pulse width - U32 fpgaD17CondDataCal; ///< Reg 702. D17 CAL word update - U32 fpgaD17CondCond; ///< Reg 706. D17 conductivity - U32 fpgaD17CondTemp; ///< Reg 710. D17 Temperature + U32 fpgaD17DataCal; ///< Reg 702. D17 CAL word update + F32 fpgaD17CondResistance; ///< Reg 706. D17 conductivity resistance + F32 fpgaD17TempResistance; ///< Reg 710. D17 Temperature resistance U08 fpgaD17CondReadCnt; ///< Reg 714. D17 successful read count U08 fpgaD17CondErrorCnt; ///< Reg 715. D17 error read count U08 fpgaD17TempReadCount; ///< Reg 716. D17 temperature successful read count U08 fpgaD17TempErrorCount; ///< Reg 717. D17 Temperature error read count U08 fpgaD17CalMemCounter; ///< Reg 718. D17 CAL counter U08 fpgaD74CalMemCounter; ///< Reg 719. D74 CAL counter - U32 fpgaD74CondDataCal; ///< Reg 720. D74 CAL word update - U32 fpgaD74CondCond; ///< Reg 724. D74 conductivity - U32 fpgaD74CondTemp; ///< Reg 728. D74 Temperature + U32 fpgaD74DataCal; ///< Reg 720. D74 CAL word update + F32 fpgaD74CondResistance; ///< Reg 724. D74 conductivity resistance + F32 fpgaD74TempResistance; ///< Reg 728. D74 Temperature resistance U08 fpgaD74CondReadCnt; ///< Reg 732. D74 successful read count U08 fpgaD74CondErrorCnt; ///< Reg 733. D74 error read count U08 fpgaD74TempReadCount; ///< Reg 734. D74 temperature successful read count U08 fpgaD74TempErrorCount; ///< Reg 735. D74 Temperature error read count - U32 fpgaD27CondDataCal; ///< Reg 736. D27 CAL word update - U32 fpgaD27CondCond; ///< Reg 740. D27 conductivity - U32 fpgaD27CondTemp; ///< Reg 744. D27 Temperature + U32 fpgaD27DataCal; ///< Reg 736. D27 CAL word update + F32 fpgaD27CondResistance; ///< Reg 740. D27 conductivity resistance + F32 fpgaD27TempResistance; ///< Reg 744. D27 Temperature reistance U08 fpgaD27CondReadCnt; ///< Reg 748. D27 successful read count U08 fpgaD27CondErrorCnt; ///< Reg 749. D27 error read count U08 fpgaD27TempReadCount; ///< Reg 750. D27 temperature successful read count U08 fpgaD27TempErrorCount; ///< Reg 751. D27 Temperature error read count U08 fpgaD27CalMemCounter; ///< Reg 752. D27 CAL counter U08 fpgaD29CalMemCounter; ///< Reg 753. D29 CAL counter - U32 fpgaD29CondDataCal; ///< Reg 754. D29 CAL word update - U32 fpgaD29CondCond; ///< Reg 758. D29 conductivity - U32 fpgaD29CondTemp; ///< Reg 762. D29 Temperature + U32 fpgaD29DataCal; ///< Reg 754. D29 CAL word update + F32 fpgaD29CondResistance; ///< Reg 758. D29 conductivity resistance + F32 fpgaD29TempResistance; ///< Reg 762. D29 Temperature resistance U08 fpgaD29CondReadCnt; ///< Reg 766. D29 successful read count U08 fpgaD29CondErrorCnt; ///< Reg 767. D29 error read count U08 fpgaD29TempReadCount; ///< Reg 768. D29 temperature successful read count U08 fpgaD29TempErrorCount; ///< Reg 769. D29 Temperature error read count - U32 fpgaD43CondDataCal; ///< Reg 770. D43 CAL word update - U32 fpgaD43CondCond; ///< Reg 774. D43 conductivity - U32 fpgaD43CondTemp; ///< Reg 778. D43 Temperature + U32 fpgaD43DataCal; ///< Reg 770. D43 CAL word update + F32 fpgaD43CondResistance; ///< Reg 774. D43 conductivity resistance + F32 fpgaD43TempResistance; ///< Reg 778. D43 Temperature resistance U08 fpgaD43CondReadCnt; ///< Reg 782. D43 successful read count U08 fpgaD43CondErrorCnt; ///< Reg 783. D43 error read count U08 fpgaD43TempReadCount; ///< Reg 784. D43 temperature successful read count U08 fpgaD43TempErrorCount; ///< Reg 785. D43 Temperature error read count U08 fpgaD43CalMemCounter; ///< Reg 786. D43 CAL counter U08 fpgaP9CalMemCounter; ///< Reg 787. P9 CAL counter - U32 conductivityP9Data; ///< Reg 788. P9 CAL word update - U32 conductivityP9Cond; ///< Reg 792. P9 Conductivity - U32 conductivityP9Temp; ///< Reg 796. P9 Temperature - U08 conductivityP9ReadCount; ///< Reg 800. P9 successful read count - U08 conductivityP9ErrorCount; ///< Reg 801. P9 error read count + U32 fpgaP9CalData; ///< Reg 788. P9 CAL word update + F32 fpgaP9CondResistance; ///< Reg 792. P9 Conductivity resistance + F32 fpgaP9TempResistance; ///< Reg 796. P9 Temperature resistance + U08 fpgaP9CondReadCount; ///< Reg 800. P9 successful read count + U08 fpgaP9CondErrorCount; ///< Reg 801. P9 error read count U08 fpgaP9TempReadCount; ///< Reg 802. P9 temperature successful read count U08 fpgaP9TempErrorCount; ///< Reg 803. P9 Temperature error read count - U32 conductivityP18Data; ///< Reg 804. P18 CAL word update - U32 conductivityP18Cond; ///< Reg 808. P18 Conductivity - U32 conductivityP18Temp; ///< Reg 812. P18 Temperature - U08 conductivityP18ReadCount; ///< Reg 816. P18 successful read count - U08 conductivityP18ErrorCount; ///< Reg 817. P18 error read count + U32 fpgaP18CalData; ///< Reg 804. P18 CAL word update + F32 fpgaP18CondResistance; ///< Reg 808. P18 Conductivity resistance + F32 fpgaP18TempReistance; ///< Reg 812. P18 Temperature resistance + U08 fpgaP18CondReadCount; ///< Reg 816. P18 successful read count + U08 fpgaP18CondErrorCount; ///< Reg 817. P18 error read count U08 fpgaP18TempReadCount; ///< Reg 818. P18 temperature successful read count U08 fpgaP18TempErrorCount; ///< Reg 819. P18 Temperature error read count U08 fpgaP18CalMemCounter; ///< Reg 820. P18 CAL counter @@ -642,7 +643,7 @@ *************************************************************************/ void initFPGADD( void ) { - // Initialize fpga driver + // Initialize fpga driver for beta 2 hardware initFPGA( (U08*)&fpgaHeader, (U08*)&fpgaBeta19SensorReadings, (U08*)&fpgaBeta19ActuatorSetPoints, sizeof(FPGA_HEADER_T), sizeof(DD_FPGA_SENSORS_BETA_1_9_T), sizeof(FPGA_ACTUATORS_BETA_1_9_T) ); @@ -717,7 +718,8 @@ // check FPGA reported correct ID // TODO: Remove beta 1.9 expected ID once Beta 1.9 is obsolete - if ( ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) || ( FPGA_BETA_1_9_EXPECTED_ID == fpgaHeader.fpgaId ) ) + if ( ( FPGA_EXPECTED_ID == fpgaHeader.fpgaId ) || ( FPGA_BETA_1_9_EXPECTED_ID == fpgaHeader.fpgaId ) || + ( FPGA_BETA_1_0_EXPECTED_ID == fpgaHeader.fpgaId ) ) { // Check FPGA compatibility w/ firmware if ( DD_FPGA_COMPATIBILITY_REV == GET_FPGA_SENSOR_FIELD( fpgaCompatibilityRev ) ) @@ -1302,744 +1304,6 @@ /*********************************************************************//** * @brief - * The setFPGAD17CondReset function resets the FPGA Conductivity - * Sensor D17. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD17CondReset( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D17_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD17CondReset function clears the reset of FPGA Conductivity - * Sensor D17. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD17CondReset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D17_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD17CondInitEnable function enables the FPGA Conductivity - * Sensor D17 initialzation procedure. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD17CondInitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D17_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD17CondInitEnable function clears the init process of FPGA Conductivity - * Sensor D17. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD17CondInitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D17_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD17CondWriteEnable function enables the FPGA Conductivity - * Sensor D17 write transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @warning: The address (setFPGAD17D74Address) and data (setFPGACD12Data) register - * must be populated before invoking this write enable function to initiate - * write transaction with the sensor. - * @return none - *************************************************************************/ -void setFPGAD17CondWriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D17_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD17CondWriteEnable function clears the write enable of FPGA Conductivity - * Sensor D17. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD17CondWriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D17_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD17CondReadEnable function enables the FPGA Conductivity - * Sensor D17 read transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @warning: The address (setFPGAD17D74Address) register must be populated - * before invoking this read enable function to initiate read transaction - * with the sensor. - * @return none - *************************************************************************/ -void setFPGAD17CondReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D17_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD17CondReadEnable function clears the read enable of FPGA Conductivity - * Sensor D17. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD17CondReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D17_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27CondReset function resets the FPGA Conductivity - * Sensor D27. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD27CondReset( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D27_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD27CondReset function clears the reset of FPGA Conductivity - * Sensor D27. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD27CondReset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D27_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27CondInitEnable function enables the FPGA Conductivity - * Sensor D27 initialzation procedure. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD27CondInitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D27_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD27CondInitEnable function clears the init process of FPGA Conductivity - * Sensor D27. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD27CondInitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D27_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27CondWriteEnable function enables the FPGA Conductivity - * Sensor D27 write transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @warning: The address (setFPGACD12Address) and data (setFPGACD12Data) register - * must be populated before invoking this write enable function to initiate - * write transaction with the sensor. - * @return none - *************************************************************************/ -void setFPGAD27CondWriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D27_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD27CondWriteEnable function clears the write enable of FPGA Conductivity - * Sensor D27. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD27CondWriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D27_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27CondReadEnable function enables the FPGA Conductivity - * Sensor D27 read transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @warning: The address (setFPGACD12Address) register must be populated - * before invoking this read enable function to initiate read transaction - * with the sensor. - * @return none - *************************************************************************/ -void setFPGAD27CondReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D27_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD27CondReadEnable function clears the read enable of FPGA Conductivity - * Sensor D27. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD27CondReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D27_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGD29CondReset function resets the FPGA Conductivity - * Sensor D29. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD29CondReset( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D29_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD29CondReset function clears the reset of FPGA Conductivity - * Sensor D29. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD29CondReset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D29_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD29CondInitEnable function enables the FPGA Conductivity - * Sensor D29 initialzation procedure. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD29CondInitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D29_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD29CondInitEnable function clears the init process of FPGA Conductivity - * Sensor D29. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD29CondInitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D29_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD29CondWriteEnable function enables the FPGA Conductivity - * Sensor D29 write transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @warning: The address (setFPGACD12Address) and data (setFPGACD12Data) register - * must be populated before invoking this write enable function to initiate - * write transaction with the sensor. - * @return none - *************************************************************************/ -void setFPGAD29CondWriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D29_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD29CondWriteEnable function clears the write enable of FPGA Conductivity - * Sensor D29. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD29CondWriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D29_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD29CondReadEnable function enables the FPGA Conductivity - * Sensor D29 read transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @warning: The address (setFPGACD12Address) register must be populated - * before invoking this read enable function to initiate read transaction - * with the sensor. - * @return none - *************************************************************************/ -void setFPGAD29CondReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, FPGA_D29_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD29CondReadEnable function clears the read enable of FPGA Conductivity - * Sensor D29. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD29CondReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD27D29Control, ~FPGA_D29_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43CondReset function resets the FPGA Conductivity - * Sensor D43. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD43CondReset( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, FPGA_D43_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD43CondReset function clears the reset of FPGA Conductivity - * Sensor D43. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD43CondReset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, ~FPGA_D43_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43CondInitEnable function enables the FPGA Conductivity - * Sensor D43 initialzation procedure. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD43CondInitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, FPGA_D43_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD43CondInitEnable function clears the init process of FPGA Conductivity - * Sensor D43. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD43CondInitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, ~FPGA_D43_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43CondWriteEnable function enables the FPGA Conductivity - * Sensor D43 write transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @warning: The address (setFPGACD12Address) and data (setFPGACD12Data) register - * must be populated before invoking this write enable function to initiate - * write transaction with the sensor. - * @return none - *************************************************************************/ -void setFPGAD43CondWriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, FPGA_D43_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD43CondWriteEnable function clears the write enable of FPGA Conductivity - * Sensor D43. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD43CondWriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, ~FPGA_D43_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43CondReadEnable function enables the FPGA Conductivity - * Sensor D43 read transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @warning: The address (setFPGACD12Address) register must be populated - * before invoking this read enable function to initiate read transaction - * with the sensor. - * @return none - *************************************************************************/ -void setFPGAD43CondReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, FPGA_D43_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD43CondReadEnable function clears the read enable of FPGA Conductivity - * Sensor D43. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD43CondReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD43Control, ~FPGA_D43_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD74CondReset function resets the FPGA Conductivity - * Sensor D74. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD74CondReset( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D74_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD74CondReset function clears the reset of FPGA Conductivity - * Sensor D74. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD74CondReset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D74_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD74CondInitEnable function enables the FPGA Conductivity - * Sensor D74 initialzation procedure. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void setFPGAD74CondInitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D74_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD74CondInitEnable function clears the init process of FPGA Conductivity - * Sensor D74. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD74CondInitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D74_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD74CondWriteEnable function enables the FPGA Conductivity - * Sensor D74 write transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @warning: The address (setFPGACD74Address) and data (setFPGACD74Data) register - * must be populated before invoking this write enable function to initiate - * write transaction with the sensor. - * @return none - *************************************************************************/ -void setFPGAD74CondWriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D74_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD74CondWriteEnable function clears the write enable of FPGA Conductivity - * Sensor D74. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD74CondWriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D74_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD74CondReadEnable function enables the FPGA Conductivity - * Sensor D74 read transaction. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @warning: The address (setFPGACD74Address) register must be populated - * before invoking this read enable function to initiate read transaction - * with the sensor. - * @return none - *************************************************************************/ -void setFPGAD74CondReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, FPGA_D74_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAD74CondReadEnable function clears the read enable of FPGA Conductivity - * Sensor D74. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param none - * @return none - *************************************************************************/ -void clearFPGAD74CondReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( fpgaConSensD17D74Control, ~FPGA_D74_RD_ENABLE_BIT ); -} - - -/*********************************************************************//** - * @brief - * The setFPGAD17D74Control function sets the FPGA Conductivity - * Sensor control register for D17 and D74. - * bit 7: Enables D74 read transaction (1), address needed - * bit 6: Enables D74 write transaction (1), address and data needs to be set - * bit 5: Enable D74 Init procedure (1) - * bit 4: reset D74 Conduct sensor (1) - * bit 3: Enables D17 read transaction (1), address needed - * bit 2: Enables D17 write transaction (1), address and data needs to be set - * bit 1: Enable D17 Init procedure (1) - * bit 0: reset D17 Conduct sensor (1) - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74Control - * @param control Conductivity Sensor control set - * @return none - *************************************************************************/ -void setFPGAD17D74Control( U08 control ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD17D74Control, control ); -} - -/*********************************************************************//** - * @brief - * The setFpgaCD34Control function sets the FPGA Conductivity - * Sensor control register for D27 and D29. - * bit 7: Enables D29 read transaction (1), address needed - * bit 6: Enables D29 write transaction (1), address and data needs to be set - * bit 5: Enable D29 Init procedure (1) - * bit 4: reset D29 Conduct sensor (1) - * bit 3: Enables D27 read transaction (1), address needed - * bit 2: Enables D27 write transaction (1), address and data needs to be set - * bit 1: Enable D27 Init procedure (1) - * bit 0: reset D27 Conduct sensor (1) - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensTD34Control - * @param control Conductivity sensor control set - * @return none - *************************************************************************/ -void setFPGAD27D29Control( U08 control ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD27D29Control, control ); -} - -/*********************************************************************//** - * @brief - * The setFpgaCD5Control function sets the FPGA Conductivity - * Sensor control register for D43. - * bit 4- 7: Reserved. - * bit 3: Enables D43 read transaction (1), address needed - * bit 2: Enables D43 write transaction (1), address and data needs to be set - * bit 1: Enable D43 Init procedure (1) - * bit 0: reset D43 Conduct sensor (1) - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD74Control - * @param control Conductivity sensor control set - * @return none - *************************************************************************/ -void setFPGAD43Control( U08 control ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD43Control, control ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD17D74Address function sets the conductivity sensor - * CD12 address register to perform read and write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74_Addrs - * @param address The conductivity sensor D17 and D74 address - * @return none - *************************************************************************/ -void setFPGAD17D74Address( U16 address ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD17D74_Addrs, address ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27D29Address function sets the conductivity sensor - * CD34 address register to perform read and write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29_Addrs - * @param address The conductivity sensor CD34 address - * @return none - *************************************************************************/ -void setFPGAD27D29Address( U16 address ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD27D29_Addrs, address ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43Address function sets the conductivity sensor - * D74 address register to perform read and write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43_Addrs - * @param address The conductivity sensor D43 address - * @return none - *************************************************************************/ -void setFPGAD43Address( U16 address ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD43_Addrs, address ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD17D74Data function sets the conductivity sensor - * CD12 data outputfor write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD17D74_Data_In - * @param data The conductivity sensor D17 and D74 Data - * @return none - *************************************************************************/ -void setFPGAD17D74Data( U32 data ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD17D74_Data_In, data ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD27D29Data function sets the conductivity sensor - * CD34 data outputfor write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD27D29_Data_In - * @param data The conductivity sensor D27 and D29 Data - * @return none - *************************************************************************/ -void setFPGAD27D29Data( U32 data ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD27D29_Data_In, data ); -} - -/*********************************************************************//** - * @brief - * The setFPGAD43Data function sets the conductivity sensor - * D43 data output for write operations. - * @details \b Inputs: none - * @details \b Outputs: fpgaConSensD43_Data_In - * @param data The conductivity sensor D43 Data - * @return none - *************************************************************************/ -void setFPGAD43Data( U32 data ) -{ - SET_FPGA_ACTUATOR_FIELD( fpgaConSensD43_Data_In, data ); -} - -/*********************************************************************//** - * @brief * The setFPGAD5HeaterPWMControl function sets the primary heater * PWM input. * @details \b Inputs: none @@ -2773,7 +2037,7 @@ *************************************************************************/ U08 getFPGAD17CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD17CondReadCnt ); + return fpgaSensorReadings.fpgaD17CondReadCnt; } /*********************************************************************//** @@ -2785,31 +2049,43 @@ *************************************************************************/ U08 getFPGAD17CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD17CondErrorCnt ); + return fpgaSensorReadings.fpgaD17CondErrorCnt; } /*********************************************************************//** * @brief - * The getFPGAD17Cond function gets D17 conductivity sensor value. - * @details \b Inputs: fpgaCD1 + * The getFPGAD17TempReadCount function gets the D17 (D16) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaD17TempReadCount * @details \b Outputs: none - * @return Latest D17 conductivity sensor value + * @return D17 (D16) Temperature sensor read count *************************************************************************/ -U16 getFPGAD17Cond( void ) +U08 getFPGAD17TempReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD17CondCond ); + return fpgaSensorReadings.fpgaD17TempReadCount; } /*********************************************************************//** * @brief + * The getFPGAD17TempErrorCount function gets the D17 (D16) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaD17TempErrorCount + * @details \b Outputs: none + * @return D17 (D16) Temperature sensor error count + *************************************************************************/ +U08 getFPGAD17TempErrorCount( void ) +{ + return fpgaSensorReadings.fpgaD17TempErrorCount; +} + +/*********************************************************************//** + * @brief * The getFPGAD17CondTemp function gets D17 conductivity sensor temperature value. * @details \b Inputs: fpgaCD1Temp * @details \b Outputs: none * @return Latest D17 conductivity sensor temperature value *************************************************************************/ -U16 getFPGAD17CondTemp( void ) +F32 getFPGAD17CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD17CondTemp ); + return fpgaSensorReadings.fpgaD17TempResistance; } /*********************************************************************//** @@ -2819,21 +2095,44 @@ * @details \b Outputs: none * @return Latest D17 conductivity sensor register data value *************************************************************************/ -U32 getFPGAD17CondData( void ) +F32 getFPGAD17CondData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD17CondCond ); + return fpgaSensorReadings.fpgaD17CondResistance; } /*********************************************************************//** * @brief + * The getFPGAD17CondData function gets the D17 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaD17DataCal + * @details \b Outputs: none + * @return D17 calibration data + *************************************************************************/ +U32 getFPGAD17CondCalData( void ) +{ + return fpgaSensorReadings.fpgaD17DataCal; +} + +/*********************************************************************//** + * @brief + * The getFPGAD17CalMemCounter function gets the D17 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaD17CalMemCounter + * @details \b Outputs: none + * @return D17 memory count + *************************************************************************/ +U08 getFPGAD17CalMemCounter( void ) +{ + return fpgaSensorReadings.fpgaD17CalMemCounter; +} +/*********************************************************************//** + * @brief * The getFPGAD27CondReadCount function gets D27 conductivity sensor read count. * @details \b Inputs: fpgaD27CondReadCnt * @details \b Outputs: none * @return Latest D27 conductivity sensor read count *************************************************************************/ U08 getFPGAD27CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD27CondReadCnt ); + return fpgaSensorReadings.fpgaD27CondReadCnt; } /*********************************************************************//** @@ -2845,19 +2144,43 @@ *************************************************************************/ U08 getFPGAD27CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD27CondErrorCnt ); + return fpgaSensorReadings.fpgaD27CondErrorCnt; } /*********************************************************************//** * @brief - * The getFPGAD27Cond function gets D27 conductivity sensor value. - * @details \b Inputs: fpgaD27Cond + * The getFPGAD27TempReadCount function gets the D27 (D28) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaD27TempReadCount * @details \b Outputs: none + * @return D27 (D28) Temperature sensor read count + *************************************************************************/ +U08 getFPGAD27TempReadCount( void ) +{ + return fpgaSensorReadings.fpgaD27TempReadCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAD27TempErrorCount function gets the D27 (D28) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaD27TempErrorCount + * @details \b Outputs: none + * @return D27 (D28) Temperature sensor error count + *************************************************************************/ +U08 getFPGAD27TempErrorCount( void ) +{ + return fpgaSensorReadings.fpgaD27TempErrorCount; +} + +/*********************************************************************//** + * @brief + * The getFPGAD27CondData function gets D27 conductivity sensor value. + * @details \b Inputs: fpgaD27CondResistance + * @details \b Outputs: none * @return Latest D27 conductivity sensor value *************************************************************************/ -U16 getFPGAD27Cond( void ) +F32 getFPGAD27CondData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD27CondCond ); + return fpgaSensorReadings.fpgaD27CondResistance; } /*********************************************************************//** @@ -2867,33 +2190,45 @@ * @details \b Outputs: none * @return Latest D27 conductivity sensor temperature value *************************************************************************/ -U16 getFPGAD27CondTemp( void ) +F32 getFPGAD27CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD27CondTemp ); + return fpgaSensorReadings.fpgaD27TempResistance; } /*********************************************************************//** * @brief - * The getFPGAD27CondData function gets D27 conductivity sensor register value. - * @details \b Inputs: fpgaD27CondDataOut + * The getFPGAD27CondCalData function gets the D27 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaD27DataCal * @details \b Outputs: none - * @return Latest D27 conductivity sensor register data value + * @return D27 calibration data *************************************************************************/ -U32 getFPGAD27CondData( void ) +U32 getFPGAD27CondCalData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD27CondCond ); + return fpgaSensorReadings.fpgaD27DataCal; } /*********************************************************************//** * @brief + * The getFPGAD27CalMemCounter function gets the D27 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaD27CalMemCounter + * @details \b Outputs: none + * @return D27 memory count + *************************************************************************/ +U08 getFPGAD27CalMemCounter( void ) +{ + return fpgaSensorReadings.fpgaD27CalMemCounter; +} + +/*********************************************************************//** + * @brief * The getFPGAD29CondReadCount function gets D29 conductivity sensor read count. * @details \b Inputs: fpgaD29CondReadCnt * @details \b Outputs: none * @return Latest D29 conductivity sensor read count *************************************************************************/ U08 getFPGAD29CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD29CondReadCnt ); + return fpgaSensorReadings.fpgaD29CondReadCnt; } /*********************************************************************//** @@ -2905,55 +2240,90 @@ *************************************************************************/ U08 getFPGAD29CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD29CondErrorCnt ); + return fpgaSensorReadings.fpgaD29CondErrorCnt; } /*********************************************************************//** * @brief - * The getFPGAD29Cond function gets D29 conductivity sensor value. - * @details \b Inputs: fpgaD29Cond + * The getFPGAD29TempReadCount function gets the D29 (D28) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaD29TempReadCount * @details \b Outputs: none - * @return Latest D29 conductivity sensor value + * @return D29 (D28) Temperature sensor read count *************************************************************************/ -U16 getFPGAD29Cond( void ) +U08 getFPGAD29TempReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD29CondCond ); + return fpgaSensorReadings.fpgaD29TempReadCount; } /*********************************************************************//** * @brief + * The getFPGAD29TempErrorCount function gets the D29 (D28) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaD29TempErrorCount + * @details \b Outputs: none + * @return D29 (D28) Temperature sensor error count + *************************************************************************/ +U08 getFPGAD29TempErrorCount( void ) +{ + return fpgaSensorReadings.fpgaD29TempErrorCount; +} +/*********************************************************************//** + * @brief * The getFPGAD29CondTemp function gets D29 conductivity sensor temperature value. - * @details \b Inputs: fpgaD29CondTemp + * @details \b Inputs: fpgaD29TempResistance * @details \b Outputs: none * @return Latest D29 conductivity sensor temperature value *************************************************************************/ -U16 getFPGAD29CondTemp( void ) +F32 getFPGAD29CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD29CondTemp ); + return fpgaSensorReadings.fpgaD29TempResistance; } /*********************************************************************//** * @brief * The getFPGAD29CondData function gets D29 conductivity sensor register value. - * @details \b Inputs: fpgaD29CondDataOut + * @details \b Inputs: fpgaD29CondResistance * @details \b Outputs: none * @return Latest D29 conductivity sensor register data value *************************************************************************/ -U32 getFPGAD29CondData( void ) +F32 getFPGAD29CondData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD29CondCond ); + return fpgaSensorReadings.fpgaD29CondResistance; } /*********************************************************************//** * @brief + * The getFPGAD29CondCalData function gets the D29 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaD29DataCal + * @details \b Outputs: none + * @return D29 calibration data + *************************************************************************/ +U32 getFPGAD29CondCalData( void ) +{ + return fpgaSensorReadings.fpgaD29DataCal; +} + +/*********************************************************************//** + * @brief + * The getFPGAD29CalMemCounter function gets the D29 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaD29CalMemCounter + * @details \b Outputs: none + * @return D29 memory count + *************************************************************************/ +U08 getFPGAD29CalMemCounter( void ) +{ + return fpgaSensorReadings.fpgaD29CalMemCounter; +} + +/*********************************************************************//** + * @brief * The getFPGAD43CondReadCount function gets D43 conductivity sensor read count. * @details \b Inputs: fpgaD43CondReadCnt * @details \b Outputs: none * @return Latest D43 conductivity sensor read count *************************************************************************/ U08 getFPGAD43CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD43CondReadCnt ); + return fpgaSensorReadings.fpgaD43CondReadCnt; } /*********************************************************************//** @@ -2965,31 +2335,43 @@ *************************************************************************/ U08 getFPGAD43CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD43CondErrorCnt ); + return fpgaSensorReadings.fpgaD43CondErrorCnt; } /*********************************************************************//** * @brief - * The getFPGAD43Cond function gets D43 conductivity sensor value. - * @details \b Inputs: fpgaD43Cond + * The getFPGAD43TempReadCount function gets the D43 (D44) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaD43TempReadCount * @details \b Outputs: none - * @return Latest D43 conductivity sensor value + * @return D43 (D44) Temperature sensor read count *************************************************************************/ -U16 getFPGAD43Cond( void ) +U08 getFPGAD43TempReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD43CondCond ); + return fpgaSensorReadings.fpgaD43TempReadCount; } /*********************************************************************//** * @brief + * The getFPGAD43TempErrorCount function gets the D43 (D44) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaD43TempErrorCount + * @details \b Outputs: none + * @return D43 (D44) Temperature sensor error count + *************************************************************************/ +U08 getFPGAD43TempErrorCount( void ) +{ + return fpgaSensorReadings.fpgaD43TempErrorCount; +} + +/*********************************************************************//** + * @brief * The getFPGAD43CondTemp function gets D43 conductivity sensor temperature value. * @details \b Inputs: fpgaD43CondTemp * @details \b Outputs: none * @return Latest D43 conductivity sensor temperature value *************************************************************************/ -U16 getFPGAD43CondTemp( void ) +F32 getFPGAD43CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD43CondTemp ); + return fpgaSensorReadings.fpgaD43TempResistance; } /*********************************************************************//** @@ -2999,21 +2381,45 @@ * @details \b Outputs: none * @return Latest D43 conductivity sensor register data value *************************************************************************/ -U32 getFPGAD43CondData( void ) +F32 getFPGAD43CondData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD43CondCond ); + return fpgaSensorReadings.fpgaD43CondResistance; } /*********************************************************************//** * @brief + * The getFPGAD43CondCalData function gets the D43 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaD43DataCal + * @details \b Outputs: none + * @return D43 calibration data + *************************************************************************/ +U32 getFPGAD43CondCalData( void ) +{ + return fpgaSensorReadings.fpgaD43DataCal; +} + +/*********************************************************************//** + * @brief + * The getFPGAD43CalMemCounter function gets the D43 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaD43CalMemCounter + * @details \b Outputs: none + * @return D43 memory count + *************************************************************************/ +U08 getFPGAD43CalMemCounter( void ) +{ + return fpgaSensorReadings.fpgaD43CalMemCounter; +} + +/*********************************************************************//** + * @brief * The getFPGAD74CondReadCount function gets D74 conductivity sensor read count. * @details \b Inputs: fpgaD74CondReadCnt * @details \b Outputs: none * @return Latest D74 conductivity sensor read count *************************************************************************/ U08 getFPGAD74CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD74CondReadCnt ); + return fpgaSensorReadings.fpgaD74CondReadCnt; } /*********************************************************************//** @@ -3025,31 +2431,43 @@ *************************************************************************/ U08 getFPGAD74CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD74CondErrorCnt ); + return fpgaSensorReadings.fpgaD74CondErrorCnt; } /*********************************************************************//** * @brief - * The getFPGAD74Cond function gets D74 conductivity sensor value. - * @details \b Inputs: fpgaD74Cond + * The getFPGAD74TempReadCount function gets the D74 (D75) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaD74TempReadCount * @details \b Outputs: none - * @return Latest D74 conductivity sensor value + * @return D74 (D75) Temperature sensor read count *************************************************************************/ -U16 getFPGAD74Cond( void ) +U08 getFPGAD74TempReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD74CondCond ); + return fpgaSensorReadings.fpgaD74TempReadCount; } /*********************************************************************//** * @brief + * The getFPGAD74TempErrorCount function gets the D74 (D75) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaD74TempErrorCount + * @details \b Outputs: none + * @return D74 (D75) Temperature sensor error count + *************************************************************************/ +U08 getFPGAD74TempErrorCount( void ) +{ + return fpgaSensorReadings.fpgaD74TempErrorCount; +} + +/*********************************************************************//** + * @brief * The getFPGAD74CondTemp function gets D74 conductivity sensor temperature value. * @details \b Inputs: fpgaD74CondTemp * @details \b Outputs: none * @return Latest D74 conductivity sensor temperature value *************************************************************************/ -U16 getFPGAD74CondTemp( void ) +F32 getFPGAD74CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD74CondTemp ); + return fpgaSensorReadings.fpgaD74TempResistance; } /*********************************************************************//** @@ -3059,13 +2477,36 @@ * @details \b Outputs: none * @return Latest D74 conductivity sensor register data value *************************************************************************/ -U32 getFPGAD74CondData( void ) +F32 getFPGAD74CondData( void ) { - return GET_FPGA_SENSOR_FIELD( fpgaD74CondCond ); + return fpgaSensorReadings.fpgaD74CondResistance; } +/*********************************************************************//** + * @brief + * The getFPGAD74CondCalData function gets the D74 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaD74DataCal + * @details \b Outputs: none + * @return D74 calibration data + *************************************************************************/ +U32 getFPGAD74CondCalData( void ) +{ + return fpgaSensorReadings.fpgaD74DataCal; +} /*********************************************************************//** * @brief + * The getFPGAD74CalMemCounter function gets the D74 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaD74CalMemCounter + * @details \b Outputs: none + * @return D74 memory count + *************************************************************************/ +U08 getFPGAD74CalMemCounter( void ) +{ + return fpgaSensorReadings.fpgaD74CalMemCounter; +} + +/*********************************************************************//** + * @brief * The getFPGAD63LevelSensor function gets the latest FPGA D63 upper level * sensor reading. * @details \b Inputs: fpgaD63LevelSensor @@ -4247,479 +3688,248 @@ /*********************************************************************//** * @brief - * The setFPGAP9Control function sets the FPGA P9 sensor control register - * to perform a given action. - * bit 4..7: unused - * bit 3: Enable P9 read transaction; address needed - * bit 2: Enable P9 write transaction; address and data needs to be set - * bit 1: Enable P9 initialization procedure - * bit 0: reset P9 sensor + * The setFPGAP40PumpEnable function enables or disables the P40 pump. * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @param control bits indicating control action to take + * @details \b Outputs: p40PumpControl + * @param enable flag indicating whether to enable or disable the P40 pump. * @return none *************************************************************************/ -void setFPGAP9Control( U08 control ) +void setFPGAP40PumpEnable( BOOL enable ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP9Control, control ); + SET_FPGA_ACTUATOR_FIELD( p40PumpControl, ( TRUE == enable ? 0x1 : 0x0 ) ); } /*********************************************************************//** * @brief - * The setFPGAP9Address function sets the read/write address for a read/write - * action on the P9 sensor. + * The setFPGAP40PumpPWM function sets the P40 pump PWM duty cycle. + * The higher the PWM duty cycle (0..500), the faster the pump will go. + * @note PWM values < 5% or > 95% will cause pump to stop so effective + * range is actually 25..475. * @details \b Inputs: none - * @details \b Outputs: conductivityP9Address - * @param address The P9 sensor address to read from or write to + * @details \b Outputs: p40PumpPWMDutyCyclePct + * @param pwm PWM duty cycle magnitude * @return none *************************************************************************/ -void setFPGAP9Address( U16 address ) +void setFPGAP40PumpPWM( U16 pwm ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP9Address, address ); + SET_FPGA_ACTUATOR_FIELD( p40PumpPWMDutyCyclePct, pwm ); } /*********************************************************************//** * @brief - * The setFPGAP9Data function sets the write data for a write action on - * the P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Data - * @param data The 32-bit data to write to the P9 sensor - * @return none + * The getFPGAP12PumpPWM function gets a read back from FPGA of RO pump PWM + * duty cycle. + * @details \b Inputs: p40PumpPWMReadback + * @details \b Outputs: none + * @return measured speed (RPM) of the P40 pump *************************************************************************/ -void setFPGAP9Data( U32 data ) +U16 getFPGAP40PumpPWM( void ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP9Data, data ); + return GET_FPGA_SENSOR_FIELD( p40PumpPWMReadback ); } /*********************************************************************//** * @brief - * The setFPGAP18Control function sets the FPGA P18 sensor control register - * to perform a given action. - * bit 4..7: unused - * bit 3: Enable P18 read transaction; address needed - * bit 2: Enable P18 write transaction; address and data needs to be set - * bit 1: Enable P18 initialization procedure - * bit 0: reset P18 sensor - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @param control bits indicating control action to take - * @return none + * The getFPGAP12PumpTachCount function gets the running 16-bit tachometer count + * from the P40 pump hall sensor. + * @details \b Inputs: p40PumpTachCount + * @details \b Outputs: none + * @return P40 pump tachometer count *************************************************************************/ -void setFPGAP18Control( U08 control ) +U16 getFPGAP40PumpTachCount( void ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP18Control, control ); + return GET_FPGA_SENSOR_FIELD( p40PumpTachCount ); } /*********************************************************************//** * @brief - * The setFPGAP18Address function sets the read/write address for a read/write - * action on the P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Address - * @param address The P18 sensor address to read from or write to - * @return none + * The getFPGAP9CondReadCount function gets the P9 conductivity read count. + * @details \b Inputs: fpgaSensorReadings.fpgaP9CondReadCount + * @details \b Outputs: none + * @return P9 Conductivity sensor read count *************************************************************************/ -void setFPGAP18Address( U16 address ) +U08 getFPGAP9CondReadCount( void ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP18Address, address ); + return fpgaSensorReadings.fpgaP9CondReadCount; } /*********************************************************************//** * @brief - * The setFPGAP18Data function sets the write data for a write action on - * the P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Data - * @param data The 32-bit data to write to the P18 sensor - * @return none + * The getFPGAP9CondErrorCount function gets the P9 conductivity error count. + * @details \b Inputs: fpgaSensorReadings.fpgaP9CondErrorCount + * @details \b Outputs: none + * @return P9 Conductivity sensor error count *************************************************************************/ -void setFPGAP18Data( U32 data ) +U08 getFPGAP9CondErrorCount( void ) { - SET_FPGA_ACTUATOR_FIELD( conductivityP18Data, data ); + return fpgaSensorReadings.fpgaP9CondErrorCount; } /*********************************************************************//** * @brief - * The setFPGAP9Reset function sets the reset command bit for P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none + * The getFPGAP9TempReadCount function gets the P9 (P10) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaP9TempReadCount + * @details \b Outputs: none + * @return P9 (P10) Temperature sensor read count *************************************************************************/ -void setFPGAP9Reset( void ) +U08 getFPGAP9TempReadCount( void ) { - SET_FPGA_ACTUATOR_BITS( conductivityP9Control, FPGA_CONDUCTIVITY_RESET_BIT ); + return fpgaSensorReadings.fpgaP9TempReadCount; } /*********************************************************************//** * @brief - * The clearFPGAP9Reset function clears the reset command bit for P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none + * The getFPGAP9TempErrorCount function gets the P9 (P10) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaP9TempErrorCount + * @details \b Outputs: none + * @return P9 (P10) Temperature sensor error count *************************************************************************/ -void clearFPGAP9Reset( void ) +U08 getFPGAP9TempErrorCount( void ) { - CLEAR_FPGA_ACTUATOR_BITS( conductivityP9Control, ~FPGA_CONDUCTIVITY_RESET_BIT ); + return fpgaSensorReadings.fpgaP9TempErrorCount; } /*********************************************************************//** * @brief - * The setFPGAP9InitEnable function sets the initialize command bit for - * P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void setFPGAP9InitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP9Control, FPGA_CONDUCTIVITY_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP9InitEnable function clears the initialize command bit for - * P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void clearFPGAP9InitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP9Control, ~FPGA_CONDUCTIVITY_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP9WriteEnable function sets the write enable command bit for - * P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void setFPGAP9WriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP9Control, FPGA_CONDUCTIVITY_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP9WriteEnable function clears the write enable command bit - * for P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void clearFPGAP9WriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP9Control, ~FPGA_CONDUCTIVITY_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP9ReadEnable function sets the read enable command bit for - * P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void setFPGAP9ReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP9Control, FPGA_CONDUCTIVITY_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP9ReadEnable function clears the read enable command bit - * for P9 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP9Control - * @return none - *************************************************************************/ -void clearFPGAP9ReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP9Control, ~FPGA_CONDUCTIVITY_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP18Reset function sets the reset command bit for P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void setFPGAP18Reset( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP18Control, FPGA_CONDUCTIVITY_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP18Reset function clears the reset command bit for P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void clearFPGAP18Reset( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP18Control, ~FPGA_CONDUCTIVITY_RESET_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP18InitEnable function sets the initialize command bit for - * P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void setFPGAP18InitEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP18Control, FPGA_CONDUCTIVITY_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP18InitEnable function clears the initialize command bit for - * P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void clearFPGAP18InitEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP18Control, ~FPGA_CONDUCTIVITY_INIT_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP18WriteEnable function sets the write enable command bit for - * P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void setFPGAP18WriteEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP18Control, FPGA_CONDUCTIVITY_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP18WriteEnable function clears the write enable command bit - * for P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void clearFPGAP18WriteEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP18Control, ~FPGA_CONDUCTIVITY_WR_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP18ReadEnable function sets the read enable command bit for - * P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void setFPGAP18ReadEnable( void ) -{ - SET_FPGA_ACTUATOR_BITS( conductivityP18Control, FPGA_CONDUCTIVITY_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The clearFPGAP18ReadEnable function clears the read enable command bit - * for P18 sensor. - * @details \b Inputs: none - * @details \b Outputs: conductivityP18Control - * @return none - *************************************************************************/ -void clearFPGAP18ReadEnable( void ) -{ - CLEAR_FPGA_ACTUATOR_BITS( conductivityP18Control, ~FPGA_CONDUCTIVITY_RD_ENABLE_BIT ); -} - -/*********************************************************************//** - * @brief - * The getFPGAP9ReadCount function gets the latest P9 sensor read count. - * @details \b Inputs: conductivityP9ReadCount + * The getFPGAP9CondData function gets the P9 conductivity data. + * @details \b Inputs: fpgaSensorReadings.fpgaP9CondResistance * @details \b Outputs: none - * @return Current read count for P9 sensor. + * @return P9 Conductivity data *************************************************************************/ -U08 getFPGAP9ReadCount( void ) +F32 getFPGAP9CondData( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP9ReadCount ); + return fpgaSensorReadings.fpgaP9CondResistance; } /*********************************************************************//** * @brief - * The getFPGAP9ErrorCount function gets the latest P9 sensor error count. - * @details \b Inputs: conductivityP9ErrorCount + * The getFPGAP9CondTemp function gets the P9 (P10) temperature data. + * @details \b Inputs: fpgaSensorReadings.fpgaP9TempResistance * @details \b Outputs: none - * @return Current error count for P9 sensor. + * @return P9 (P10) Temperature data *************************************************************************/ -U08 getFPGAP9ErrorCount( void ) +F32 getFPGAP9CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP9ErrorCount ); + return fpgaSensorReadings.fpgaP9TempResistance; } /*********************************************************************//** * @brief - * The getFPGAP9Conductivity function gets the latest P9 sensor conductivity - * reading. - * @details \b Inputs: conductivityP9Cond + * The getFPGAP9CondCalData function gets the P9 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaP9CalData * @details \b Outputs: none - * @return Current conductivity reading from P9 sensor. + * @return P9 calibration data *************************************************************************/ -U16 getFPGAP9Conductivity( void ) +U32 getFPGAP9CondCalData( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP9Cond ); + return fpgaSensorReadings.fpgaP9CalData; } /*********************************************************************//** * @brief - * The getFPGAP9Temperature function gets the latest P9 sensor temperature. - * @details \b Inputs: conductivityP9Temp + * The getFPGAP9CalMemCounter function gets the P9 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaP9CalMemCounter * @details \b Outputs: none - * @return Current temperature from P9 sensor. + * @return P9 memory count *************************************************************************/ -U16 getFPGAP9Temperature( void ) +U08 getFPGAP9CalMemCounter( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP9Temp ); + return fpgaSensorReadings.fpgaP9CalMemCounter; } /*********************************************************************//** * @brief - * The getFPGAP9Data function gets the latest P9 sensor data from a read - * action. - * @details \b Inputs: conductivityP9Data + * The getFPGAP18CondReadCount function gets the P18 conductivity read count. + * @details \b Inputs: fpgaSensorReadings.fpgaP18CondReadCount * @details \b Outputs: none - * @return Latest data read from P9 sensor. + * @return P18 Conductivity sensor read count *************************************************************************/ -U32 getFPGAP9Data( void ) +U08 getFPGAP18CondReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP9Data ); + return fpgaSensorReadings.fpgaP18CondReadCount; } /*********************************************************************//** * @brief - * The getFPGAP18ReadCount function gets the latest P18 sensor read count. - * @details \b Inputs: conductivityP18ReadCount + * The getFPGAP18CondErrorCount function gets the P18 conductivity error count. + * @details \b Inputs: fpgaSensorReadings.fpgaP18CondErrorCount * @details \b Outputs: none - * @return Current read count for P18 sensor. + * @return P18 Conductivity sensor error count *************************************************************************/ -U08 getFPGAP18ReadCount( void ) +U08 getFPGAP18CondErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP18ReadCount ); + return fpgaSensorReadings.fpgaP18CondErrorCount; } /*********************************************************************//** * @brief - * The getFPGAP18ErrorCount function gets the latest P18 sensor error count. - * @details \b Inputs: conductivityP18ErrorCount + * The getFPGAP18TempReadCount function gets the P18 (P19) temperature read count. + * @details \b Inputs: fpgaSensorReadings.fpgaP18TempReadCount * @details \b Outputs: none - * @return Current error count for P18 sensor. + * @return P18 (P19) Temperature sensor read count *************************************************************************/ -U08 getFPGAP18ErrorCount( void ) +U08 getFPGAP18TempReadCount( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP18ErrorCount ); + return fpgaSensorReadings.fpgaP18TempReadCount; } /*********************************************************************//** * @brief - * The getFPGAP18Conductivity function gets the latest P18 sensor conductivity - * reading. - * @details \b Inputs: conductivityP18Cond + * The getFPGAP18TempErrorCount function gets the P18 (P19) temperature error count. + * @details \b Inputs: fpgaSensorReadings.fpgaP18TempErrorCount * @details \b Outputs: none - * @return Current conductivity reading from P18 sensor. + * @return P18 (P19) Temperature sensor error count *************************************************************************/ -U16 getFPGAP18Conductivity( void ) +U08 getFPGAP18TempErrorCount( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP18Cond ); + return fpgaSensorReadings.fpgaP18TempErrorCount; } /*********************************************************************//** * @brief - * The getFPGAP18Temperature function gets the latest P18 sensor temperature. - * @details \b Inputs: conductivityP18Temp + * The getFPGAP18CondData function gets the P18 conductivity data. + * @details \b Inputs: fpgaSensorReadings.fpgaP18CondResistance * @details \b Outputs: none - * @return Current temperature from P18 sensor. + * @return P18 Conductivity data *************************************************************************/ -U16 getFPGAP18Temperature( void ) +F32 getFPGAP18CondData( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP18Temp ); + return fpgaSensorReadings.fpgaP18CondResistance; } /*********************************************************************//** * @brief - * The getFPGAP18Data function gets the latest P18 sensor data from a read - * action. - * @details \b Inputs: conductivityP18Data + * The getFPGAP18CondTemp function gets the P18 (P19) temperature data. + * @details \b Inputs: fpgaSensorReadings.fpgaP18TempReistance * @details \b Outputs: none - * @return Latest data read from P18 sensor. + * @return P18 (P19) Temperature data *************************************************************************/ -U32 getFPGAP18Data( void ) +F32 getFPGAP18CondTemp( void ) { - return GET_FPGA_SENSOR_FIELD( conductivityP18Data ); + return fpgaSensorReadings.fpgaP18TempReistance; } /*********************************************************************//** * @brief - * The setFPGAP40PumpEnable function enables or disables the P40 pump. - * @details \b Inputs: none - * @details \b Outputs: p40PumpControl - * @param enable flag indicating whether to enable or disable the P40 pump. - * @return none - *************************************************************************/ -void setFPGAP40PumpEnable( BOOL enable ) -{ - SET_FPGA_ACTUATOR_FIELD( p40PumpControl, ( TRUE == enable ? 0x1 : 0x0 ) ); -} - -/*********************************************************************//** - * @brief - * The setFPGAP40PumpPWM function sets the P40 pump PWM duty cycle. - * The higher the PWM duty cycle (0..500), the faster the pump will go. - * @note PWM values < 5% or > 95% will cause pump to stop so effective - * range is actually 25..475. - * @details \b Inputs: none - * @details \b Outputs: p40PumpPWMDutyCyclePct - * @param pwm PWM duty cycle magnitude - * @return none - *************************************************************************/ -void setFPGAP40PumpPWM( U16 pwm ) -{ - SET_FPGA_ACTUATOR_FIELD( p40PumpPWMDutyCyclePct, pwm ); -} - -/*********************************************************************//** - * @brief - * The getFPGAP12PumpPWM function gets a read back from FPGA of RO pump PWM - * duty cycle. - * @details \b Inputs: p40PumpPWMReadback + * The getFPGAP18CondCalData function gets the P18 cal data. + * @details \b Inputs: fpgaSensorReadings.fpgaP18CalData * @details \b Outputs: none - * @return measured speed (RPM) of the P40 pump + * @return P18 calibration data *************************************************************************/ -U16 getFPGAP40PumpPWM( void ) +U32 getFPGAP18CondCalData( void ) { - return GET_FPGA_SENSOR_FIELD( p40PumpPWMReadback ); + return fpgaSensorReadings.fpgaP18CalData; } /*********************************************************************//** * @brief - * The getFPGAP12PumpTachCount function gets the running 16-bit tachometer count - * from the P40 pump hall sensor. - * @details \b Inputs: p40PumpTachCount + * The getFPGAP18CalMemCounter function gets the P18 memory count. + * @details \b Inputs: fpgaSensorReadings.fpgaP18CalMemCounter * @details \b Outputs: none - * @return P40 pump tachometer count + * @return P18 memory count *************************************************************************/ -U16 getFPGAP40PumpTachCount( void ) +U08 getFPGAP18CalMemCounter( void ) { - return GET_FPGA_SENSOR_FIELD( p40PumpTachCount ); + return fpgaSensorReadings.fpgaP18CalMemCounter; } - /**@}*/ Index: firmware/App/Services/Messaging.c =================================================================== diff -u -r50b3e0bc180241fdae6e8d1bc366d69603164bbb -r3d0c86bab8540914d9f3cfdbdd321f35db623999 --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision 50b3e0bc180241fdae6e8d1bc366d69603164bbb) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 3d0c86bab8540914d9f3cfdbdd321f35db623999) @@ -7,8 +7,8 @@ * * @file Messaging.c * -* @author (last) Raghu Kallala -* @date (last) 06-Apr-2026 +* @author (last) Michael Garthwaite +* @date (last) 15-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 07-Aug-2024 @@ -129,28 +129,19 @@ { MSG_ID_DD_PRESSURE_SENSOR_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testDDPressureSensorDataPublishIntervalOverride }, { MSG_ID_DD_PRESSURE_SENSOR_FILTER_READINGS_OVERRIDE_REQUEST, &testDDPressureSensorFilteredReadingsOverride }, { MSG_ID_DD_PRESSURE_SENSOR_FILTER_TEMPERATURE_OVERRIDE_REQUEST, &testDDPressureSensorFilteredTemperatureReadingsOverride }, -#ifdef __TEENSY_CONDUCTIVITY_DRIVER__ { MSG_ID_DD_CONDUCTIVITY_SENSOR_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testDDConductivitySensorDataPublishIntervalOverride }, { MSG_ID_FP_CONDUCTIVITY_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testFPConductivitySensorDataPublishIntervalOverride }, + { MSG_ID_DD_CONDUCTIVITY_SENSOR_READINGS_OVERRIDE_REQUEST, &testConductivitySensorReadingsOverride }, + { MSG_ID_DD_CONDUCTIVITY_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testConductivitySensorTemperatureOverride }, + { MSG_ID_FP_CONDUCTIVITY_SENSOR_READINGS_OVERRIDE_REQUEST, &testConductivitySensorReadingsOverride }, + { MSG_ID_FP_CONDUCTIVITY_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testConductivitySensorTemperatureOverride }, { MSG_ID_DD_SET_CONDUCTIVITY_MODEL_REQUEST, &testSetTeenyConductivityModel }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_READINGS_OVERRIDE_REQUEST, &testTeensyConductivitySensorReadingsOverride }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testTeensyConductivitySensorTemperatureReadingsOverride }, { MSG_ID_DD_CONDUCTIVITY_SENSOR_RESISTANCE_OVERRIDE_REQUEST, &testTeensyConductivitySensorResistanceReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_OVERRIDE_REQUEST, &testTeensyConductivitySensorReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_TEMP_OVERRIDE_REQUEST, &testTeensyConductivitySensorTemperatureReadingsOverride }, { MSG_ID_FP_CONDUCTIVITY_SENSOR_RESISTANCE_OVERRIDE_REQUEST, &testTeensyConductivitySensorResistanceReadingsOverride }, -#else - { MSG_ID_DD_CONDUCTIVITY_SENSOR_READINGS_OVERRIDE_REQUEST, &testDDConductivitySensorReadingsOverride }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_TEMPERATURE_OVERRIDE_REQUEST, &testDDConductivitySensorTemperatureReadingsOverride }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_READ_COUNTER_OVERRIDE_REQUEST, &testDDConductivitySensorReadCounterOverride }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_ERROR_COUNTER_OVERRIDE_REQUEST, &testDDConductivitySensorErrorCounterOverride }, - { MSG_ID_DD_CONDUCTIVITY_SENSOR_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testDDConductivitySensorDataPublishIntervalOverride }, - { MSG_ID_FP_CONDUCTIVITY_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testFPConductivitySensorDataPublishIntervalOverride }, - { MSG_ID_FP_CONDUCTIVITY_OVERRIDE_REQUEST, &testFPConductivitySensorReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_TEMP_OVERRIDE_REQUEST, &testFPConductivitySensorTemperatureReadingsOverride }, - { MSG_ID_FP_CONDUCTIVITY_READ_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorReadCounterOverride }, - { MSG_ID_FP_CONDUCTIVITY_ERROR_COUNT_OVERRIDE_REQUEST, &testFPConductivitySensorErrorCounterOverride }, -#endif + { MSG_ID_DD_CONDUCTIVITY_SENSOR_CONDUCTIVITY_READ_COUNTER_OVERRIDE_REQUEST, &testConductivitySensorConductivityReadCounterOverride }, + { MSG_ID_DD_CONDUCTIVITY_SENSOR_CONDUCTIVITY_ERROR_COUNTER_OVERRIDE_REQUEST, &testConductivitySensorConductivityErrorCounterOverride }, + { MSG_ID_FP_CONDUCTIVITY_SENSOR_CONDUCTIVITY_READ_COUNT_OVERRIDE_REQUEST, &testConductivitySensorConductivityReadCounterOverride }, + { MSG_ID_FP_CONDUCTIVITY_SENSOR_CONDUCTIVITY_ERROR_COUNT_OVERRIDE_REQUEST, &testConductivitySensorConductivityErrorCounterOverride }, { MSG_ID_DD_CONCENTRATE_PUMP_PUBLISH_INTERVAL_OVERRIDE_REQUEST, &testConcentratePumpDataPublishIntervalOverride }, { MSG_ID_DD_CONCENTRATE_PUMP_TARGET_SPEED_OVERRIDE_REQUEST, &testConcentratePumpTargetSpeedOverride }, { MSG_ID_DD_CONCENTRATE_PUMP_MEASURED_SPEED_OVERRIDE_REQUEST, &testConcentratePumpMeasuredSpeedOverride }, @@ -292,6 +283,10 @@ { MSG_ID_DD_BICART_LOWER_PRESSURE_OVERRIDE_REQUEST, &testDryBiCartLowerCartPressureOverride } , { MSG_ID_FP_SET_OPERATION_SUB_MODE_REQUEST, &testSetFPOperationSubMode }, { MSG_ID_FP_BOOST_PUMP_INSTALL_STATUS_REQUEST, &testGetFPBoostPumpInstallStatus }, + { MSG_ID_DD_CONDUCTIVITY_SENSOR_VERSION_REQUEST, &testHandleConductivitySensorVersionRequest }, + { MSG_ID_FP_CONDUCTIVITY_SENSOR_VERSION_REQUEST, &testHandleConductivitySensorVersionRequest }, + { MSG_ID_DD_TEMPERATURE_SENSOR_FILTERED_TEMP_OVERRIDE_REQUEST, &testDDTemperatureSensorFilteredReadingsOverride }, + { MSG_ID_FP_SET_RECOVERY_VALVES_REQUEST, &testIOFPSetValveRecoveryConfig }, }; /// Calculation for number of entries in the incoming message function handler look-up table.