aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
new file mode 100644
index 000000000..55da2ecfa
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c
@@ -0,0 +1,154 @@
+/************************************************************************************************************************
+ * Heaters_init.c
+ **************************************************************************************************************************/
+
+////////////////////////////////State machine operation////////////////////////////////////
+//the state machine operation is used to operate in runtime correct profile flow execution
+//by recieved esign flow of the user from the UI
+///////////////////////////////////////////////////////////////////////////////////////////
+#include "include.h"
+
+#include <Modules/Stubs_Handler/DataDef.h>
+//#include "PMR/Hardware/PIDControlConfig.pb-c.h"
+//#include "PMR/Hardware/PIDCluster.pb-c.h"
+//#include "PMR/Hardware/HeaterControl.pb-c.h"
+//#include "PMR/Hardware/HeaterCommandRequest.pb-c.h"
+//#include "PMR/Hardware/HeaterCommandRequest.pb-c.h"
+#include "PMR/Hardware/HardwarePidControl.pb-c.h"
+#include "PMR/Hardware/HardwarePidControlType.pb-c.h"
+#include "PMR/common/MessageContainer.pb-c.h"
+
+#include "../control/control.h"
+#include "../control/pidalgo.h"
+#include "include.h"
+#include <driverlib/timer.h>
+
+#include "heaters.h"
+#include "Drivers/Heater/Heater.h"
+
+
+
+/******************** STRUCTURES AND ENUMs ********************************************/
+typedef enum {
+ HeatersInitialState,
+ HeatersInit,
+ HeatersControlledOp,
+ HeatersShutdown,
+ HeatersTest,
+ MaxHeatersStates
+}HEATERS_STATES_ENUM;
+typedef enum {
+ HeatersCold,
+ HeatersAtPIDStrip,
+ HeatersOverHeat,
+ HeatersOnTest
+}HEATERS_EVENTS_ENUM;
+
+/******************** GLOBAL PARAMETERS ********************************************/
+HeaterPIDControlConfig HeaterControl[MAX_HEATERS_NUM] = {0};
+HeaterControlConfig_t HeaterPIDConfig[MAX_HEATERS_NUM] = {0};
+uint32_t DeviceId2Heater[MAX_HEATERS_NUM] = {0};
+bool AcHeaterConfigured[MAX_AC_HEATERS] = {0};
+
+/******************** CODE ********************************************/
+/*
+ * HeatersInit
+ * called by: General Hardware Init
+ * initialized all global data
+ */
+uint32_t Heaters_Init(void)
+{
+ return OK;
+}
+
+
+uint32_t HeaterConfigRequestMessage(HardwarePidControl* request)
+{
+ //uint32_t status = OK;
+ HardwarePidControlType HeaterId;
+
+ HeaterId = request->hardwarepidcontroltype;
+ int ValidationError = 0;
+
+ if ((HeaterId)&&(HeaterId< MAX_HEATERS_NUM))
+ {
+ HeaterControl[HeaterId].id = HeaterId;
+ //strncpy (HeaterControl[HeaterId].name, request->name, 20);
+ HeaterControl[HeaterId].outputproportionalpowerlimit = request->outputproportionalpowerlimit;
+ HeaterControl[HeaterId].outputproportionalband = request->outputproportionalband;
+ HeaterControl[HeaterId].integraltime = request->integraltime;
+ HeaterControl[HeaterId].derivativetime = request->derivativetime;
+ HeaterControl[HeaterId].sensorcorrectionadjustment = request->sensorcorrectionadjustment;
+ //HeaterControl[HeaterId].sensortypeandsetpointlimits = request->sensortypeandsetpointlimits;
+ HeaterControl[HeaterId].setpointramprateorsoftstartramp = request->setpointramprateorsoftstartramp;
+ HeaterControl[HeaterId].setpointcontroloutputrate = request->setpointcontroloutputrate;
+ HeaterControl[HeaterId].controloutputtype = request->controloutputtype;
+ HeaterControl[HeaterId].ssrcontroloutputtype = request->ssrcontroloutputtype;
+ HeaterControl[HeaterId].outputonoffhysteresisvalues = request->outputonoffhysteresisvalue;
+ HeaterControl[HeaterId].processvariablesamplingrate = request->processvariablesamplingrate;
+ HeaterControl[HeaterId].pvinputfilterfactormode = request->pvinputfilterfactormode;
+
+ if (HeaterId < MAX_AC_HEATERS)
+ AcHeaterConfigured[HeaterId] = true;
+
+ //check if all A/C heaters are defined. if they are - validate the configuration
+ if (HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].id
+ &&HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].id
+ &&HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2].id)
+ {
+ if (HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].outputproportionalpowerlimit
+ + HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].outputproportionalpowerlimit
+ + HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2].outputproportionalpowerlimit> 100)
+ ValidationError += 2;
+ if (ValidationError)
+ {
+ LOG_ERROR (ValidationError, "Validation Error in Heaters Control");
+ return ERROR;
+ }
+ }
+ return OK;
+ }
+ return ERROR;
+
+}
+
+/*
+ * HeaterConfigSetSharedHeatersParams - prepare the time slices for A/C heaters co-ordinated operation
+ * called by the general hardware HWConfigurationFunc
+ * parameters - the cycle time for the coordinated operation, the size (in MCU cycles) of a single step.
+ */
+uint32_t HeaterConfigSetSharedHeatersParams(uint32_t outputproportionalcycletime, uint32_t outputproportionalsinglestep)
+{
+ int Slice_i;
+ int Heater1000Slices,Heater200aSlices /*,Heater200bSlices Currently both 200W heaters will work together*/;
+
+ //A/C Heaters Cycle time in milliseconds - one for all heaters
+ OutputProportionalCycleTime = outputproportionalcycletime;
+
+ //A/C Heaters step size from one decision point to another - in cpu clocks. 120000 = 1 millisecod
+ OutputProportionalSingleStep = outputproportionalsinglestep;
+
+ // calculate how many milliseconds is in each operating cycle (should be an integer number)
+ uint32_t MillisecondsPerChange = OutputProportionalSingleStep/120000;
+
+ // calculate how many time slices are used. the total cycle time / the length of one operating cycle. (one added to put a time gap??? TBD)
+ NumberOFSlicesInUse = (OutputProportionalCycleTime/MillisecondsPerChange);
+
+ if (NumberOFSlicesInUse > MAX_TIMESLICES )
+ {
+ LOG_ERROR (NumberOFSlicesInUse, "NumberOFSlicesInUse too high");
+ return ERROR;//NumberOFSlicesInUse = MAX_TIMESLICES;
+ }
+
+ // all numbers are rounded down. better to have carefully calculated numbers
+ Heater1000Slices = HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].outputproportionalpowerlimit * NumberOFSlicesInUse / 100;
+ Heater200aSlices = HeaterControl[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].outputproportionalpowerlimit * NumberOFSlicesInUse / 100;
+
+ //mark the time slices for heaters operation as empty / Heater1000 / Heater 200
+ memset (TimeSliceAllocation,0xFF,sizeof(TimeSliceAllocation));
+ for (Slice_i = 0; Slice_i < Heater1000Slices;Slice_i++ ) TimeSliceAllocation[Slice_i] = HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w;
+ for (Slice_i = Heater1000Slices; Slice_i < Heater1000Slices+Heater200aSlices;Slice_i++ ) TimeSliceAllocation[Slice_i] = HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1;
+
+ return OK;
+
+}