Created a version that regulates negatively. Buggy, though. Enough for pre-compliance but must be fixed afterwards

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@264 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-25 06:33:49 +00:00
parent a41e792565
commit 6cc49f4e47
11 changed files with 147 additions and 42 deletions

View File

@@ -48,7 +48,7 @@
#define HSB_MAINREPR_TASK_PRIORITY (2)
#define HSB_MAINREPR_TASK_STACKSIZE (1024)
#define HSB_MAINREPR_OOL_DURATION (20)
#define HSB_MAINREPR_OOL_VALUE (200)
#define HSB_MAINREPR_OOL_VALUE (300)
#define HSB_ADC_ANODE_MIN_VOLTAGE (0)
#define HSB_ADC_ANODE_MAX_VOLTAGE (10042)

View File

@@ -27,6 +27,8 @@
#include "ADConverter.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
@@ -100,20 +102,21 @@ static int calculateVoltage(const struct ADConverter* self, uint32_t adcValue)
int returnValue = 0;
if (self->initialized)
{
uint32_t maxAdcValue = ((1 << self->adcDevice->resolutionInBits) - 1);
int maxAdcValue = ((1 << self->adcDevice->resolutionInBits) - 1);
returnValue = adcValue * (self->maxVoltage - self->minVoltage);
returnValue = (int)adcValue * (self->maxVoltage - self->minVoltage);
returnValue = returnValue / maxAdcValue;
returnValue = returnValue + self->minVoltage;
if (returnValue < self->minVoltage)
{
returnValue = self->minVoltage;
}
else if (returnValue > self->maxVoltage)
{
returnValue = self->maxVoltage;
}
LOGGER_DEBUG(mainLog, "%X, %d, %d, %d", adcValue, self->maxVoltage, self->minVoltage, returnValue);
// if (returnValue < self->minVoltage)
// {
// returnValue = self->minVoltage;
// }
// else if (returnValue > self->maxVoltage)
// {
// returnValue = self->maxVoltage;
// }
}
else
{

View File

@@ -27,6 +27,8 @@
#include "DAConverter.h"
#include "Logger.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
@@ -89,6 +91,7 @@ extern ErrorStatus DAConverter_setOutputVoltage(const struct DAConverter* self,
uint32_t dacValue;
dacValue = calculateDACValue(self, voltage);
DACDevice_write(self->dacDevice, dacValue);
LOGGER_DEBUG(mainLog, "Voltage %d --- value %X", voltage, dacValue);
}
}
else
@@ -105,8 +108,8 @@ static uint32_t calculateDACValue(const struct DAConverter* self, int voltage)
if (self->initialized)
{
uint32_t maxDacValue = ((1 << self->dacDevice->resolutionInBits) - 1);
dacValue = (voltage - self->minVoltage) * maxDacValue;
dacValue/= (self->maxVoltage - self->minVoltage);
dacValue = (abs(voltage) - abs(self->minVoltage)) * maxDacValue;
dacValue/= (abs(self->maxVoltage) - abs(self->minVoltage));
if (dacValue > maxDacValue)
{
dacValue = maxDacValue;

View File

@@ -138,7 +138,7 @@ void SignalProfileGenerator_calculate(struct SignalProfileGenerator* self)
{
self->isProcessRunning = true;
self->signal = ((self->repairPreset->preset[self->currentPresetIndex].voltage * SPG_FIXPOINT_FACTOR - self->startVoltage * SPG_FIXPOINT_FACTOR) / self->repairPreset->preset[self->currentPresetIndex].softstartDuration) * (self->secondsCounter - self->startTime) + self->startVoltage * SPG_FIXPOINT_FACTOR;
self->signal = ((self->repairPreset->preset[self->currentPresetIndex].voltage * SPG_FIXPOINT_FACTOR - (self->startVoltage * SPG_FIXPOINT_FACTOR)) / self->repairPreset->preset[self->currentPresetIndex].softstartDuration) * (self->secondsCounter - self->startTime) + (self->startVoltage * SPG_FIXPOINT_FACTOR);
self->signal = self->signal / SPG_FIXPOINT_FACTOR;
incrementSecondsCounter(self);

View File

@@ -240,6 +240,16 @@ static void initTask(void* parameters)
// Construct the repair menu
repairMenus_construct();
// DAConverter_setOutputVoltage(dacRow1, -500);
// DAConverter_setOutputVoltage(dacRow2, -400);
// DAConverter_setOutputVoltage(dacRow3, -300);
//
// while (1)
// {
// LOGGER_DEBUG(mainLog, "%i %i %i", ADConverter_getInputVoltage(adcRow1), ADConverter_getInputVoltage(adcRow2), ADConverter_getInputVoltage(adcRow3));
// vTaskDelay(1000);
// }
// xTaskCreate(printSystemInfoTask, (const char* const)"SysInfoTask", 512, NULL, 0, &sysTaskHandle);

View File

@@ -71,16 +71,36 @@ static const char cursorValue[2] = {0x7E, '\0'};
// TEMPORARY PRESET STORAGE
static const struct RepairPreset preset1 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 60, .preset[0].voltage = 1000};
static const struct RepairPreset preset2 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000};
static const struct RepairPreset preset3 = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300};
static const struct RepairPreset preset4 = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400};
static const struct RepairPreset preset5 = {.numberOfStages = 1, .preset[0].softstartDuration = 500, .preset[0].duration = 1000, .preset[0].voltage = 500};
static const struct RepairPreset preset6 = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = 600};
static const struct RepairPreset preset7 = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700};
static const struct RepairPreset preset8 = {.numberOfStages = 1, .preset[0].softstartDuration = 800, .preset[0].duration = 1600, .preset[0].voltage = 800};
static const struct RepairPreset preset9 = {.numberOfStages = 2, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 6000, .preset[1].softstartDuration = 100, .preset[1].duration = 1800, .preset[1].voltage = 8000};
static const struct RepairPreset* presetArray[9] = {&preset1, &preset2, &preset3, &preset4, &preset5, &preset6, &preset7, &preset8, &preset9};
static const struct RepairPreset preset1t = {.numberOfStages = 1, .preset[0].softstartDuration = 100, .preset[0].duration = 200, .preset[0].voltage = 1000};
static const struct RepairPreset preset2t = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000};
static const struct RepairPreset preset3t = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300};
static const struct RepairPreset preset4t = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400};
static const struct RepairPreset preset5t = {.numberOfStages = 1, .preset[0].softstartDuration = 500, .preset[0].duration = 1000, .preset[0].voltage = 500};
static const struct RepairPreset preset6t = {.numberOfStages = 1, .preset[0].softstartDuration = 120, .preset[0].duration = 240, .preset[0].voltage = 800};
static const struct RepairPreset preset7t = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700};
static const struct RepairPreset preset8t = {.numberOfStages = 1, .preset[0].softstartDuration = 120, .preset[0].duration = 300, .preset[0].voltage = 4000};
static const struct RepairPreset preset9t = {.numberOfStages = 2, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 4000, .preset[1].softstartDuration = 100, .preset[1].duration = 1800, .preset[1].voltage = 5000};
static const struct RepairPreset preset1a = {.numberOfStages = 1, .preset[0].softstartDuration = 000, .preset[0].duration = 200, .preset[0].voltage = 1000};
static const struct RepairPreset preset2a = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000};
static const struct RepairPreset preset3a = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300};
static const struct RepairPreset preset4a = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400};
static const struct RepairPreset preset5a = {.numberOfStages = 1, .preset[0].softstartDuration = 500, .preset[0].duration = 1000, .preset[0].voltage = 500};
static const struct RepairPreset preset6a = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = 800};
static const struct RepairPreset preset7a = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700};
static const struct RepairPreset preset8a = {.numberOfStages = 1, .preset[0].softstartDuration = 120, .preset[0].duration = 300, .preset[0].voltage = 6000};
static const struct RepairPreset preset9a = {.numberOfStages = 2, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 6000, .preset[1].softstartDuration = 100, .preset[1].duration = 1800, .preset[1].voltage = 8000};
static const struct RepairPreset preset1n = {.numberOfStages = 1, .preset[0].softstartDuration = 100, .preset[0].duration = 200, .preset[0].voltage = -1000};
static const struct RepairPreset preset2n = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = -1800};
static const struct RepairPreset preset3n = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = -300};
static const struct RepairPreset preset4n = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = -400};
static const struct RepairPreset preset5n = {.numberOfStages = 1, .preset[0].softstartDuration = 500, .preset[0].duration = 1000, .preset[0].voltage = -500};
static const struct RepairPreset preset6n = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = -600};
static const struct RepairPreset preset7n = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = -700};
static const struct RepairPreset preset8n = {.numberOfStages = 1, .preset[0].softstartDuration = 120, .preset[0].duration = 300, .preset[0].voltage = -1800};
static const struct RepairPreset preset9n = {.numberOfStages = 2, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = -1200, .preset[1].softstartDuration = 100, .preset[1].duration = 1800, .preset[1].voltage = -1600};
static const struct RepairPreset* presetArray[9];
// -----------------------------------------------------------------------------
// Function declarations
@@ -161,6 +181,43 @@ ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* displa
if (returnValue == SUCCESS)
{
if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
presetArray[0] = &preset1n;
presetArray[1] = &preset2n;
presetArray[2] = &preset3n;
presetArray[3] = &preset4n;
presetArray[4] = &preset5n;
presetArray[5] = &preset6n;
presetArray[6] = &preset7n;
presetArray[7] = &preset8n;
presetArray[8] = &preset9n;
}
else if (PCBA_getInstance()->pcba == PCBA_Anode)
{
presetArray[0] = &preset1a;
presetArray[1] = &preset2a;
presetArray[2] = &preset3a;
presetArray[3] = &preset4a;
presetArray[4] = &preset5a;
presetArray[5] = &preset6a;
presetArray[6] = &preset7a;
presetArray[7] = &preset8a;
presetArray[8] = &preset9a;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
presetArray[0] = &preset1t;
presetArray[1] = &preset2t;
presetArray[2] = &preset3t;
presetArray[3] = &preset4t;
presetArray[4] = &preset5t;
presetArray[5] = &preset6t;
presetArray[6] = &preset7t;
presetArray[7] = &preset8t;
presetArray[8] = &preset9t;
}
// Construct the menu based on PCBA information
returnValue = repairMenu_createMenu(self);

View File

@@ -232,7 +232,7 @@ static void repairProcess_task(void* parameters)
LOGGER_DEBUG(mainLog, "Signal: %d, TimeToRemain %d", self->signalProfileGenerator.signal, SignalProfileGenerator_getRemainingTime(&self->signalProfileGenerator));
// Check for correct signal
if (self->signalProfileGenerator.signal >= 0)
// if (self->signalProfileGenerator.signal >= 0)
{
// Regulation is unique for each row
// For TESLA repair only row 1 (out of 0,1,2) is used
@@ -246,22 +246,8 @@ static void repairProcess_task(void* parameters)
// Calculate the error
self->row[loopCounter].pidError = self->signalProfileGenerator.signal - (int)self->row[loopCounter].lastADCValue;
// Calculate the PID
int pidCalculate = PID_calculate(&self->row[loopCounter].pid, self->row[loopCounter].pidError);
self->row[loopCounter].lastDACValue = PID_calculate(&self->row[loopCounter].pid, self->row[loopCounter].pidError);
///TODO MUST BE MOVED TO DACDevice
// Verify that pid value does not overflow the DAC
if (pidCalculate > 0xFFF)
{
self->row[loopCounter].lastDACValue = 0xFFF;
}
else if (pidCalculate < 0)
{
self->row[loopCounter].lastDACValue = 0;
}
else
{
self->row[loopCounter].lastDACValue = pidCalculate;
}
// Check if the error condition exceeds the tolerated duration
if (self->row[loopCounter].errorData.outOfLimitsCounter >= self->row[loopCounter].errorData.outOfLimitsDuration)

View File

@@ -27,6 +27,8 @@
#include "repairProcessRow.h"
#include "PCBA.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
@@ -58,6 +60,9 @@ ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const stru
{
ErrorStatus returnValue = SUCCESS;
int iMin = 0;
int iMax = 0;
if (!self->initialized)
{
if (returnValue == SUCCESS)
@@ -75,7 +80,22 @@ ErrorStatus repairProcessRow_construct(struct RepairProcessRow* self, const stru
if (returnValue == SUCCESS)
{
returnValue = PID_construct(&self->pid, 3000, 2000, 0, 0, 100000000);
if (PCBA_getInstance()->pcba == PCBA_Anode)
{
iMin = 0;
iMax = 100000000;
}
else if (PCBA_getInstance()->pcba == PCBA_CathodeMCP)
{
iMin = -100000000;
iMax = 0;
}
else if (PCBA_getInstance()->pcba == PCBA_Tesla)
{
iMin = 0;
iMax = 100000000;
}
returnValue = PID_construct(&self->pid, 3000, 2000, 0, iMin, iMax);
}
if (returnValue == SUCCESS)
{