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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user