Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r766708fceb0bdf1af8c7897df29d4f5036bfd3db -r27f3db92495948d4c1192421c1b0c20338c4a034 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 766708fceb0bdf1af8c7897df29d4f5036bfd3db) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 27f3db92495948d4c1192421c1b0c20338c4a034) @@ -19,11 +19,12 @@ #include "reg_het.h" #include "gio.h" -#include "Valves.h" #include "FPGA.h" -#include "Timers.h" -#include "TaskPriority.h" +#include "SafetyShutdown.h" #include "SystemCommMessages.h" +#include "TaskPriority.h" +#include "Timers.h" +#include "Valves.h" /** * @addtogroup Valves @@ -86,13 +87,17 @@ #define MAX_DEVIATION_FROM_TARGET_IN_COUNTS 150 ///< Maximum deviation from target in counts #define MAX_DEVIATION_FROM_TRAGET_IN_POS_B 1000 ///< Maximum allowed deviation from position B in counts #define MAX_ALLOWED_FAILED_HOMINGS 3U ///< Maximum allowed failed homings -#define HOMING_EDGE_DETECTION_TIME_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ) ///< The time that the valve must be at the edge to be considered for edge detection +/// The time that the valve must be at the edge to be considered for edge detection +static const U32 HOMING_EDGE_DETECTION_TIME_INTERVAL = ( MS_PER_SECOND / ( 2 * TASK_PRIORITY_INTERVAL ) ); #define VALVES_CURRENT_THRESHOLD_AMPS 1.0 ///< Valves current threshold -#define MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ) ///< Valves over current time interval counter -#define MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ) ///< Valves out of range time interval counter +/// Valves over current time interval counter +static const U32 MAX_OVER_CURRENT_TIME_INTERVAL_COUNTER = ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ); +/// Valves out of range time interval counter +static const U32 MAX_POS_DEVIATION_TIME_INTERVAL_COUNTER = ( MS_PER_SECOND / ( TASK_PRIORITY_INTERVAL ) ); #define VALVE_TRANSITION_TIMEOUT_MS 3000U ///< Valves transition time out in ms -#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Valve data publication time interval +/// Valve data publication time interval +#define VALVES_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) #define VALVE_MAX_ALLOWED_PWM_PERCENT 100U ///< Valve maximum allowed PWM in percent #define VALVE_CW_PWM_TO_CNT_CONVERSION( pwm ) ( ( 20 * pwm ) + 2500 ) ///< Valve clockwise PWM to count conversion @@ -821,7 +826,9 @@ // If we are in Pos B, enable current relaxation if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { + // Enable current relaxation setFPGAValveSetPoint( valve, currentPosition, TRUE ); + valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; } // Go back to Idle state @@ -836,6 +843,13 @@ #ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); #endif + // If the valve transition timeout is active and the valve's commanded positions is position C, activate safety shutdown + if ( isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) && valvesStatus[ valve ].commandedPosition == VALVE_POSITION_C_CLOSE ) + { + activateSafetyShutdown(); + // Set the alarm + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); + } } // Check if the valve is close to the temporary target position and if it is, assign the next target position else if ( abs( currentPosition - targetPosition ) < MAX_DEVIATION_FROM_TARGET_IN_COUNTS ) @@ -954,6 +968,7 @@ BOOL result = TRUE; #ifndef DISABLE_3WAY_VALVES +#ifndef DISABLE_VALVE_ALARMS // Get the status of the valves from FPGA U16 status = getFPGAValvesStatus(); @@ -999,6 +1014,7 @@ } } #endif +#endif return result; } @@ -1362,14 +1378,16 @@ currentPWM = pwmInCounts[ valve ]; // Check if the direction is clockwise or not to use the right conversion equation - if ( valvesStatus[ valve ].bypassModeStatus.direction == VAVLE_DIR_CLOCKWISE ) + // TODO check the PWM conversion macros. These macros are not needed anywhere and they + // are only used for Bypass mode so they are not critical. + /*if ( valvesStatus[ valve ].bypassModeStatus.direction == VAVLE_DIR_CLOCKWISE ) { currentPWM = VALVE_CW_CNT_TO_PWM_CONVERSION( currentPWM ); } else { currentPWM = VALVE_CCW_CNT_TO_PWM_CONVERSION( currentPWM ); - } + }*/ valvesStatus[ valve ].bypassModeStatus.currentPWMInPercent = currentPWM; }