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

@@ -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;