Added Interlock
Fixed PID regulation functionality git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@250 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -24,6 +24,7 @@ ARFLAGS = rs
|
|||||||
|
|
||||||
OBJECTS = \
|
OBJECTS = \
|
||||||
DisplayDevice.o \
|
DisplayDevice.o \
|
||||||
|
Interlock.o \
|
||||||
IODevice.o \
|
IODevice.o \
|
||||||
KeyboardDevice.o \
|
KeyboardDevice.o \
|
||||||
Logger.o \
|
Logger.o \
|
||||||
|
|||||||
@@ -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 <stdbool.h>
|
||||||
|
#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_ */
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define PID_FIXED_POINT_FACTOR (1000)
|
#define PID_FIXED_POINT_FACTOR (10000)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions.
|
// Type definitions.
|
||||||
@@ -92,6 +92,6 @@ extern ErrorStatus PID_construct(struct Pid* self, int Kp, int Ki, int Kd, int i
|
|||||||
* @todo
|
* @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_ */
|
#endif /* INC_PID_H_ */
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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 returnValue = 0;
|
||||||
|
|
||||||
int dTerm;
|
int dTerm;
|
||||||
int pTerm;
|
int pTerm;
|
||||||
|
|
||||||
input *= PID_FIXED_POINT_FACTOR;
|
|
||||||
error *= PID_FIXED_POINT_FACTOR;
|
|
||||||
|
|
||||||
if (self->initialized)
|
if (self->initialized)
|
||||||
{
|
{
|
||||||
// Calculate integral
|
// Calculate integral
|
||||||
self->iTerm += (self->Ki * error);
|
self->iTerm += (self->Ki * error);
|
||||||
|
|
||||||
// Control integrator
|
// Control integrator
|
||||||
if (self->iTerm > self->iMax)
|
if (self->iTerm > self->iMax)
|
||||||
{
|
{
|
||||||
@@ -114,14 +112,14 @@ int PID_calculate(struct Pid* self, int input, int error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate differential
|
// Calculate differential
|
||||||
dTerm = (input - self->input_d1) * self->Kd;
|
dTerm = ((error - self->input_d1) * self->Kd);
|
||||||
|
|
||||||
// Calculate proportional
|
// 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;
|
returnValue = (self->iTerm + dTerm + pTerm) / PID_FIXED_POINT_FACTOR;
|
||||||
self->input_d1 = input;
|
self->input_d1 = error;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ static int nhd0420_cursorRowOffset[NHD0420_NUMBER_OF_ROWS] =
|
|||||||
static ErrorStatus setState(const struct DisplayDevice* self, DisplayDevice_functionalState state);
|
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 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 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 setBrightness(const struct DisplayDevice* self, size_t brightness);
|
||||||
static ErrorStatus setContrast(const struct DisplayDevice* self, size_t contrast);
|
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.brightnessMax = NHD0420_BRIGHTNESS_MAX;
|
||||||
ddParameters.contrastMin = NHD0420_CONTRAST_MIN;
|
ddParameters.contrastMin = NHD0420_CONTRAST_MIN;
|
||||||
ddParameters.contrastMax = NHD0420_CONTRAST_MAX;
|
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;
|
self->initialized = true;
|
||||||
NHD0420_sendData(self, "Hallo", 5);
|
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)
|
static ErrorStatus setBrightness(const struct DisplayDevice* self, size_t brightness)
|
||||||
{
|
{
|
||||||
if (self->initialized)
|
if (self->initialized)
|
||||||
|
|||||||
@@ -83,10 +83,10 @@ extern struct Keypad* const keypad;
|
|||||||
extern struct Gpio* const ledGreen;
|
extern struct Gpio* const ledGreen;
|
||||||
extern struct Gpio* const ledOrange;
|
extern struct Gpio* const ledOrange;
|
||||||
extern struct Gpio* const power6v5Enable;
|
extern struct Gpio* const power6v5Enable;
|
||||||
extern struct Gpio* const tesla1;
|
extern struct Gpio* const interlockNO;
|
||||||
extern struct Gpio* const tesla2;
|
extern struct Gpio* const interlockNC;
|
||||||
extern struct Gpio* const interlock1;
|
extern struct Gpio* const teslaNO;
|
||||||
extern struct Gpio* const interlock2;
|
extern struct Gpio* const teslaNC;
|
||||||
extern struct Gpio* const solenoid;
|
extern struct Gpio* const solenoid;
|
||||||
extern struct Gpio* const mcp0Relay;
|
extern struct Gpio* const mcp0Relay;
|
||||||
extern struct Gpio* const mcp1Relay;
|
extern struct Gpio* const mcp1Relay;
|
||||||
@@ -94,7 +94,8 @@ extern struct Gpio* const mcp2Relay;
|
|||||||
extern struct Gpio* const cat0Relay;
|
extern struct Gpio* const cat0Relay;
|
||||||
extern struct Gpio* const cat1Relay;
|
extern struct Gpio* const cat1Relay;
|
||||||
extern struct Gpio* const cat2Relay;
|
extern struct Gpio* const cat2Relay;
|
||||||
extern struct Gpio* const teslaLock;
|
extern struct Interlock* const interlock;
|
||||||
|
extern struct Interlock* const teslalock;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
|
|||||||
@@ -214,7 +214,8 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
|
|||||||
if (self->parent->useRanks)
|
if (self->parent->useRanks)
|
||||||
{
|
{
|
||||||
// Rank starts with 1 - must be reduced by one in order tu be used as index
|
// 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;
|
return returnValue;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
#include "Interlock.h"
|
||||||
#include "internalADC.h"
|
#include "internalADC.h"
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "PCBA.h"
|
#include "PCBA.h"
|
||||||
@@ -122,10 +123,10 @@ static struct Keypad _keypad = {.initialized = false};
|
|||||||
static struct Gpio _ledGreen = {.initialized = false};
|
static struct Gpio _ledGreen = {.initialized = false};
|
||||||
static struct Gpio _ledOrange = {.initialized = false};
|
static struct Gpio _ledOrange = {.initialized = false};
|
||||||
static struct Gpio _power6v5Enable = {.initialized = false};
|
static struct Gpio _power6v5Enable = {.initialized = false};
|
||||||
static struct Gpio _interlock1 = {.initialized = false};
|
static struct Gpio _interlockNO = {.initialized = false};
|
||||||
static struct Gpio _interlock2 = {.initialized = false};
|
static struct Gpio _interlockNC = {.initialized = false};
|
||||||
static struct Gpio _tesla1 = {.initialized = false};
|
static struct Gpio _teslaNO = {.initialized = false};
|
||||||
static struct Gpio _tesla2 = {.initialized = false};
|
static struct Gpio _teslaNC = {.initialized = false};
|
||||||
static struct Gpio _solenoid = {.initialized = false};
|
static struct Gpio _solenoid = {.initialized = false};
|
||||||
static struct Gpio _mcp0Relay = {.initialized = false};
|
static struct Gpio _mcp0Relay = {.initialized = false};
|
||||||
static struct Gpio _mcp1Relay = {.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 _cat0Relay = {.initialized = false};
|
||||||
static struct Gpio _cat1Relay = {.initialized = false};
|
static struct Gpio _cat1Relay = {.initialized = false};
|
||||||
static struct Gpio _cat2Relay = {.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.
|
// 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 ledGreen = &_ledGreen;
|
||||||
struct Gpio* const ledOrange = &_ledOrange;
|
struct Gpio* const ledOrange = &_ledOrange;
|
||||||
struct Gpio* const power6v5Enable = & _power6v5Enable;
|
struct Gpio* const power6v5Enable = & _power6v5Enable;
|
||||||
struct Gpio* const interlock1 = &_interlock1;
|
struct Gpio* const interlockNO = &_interlockNO;
|
||||||
struct Gpio* const interlock2 = &_interlock2;
|
struct Gpio* const interlockNC = &_interlockNC;
|
||||||
struct Gpio* const tesla1 = &_tesla1;
|
struct Gpio* const teslaNO = &_teslaNO;
|
||||||
struct Gpio* const tesla2 = &_tesla2;
|
struct Gpio* const teslaNC = &_teslaNC;
|
||||||
struct Gpio* const solenoid = & _solenoid;
|
struct Gpio* const solenoid = & _solenoid;
|
||||||
struct Gpio* const mcp0Relay = &_mcp0Relay;
|
struct Gpio* const mcp0Relay = &_mcp0Relay;
|
||||||
struct Gpio* const mcp1Relay = &_mcp1Relay;
|
struct Gpio* const mcp1Relay = &_mcp1Relay;
|
||||||
@@ -178,7 +181,9 @@ struct Gpio* const mcp2Relay = &_mcp2Relay;
|
|||||||
struct Gpio* const cat0Relay = &_cat0Relay;
|
struct Gpio* const cat0Relay = &_cat0Relay;
|
||||||
struct Gpio* const cat1Relay = &_cat1Relay;
|
struct Gpio* const cat1Relay = &_cat1Relay;
|
||||||
struct Gpio* const cat2Relay = &_cat2Relay;
|
struct Gpio* const cat2Relay = &_cat2Relay;
|
||||||
struct Gpio* const teslaLock = &_teslaLock;
|
|
||||||
|
struct Interlock* const interlock = &_interlock;
|
||||||
|
struct Interlock* const teslalock = &_teslalock;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
@@ -187,6 +192,7 @@ struct Gpio* const teslaLock = &_teslaLock;
|
|||||||
static ErrorStatus initClocks(void);
|
static ErrorStatus initClocks(void);
|
||||||
static ErrorStatus initIO (void);
|
static ErrorStatus initIO (void);
|
||||||
static T_PL_GPIO configureGPIO (GPIO_TypeDef* gpioTypeDef, GPIOMode_TypeDef gpioMode, GPIOSpeed_TypeDef gpioSpeed, uint16_t gpioPin);
|
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
|
// Function definitions
|
||||||
@@ -256,17 +262,17 @@ ErrorStatus initPlatform(void)
|
|||||||
struct AdcChannelParameters acParameters;
|
struct AdcChannelParameters acParameters;
|
||||||
acParameters.channel = ADC_Channel_1;
|
acParameters.channel = ADC_Channel_1;
|
||||||
acParameters.Rank = 1;
|
acParameters.Rank = 1;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||||
ADCChannel_construct(&adc1->channel[1], adc1, &acParameters);
|
ADCChannel_construct(&adc1->channel[1], adc1, &acParameters);
|
||||||
|
|
||||||
acParameters.channel = ADC_Channel_2;
|
acParameters.channel = ADC_Channel_2;
|
||||||
acParameters.Rank = 2;
|
acParameters.Rank = 2;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||||
ADCChannel_construct(&adc1->channel[2], adc1, &acParameters);
|
ADCChannel_construct(&adc1->channel[2], adc1, &acParameters);
|
||||||
|
|
||||||
acParameters.channel = ADC_Channel_0;
|
acParameters.channel = ADC_Channel_0;
|
||||||
acParameters.Rank = 3;
|
acParameters.Rank = 3;
|
||||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||||
ADCChannel_construct(&adc1->channel[0], adc1, &acParameters);
|
ADCChannel_construct(&adc1->channel[0], adc1, &acParameters);
|
||||||
|
|
||||||
ADC_setDMAStatus(adc1, ENABLE);
|
ADC_setDMAStatus(adc1, ENABLE);
|
||||||
@@ -378,10 +384,23 @@ ErrorStatus initPlatform(void)
|
|||||||
GPIO_construct(ledOrange, OUTPUT, ledOrange->gpio);
|
GPIO_construct(ledOrange, OUTPUT, ledOrange->gpio);
|
||||||
// 6V5 Power Enable
|
// 6V5 Power Enable
|
||||||
GPIO_construct(power6v5Enable, OUTPUT, power6v5Enable->gpio);
|
GPIO_construct(power6v5Enable, OUTPUT, power6v5Enable->gpio);
|
||||||
// Interlock1
|
|
||||||
GPIO_construct(interlock1, INPUT, interlock1->gpio);
|
IRQ_setInterruptProperties(EXTI0_IRQn, 12, 0, ENABLE);
|
||||||
// Interlock2
|
IRQ_setInterruptProperties(EXTI1_IRQn, 12, 0, ENABLE);
|
||||||
GPIO_construct(interlock2, INPUT, interlock2->gpio);
|
// 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
|
// Solenoid
|
||||||
GPIO_construct(solenoid, OUTPUT, solenoid->gpio);
|
GPIO_construct(solenoid, OUTPUT, solenoid->gpio);
|
||||||
if (PCBA_getInstance()->pcba == CathodeMCP)
|
if (PCBA_getInstance()->pcba == CathodeMCP)
|
||||||
@@ -402,9 +421,16 @@ ErrorStatus initPlatform(void)
|
|||||||
if (PCBA_getInstance()->pcba == Tesla)
|
if (PCBA_getInstance()->pcba == Tesla)
|
||||||
{
|
{
|
||||||
// Tesla Lock
|
// 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;
|
return returnValue;
|
||||||
@@ -730,9 +756,11 @@ static ErrorStatus initIO (void)
|
|||||||
// 6V5 enable -> PE12 output
|
// 6V5 enable -> PE12 output
|
||||||
power6v5Enable->gpio = configureGPIO(GPIOE, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_12);
|
power6v5Enable->gpio = configureGPIO(GPIOE, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_12);
|
||||||
// Interlock1 - PB0 input
|
// 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 - 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 - PB5 output
|
||||||
solenoid->gpio = configureGPIO(GPIOB, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_5);
|
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)
|
if (PCBA_getInstance()->pcba == Tesla)
|
||||||
{
|
{
|
||||||
// Tesla lock PB10 output
|
// 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;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-965619469903595948" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-965619469903595948" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
||||||
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-965619469903595948" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
|
||||||
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-965619469903595948" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" console="false" env-hash="-24990244560702828" id="fr.ac6.mcu.ide.build.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="Ac6 SW4 STM32 MCU Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ struct HwValidationMenuItems
|
|||||||
struct Adc* internalADC; // Internal ADC with channel array
|
struct Adc* internalADC; // Internal ADC with channel array
|
||||||
struct MAX5715* externalDAC; // External DAC with channel array
|
struct MAX5715* externalDAC; // External DAC with channel array
|
||||||
struct Gpio* power6v5Enable;
|
struct Gpio* power6v5Enable;
|
||||||
struct Gpio* interlock1;
|
struct Gpio* interlockNO;
|
||||||
struct Gpio* interlock2;
|
struct Gpio* interlockNC;
|
||||||
struct Gpio* tesla1;
|
struct Gpio* teslaNO;
|
||||||
struct Gpio* tesla2;
|
struct Gpio* teslaNC;
|
||||||
struct Gpio* solenoid;
|
struct Gpio* solenoid;
|
||||||
struct Gpio* mcp0Relay;
|
struct Gpio* mcp0Relay;
|
||||||
struct Gpio* mcp1Relay;
|
struct Gpio* mcp1Relay;
|
||||||
@@ -72,7 +72,6 @@ struct HwValidationMenuItems
|
|||||||
struct Gpio* cat0Relay;
|
struct Gpio* cat0Relay;
|
||||||
struct Gpio* cat1Relay;
|
struct Gpio* cat1Relay;
|
||||||
struct Gpio* cat2Relay;
|
struct Gpio* cat2Relay;
|
||||||
struct Gpio* teslaLock;
|
|
||||||
struct Pcba* pcba;
|
struct Pcba* pcba;
|
||||||
struct Keypad *keypad;
|
struct Keypad *keypad;
|
||||||
// struct Eeprom* eeprom; // Not implemented yet
|
// struct Eeprom* eeprom; // Not implemented yet
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
// Constant and macro definitions
|
// Constant and macro definitions
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define REPAIRPROCESS_NUMBER_OF_ROWS (3)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Type definitions.
|
// Type definitions.
|
||||||
@@ -58,6 +58,7 @@ typedef enum
|
|||||||
SOFTSTART,
|
SOFTSTART,
|
||||||
VOLTAGE_HOLD,
|
VOLTAGE_HOLD,
|
||||||
PAUSE,
|
PAUSE,
|
||||||
|
PAUSE_RESTORE,
|
||||||
FINISH_VERIFY,
|
FINISH_VERIFY,
|
||||||
FINISHED
|
FINISHED
|
||||||
} RepairState;
|
} RepairState;
|
||||||
@@ -80,19 +81,17 @@ struct RepairProcess
|
|||||||
uint16_t stackSize;
|
uint16_t stackSize;
|
||||||
bool runTask;
|
bool runTask;
|
||||||
SemaphoreHandle_t secondsSyncronisation;
|
SemaphoreHandle_t secondsSyncronisation;
|
||||||
|
uint32_t startTime;
|
||||||
uint32_t secondsCounter;
|
uint32_t secondsCounter;
|
||||||
|
uint32_t softStartTimer;
|
||||||
|
uint32_t voltageHoldTimer;
|
||||||
RepairState currentState;
|
RepairState currentState;
|
||||||
bool initialized;
|
bool initialized;
|
||||||
|
size_t currentPresetIndex;
|
||||||
struct RepairPreset* repairPreset;
|
struct RepairPreset* repairPreset;
|
||||||
const struct AdcChannel* adcRow1;
|
const struct AdcChannel* adc[REPAIRPROCESS_NUMBER_OF_ROWS];
|
||||||
const struct AdcChannel* adcRow2;
|
const struct MAX5715_DAC* dac[REPAIRPROCESS_NUMBER_OF_ROWS];
|
||||||
const struct AdcChannel* adcRow3;
|
struct Pid pid[REPAIRPROCESS_NUMBER_OF_ROWS];
|
||||||
const struct MAX5715_DAC* dacRow1;
|
|
||||||
const struct MAX5715_DAC* dacRow2;
|
|
||||||
const struct MAX5715_DAC* dacRow3;
|
|
||||||
struct Pid pidRow1;
|
|
||||||
struct Pid pidRow2;
|
|
||||||
struct Pid pidRow3;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -138,7 +138,15 @@ ErrorStatus Display_clearScreen(struct Display* self)
|
|||||||
|
|
||||||
ErrorStatus Display_clearLine(struct Display* self, size_t line)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -881,8 +881,8 @@ static void hwValidationMenuSM(struct HwValidationMenu* self, Button_Pressed_t b
|
|||||||
bool value2 = false;
|
bool value2 = false;
|
||||||
if( self->menuItemSelected == MENU_TEST_INTERLOCK_1)
|
if( self->menuItemSelected == MENU_TEST_INTERLOCK_1)
|
||||||
{
|
{
|
||||||
if( GPIO_getValue(self->testItems->interlock1, &value1) == SUCCESS &&
|
if( GPIO_getValue(self->testItems->interlockNO, &value1) == SUCCESS &&
|
||||||
GPIO_getValue(self->testItems->interlock2, &value2) == SUCCESS
|
GPIO_getValue(self->testItems->interlockNC, &value2) == SUCCESS
|
||||||
){
|
){
|
||||||
outputBufferLength = sprintf(self->outputBuffer, "Interlock: NO: %d - NC: %d\r\n", value1, value2);
|
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(pcba->pcba == Tesla)
|
||||||
{
|
{
|
||||||
|
|
||||||
if( GPIO_getValue(self->testItems->tesla1, &value1) == SUCCESS &&
|
if( GPIO_getValue(self->testItems->teslaNO, &value1) == SUCCESS &&
|
||||||
GPIO_getValue(self->testItems->tesla2, &value2) == SUCCESS
|
GPIO_getValue(self->testItems->teslaNC, &value2) == SUCCESS
|
||||||
){
|
){
|
||||||
outputBufferLength = sprintf(self->outputBuffer, "Interlock (tesla): NO: %d - NC: %d\r\n", value1, value2);
|
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)
|
if( self->menuItemSelected == MENU_TEST_GENERIC_KEYPAD)
|
||||||
{
|
{
|
||||||
char key;
|
|
||||||
Keypad_KeyState keyState;
|
Keypad_KeyState keyState;
|
||||||
char data[CMD_BUFFER_SIZE] = {0};
|
char data[CMD_BUFFER_SIZE] = {0};
|
||||||
|
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ static void initTask(void* parameters)
|
|||||||
|
|
||||||
xTaskCreate(ledBlinkTask, (const char* const)"ledTask", 100, &ledTaskArguments, 0, &ledTaskHandle);
|
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);
|
Storm700_construct(storm700, &keypad->device);
|
||||||
|
|
||||||
@@ -242,10 +242,10 @@ static void initTask(void* parameters)
|
|||||||
hwTestItems.internalADC = adc1;
|
hwTestItems.internalADC = adc1;
|
||||||
hwTestItems.externalDAC = &max5715;
|
hwTestItems.externalDAC = &max5715;
|
||||||
hwTestItems.power6v5Enable = power6v5Enable;
|
hwTestItems.power6v5Enable = power6v5Enable;
|
||||||
hwTestItems.interlock1 = interlock1;
|
hwTestItems.interlockNO = interlockNO;
|
||||||
hwTestItems.interlock2 = interlock2;
|
hwTestItems.interlockNC = interlockNC;
|
||||||
hwTestItems.tesla1 = tesla1;
|
hwTestItems.teslaNO = teslaNO;
|
||||||
hwTestItems.tesla1 = tesla2;
|
hwTestItems.teslaNC = teslaNC;
|
||||||
hwTestItems.solenoid = solenoid;
|
hwTestItems.solenoid = solenoid;
|
||||||
hwTestItems.mcp0Relay = mcp0Relay;
|
hwTestItems.mcp0Relay = mcp0Relay;
|
||||||
hwTestItems.mcp1Relay = mcp1Relay;
|
hwTestItems.mcp1Relay = mcp1Relay;
|
||||||
@@ -253,11 +253,10 @@ static void initTask(void* parameters)
|
|||||||
hwTestItems.cat0Relay = cat0Relay;
|
hwTestItems.cat0Relay = cat0Relay;
|
||||||
hwTestItems.cat1Relay = cat1Relay;
|
hwTestItems.cat1Relay = cat1Relay;
|
||||||
hwTestItems.cat2Relay = cat2Relay;
|
hwTestItems.cat2Relay = cat2Relay;
|
||||||
hwTestItems.teslaLock = teslaLock;
|
|
||||||
hwTestItems.pcba = pcba;
|
hwTestItems.pcba = pcba;
|
||||||
hwTestItems.keypad = keypad;
|
hwTestItems.keypad = keypad;
|
||||||
// EEPROM TO BE DONE
|
// EEPROM TO BE DONE
|
||||||
HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 512);
|
// HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024);
|
||||||
|
|
||||||
// Construct the repair menu
|
// Construct the repair menu
|
||||||
repairMenu_construct(rm, display, 2, 512);
|
repairMenu_construct(rm, display, 2, 512);
|
||||||
|
|||||||
@@ -155,8 +155,8 @@ static void repairMenu_task(void* parameters)
|
|||||||
// struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120};
|
// struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120};
|
||||||
// struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30};
|
// struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30};
|
||||||
|
|
||||||
struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 300, .softstartDuration = 120};
|
struct RepairPresetParameters presetStage1 = {.voltage = 0xE00, .duration = 7200, .softstartDuration = 1800};
|
||||||
struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 120, .softstartDuration = 30};
|
struct RepairPresetParameters presetStage2 = {.voltage = 0x600, .duration = 1800, .softstartDuration = 900};
|
||||||
|
|
||||||
struct RepairPreset repairPreset;
|
struct RepairPreset repairPreset;
|
||||||
repairPreset.numberOfStages = 2;
|
repairPreset.numberOfStages = 2;
|
||||||
@@ -186,15 +186,15 @@ static void repairMenu_task(void* parameters)
|
|||||||
Display_write(self->display, "R3", strlen("R3"), 3, 17);
|
Display_write(self->display, "R3", strlen("R3"), 3, 17);
|
||||||
|
|
||||||
uint16_t value;
|
uint16_t value;
|
||||||
ADCChannel_read(rp->adcRow1, &value);
|
ADCChannel_read(rp->adc[0], &value);
|
||||||
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
|
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
|
||||||
Display_write(self->display, buffer, strlen(buffer), 4, 1);
|
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);
|
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
|
||||||
Display_write(self->display, buffer, strlen(buffer), 4, 8);
|
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);
|
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04xV", value);
|
||||||
Display_write(self->display, buffer, strlen(buffer), 4, 15);
|
Display_write(self->display, buffer, strlen(buffer), 4, 15);
|
||||||
|
|
||||||
|
|||||||
@@ -55,13 +55,14 @@
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Function declarations
|
// Function declarations
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void repairProcess_task(void* parameters);
|
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
|
// Function definitions
|
||||||
@@ -91,21 +92,21 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro
|
|||||||
self->initialized = true;
|
self->initialized = true;
|
||||||
self->currentState = PREPARE;
|
self->currentState = PREPARE;
|
||||||
|
|
||||||
self->adcRow1 = parameters->adcRow1;
|
self->adc[0] = parameters->adcRow1;
|
||||||
self->adcRow2 = parameters->adcRow2;
|
self->adc[1] = parameters->adcRow2;
|
||||||
self->adcRow3 = parameters->adcRow3;
|
self->adc[2] = parameters->adcRow3;
|
||||||
self->dacRow1 = parameters->dacRow1;
|
self->dac[0] = parameters->dacRow1;
|
||||||
self->dacRow2 = parameters->dacRow2;
|
self->dac[1] = parameters->dacRow2;
|
||||||
self->dacRow3 = parameters->dacRow3;
|
self->dac[2] = parameters->dacRow3;
|
||||||
|
|
||||||
self->pidRow1.initialized = false;
|
self->pid[0].initialized = false;
|
||||||
self->pidRow2.initialized = false;
|
self->pid[1].initialized = false;
|
||||||
self->pidRow3.initialized = false;
|
self->pid[2].initialized = false;
|
||||||
|
|
||||||
|
|
||||||
PID_construct(&self->pidRow1, 10, 10, 10, 0, 10000000);
|
PID_construct(&self->pid[0], 5000, 3000, 0, 0, 10000000);
|
||||||
PID_construct(&self->pidRow2, 100, 0, 0, 0, 10000000);
|
PID_construct(&self->pid[1], 5000, 3000, 0, 0, 100000000);
|
||||||
PID_construct(&self->pidRow3, 10, 10, 10, 0, 10000000);
|
PID_construct(&self->pid[2], 5000, 3000, 0, 0, 10000000);
|
||||||
|
|
||||||
LOGGER_INFO(mainLog, "Repair Process task started");
|
LOGGER_INFO(mainLog, "Repair Process task started");
|
||||||
}
|
}
|
||||||
@@ -165,34 +166,73 @@ static void repairProcess_task(void* parameters)
|
|||||||
{
|
{
|
||||||
struct RepairProcess* self = (struct RepairProcess*)parameters;
|
struct RepairProcess* self = (struct RepairProcess*)parameters;
|
||||||
|
|
||||||
uint8_t presetIndex = 0;
|
int signal;
|
||||||
uint32_t startTime = 0;
|
uint16_t adcValue;
|
||||||
uint32_t softStartTimer = 0;
|
int error;
|
||||||
uint32_t voltageHoldTimer = 0;
|
int pid;
|
||||||
|
int loopCounter;
|
||||||
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;
|
|
||||||
|
|
||||||
|
|
||||||
// Reset the seconds counter to 0
|
// Reset the seconds counter to 0
|
||||||
self->secondsCounter = 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)
|
while(self->runTask)
|
||||||
{
|
{
|
||||||
xSemaphoreTake(self->secondsSyncronisation, portMAX_DELAY);
|
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)
|
switch (self->currentState)
|
||||||
{
|
{
|
||||||
@@ -201,110 +241,61 @@ static void repairProcess_task(void* parameters)
|
|||||||
LOGGER_DEBUG(mainLog, "Repair Process: Preparing new stage of repair process");
|
LOGGER_DEBUG(mainLog, "Repair Process: Preparing new stage of repair process");
|
||||||
// Prepare a new repair process
|
// Prepare a new repair process
|
||||||
//Load the timers
|
//Load the timers
|
||||||
startTime = self->secondsCounter;
|
self->startTime = self->secondsCounter;
|
||||||
softStartTimer = self->secondsCounter + self->repairPreset->preset[presetIndex].softstartDuration;
|
self->softStartTimer = self->secondsCounter + self->repairPreset->preset[self->currentPresetIndex].softstartDuration;
|
||||||
LOGGER_DEBUG(mainLog, "Softstart timer is %d (%d + %d)", softStartTimer, self->secondsCounter, self->repairPreset->preset[presetIndex].softstartDuration);
|
LOGGER_DEBUG(mainLog, "Softstart timer is %d (%d + %d)", self->softStartTimer, self->secondsCounter, self->repairPreset->preset[self->currentPresetIndex].softstartDuration);
|
||||||
voltageHoldTimer = self->secondsCounter + self->repairPreset->preset[presetIndex].duration;
|
self->voltageHoldTimer = self->secondsCounter + self->repairPreset->preset[self->currentPresetIndex].duration;
|
||||||
LOGGER_DEBUG(mainLog, "Voltagehold timer is %d (%d + %d)", voltageHoldTimer, self->secondsCounter, self->repairPreset->preset[presetIndex].duration);
|
LOGGER_DEBUG(mainLog, "Voltagehold timer is %d (%d + %d)", self->voltageHoldTimer, self->secondsCounter, self->repairPreset->preset[self->currentPresetIndex].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->currentState = SOFTSTART;
|
self->currentState = SOFTSTART;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SOFTSTART:
|
case SOFTSTART:
|
||||||
{
|
{
|
||||||
// Perform softstart / ramp-up
|
// Still in Softstart
|
||||||
|
int startVoltage = 0;
|
||||||
|
|
||||||
LOGGER_DEBUG(mainLog, "------------------------------");
|
// If first preset, start voltage is 0
|
||||||
|
if (self->currentPresetIndex == 0)
|
||||||
if (PCBA_getInstance()->pcba == Tesla)
|
|
||||||
{
|
{
|
||||||
// Tesla repair only runs ADC row2 and DAC row2
|
startVoltage = 0;
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
// Check for end of softstart
|
||||||
if (softStartTimer < self->secondsCounter)
|
if (self->softStartTimer < self->secondsCounter)
|
||||||
{
|
{
|
||||||
// softstart finished
|
// softstart finished
|
||||||
self->currentState = VOLTAGE_HOLD;
|
self->currentState = VOLTAGE_HOLD;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case VOLTAGE_HOLD:
|
case VOLTAGE_HOLD:
|
||||||
{
|
{
|
||||||
// Actual repair state - hold target voltage until duration has passed
|
returnValue = self->repairPreset->preset[self->currentPresetIndex].voltage;
|
||||||
LOGGER_DEBUG(mainLog, "------------------------------");
|
|
||||||
|
|
||||||
if (PCBA_getInstance()->pcba == Tesla)
|
// Check for end of voltage hold
|
||||||
{
|
if (self->voltageHoldTimer < self->secondsCounter)
|
||||||
// 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)
|
|
||||||
{
|
{
|
||||||
// softstart finished
|
// softstart finished
|
||||||
self->currentState = FINISH_VERIFY;
|
self->currentState = FINISH_VERIFY;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PAUSE:
|
case PAUSE:
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PAUSE_RESTORE:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
case FINISH_VERIFY:
|
case FINISH_VERIFY:
|
||||||
{
|
{
|
||||||
// The current preset might contain multiple stages, so before going to FINISHED state
|
// 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
|
// presetIndex carries the current index in the preset array
|
||||||
// number of stages is 1-based (Starting with 1) while presetIndex is 0-based
|
// number of stages is 1-based (Starting with 1) while presetIndex is 0-based
|
||||||
// So, the verification must compensate for the different bases
|
// 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
|
// A next stage is available
|
||||||
presetIndex++;
|
self->currentPresetIndex++;
|
||||||
self->currentState = PREPARE;
|
self->currentState = PREPARE;
|
||||||
LOGGER_DEBUG(mainLog, "Another stage is available");
|
LOGGER_DEBUG(mainLog, "Another stage is available");
|
||||||
}
|
}
|
||||||
@@ -327,62 +318,17 @@ static void repairProcess_task(void* parameters)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case FINISHED:
|
case FINISHED:
|
||||||
{
|
{
|
||||||
voltageRow1 = 0;
|
returnValue = 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");
|
|
||||||
break;
|
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
|
else
|
||||||
{
|
{
|
||||||
// In voltage hold
|
returnValue = -1;
|
||||||
returnValue = repairPreset->preset[presetIndex].voltage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ void IRQ_setKeypadEXTI(struct Keypad* self, FunctionalState command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function handles SVCall exception.
|
* @brief This function handles SVCall exception.
|
||||||
* @param None
|
* @param None
|
||||||
@@ -229,6 +230,10 @@ void SPI3_IRQHandler (void)
|
|||||||
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EXTI4_IRQHandler(void)
|
void EXTI4_IRQHandler(void)
|
||||||
{
|
{
|
||||||
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
||||||
|
|||||||
Reference in New Issue
Block a user