aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/StateMachines
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-02-18 10:19:36 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-02-18 10:19:36 +0200
commitb14dc1bc35994c4da27bd64e7de65ff66ae7ee0d (patch)
tree514890d752ef029d97730b6021682e95f17691ee /Software/Embedded_SW/Embedded/StateMachines
parent493a38117c886c9c9599b67c5297025e54917cfe (diff)
downloadTango-b14dc1bc35994c4da27bd64e7de65ff66ae7ee0d.tar.gz
Tango-b14dc1bc35994c4da27bd64e7de65ff66ae7ee0d.zip
preparing rapid release
Diffstat (limited to 'Software/Embedded_SW/Embedded/StateMachines')
-rw-r--r--Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c131
-rw-r--r--Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.h1
2 files changed, 132 insertions, 0 deletions
diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c
index d1f667405..ba3a3e1a7 100644
--- a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c
+++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.c
@@ -28,6 +28,7 @@
#include "drivers/I2C_Communication/DAC/Blower.h"
#include "drivers/I2C_Communication/ADC_MUX/ADC_MUX.h"
+#include "drivers/adc_sampling/adc.h"
#include "drivers/Valves/Valve.h"
#include "heaters/heaters_ex.h"
@@ -39,6 +40,7 @@
INIT_SEQUENCE_BUILT_IN_TEST,
INIT_SEQUENCE_INITIAL_BLOWER_ACTIVATION,
//INIT_SEQUENCE_DISPENSER_PRESSURE_BUILDUP_TEST,
+ INIT_SEQUENCE_POWER_MANAGEMENT_INIT,
INIT_SEQUENCE_WAIT_FOR_COOLER,
INIT_SEQUENCE_THREAD_DETECTION,
INIT_SEQUENCE_START_HEATING,
@@ -208,6 +210,132 @@ uint32_t InitSequenceBlowerCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
//InitSequenceStateMachine(InitStages);
return OK;
}
+///////////////////////////////////////////////////////////////////////////////////////////////////////
+#define MAX_CURRENT_READING 5
+#define CURRENT_READING_ERROR_UNSTABLE 100
+int Heater_Current[MAX_CURRENT_READING] ;
+bool initial_wait = false;
+int count_Heater_Current = 0;
+int Maxcount_Heater_Current = 0;
+bool MainHeaterStable = false,SecondaryHeaterStable = false;
+double MainCurrent,SecondaryCurrent,StableCurrent;
+double InitDrierAcVoltage = 0.0;
+int InitDrierAcVoltageCount = 0;
+double Zone2Resistance = 0.0;
+void InitCurrentReadingStable(void)
+{
+ memset(Heater_Current,0,sizeof(Heater_Current));
+ initial_wait = false;
+ count_Heater_Current = 0;
+ Maxcount_Heater_Current = 0;
+ StableCurrent = 0.0;
+}
+
+bool DetectIfCurrentReadingStable(double HeaterCurrent)
+{
+ bool ret = false;
+ int i=0;
+ int sum = 0;
+ int average = 0;
+
+ Maxcount_Heater_Current++;
+ Heater_Current[count_Heater_Current++] = HeaterCurrent;
+ if ( count_Heater_Current >= 5)
+ {
+ count_Heater_Current = 0;
+ initial_wait = true;
+ }
+ if (initial_wait == false)
+ return false;
+ for (i=0;i<MAX_CURRENT_READING;i++)
+ sum += Heater_Current[i];
+ average = sum/MAX_CURRENT_READING;
+ if (fabs(average - HeaterCurrent)<0.2)
+ {
+ ret = true;
+ StableCurrent = average;
+ }
+ return ret;
+}
+double GetZone2RMSCurrent(double VAC)
+{
+ return (VAC/Zone2Resistance);
+}
+uint32_t PowerManagementCallBack(uint32_t IfIndex, uint32_t BusyFlag)
+{
+
+ if ((MainHeaterStable == false)&&(Maxcount_Heater_Current<CURRENT_READING_ERROR_UNSTABLE))
+ {
+ InitDrierAcVoltage += ReadVAC();
+ InitDrierAcVoltageCount++;
+ MainHeaterStable = DetectIfCurrentReadingStable(Get_Heaters_Current(HEATER_DRYER_CURRENT_1));
+ Read_Heaters_Current(HEATER_DRYER_CURRENT_1);
+ if (MainHeaterStable == true)
+ {
+ ReportWithPackageFilter(InitFilter,"main heater current stable", __FILE__,__LINE__,(int)(StableCurrent*100), RpMessage, Maxcount_Heater_Current, 0);
+ InitDrierAcVoltage /= InitDrierAcVoltageCount;
+ MainCurrent = StableCurrent;
+ InitCurrentReadingStable();
+ DeActivateHeater(HEATER_TYPE__DryerMainHeater);
+ ActivateHeater(HEATER_TYPE__DryerSecondaryHeater);
+ ReportWithPackageFilter(InitFilter,"starting secondary heater ", __FILE__,__LINE__,(int)(StableCurrent*100), RpMessage, Maxcount_Heater_Current, 0);
+ }
+ }
+ else
+ {
+ DeActivateHeater(HEATER_TYPE__DryerMainHeater);
+ if (Maxcount_Heater_Current>=CURRENT_READING_ERROR_UNSTABLE)
+ {
+ ReportWithPackageFilter(InitFilter,"drier heaters current not stable", __FILE__,__LINE__,(int)(StableCurrent*100), RpMessage, Maxcount_Heater_Current, 0);
+ if (SafeRemoveControlCallback(HWControlId, PowerManagementCallBack )==OK)
+ HWControlId = 0xFF;
+ else
+ Report("Remove control callback failed",__FILE__,__LINE__,(int)HWControlId,RpWarning,(int)PowerManagementCallBack,0);
+ AlarmHandlingSetAlarm(EVENT_TYPE__DRYER_HEATERS_ZONE_1_CURRENT_OUT_OF_RANGE,ON);
+ DeActivateHeater(HEATER_TYPE__DryerSecondaryHeater);
+ DeActivateHeater(HEATER_TYPE__DryerMainHeater);
+ InitStages++;
+ }
+ else //go to secondary
+ {
+ if ((SecondaryHeaterStable == false)&&(Maxcount_Heater_Current<CURRENT_READING_ERROR_UNSTABLE))
+ {
+ SecondaryHeaterStable = DetectIfCurrentReadingStable(Get_Heaters_Current(HEATER_DRYER_CURRENT_2));
+ Read_Heaters_Current(HEATER_DRYER_CURRENT_2);
+ if (SecondaryHeaterStable == true)
+ {
+ ReportWithPackageFilter(InitFilter,"main heater current stable", __FILE__,__LINE__,(int)(StableCurrent*100), RpMessage, Maxcount_Heater_Current, 0);
+ SecondaryCurrent = StableCurrent;
+ InitCurrentReadingStable();
+ DeActivateHeater(HEATER_TYPE__DryerSecondaryHeater);
+ //do stuff for RMS 2
+ Zone2Resistance = InitDrierAcVoltage/SecondaryCurrent;
+ }
+ }
+ else
+ {
+ if (SafeRemoveControlCallback(HWControlId, PowerManagementCallBack )==OK)
+ HWControlId = 0xFF;
+ else
+ Report("Remove control callback failed",__FILE__,__LINE__,(int)HWControlId,RpWarning,(int)PowerManagementCallBack,0);
+ DeActivateHeater(HEATER_TYPE__DryerSecondaryHeater);
+ DeActivateHeater(HEATER_TYPE__DryerMainHeater);
+ if (Maxcount_Heater_Current>=CURRENT_READING_ERROR_UNSTABLE)
+ AlarmHandlingSetAlarm(EVENT_TYPE__DRYER_HEATERS_ZONE_2_CURRENT_OUT_OF_RANGE,ON);
+ InitStages++;
+ }
+ }
+ }
+return OK;
+}
+uint32_t InitSequencePowerManagementInit(void)
+{
+ InitCurrentReadingStable();
+ ActivateHeater(HEATER_TYPE__DryerMainHeater);
+ HWControlId = AddControlCallback("Init Power", PowerManagementCallBack, eHundredMillisecond, TemplateDataReadCBFunction,0,0, 0 );
+ ReportWithPackageFilter(InitFilter,"starting main heater ", __FILE__,__LINE__,(int)(StableCurrent*100), RpMessage, Maxcount_Heater_Current, 0);
+ return OK;
+}
uint32_t InitSequenceInitialBlowerActivation(void)
{
MachineStateDetail = MACHINE_STATE_INITIAL_BLOWER_ACTIVATION;
@@ -385,6 +513,9 @@ uint32_t InitSequenceStateMachine( INIT_SEQUENCE_STAGES_ENUM ReadValue)
case INIT_SEQUENCE_INITIAL_BLOWER_ACTIVATION:
InitSequenceInitialBlowerActivation();
break;
+ case INIT_SEQUENCE_POWER_MANAGEMENT_INIT:
+ InitSequencePowerManagementInit();
+ break;
/*case INIT_SEQUENCE_DISPENSER_PRESSURE_BUILDUP_TEST:
InitSequenceDispenserPressureBuildUpTest();
break;*/
diff --git a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.h b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.h
index 105537721..f65329c4b 100644
--- a/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.h
+++ b/Software/Embedded_SW/Embedded/StateMachines/Initialization/InitSequence.h
@@ -33,6 +33,7 @@ void StopInitSequence(void);
MACHINE_STATE_STAGES_ENUM GetMachineState(void);
void SetMachineState(MACHINE_STATE_STAGES_ENUM);
void InitSequenceSetStartHeating(bool StartHeating);
+double GetZone2RMSCurrent(double VAC);
#endif /* STATEMACHINES_INITIALIZATION_INITSEQUENCE_H_ */