From 54b6afe5a383e8380a69f77060655cdb4d142a43 Mon Sep 17 00:00:00 2001 From: mmi Date: Thu, 12 Oct 2017 07:16:50 +0000 Subject: [PATCH] Added Interlock Fixed PID regulation functionality git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@250 05563f52-14a8-4384-a975-3d1654cca0fa --- .../3 - Implementation/0 - Code/HAL/Makefile | 1 + .../0 - Code/HAL/inc/Interlock.h | 133 +++++++++ .../3 - Implementation/0 - Code/HAL/inc/PID.h | 4 +- .../0 - Code/HAL/src/Interlock.c | 114 ++++++++ .../3 - Implementation/0 - Code/HAL/src/PID.c | 14 +- .../0 - Code/HAL/src/nhd0420.c | 34 +-- .../0 - Code/Platform/inc/platform.h | 11 +- .../0 - Code/Platform/src/internalADC.c | 3 +- .../0 - Code/Platform/src/oli_stm32_h107.c | 114 ++++++-- .../.settings/language.settings.xml | 4 +- .../hsb-mrts/.settings/language.settings.xml | 4 +- .../0 - Code/hsb-mrts/inc/hwValidationMenu.h | 9 +- .../0 - Code/hsb-mrts/inc/repairProcess.h | 19 +- .../0 - Code/hsb-mrts/src/Display.c | 10 +- .../0 - Code/hsb-mrts/src/hwValidationMenu.c | 9 +- .../0 - Code/hsb-mrts/src/main.c | 13 +- .../0 - Code/hsb-mrts/src/repairMenu.c | 10 +- .../0 - Code/hsb-mrts/src/repairProcess.c | 254 +++++++----------- .../0 - Code/hsb-mrts/src/stm32f10x_it.c | 5 + 19 files changed, 504 insertions(+), 261 deletions(-) create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/Makefile b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/Makefile index 262f52c..8089fcd 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/Makefile +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/Makefile @@ -24,6 +24,7 @@ ARFLAGS = rs OBJECTS = \ DisplayDevice.o \ +Interlock.o \ IODevice.o \ KeyboardDevice.o \ Logger.o \ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h new file mode 100644 index 0000000..dd30fc2 --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h @@ -0,0 +1,133 @@ +// ----------------------------------------------------------------------------- +/// @file Interlock.h +/// @brief File description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file Interlock.h +/// @ingroup {group_name} + +#ifndef INC_INTERLOCK_H_ +#define INC_INTERLOCK_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include +#include "stm32f10x.h" + +#include "platform.h" +#include "gpio.h" + +#include "stm32f10x_exti.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +struct InterlockElement +{ + struct Gpio* io; + EXTI_InitTypeDef ioEXTI; +}; + +struct Interlock +{ + struct InterlockElement NO; + struct InterlockElement NC; + bool initialized; +}; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +/** ---------------------------------------------------------------------------- + * Interlock_construct + * Description of function + * + * @param self + * @param NO + * @param NOEXTI + * @param NC + * @param NCEXTI + * + * @return ErrorStatus + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI); + + +/** ---------------------------------------------------------------------------- + * Interlock_getStatus + * Get the current status of the interlock + * + * @param self Interlock object + * @param command Interrupt status + * @param NO value on GPIO NO + * @param NC value on GPIO NC + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* NO, int* NC); + + +/** ---------------------------------------------------------------------------- + * Interlock_isClosed + * Check for interlock closed. Scans both I/Os + * + * @param self The interlock object + * + * @return bool TRUE is NC=1 and NO=0 + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern bool Interlock_isClosed(struct Interlock* self); + + +/** ---------------------------------------------------------------------------- + * Interlock_setEXTI + * Description of function + * + * @param self + * @param command + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void Interlock_setEXTI(struct Interlock* self, FunctionalState command); + +#endif /* INC_INTERLOCK_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/PID.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/PID.h index b5b6419..b15725b 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/PID.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/PID.h @@ -39,7 +39,7 @@ // Constant and macro definitions // ----------------------------------------------------------------------------- -#define PID_FIXED_POINT_FACTOR (1000) +#define PID_FIXED_POINT_FACTOR (10000) // ----------------------------------------------------------------------------- // Type definitions. @@ -92,6 +92,6 @@ extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int i * @todo * ----------------------------------------------------------------------------- */ -extern int PID_calculate(struct Pid* self, int input, int error); +extern int PID_calculate(struct Pid* self, int error); #endif /* INC_PID_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c new file mode 100644 index 0000000..d93145a --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c @@ -0,0 +1,114 @@ +// ----------------------------------------------------------------------------- +/// @file Interlock.c +/// @brief Description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2017 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @file Interlock.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "Interlock.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + +ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI) +{ + ErrorStatus returnValue = SUCCESS; + if (!self->initialized) + { + self->NO.io = NO; + self->NO.ioEXTI = NOEXTI; + self->NC.io = NC; + self->NC.ioEXTI = NCEXTI; + self->initialized = true; + } + else + { + returnValue = ERROR; + } + return returnValue; +} + + +void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* NO, int* NC) +{ + *command = self->NO.ioEXTI.EXTI_LineCmd; + + IODevice_read((struct IODevice*)self->NO.io, (char*)NO, 1, NULL); + IODevice_read((struct IODevice*)self->NC.io, (char*)NC, 1, NULL); +} + + +bool Interlock_isClosed(struct Interlock* self) +{ + bool returnValue; + + char no; + char nc; + + IODevice_read((struct IODevice*)self->NO.io, &no, 1, NULL); + IODevice_read((struct IODevice*)self->NC.io, &nc, 1, NULL); + + if ((no != 0) && (nc == 0)) + { + returnValue = true; + } + else + { + returnValue = false; + } + return returnValue; +} + + +void Interlock_setEXTI(struct Interlock* self, FunctionalState command) +{ + self->NO.ioEXTI.EXTI_LineCmd = command; + EXTI_Init(&self->NO.ioEXTI); + + self->NC.ioEXTI.EXTI_LineCmd = command; + EXTI_Init(&self->NC.ioEXTI); +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/PID.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/PID.c index ac1d0e7..e53b690 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/PID.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/PID.c @@ -89,20 +89,18 @@ ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int iMin, in } -int PID_calculate(struct Pid* self, int input, int error) +int PID_calculate(struct Pid* self, int error) { int returnValue = 0; int dTerm; int pTerm; - input *= PID_FIXED_POINT_FACTOR; - error *= PID_FIXED_POINT_FACTOR; - if (self->initialized) { // Calculate integral self->iTerm += (self->Ki * error); + // Control integrator if (self->iTerm > self->iMax) { @@ -114,14 +112,14 @@ int PID_calculate(struct Pid* self, int input, int error) } // Calculate differential - dTerm = (input - self->input_d1) * self->Kd; + dTerm = ((error - self->input_d1) * self->Kd); // Calculate proportional - pTerm = self->Kp * error; - + pTerm = (self->Kp * error); + LOGGER_WARNING(mainLog, "pTerm %d, Kp %d, error %d", pTerm, self->Kp, error); returnValue = (self->iTerm + dTerm + pTerm) / PID_FIXED_POINT_FACTOR; - self->input_d1 = input; + self->input_d1 = error; } else { diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/nhd0420.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/nhd0420.c index 4ab212e..4079dc5 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/nhd0420.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/nhd0420.c @@ -69,7 +69,6 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] = static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state); static ErrorStatus write(const struct DisplayDevice* self, const char* buffer, size_t length, size_t row, size_t column); static ErrorStatus clear(const struct DisplayDevice* self); -static ErrorStatus clearLine(const struct DisplayDevice* self, size_t row); static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness); static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast); @@ -95,7 +94,7 @@ ErrorStatus NHD0420_construct(struct NHD0420* self, const struct IODevice* devic ddParameters.brightnessMax = NHD0420_BRIGHTNESS_MAX; ddParameters.contrastMin = NHD0420_CONTRAST_MIN; ddParameters.contrastMax = NHD0420_CONTRAST_MAX; - DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, clearLine, setBrightness, setContrast, NULL); + DisplayDevice_construct(&self->displayDevice, &ddParameters, NULL, setState, write, clear, NULL, setBrightness, setContrast, NULL); self->initialized = true; NHD0420_sendData(self, "Hallo", 5); @@ -422,37 +421,6 @@ static ErrorStatus clear(const struct DisplayDevice* self) } -static ErrorStatus clearLine(const struct DisplayDevice* self, size_t row) -{ - ErrorStatus returnValue = SUCCESS; - - if (self->initialized) - { - // Set cursor on display - returnValue = NHD0420_setCursorToPosition((const struct NHD0420*)self, row, 1); - - char buffer[self->parameters.numberOfColumns]; - - int loopcounter; - for (loopcounter = 0; loopcounter < self->parameters.numberOfColumns; loopcounter++) - { - buffer[loopcounter] = 0x20; - } - - if (returnValue == SUCCESS) - { - returnValue = NHD0420_sendData((const struct NHD0420*)self, buffer, self->parameters.numberOfColumns); - } - } - - else - { - returnValue = ERROR; - } - return returnValue; -} - - static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness) { if (self->initialized) diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h index 99106c9..bf75984 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/platform.h @@ -83,10 +83,10 @@ extern struct Keypad* const keypad; extern struct Gpio* const ledGreen; extern struct Gpio* const ledOrange; extern struct Gpio* const power6v5Enable; -extern struct Gpio* const tesla1; -extern struct Gpio* const tesla2; -extern struct Gpio* const interlock1; -extern struct Gpio* const interlock2; +extern struct Gpio* const interlockNO; +extern struct Gpio* const interlockNC; +extern struct Gpio* const teslaNO; +extern struct Gpio* const teslaNC; extern struct Gpio* const solenoid; extern struct Gpio* const mcp0Relay; extern struct Gpio* const mcp1Relay; @@ -94,7 +94,8 @@ extern struct Gpio* const mcp2Relay; extern struct Gpio* const cat0Relay; extern struct Gpio* const cat1Relay; extern struct Gpio* const cat2Relay; -extern struct Gpio* const teslaLock; +extern struct Interlock* const interlock; +extern struct Interlock* const teslalock; // ----------------------------------------------------------------------------- // Function declarations diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/internalADC.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/internalADC.c index 29c2cb2..6a17dd8 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/internalADC.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/internalADC.c @@ -214,7 +214,8 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value) if (self->parent->useRanks) { // Rank starts with 1 - must be reduced by one in order tu be used as index - *value = self->parent->channelValue[self->Rank - 1]; +// *value = self->parent->channelValue[self->Rank - 1]; + *value = self->parent->channelValue[self->channel]; } return returnValue; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c index a0005ac..e77dbc9 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c @@ -37,6 +37,7 @@ #include "Logger.h" #include "platform.h" +#include "Interlock.h" #include "internalADC.h" #include "gpio.h" #include "PCBA.h" @@ -122,10 +123,10 @@ static struct Keypad _keypad = {.initialized = false}; static struct Gpio _ledGreen = {.initialized = false}; static struct Gpio _ledOrange = {.initialized = false}; static struct Gpio _power6v5Enable = {.initialized = false}; -static struct Gpio _interlock1 = {.initialized = false}; -static struct Gpio _interlock2 = {.initialized = false}; -static struct Gpio _tesla1 = {.initialized = false}; -static struct Gpio _tesla2 = {.initialized = false}; +static struct Gpio _interlockNO = {.initialized = false}; +static struct Gpio _interlockNC = {.initialized = false}; +static struct Gpio _teslaNO = {.initialized = false}; +static struct Gpio _teslaNC = {.initialized = false}; static struct Gpio _solenoid = {.initialized = false}; static struct Gpio _mcp0Relay = {.initialized = false}; static struct Gpio _mcp1Relay = {.initialized = false}; @@ -133,7 +134,9 @@ static struct Gpio _mcp2Relay = {.initialized = false}; static struct Gpio _cat0Relay = {.initialized = false}; static struct Gpio _cat1Relay = {.initialized = false}; static struct Gpio _cat2Relay = {.initialized = false}; -static struct Gpio _teslaLock = {.initialized = false}; + +static struct Interlock _interlock = {.initialized = false}; +static struct Interlock _teslalock = {.initialized = false}; // The following pointers are for export (see platform.h) and external use. @@ -167,10 +170,10 @@ struct Keypad* const keypad = &_keypad; struct Gpio* const ledGreen = &_ledGreen; struct Gpio* const ledOrange = &_ledOrange; struct Gpio* const power6v5Enable = & _power6v5Enable; -struct Gpio* const interlock1 = &_interlock1; -struct Gpio* const interlock2 = &_interlock2; -struct Gpio* const tesla1 = &_tesla1; -struct Gpio* const tesla2 = &_tesla2; +struct Gpio* const interlockNO = &_interlockNO; +struct Gpio* const interlockNC = &_interlockNC; +struct Gpio* const teslaNO = &_teslaNO; +struct Gpio* const teslaNC = &_teslaNC; struct Gpio* const solenoid = & _solenoid; struct Gpio* const mcp0Relay = &_mcp0Relay; struct Gpio* const mcp1Relay = &_mcp1Relay; @@ -178,7 +181,9 @@ struct Gpio* const mcp2Relay = &_mcp2Relay; struct Gpio* const cat0Relay = &_cat0Relay; struct Gpio* const cat1Relay = &_cat1Relay; struct Gpio* const cat2Relay = &_cat2Relay; -struct Gpio* const teslaLock = &_teslaLock; + +struct Interlock* const interlock = &_interlock; +struct Interlock* const teslalock = &_teslalock; // ----------------------------------------------------------------------------- // Function declarations @@ -187,6 +192,7 @@ struct Gpio* const teslaLock = &_teslaLock; static ErrorStatus initClocks(void); static ErrorStatus initIO (void); static T_PL_GPIO configureGPIO (GPIO_TypeDef* gpioTypeDef, GPIOMode_TypeDef gpioMode, GPIOSpeed_TypeDef gpioSpeed, uint16_t gpioPin); +static EXTI_InitTypeDef configureEXTI (uint32_t line, EXTIMode_TypeDef mode, EXTITrigger_TypeDef trigger, FunctionalState command); // ----------------------------------------------------------------------------- // Function definitions @@ -256,17 +262,17 @@ ErrorStatus initPlatform(void) struct AdcChannelParameters acParameters; acParameters.channel = ADC_Channel_1; acParameters.Rank = 1; - acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5; + acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5; ADCChannel_construct(&adc1->channel[1], adc1, &acParameters); acParameters.channel = ADC_Channel_2; acParameters.Rank = 2; - acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5; + acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5; ADCChannel_construct(&adc1->channel[2], adc1, &acParameters); acParameters.channel = ADC_Channel_0; acParameters.Rank = 3; - acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5; + acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5; ADCChannel_construct(&adc1->channel[0], adc1, &acParameters); ADC_setDMAStatus(adc1, ENABLE); @@ -378,10 +384,23 @@ ErrorStatus initPlatform(void) GPIO_construct(ledOrange, OUTPUT, ledOrange->gpio); // 6V5 Power Enable GPIO_construct(power6v5Enable, OUTPUT, power6v5Enable->gpio); - // Interlock1 - GPIO_construct(interlock1, INPUT, interlock1->gpio); - // Interlock2 - GPIO_construct(interlock2, INPUT, interlock2->gpio); + + IRQ_setInterruptProperties(EXTI0_IRQn, 12, 0, ENABLE); + IRQ_setInterruptProperties(EXTI1_IRQn, 12, 0, ENABLE); + // InterlockNO + EXTI_InitTypeDef intNOEXTI; // = configureEXTI(EXTI_Line0, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, ENABLE); + intNOEXTI.EXTI_Line = EXTI_Line0; + intNOEXTI.EXTI_Mode = EXTI_Mode_Interrupt; + intNOEXTI.EXTI_Trigger = EXTI_Trigger_Rising_Falling; + intNOEXTI.EXTI_LineCmd = ENABLE; + EXTI_Init(&intNOEXTI); + GPIO_construct(interlockNO, INPUT, interlockNO->gpio); + // InterlockNC + EXTI_InitTypeDef intNCEXTI = configureEXTI(EXTI_Line1, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, ENABLE); + GPIO_construct(interlockNC, INPUT, interlockNC->gpio); + +// Interlock_construct(interlock, interlockNO, intNOEXTI, interlockNC, intNCEXTI); + // Solenoid GPIO_construct(solenoid, OUTPUT, solenoid->gpio); if (PCBA_getInstance()->pcba == CathodeMCP) @@ -402,9 +421,16 @@ ErrorStatus initPlatform(void) if (PCBA_getInstance()->pcba == Tesla) { // Tesla Lock - GPIO_construct(teslaLock, INPUT, teslaLock->gpio); + EXTI_InitTypeDef teslaNOEXTI = configureEXTI(EXTI_Line9, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE); + GPIO_construct(teslaNO, INPUT, teslaNO->gpio); + EXTI_InitTypeDef teslaNCEXTI = configureEXTI(EXTI_Line10, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE); + GPIO_construct(teslaNC, INPUT, teslaNC->gpio); + + Interlock_construct(teslalock, teslaNO, teslaNOEXTI, teslaNC, teslaNCEXTI); } +// Interlock_setEXTI(interlock, ENABLE); + } return returnValue; @@ -730,9 +756,11 @@ static ErrorStatus initIO (void) // 6V5 enable -> PE12 output power6v5Enable->gpio = configureGPIO(GPIOE, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_12); // Interlock1 - PB0 input - interlock1->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_0); + interlockNO->gpio = configureGPIO(GPIOB, GPIO_Mode_IPU, GPIO_Speed_50MHz, GPIO_Pin_0); + GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0); // Interlock2 - PB1 input - interlock2->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_1); + interlockNC->gpio = configureGPIO(GPIOB, GPIO_Mode_IPU, GPIO_Speed_50MHz, GPIO_Pin_1); + GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1); // Solenoid - PB5 output solenoid->gpio = configureGPIO(GPIOB, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_5); @@ -755,7 +783,10 @@ static ErrorStatus initIO (void) if (PCBA_getInstance()->pcba == Tesla) { // Tesla lock PB10 output - teslaLock->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_10); + teslaNO->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_9); + GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9); + teslaNC->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_10); + GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10); } @@ -776,3 +807,44 @@ static T_PL_GPIO configureGPIO (GPIO_TypeDef* gpioTypeDef, GPIOMode_TypeDef gpio return gpio; } + +static EXTI_InitTypeDef configureEXTI (uint32_t line, EXTIMode_TypeDef mode, EXTITrigger_TypeDef trigger, FunctionalState command) +{ + EXTI_InitTypeDef EXTI_InitStruct; + + EXTI_InitStruct.EXTI_Line = line; + EXTI_InitStruct.EXTI_Mode = mode; + EXTI_InitStruct.EXTI_Trigger = trigger; + EXTI_InitStruct.EXTI_LineCmd = command; + EXTI_Init(&EXTI_InitStruct); + + return EXTI_InitStruct; +} + + + + + + + +void EXTI0_IRQHandler(void) +{ + static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; + + EXTI_ClearITPendingBit(EXTI_Line0); + GPIO_setValue(ledGreen, true); + LOGGER_ERROR_ISR(mainLog, "EXTI0 IRQ TRIGGERED"); + + portEND_SWITCHING_ISR(higherPriorityTaskWoken); +} + + +void EXTI1_IRQHandler(void) +{ + static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; + + EXTI_ClearITPendingBit(EXTI_Line1); + LOGGER_ERROR_ISR(mainLog, "EXTI1 IRQ TRIGGERED"); + + portEND_SWITCHING_ISR(higherPriorityTaskWoken); +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml index db8a25d..700f76c 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/STM32F10x_StdPeriph_Lib_V3.5.0/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml index 981712a..b045136 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/.settings/language.settings.xml @@ -6,7 +6,7 @@ - + @@ -18,7 +18,7 @@ - + diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hwValidationMenu.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hwValidationMenu.h index 3878989..fb97646 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hwValidationMenu.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hwValidationMenu.h @@ -61,10 +61,10 @@ struct HwValidationMenuItems struct Adc* internalADC; // Internal ADC with channel array struct MAX5715* externalDAC; // External DAC with channel array struct Gpio* power6v5Enable; - struct Gpio* interlock1; - struct Gpio* interlock2; - struct Gpio* tesla1; - struct Gpio* tesla2; + struct Gpio* interlockNO; + struct Gpio* interlockNC; + struct Gpio* teslaNO; + struct Gpio* teslaNC; struct Gpio* solenoid; struct Gpio* mcp0Relay; struct Gpio* mcp1Relay; @@ -72,7 +72,6 @@ struct HwValidationMenuItems struct Gpio* cat0Relay; struct Gpio* cat1Relay; struct Gpio* cat2Relay; - struct Gpio* teslaLock; struct Pcba* pcba; struct Keypad *keypad; // struct Eeprom* eeprom; // Not implemented yet diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h index 9a53a37..c8a8f11 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h @@ -46,7 +46,7 @@ // Constant and macro definitions // ----------------------------------------------------------------------------- - +#define REPAIRPROCESS_NUMBER_OF_ROWS (3) // ----------------------------------------------------------------------------- // Type definitions. @@ -58,6 +58,7 @@ typedef enum SOFTSTART, VOLTAGE_HOLD, PAUSE, + PAUSE_RESTORE, FINISH_VERIFY, FINISHED } RepairState; @@ -80,19 +81,17 @@ struct RepairProcess uint16_t stackSize; bool runTask; SemaphoreHandle_t secondsSyncronisation; + uint32_t startTime; uint32_t secondsCounter; + uint32_t softStartTimer; + uint32_t voltageHoldTimer; RepairState currentState; bool initialized; + size_t currentPresetIndex; struct RepairPreset* repairPreset; - const struct AdcChannel* adcRow1; - const struct AdcChannel* adcRow2; - const struct AdcChannel* adcRow3; - const struct MAX5715_DAC* dacRow1; - const struct MAX5715_DAC* dacRow2; - const struct MAX5715_DAC* dacRow3; - struct Pid pidRow1; - struct Pid pidRow2; - struct Pid pidRow3; + const struct AdcChannel* adc[REPAIRPROCESS_NUMBER_OF_ROWS]; + const struct MAX5715_DAC* dac[REPAIRPROCESS_NUMBER_OF_ROWS]; + struct Pid pid[REPAIRPROCESS_NUMBER_OF_ROWS]; }; // ----------------------------------------------------------------------------- diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c index 9d80e92..9332be6 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c @@ -138,7 +138,15 @@ ErrorStatus Display_clearScreen(struct Display* self) ErrorStatus Display_clearLine(struct Display* self, size_t line) { - return DisplayDevice_clearLine(self->displayDevice, line); + char buffer[self->displayDevice->parameters.numberOfColumns]; + + int loopcounter; + for (loopcounter = 0; loopcounter < self->displayDevice->parameters.numberOfColumns; loopcounter++) + { + buffer[loopcounter] = 0x20; + } + + return Display_write(self, buffer, self->displayDevice->parameters.numberOfColumns, line, 1); } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hwValidationMenu.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hwValidationMenu.c index 7b5b67a..46d24e5 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hwValidationMenu.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hwValidationMenu.c @@ -881,8 +881,8 @@ static void hwValidationMenuSM(struct HwValidationMenu* self, Button_Pressed_t b bool value2 = false; if( self->menuItemSelected == MENU_TEST_INTERLOCK_1) { - if( GPIO_getValue(self->testItems->interlock1, &value1) == SUCCESS && - GPIO_getValue(self->testItems->interlock2, &value2) == SUCCESS + if( GPIO_getValue(self->testItems->interlockNO, &value1) == SUCCESS && + GPIO_getValue(self->testItems->interlockNC, &value2) == SUCCESS ){ outputBufferLength = sprintf(self->outputBuffer, "Interlock: NO: %d - NC: %d\r\n", value1, value2); } @@ -898,8 +898,8 @@ static void hwValidationMenuSM(struct HwValidationMenu* self, Button_Pressed_t b if(pcba->pcba == Tesla) { - if( GPIO_getValue(self->testItems->tesla1, &value1) == SUCCESS && - GPIO_getValue(self->testItems->tesla2, &value2) == SUCCESS + if( GPIO_getValue(self->testItems->teslaNO, &value1) == SUCCESS && + GPIO_getValue(self->testItems->teslaNC, &value2) == SUCCESS ){ outputBufferLength = sprintf(self->outputBuffer, "Interlock (tesla): NO: %d - NC: %d\r\n", value1, value2); } @@ -1106,7 +1106,6 @@ static void hwValidationMenuSM(struct HwValidationMenu* self, Button_Pressed_t b { if( self->menuItemSelected == MENU_TEST_GENERIC_KEYPAD) { - char key; Keypad_KeyState keyState; char data[CMD_BUFFER_SIZE] = {0}; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c index 45ab8ef..5e42dac 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c @@ -197,7 +197,7 @@ static void initTask(void* parameters) xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle); - Logger_construct(mainLog, &uart3->device, 1, 512); + Logger_construct(mainLog, &uart1->device, 1, 512); Storm700_construct(storm700, &keypad->device); @@ -242,10 +242,10 @@ static void initTask(void* parameters) hwTestItems.internalADC = adc1; hwTestItems.externalDAC = &max5715; hwTestItems.power6v5Enable = power6v5Enable; - hwTestItems.interlock1 = interlock1; - hwTestItems.interlock2 = interlock2; - hwTestItems.tesla1 = tesla1; - hwTestItems.tesla1 = tesla2; + hwTestItems.interlockNO = interlockNO; + hwTestItems.interlockNC = interlockNC; + hwTestItems.teslaNO = teslaNO; + hwTestItems.teslaNC = teslaNC; hwTestItems.solenoid = solenoid; hwTestItems.mcp0Relay = mcp0Relay; hwTestItems.mcp1Relay = mcp1Relay; @@ -253,11 +253,10 @@ static void initTask(void* parameters) hwTestItems.cat0Relay = cat0Relay; hwTestItems.cat1Relay = cat1Relay; hwTestItems.cat2Relay = cat2Relay; - hwTestItems.teslaLock = teslaLock; hwTestItems.pcba = pcba; hwTestItems.keypad = keypad; // EEPROM TO BE DONE - HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 512); +// HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024); // Construct the repair menu repairMenu_construct(rm, display, 2, 512); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c index c6e9fd4..2e690b8 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c @@ -155,8 +155,8 @@ static void repairMenu_task(void* parameters) // struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120}; // struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30}; - struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120}; - struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30}; + struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 7200, .softstartDuration = 1800}; + struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 1800, .softstartDuration = 900}; struct RepairPreset repairPreset; repairPreset.numberOfStages = 2; @@ -186,15 +186,15 @@ static void repairMenu_task(void* parameters) Display_write(self->display, "R3", strlen("R3"), 3, 17); uint16_t value; - ADCChannel_read(rp->adcRow1, &value); + ADCChannel_read(rp->adc[0], &value); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value); Display_write(self->display, buffer, strlen(buffer), 4, 1); - ADCChannel_read(rp->adcRow2, &value); + ADCChannel_read(rp->adc[1], &value); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value); Display_write(self->display, buffer, strlen(buffer), 4, 8); - ADCChannel_read(rp->adcRow3, &value); + ADCChannel_read(rp->adc[2], &value); snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value); Display_write(self->display, buffer, strlen(buffer), 4, 15); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c index 329bb38..29f74d5 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c @@ -55,13 +55,14 @@ // ----------------------------------------------------------------------------- + // ----------------------------------------------------------------------------- // Function declarations // ----------------------------------------------------------------------------- static void repairProcess_task(void* parameters); -static int SignalProfileGenerator(uint32_t startTime, uint32_t currentTime, struct RepairPreset* repairPreset, int presetIndex); +static int SignalProfileGenerator(struct RepairProcess* self); // ----------------------------------------------------------------------------- // Function definitions @@ -91,21 +92,21 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro self->initialized = true; self->currentState = PREPARE; - self->adcRow1 = parameters->adcRow1; - self->adcRow2 = parameters->adcRow2; - self->adcRow3 = parameters->adcRow3; - self->dacRow1 = parameters->dacRow1; - self->dacRow2 = parameters->dacRow2; - self->dacRow3 = parameters->dacRow3; + self->adc[0] = parameters->adcRow1; + self->adc[1] = parameters->adcRow2; + self->adc[2] = parameters->adcRow3; + self->dac[0] = parameters->dacRow1; + self->dac[1] = parameters->dacRow2; + self->dac[2] = parameters->dacRow3; - self->pidRow1.initialized = false; - self->pidRow2.initialized = false; - self->pidRow3.initialized = false; + self->pid[0].initialized = false; + self->pid[1].initialized = false; + self->pid[2].initialized = false; - PID_construct(&self->pidRow1, 10, 10, 10, 0, 10000000); - PID_construct(&self->pidRow2, 100, 0, 0, 0, 10000000); - PID_construct(&self->pidRow3, 10, 10, 10, 0, 10000000); + PID_construct(&self->pid[0], 5000, 3000, 0, 0, 10000000); + PID_construct(&self->pid[1], 5000, 3000, 0, 0, 100000000); + PID_construct(&self->pid[2], 5000, 3000, 0, 0, 10000000); LOGGER_INFO(mainLog, "Repair Process task started"); } @@ -165,34 +166,73 @@ static void repairProcess_task(void* parameters) { struct RepairProcess* self = (struct RepairProcess*)parameters; - uint8_t presetIndex = 0; - uint32_t startTime = 0; - uint32_t softStartTimer = 0; - uint32_t voltageHoldTimer = 0; - - uint32_t pidError; - - uint16_t voltageRow1 = 0; - uint16_t voltageRow2 = 0; - uint16_t voltageRow3 = 0; - - uint16_t adcVoltageRow1 = 0; - uint16_t adcVoltageRow2 = 0; - uint16_t adcVoltageRow3 = 0; - - uint16_t voltageTarget = 0; - uint16_t dacVoltageRow1 = 0; - uint16_t dacVoltageRow2 = 0; - uint16_t dacVoltageRow3 = 0; - + int signal; + uint16_t adcValue; + int error; + int pid; + int loopCounter; // Reset the seconds counter to 0 self->secondsCounter = 0; + MAX5715Channel_setValue(self->dac[0], 0); + MAX5715Channel_setValue(self->dac[1], 0); + MAX5715Channel_setValue(self->dac[2], 0); while(self->runTask) { xSemaphoreTake(self->secondsSyncronisation, portMAX_DELAY); + LOGGER_DEBUG(mainLog, "----------------------------------------"); + + // The signal profile is identical for all rows in the regulation process + signal = SignalProfileGenerator(self); + LOGGER_DEBUG(mainLog, "Signal: %d", signal); + + // Check for correct signal + if (signal >= 0) + { + // Regulation is unique for each row + // For TESLA repair only row 1 (out of 0,1,2) is used + // For ANODE and Cathode/MCP, all 3 rows are used + for (loopCounter = ((PCBA_getInstance()->pcba == Tesla) ? 1 : 0); loopCounter <= ((PCBA_getInstance()->pcba == Tesla) ? 1 : 2); loopCounter++) + { + // Read the last ADC channel value + ADCChannel_read(self->adc[loopCounter], &adcValue); + // Calculate the error + error = signal - (int)adcValue; + // Calculate the PID + pid = PID_calculate(&self->pid[loopCounter], error); + ///TODO MUST BE MOVED TO DACDevice + // Verify that pid value does not overflow the DAC + if (pid > 0xFFF) + { + pid = 0xFFF; + } + else if (pid < 0) + { + pid = 0; + } + // Send the PID value to the DAC + MAX5715Channel_setValue(self->dac[loopCounter], pid); + + LOGGER_DEBUG(mainLog, "Row %d --- ADC: %d Error: %d PID: %d", loopCounter, adcValue, error, pid); + } + } + + self->secondsCounter++; + } + + LOGGER_INFO(mainLog, "Deleting repairProcess task"); + vTaskDelete(self->taskHandle); +} + + +static int SignalProfileGenerator(struct RepairProcess* self) +{ + int returnValue = 0; + + if (self->initialized) + { switch (self->currentState) { @@ -201,110 +241,61 @@ static void repairProcess_task(void* parameters) LOGGER_DEBUG(mainLog, "Repair Process: Preparing new stage of repair process"); // Prepare a new repair process //Load the timers - startTime = self->secondsCounter; - softStartTimer = self->secondsCounter + self->repairPreset->preset[presetIndex].softstartDuration; - LOGGER_DEBUG(mainLog, "Softstart timer is %d (%d + %d)", softStartTimer, self->secondsCounter, self->repairPreset->preset[presetIndex].softstartDuration); - voltageHoldTimer = self->secondsCounter + self->repairPreset->preset[presetIndex].duration; - LOGGER_DEBUG(mainLog, "Voltagehold timer is %d (%d + %d)", voltageHoldTimer, self->secondsCounter, self->repairPreset->preset[presetIndex].duration); - - voltageTarget = self->repairPreset->preset[presetIndex].voltage; - - - voltageRow1 = 0; - voltageRow2 = 0; - voltageRow3 = 0; - // Anode and CathodeMCP run all 3 ADCs and DACs - MAX5715Channel_setValue(self->dacRow1, voltageRow1); - MAX5715Channel_setValue(self->dacRow2, voltageRow2); - MAX5715Channel_setValue(self->dacRow3, voltageRow3); - - - - ///TODO CHECK FOR SAFETLY BEFORE START + self->startTime = self->secondsCounter; + self->softStartTimer = self->secondsCounter + self->repairPreset->preset[self->currentPresetIndex].softstartDuration; + LOGGER_DEBUG(mainLog, "Softstart timer is %d (%d + %d)", self->softStartTimer, self->secondsCounter, self->repairPreset->preset[self->currentPresetIndex].softstartDuration); + self->voltageHoldTimer = self->secondsCounter + self->repairPreset->preset[self->currentPresetIndex].duration; + LOGGER_DEBUG(mainLog, "Voltagehold timer is %d (%d + %d)", self->voltageHoldTimer, self->secondsCounter, self->repairPreset->preset[self->currentPresetIndex].duration); self->currentState = SOFTSTART; + break; } - case SOFTSTART: { - // Perform softstart / ramp-up + // Still in Softstart + int startVoltage = 0; - LOGGER_DEBUG(mainLog, "------------------------------"); - - if (PCBA_getInstance()->pcba == Tesla) + // If first preset, start voltage is 0 + if (self->currentPresetIndex == 0) { - // Tesla repair only runs ADC row2 and DAC row2 - voltageRow2 = SignalProfileGenerator(startTime, self->secondsCounter, self->repairPreset, presetIndex); - LOGGER_DEBUG(mainLog, "Softstart running -> new target is %x", voltageRow2); - ADCChannel_read(self->adcRow3, &adcVoltageRow2); - LOGGER_DEBUG(mainLog, "Softstart running ->ADC reads %x", adcVoltageRow2); - pidError = voltageRow2 - adcVoltageRow2; - LOGGER_DEBUG(mainLog, "Softstart running ->PID Error %x", pidError); - int pidCalc = PID_calculate(&self->pidRow2, voltageRow2, pidError); - LOGGER_DEBUG(mainLog, "Softstart running ->PID calculates %x", pidCalc); - - if (pidCalc >= 0) - { - MAX5715Channel_setValue(self->dacRow2, pidCalc); - } + startVoltage = 0; } - else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP)) + else { - + // Softstart for another stage - start voltage is hold voltage of previous preset + startVoltage = self->repairPreset->preset[self->currentPresetIndex - 1].voltage; } + returnValue = ((self->repairPreset->preset[self->currentPresetIndex].voltage - startVoltage) / self->repairPreset->preset[self->currentPresetIndex].softstartDuration) * (self->secondsCounter - self->startTime) + startVoltage; // Check for end of softstart - if (softStartTimer < self->secondsCounter) + if (self->softStartTimer < self->secondsCounter) { // softstart finished self->currentState = VOLTAGE_HOLD; } break; } - case VOLTAGE_HOLD: { - // Actual repair state - hold target voltage until duration has passed - LOGGER_DEBUG(mainLog, "------------------------------"); + returnValue = self->repairPreset->preset[self->currentPresetIndex].voltage; - if (PCBA_getInstance()->pcba == Tesla) - { - // Tesla repair only runs ADC row2 and DAC row2 - - voltageRow2 = SignalProfileGenerator(startTime, self->secondsCounter, self->repairPreset, presetIndex); - LOGGER_DEBUG(mainLog, "Voltage Hold running -> new target is %x", voltageRow2); - ADCChannel_read(self->adcRow3, &adcVoltageRow2); - LOGGER_DEBUG(mainLog, "Voltage Hold running ->ADC reads %x", adcVoltageRow2); - pidError = voltageRow2 - adcVoltageRow2; - LOGGER_DEBUG(mainLog, "Voltage Hold running ->PID Error %x", pidError); - int pidCalc = PID_calculate(&self->pidRow2, voltageRow2, pidError); - LOGGER_DEBUG(mainLog, "Voltage Hold running ->PID calculates %x", pidCalc); - - if (pidCalc >= 0) - { - MAX5715Channel_setValue(self->dacRow2, pidCalc); - } - } - else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP)) - { - - } - - // Check for end of softstart - if (voltageHoldTimer < self->secondsCounter) + // Check for end of voltage hold + if (self->voltageHoldTimer < self->secondsCounter) { // softstart finished self->currentState = FINISH_VERIFY; } break; } - case PAUSE: { break; } - + case PAUSE_RESTORE: + { + break; + } case FINISH_VERIFY: { // The current preset might contain multiple stages, so before going to FINISHED state @@ -313,10 +304,10 @@ static void repairProcess_task(void* parameters) // presetIndex carries the current index in the preset array // number of stages is 1-based (Starting with 1) while presetIndex is 0-based // So, the verification must compensate for the different bases - if (self->repairPreset->numberOfStages > (presetIndex + 1)) + if (self->repairPreset->numberOfStages > (self->currentPresetIndex + 1)) { // A next stage is available - presetIndex++; + self->currentPresetIndex++; self->currentState = PREPARE; LOGGER_DEBUG(mainLog, "Another stage is available"); } @@ -327,62 +318,17 @@ static void repairProcess_task(void* parameters) } break; } - case FINISHED: { - voltageRow1 = 0; - voltageRow2 = 0; - voltageRow3 = 0; - // Anode and CathodeMCP run all 3 ADCs and DACs - MAX5715Channel_setValue(self->dacRow1, voltageRow1); - MAX5715Channel_setValue(self->dacRow2, voltageRow2); - MAX5715Channel_setValue(self->dacRow3, voltageRow3); - -// LOGGER_DEBUG(mainLog, "Repair process finished"); + returnValue = 0; break; } - - default: - LOGGER_ERROR(mainLog, "Repair Process state machine reached unknown state"); } - - - self->secondsCounter++; - } - - LOGGER_INFO(mainLog, "Deleting repairProcess task"); - vTaskDelete(self->taskHandle); -} - - -static int SignalProfileGenerator(uint32_t startTime, uint32_t currentTime, struct RepairPreset* repairPreset, int presetIndex) -{ - int returnValue = 0; - - // Differ between softstart period and voltage hold - if (currentTime - startTime < repairPreset->preset[presetIndex].softstartDuration) - { - // Still in Softstart - int startVoltage = 0; - - // If first preset, start voltage is 0 - if (presetIndex == 0) - { - startVoltage = 0; - } - else - { - // Softstart for another stage - start voltage is hold voltage of previous preset - startVoltage = repairPreset->preset[presetIndex - 1].voltage; - } - returnValue = ((repairPreset->preset[presetIndex].voltage - startVoltage) / repairPreset->preset[presetIndex].softstartDuration) * (currentTime - startTime) + startVoltage; } else { - // In voltage hold - returnValue = repairPreset->preset[presetIndex].voltage; + returnValue = -1; } - return returnValue; } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c index 39c9755..ccf2ff7 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c @@ -101,6 +101,7 @@ void IRQ_setKeypadEXTI(struct Keypad* self, FunctionalState command) } + /** * @brief This function handles SVCall exception. * @param None @@ -229,6 +230,10 @@ void SPI3_IRQHandler (void) portEND_SWITCHING_ISR(higherPriorityTaskWoken); } + + + + void EXTI4_IRQHandler(void) { static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;