diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-27 14:22:21 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-27 14:22:21 +0300 |
| commit | 2a3653d4eb3dce191dff82689cbd89aa27e10234 (patch) | |
| tree | 68347c9513667e8759e712caefb53874659b00f7 /Software/Embedded_SW | |
| parent | 75589ef9b20ef6e894c0fc1a0bcf3924b4dff9be (diff) | |
| download | Tango-2a3653d4eb3dce191dff82689cbd89aa27e10234.tar.gz Tango-2a3653d4eb3dce191dff82689cbd89aa27e10234.zip | |
Heaters control trial
Diffstat (limited to 'Software/Embedded_SW')
5 files changed, 157 insertions, 31 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c index 3e9218392..ec909136a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c @@ -160,26 +160,12 @@ void OneMilliSecondMillisecInterrupt(UArg arg0) return ; } uint32_t PT100Activity = 0; -int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback) -{ - if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1; - PT100Activity++; - PT100Data[TempSensorId].Callback = Callback; - PT100Data[TempSensorId].Data = Data; - PT100Data[TempSensorId].Length = Length; - PT100Data[TempSensorId].DataRequired = false; - PT100Data[TempSensorId].Active = true; - - return OK; -} -int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback) +int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, MSecFptr Callback) { if (TempSensorId >= MAX_TEMPERATURE_SENSOR_ID) return -1; PT100Activity++; //read request PT100Activity++; //get response PT100Data[TempSensorId].Callback = Callback; - PT100Data[TempSensorId].Data = Data; - PT100Data[TempSensorId].Length = Length; PT100Data[TempSensorId].DataRequired = true; PT100Data[TempSensorId].Active = true; @@ -297,13 +283,13 @@ uint32_t MillisecLoop(uint32_t tick) //FPGA_GetTempSensorBusy(); if (PT100Activity) { - for (Sensor_i = TEMP_SENSE_ANALOG_MIXCHIP_TEMP;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) + for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) { //if (TempDriverDriverResponse[Sensor_i].Busy == true) // continue; if (PT100Data[Sensor_i].WaitForData == true) //Read request sent, data is waiting { - if (SPIGetFPGAResponse(Sensor_i,&MotorInfo) == OK) //got the data from the FPGA + if (TemperatureSensorReadFromFPGA_Res(Sensor_i) == OK) //got the data from the FPGA { PT100Data[Sensor_i].WaitForData = false; if (PT100Data[Sensor_i].Callback) @@ -313,7 +299,7 @@ uint32_t MillisecLoop(uint32_t tick) } if (PT100Data[Sensor_i].Active == true) { - SPISendFPGARequest(Sensor_i,PT100Data[Sensor_i].Data,PT100Data[Sensor_i].Length); + TemperatureSensorReadFromFPGA(Sensor_i); PT100Data[Sensor_i].Active = false; if (PT100Data[Sensor_i].DataRequired == true) { @@ -333,6 +319,8 @@ uint32_t MillisecLoop(uint32_t tick) Dancer_Data[WINDER_DANCER] = Read_Dancer_Position(WINDER_DANCER); if (Hundred_msTick) { + for (Sensor_i = 0;Sensor_i < MAX_TEMPERATURE_SENSOR_ID;Sensor_i++) + MillisecReadFromTempSensor(Sensor_i, NULL); } if (Onesecond_Tick) diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h index 6949a4abe..cf49e697a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h +++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.h @@ -18,8 +18,7 @@ int32_t MillisecWriteToMotor(TimerMotors_t MotorId, unsigned long Data, int Leng int32_t MillisecSetMotorSpeed(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback); int32_t MillisecReadFromMotor(TimerMotors_t MotorId, unsigned long Data, int Length, MSecFptr Callback); -int32_t MillisecWriteToTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback); -int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, unsigned long Data, int Length, MSecFptr Callback); +int32_t MillisecReadFromTempSensor(uint32_t TempSensorId, MSecFptr Callback); uint32_t getMotorStatusData(int MotorId); uint32_t getMotorSpeedData(int MotorId); diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h index 6250b78af..3e02e7349 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters.h @@ -13,6 +13,7 @@ extern uint32_t OutputProportionalSingleStep; //A/C Heaters step size from one extern uint32_t OutputProportionalCycleTime; //A/C Heaters Cycle time in milliseconds - one for all heaters //extern uint32_t Heater_timerBase; //Timer handle extern char TimeSliceAllocation[MAX_TIMESLICES]; +extern int DCTimeSliceAllocation[MAX_HEATERS_NUM]; extern int NumberOFSlicesInUse; diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c index ba766509b..8c1679828 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_init.c @@ -25,6 +25,7 @@ #include "heaters_ex.h" #include "heaters.h" #include "Drivers/Heater/Heater.h" +#include "Drivers/Heater/TemperatureSensor.h" @@ -60,7 +61,7 @@ bool FastHeating = 1; uint32_t Heaters_Init(void) { //ROM_TimerDisable(Heater_timerBase, TIMER_A); - + FPGA_SensorInitConfig(); return OK; } char stubToken[36] = {0}; @@ -361,3 +362,34 @@ uint32_t HeaterRecalculateSharedHeatersParams(uint32_t deviceId, uint32_t new_ou return OK; } + +/* + * HeaterRecalculateHeaterParams - prepare the time slices for D/C heaters 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 HeaterRecalculateHeaterParams(uint32_t deviceId, uint32_t new_outputproportionalpowerlimit) +{ + // 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 + HeaterControl[deviceId].outputproportionalpowerlimit = new_outputproportionalpowerlimit; + + //mark the time slices for heaters operation as empty / Heater1000 / Heater 200 + DCTimeSliceAllocation[deviceId] = HeaterControl[deviceId].outputproportionalpowerlimit * NumberOFSlicesInUse / 100; + + + + return OK; + +} diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c index 250158d6a..0aa992819 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c @@ -50,6 +50,7 @@ uint32_t OutputProportionalSingleStep = 0; //A/C Heaters step size from one dec uint32_t Heater_timerBase = TIMER2_BASE; //Timer handle uint32_t OutputProportionalCycleTime = 0; //A/C Heaters Cycle time in milliseconds - one for all heaters char TimeSliceAllocation[MAX_TIMESLICES] = {0xFF}; +int DCTimeSliceAllocation[MAX_HEATERS_NUM] = {0}; bool InitialHeatingState = true; bool TimerActivated = false; @@ -57,7 +58,8 @@ bool TimerActivated = false; Mailbox_Handle HeatersControlMsgQ = NULL; /******************** FUNCTIONS ********************************************/ -uint32_t HeaterControlCBFunction(uint32_t deviceID, uint32_t ReadValue); +uint32_t HeaterControlCBFunction(uint32_t deviceID, uint32_t readValue); +uint32_t DCHeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue); uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue); void HeatersStartControlTimer (void); @@ -186,7 +188,11 @@ uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue) HeaterPIDConfig[HeaterId].m_mesuredParam = 0; HeaterPIDConfig[HeaterId].m_preError = 0; HeaterPIDConfig[HeaterId].m_SetParam = SetTemperatue;//need to update SetParams on presegment stage - ControlIdtoHeaterId [HeaterId] = AddControlCallback( HeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0); + if (HeaterId > HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //DC Heaters + ControlIdtoHeaterId [HeaterId] = AddControlCallback( DCHeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0); + else if (HeaterId < HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters + ControlIdtoHeaterId [HeaterId] = AddControlCallback( HeaterControlCBFunction, eHundredMillisecond,TemperatureSensorRead,(IfTypeHeaters*0x100+HeaterId),HeaterId,0); + return OK; } @@ -197,7 +203,7 @@ uint32_t PrepareHeater(int HeaterId, uint32_t SetTemperatue) * initialized all global data */ -uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) +uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue) { int index=MAX_HEATERS_NUM; static bool InitialHeating = true; @@ -209,6 +215,11 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) return 0xFFFFFFFF; } index = IfIndex&0xFF; + if (index >= HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters + { + LOG_ERROR (IfIndex, "Wrong Interface "); + return 0xFFFFFFFF; + } if (HeaterCmd[index].targettemperatue == 0) { LOG_ERROR (0, "unconfigured"); @@ -216,7 +227,7 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } static uint32_t Temperature[2] = {0}; if (index<2) - Temperature[index] = ReadValue; + Temperature[index] = readValue; HeatingTestSendResonse(0, false,GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w),GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1), Temperature[0],Temperature[1], HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].m_calculatedError, HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].m_calculatedError,"Standard"); @@ -224,22 +235,22 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) // check if the read value is within the proportional band if (InitialHeating) { - if (ReadValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100)))) + if (readValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100)))) { DeActivateHeater(index); //Heaters OFF until coming into the proportional band /* len = usnprintf(str, 100, "\r\n HeaterControlCBFunction devId %d temp %d over proportional band 1.0%d of set temp %d " - ,index, ReadValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue); + ,index, readValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue); Report(str, __FILE__,__LINE__,0, RpMessage, index, deviceID); */ return OK; } - if (ReadValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100)))) + if (readValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100)))) { /* len = usnprintf(str, 100, "\r\n HeaterControlCBFunction devId %d temp %d below proportional band %d of set temp %d " - ,index, ReadValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue); + ,index, readValue,HeaterControl[index].outputproportionalband,HeaterCmd[index].targettemperatue); Report(str, __FILE__,__LINE__,0, RpMessage, index, deviceID); //Heaters ON until coming into the proportional band */ @@ -258,7 +269,7 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) } if(HeaterPIDConfig[index].m_isEnabled && (HeaterPIDConfig[index].m_SetParam != 0)) { - HeaterPIDConfig[index].m_mesuredParam = ReadValue; + HeaterPIDConfig[index].m_mesuredParam = readValue; HeaterPIDConfig[index].m_calculatedError = PIDAlgorithmCalculation(HeaterPIDConfig[index].m_SetParam , HeaterPIDConfig[index].m_mesuredParam, &HeaterPIDConfig[index].m_params, &HeaterPIDConfig[index].m_preError, &HeaterPIDConfig[index].m_integral); if (HeaterPIDConfig[index].m_calculatedError >= HeaterPIDConfig[index].m_params.MAX) @@ -278,6 +289,90 @@ uint32_t HeaterControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) return OK; } +/* + * DCHeaterControlCBFunction + * called by: Communication from host + * initialized all global data + */ + +uint32_t DCHeaterControlCBFunction(uint32_t IfIndex, uint32_t readValue) +{ + int index=MAX_HEATERS_NUM; + static bool InitialHeating[MAX_HEATERS_NUM] = {true}; + /*char str[100]; + uint8_t len = 0;*/ + if (IfIndex>>8 != IfTypeHeaters) + { + LOG_ERROR (IfIndex, "Wrong Interface type"); + return 0xFFFFFFFF; + } + index = IfIndex&0xFF; + if (index <= HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2) //AC Heaters + { + LOG_ERROR (IfIndex, "Wrong Interface "); + return 0xFFFFFFFF; + } + if (HeaterCmd[index].targettemperatue == 0) + { + LOG_ERROR (0, "unconfigured"); + return ERROR; + } + /*static uint32_t Temperature[2] = {0}; + if (index<2) + Temperature[index] = readValue; + HeatingTestSendResonse(0, false,GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w),GetHeaterState(HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1), + Temperature[0],Temperature[1], + HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater1000w].m_calculatedError, HeaterPIDConfig[HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1].m_calculatedError,"Standard"); +*/ + HeatingTestSendResonse(0, false,GetHeaterState(index),0, + readValue,0, + HeaterPIDConfig[index].m_calculatedError, 0,"Standard"); + // check if the read value is within the proportional band + if (InitialHeating[index]) + { + if (readValue > (HeaterCmd[index].targettemperatue * (1+(HeaterControl[index].outputproportionalband/100)))) + { + DeActivateHeater(index); + //Heaters OFF until coming into the proportional band + return OK; + } + if (readValue < (HeaterCmd[index].targettemperatue * (1-(HeaterControl[index].outputproportionalband/100)))) + { + return OK; + } + else + { + InitialHeating[index] = false; + HeatersControlStart(); + //PrepareReady(Module_Heaters,ModuleDone); + HeatingTestSendResonse(0, false,GetHeaterState(index),0, + readValue,0, + HeaterPIDConfig[index].m_calculatedError, 0,"End Initial Heating"); + + } + } + if(HeaterPIDConfig[index].m_isEnabled && (HeaterPIDConfig[index].m_SetParam != 0)) + { + HeaterPIDConfig[index].m_mesuredParam = readValue; + HeaterPIDConfig[index].m_calculatedError = PIDAlgorithmCalculation(HeaterPIDConfig[index].m_SetParam , HeaterPIDConfig[index].m_mesuredParam, + &HeaterPIDConfig[index].m_params, &HeaterPIDConfig[index].m_preError, &HeaterPIDConfig[index].m_integral); + if (HeaterPIDConfig[index].m_calculatedError >= HeaterPIDConfig[index].m_params.MAX) + { + HeaterPIDConfig[index].m_calculatedError = HeaterPIDConfig[index].m_params.MAX; + } + if (HeaterPIDConfig[index].m_calculatedError < HeaterPIDConfig[index].m_params.MIN) + { + HeaterPIDConfig[index].m_calculatedError = HeaterPIDConfig[index].m_params.MIN; + } + + HeaterRecalculateHeaterParams(index, HeaterPIDConfig[index].m_calculatedError); + + //SetMotorFreq (index, HeaterControl[index].m_calculatedError); + } + + + return OK; +} /* * EightMilliSecondHeatersInterrupt - a timer based interrupt, that will handle the time sharing between the A/C heaters @@ -319,7 +414,7 @@ uint32_t HeatersControlLoop(uint32_t tick) { //char str[100]; //uint8_t len = 0; - + int DcHeaterId,HeaterSliceCounter; /*len = usnprintf(str, 100, "\r\n EightMilliSecondHeatersInterrupt SliceCounter %d Owner %d H1000 %d H2000 %d" ,SliceCounter,TimeSliceAllocation[SliceCounter],HeatersRestart,NumberOFSlicesInUse); Report(str, __FILE__,__LINE__,0, RpMessage, SliceCounter, TimeSliceAllocation[SliceCounter]); @@ -358,6 +453,17 @@ uint32_t HeatersControlLoop(uint32_t tick) DeActivateHeater (HARDWARE_PID_CONTROL_TYPE__DryerHeater200w1); DeActivateHeater (HARDWARE_PID_CONTROL_TYPE__DryerHeater200w2); } + + for ( DcHeaterId = HARDWARE_PID_CONTROL_TYPE__HeadHeaterZ1; DcHeaterId<= HARDWARE_PID_CONTROL_TYPE__MixerHeater;DcHeaterId++) + { + if (DCTimeSliceAllocation[DcHeaterId] > 0) //heater active + { + if (SliceCounter == 0) + ActivateHeater (DcHeaterId); + else if (SliceCounter == DCTimeSliceAllocation[DcHeaterId]) //turn off + DeActivateHeater (DcHeaterId); + } + } //handle the time sharing module SliceCounter++; if (SliceCounter >= NumberOFSlicesInUse) |
