Fixed issue with external DAC handlign from repair process

repair process implemented. Simple regulation without feedback (must be addeed, yet)

HW validation menu functional but buggy (IOs not OK)

Added ClearLine functionality to displayDevice

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@244 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-09 15:29:23 +00:00
parent 0e69a81570
commit a73154a5e6
25 changed files with 1054 additions and 229 deletions

View File

@@ -34,6 +34,9 @@
#include "repairPreset.h"
#include "Logger.h"
#include "MAX5715.h"
#include "PCBA.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
@@ -58,12 +61,14 @@
static void repairProcess_task(void* parameters);
static void calculateSoftStartStep (uint32_t currentTime, uint32_t softStartDuration, int targetVoltage, uint16_t* dacValue);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus repairProcess_construct(struct RepairProcess* self, int taskPriority, uint16_t stackSize)
ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, int taskPriority, uint16_t stackSize)
{
ErrorStatus returnValue = SUCCESS;
@@ -71,10 +76,11 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, int taskPriority
{
// Create a semaphore to sync access to the display shadow
vSemaphoreCreateBinary(self->secondsSyncronisation);
xSemaphoreGive(self->secondsSyncronisation);
xSemaphoreTake(self->secondsSyncronisation, 0);
if (xTaskCreate(repairProcess_task, "RepairProcess", stackSize, self, taskPriority, &self->taskHandle) != pdTRUE)
BaseType_t rv = xTaskCreate(repairProcess_task, "RepairProcess", stackSize, self, taskPriority, &self->taskHandle);
if (rv != pdTRUE)
{
returnValue = ERROR;
}
@@ -82,6 +88,21 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, int taskPriority
if (returnValue == SUCCESS)
{
self->runTask = true;
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;
LOGGER_INFO(mainLog, "Repair Process task started");
}
else
{
LOGGER_ERROR(mainLog, "FAILED to start repair Process with code %d", (int)rv);
}
}
else
@@ -95,18 +116,39 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, int taskPriority
void repairProcess_feedSecondsCounter(struct RepairProcess* self)
{
xSemaphoreGive(self->secondsSyncronisation);
if (self->initialized)
{
xSemaphoreGive(self->secondsSyncronisation);
}
}
void repairProcess_feedSecondsCounterFromISR(struct RepairProcess* self)
{
portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(self->secondsSyncronisation, &higherPriorityTaskWoken);
if (self->initialized)
{
xSemaphoreGiveFromISR(self->secondsSyncronisation, &higherPriorityTaskWoken);
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
ErrorStatus repairProcess_getRepairTime(const struct RepairProcess* self, uint32_t* repairTime)
{
ErrorStatus returnValue = SUCCESS;
if (self->initialized)
{
*repairTime = self->secondsCounter;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
@@ -114,17 +156,170 @@ static void repairProcess_task(void* parameters)
{
struct RepairProcess* self = (struct RepairProcess*)parameters;
uint8_t presetIndex = 0;
uint32_t softStartTimer = 0;
uint32_t voltageHoldTimer = 0;
uint16_t voltageTarget = 0;
uint16_t voltageRow1 = 0;
uint16_t voltageRow2 = 0;
uint16_t voltageRow3 = 0;
// Reset the seconds counter to 0
self->secondsCounter = 0;
while(self->runTask)
{
xSemaphoreTake(self->secondsSyncronisation, portMAX_DELAY);
int hours = (self->secondsCounter / (60 * 60));
int minutes = (self->secondsCounter - (hours * 60 * 60)) / 60;
int seconds = (self->secondsCounter - (hours * 60 * 60) - (minutes * 60));
LOGGER_WARNING(mainLog, "--- Repair clock %02i %02d %02d", hours, minutes, seconds);
switch (self->currentState)
{
case PREPARE:
{
LOGGER_DEBUG(mainLog, "Repair Process: Preparing new stage of repair process");
// Prepare a new repair process
//Load the timers
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->currentState = SOFTSTART;
break;
}
case SOFTSTART:
{
// Perform softstart / ramp-up
if (PCBA_getInstance()->pcba == Tesla)
{
// Tesla repair only runs ADC row2 and DAC row2
calculateSoftStartStep(self->secondsCounter, softStartTimer, voltageTarget, &voltageRow2);
LOGGER_DEBUG(mainLog, "Softstart running -> new target is %x", voltageRow2);
MAX5715Channel_setValue(self->dacRow2, voltageRow2);
}
else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP))
{
calculateSoftStartStep(self->secondsCounter, softStartTimer, voltageTarget, &voltageRow1);
calculateSoftStartStep(self->secondsCounter, softStartTimer, voltageTarget, &voltageRow2);
calculateSoftStartStep(self->secondsCounter, softStartTimer, voltageTarget, &voltageRow3);
LOGGER_DEBUG(mainLog, "Softstart running -> new target is %x %x %x", voltageRow1, voltageRow2, voltageRow3);
MAX5715Channel_setValue(self->dacRow1, voltageRow1);
MAX5715Channel_setValue(self->dacRow2, voltageRow2);
MAX5715Channel_setValue(self->dacRow3, voltageRow3);
}
// Check for end of softstart
if (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, "Voltage Hold running -> target is %x", voltageTarget);
if (PCBA_getInstance()->pcba == Tesla)
{
// Tesla repair only runs ADC row2 and DAC row2
MAX5715Channel_setValue(self->dacRow2, voltageTarget);
}
else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP))
{
MAX5715Channel_setValue(self->dacRow1, voltageTarget);
MAX5715Channel_setValue(self->dacRow2, voltageTarget);
MAX5715Channel_setValue(self->dacRow3, voltageTarget);
}
// Check for end of softstart
if (voltageHoldTimer < self->secondsCounter)
{
// softstart finished
self->currentState = FINISH_VERIFY;
}
break;
}
case PAUSE:
{
break;
}
case FINISH_VERIFY:
{
// The current preset might contain multiple stages, so before going to FINISHED state
// verify that no further stage must be entered
// 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))
{
// A next stage is available
presetIndex++;
self->currentState = PREPARE;
}
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");
break;
}
default:
LOGGER_ERROR(mainLog, "Repair Process state machine reached unknown state");
}
self->secondsCounter++;
}
LOGGER_INFO(mainLog, "Deleting repairProcess task");
vTaskDelete(self->taskHandle);
}
static void calculateSoftStartStep (uint32_t currentTime, uint32_t softStartDuration, int targetVoltage, uint16_t* dacValue)
{
int value;
value = ((currentTime * 1000) / softStartDuration) * targetVoltage;
value = value / 1000;
*dacValue = (uint16_t)value;
}