Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rfda570ba4c27bd2f3458d3549474b18f2c367aa0 -r1b01b8c723dd1b04943e07eeda9e369b6d8e4afe --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision fda570ba4c27bd2f3458d3549474b18f2c367aa0) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 1b01b8c723dd1b04943e07eeda9e369b6d8e4afe) @@ -28,9 +28,9 @@ #include "SystemCommMessages.h" #include "PIControllers.h" -#define MAIN_PRIMARY_HEATER_MAX_DUTY_CYCLE 0.89 ///< Main primary heater (heater A) max duty cycle (79.5%) -#define SMALL_PRIMAY_HEATER_MAX_DUTY_CYCLE 0.50 ///< Small Primary heater (heater B) max duty cycle (25%) -#define TRIMMER_HEATER_MAX_DUTY_CYCLE 0.50 ///< Trimmer heater max duty cycle (25%) +#define MAIN_PRIMARY_HEATER_MAX_DUTY_CYCLE 0.89 ///< Main primary heater (heater A) max duty cycle (89%) +#define SMALL_PRIMAY_HEATER_MAX_DUTY_CYCLE 0.50 ///< Small Primary heater (heater B) max duty cycle (50%) +#define TRIMMER_HEATER_MAX_DUTY_CYCLE 0.50 ///< Trimmer heater max duty cycle (50%) #define HEATERS_MIN_DUTY_CYCLE 0.00 ///< Primary and trimmer heaters minimum duty cycle (0.00%) #define PRIMARY_HEATERS_P_COEFFICIENT 0.02 ///< Primary heaters proportional coefficient @@ -598,6 +598,7 @@ { #ifdef DEBUG_ENABLED { + F32 flow = (F32)(10909.0909/getFPGAROPumpFlowRate()); char debugTempStr[ 256 ]; sprintf( debugTempStr, "MPDC: %2d, SPDC: %2d, THDC: %2d, TPi: %6.2f, TPo: %6.2f, TD1: %6.2f, " "TD2: %6.2f, TRo: %6.2f, TDi: %6.2f, TPh: %6.2f, TTh: %6.2f, PTarg: %6.2f, TTarg: %6.2f, ROFlow: %6.2f\r\n", @@ -611,7 +612,7 @@ getTemperatureValue ( TEMPSENSORS_PRIMARY_HEATER_INTERNAL_TEMP_SENSOR ), getTemperatureValue ( TEMPSENSORS_TRIMMER_HEATER_INTERNAL_TEMP_SESNOR ), primaryHeaterTargetTemperature, trimmerHeaterTargetTemperature, - (F32)(getFPGAROPumpFlowRate()*0.00018)); + (F32)(10909.0909/getFPGAROPumpFlowRate()) ); sendDebugData ( (U08*)debugTempStr, strlen(debugTempStr) ); } #endif Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rfda570ba4c27bd2f3458d3549474b18f2c367aa0 -r1b01b8c723dd1b04943e07eeda9e369b6d8e4afe --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision fda570ba4c27bd2f3458d3549474b18f2c367aa0) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 1b01b8c723dd1b04943e07eeda9e369b6d8e4afe) @@ -39,7 +39,7 @@ #define TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 5110U ///< Trimmer heater external temperature sensors reference resistance #define TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 100U ///< Trimmer heater external temperature sensors zero degree resistance -#define HEATERS_INTERNAL_ADC_TO_TEMP_CONVERSION_COEFF 0.25 ///< Heaters internal temperature sensors ADC to temperature conversion coefficient +#define HEATERS_INTERNAL_ADC_TO_TEMP_CONVERSION_COEFF 0.25 ///< Heaters internal temperature sensors ADC to temperature conversion coefficient #define TEMP_SENSORS_ADC_BITS 24U ///< External temperature sensors ADC bits #define TEMP_SENSORS_ADC_MAX_COUNT (pow(2,TEMP_SENSORS_ADC_BITS)) ///< Temperature sensors max ADC count @@ -73,6 +73,7 @@ #define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 ///< External temperature sensors error value #define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 ///< Heaters internal temperature sensor fault +#define SHIFT_BITS_BY_2 2U ///< Shift bits by 2 TODO add to AE /// Temperature sensor self test states typedef enum tempSensors_Self_Test_States @@ -98,9 +99,9 @@ static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self test state static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state static U32 sampleCount; ///< Initial ADC read index until the array if filled up for the first time -static U32 rawADCReads [ NUM_OF_TEMPERATURE_SENSORS ] ///< Raw ADC reads array +static S32 rawADCReads [ NUM_OF_TEMPERATURE_SENSORS ] ///< Raw ADC reads array [ MAX_NUM_OF_RAW_ADC_SAMPLES ]; -static U32 runningSumAndIndex [ NUM_OF_TEMPERATURE_SENSORS ] ///< Running sum and next ADC index array +static S32 runningSumAndIndex [ NUM_OF_TEMPERATURE_SENSORS ] ///< Running sum and next ADC index array [ NUM_OF_RUNNING_SUM_AND_INDEX_ARRAY_COLUMNS ]; static U32 tempSensorsConstants [ NUM_OF_TEMPERATURE_SENSORS ] ///< Temperature sensors constants [ NUM_OF_TEMP_SENSORS_CONSTANTS_ARRAY_COLUMNS ]; @@ -349,9 +350,9 @@ static void processADCRead (U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount ) { U32 error; - U32 heatersTemperature; BOOL isADCValid = TRUE; F32 temperature; + S32 convertedADC; /* * check if the index is not the heaters @@ -363,10 +364,11 @@ * set the avgCalc to true * if the avgCalc in true, calculate all the steps and immediately convert to temperature */ - if ( sensorIndex != TEMPSENSORS_PRIMARY_HEATER_INTERNAL_TEMP_SENSOR && sensorIndex != TEMPSENSORS_TRIMMER_HEATER_INTERNAL_TEMP_SESNOR ) + if ( sensorIndex != TEMPSENSORS_PRIMARY_HEATER_INTERNAL_TEMP_SENSOR && + sensorIndex != TEMPSENSORS_TRIMMER_HEATER_INTERNAL_TEMP_SESNOR ) { - error = 0; - adc = adc & MASK_OFF_U32_MSB; + error = 0; //TODO non-zero error + convertedADC = (S32)(adc & MASK_OFF_U32_MSB); /* * what if the fpga channel error is not zero? * what if the fpga channel error is zero but the individual is not? @@ -389,25 +391,14 @@ // It is a heaters temperature sensor else { - // Fault state is the 17th bit - //U32 fault = adc & MASK_OFF_LSW; - //fault = fault & 0x0001; - //U32 thermoCouple = ( adc & MASK_OFF_LSW >> SHIFT_16_BITS_FOR_WORD_SHIFT ); - U32 faultBit = adc & 0x0001; - U32 temperatureTemp = ( ( adc & 0x0000FFFC ) >> 2 ); + //U16 test = (U16)adc; + //test = test << 2; + //S16 temperatureTemp = ( (S16)test ) >> 2; - F32 temperatureTemp2 = temperatureTemp * HEATERS_INTERNAL_ADC_TO_TEMP_CONVERSION_COEFF; + U16 adcConv = ( (U16)adc ) << SHIFT_BITS_BY_2; + convertedADC = ( (S16)adcConv ) >> SHIFT_BITS_BY_2; - U32 a = 0; - - if ( faultBit == HEATERS_INTERNAL_TEMP_SENSOR_FAULT ) - { - // Fault alarm? or have a threshold? - // If the fault is 1, should we check the individuals? - } - // TODO fix these - //heatersTemperature = adc & 0xFF05; - //heatersTemperature = (heatersTemperature & 0x7FFF) >> 2; //TODO use #define for 2 + F32 temperatureTemp2 = (F32)convertedADC * HEATERS_INTERNAL_ADC_TO_TEMP_CONVERSION_COEFF; } U32 previousReadCount = readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ]; @@ -436,12 +427,12 @@ { // Update the values in the folders U32 index = runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ]; - U32 runningSum = runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ]; - U32 indexValue = rawADCReads [ sensorIndex ] [ index ]; + S32 runningSum = runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ]; + S32 indexValue = rawADCReads [ sensorIndex ] [ index ]; U32 nextIndex = INC_WRAP( index, ADC_READ_FIRST_READ_INDEX, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); - runningSum = runningSum - indexValue + adc; + runningSum = runningSum - indexValue + convertedADC; - rawADCReads [ sensorIndex ] [ index ] = adc; + rawADCReads [ sensorIndex ] [ index ] = convertedADC; runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ] = nextIndex; runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ] = runningSum; Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -rfda570ba4c27bd2f3458d3549474b18f2c367aa0 -r1b01b8c723dd1b04943e07eeda9e369b6d8e4afe --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision fda570ba4c27bd2f3458d3549474b18f2c367aa0) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 1b01b8c723dd1b04943e07eeda9e369b6d8e4afe) @@ -50,7 +50,7 @@ execSystemCommTx(); // Primary heaters state machine - //execPrimaryHeaters(); + execPrimaryHeaters(); // Trimmer heater state machine execTrimmerHeater();