Major updates:
- added DAConverter(s) - added ADConverter(s) - Fixed some display issues - Made repair process and signalProfileGenerator calculate with voltages (signed) instead of DAC/ADC values - Fixed several bugs in task handlings - Put display data mirror into dedicated file displaycontent git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@261 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "IODevice.h"
|
||||
#include "ADCDevice.h"
|
||||
|
||||
#include "stm32f10x.h"
|
||||
#include "stm32f10x_adc.h"
|
||||
@@ -43,6 +43,7 @@
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define ADC_RESOLUTION_IN_BITS (12)
|
||||
#define ADC_AVERAGE_DEPTH (10)
|
||||
#define ADC_NUMBER_OF_CHANNELS (18) // 16 IOs + Temp + Vcc
|
||||
|
||||
@@ -61,7 +62,7 @@ struct AdcChannelParameters
|
||||
|
||||
struct AdcChannel
|
||||
{
|
||||
struct IODevice device;
|
||||
struct ADCDevice adcDevice;
|
||||
struct Adc* parent;
|
||||
uint8_t channel;
|
||||
uint8_t Rank;
|
||||
|
||||
@@ -26,7 +26,11 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#include "ADCDevice.h"
|
||||
|
||||
#include "internalADC.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
@@ -49,8 +53,8 @@
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// NO WRITE - ADCs cannot write
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
|
||||
|
||||
static uint32_t channelRead(const struct ADCDevice* self);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
@@ -160,25 +164,27 @@ ErrorStatus ADCChannel_construct(struct AdcChannel* self, struct Adc* parent, st
|
||||
{
|
||||
if (!self->initialized)
|
||||
{
|
||||
IODevice_construct(&self->device, read, NULL);
|
||||
returnValue = ADCDevice_construct(&self->adcDevice, channelRead, ADC_RESOLUTION_IN_BITS);
|
||||
|
||||
if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
self->Rank = parameters->Rank;
|
||||
if ((parameters->Rank) > 0 && (parameters->Rank <= 16))
|
||||
{
|
||||
self->Rank = parameters->Rank;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
if (parameters->channel < ADC_NUMBER_OF_CHANNELS)
|
||||
{
|
||||
self->channel = parameters->channel;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
if (parameters->channel < ADC_NUMBER_OF_CHANNELS)
|
||||
{
|
||||
self->channel = parameters->channel;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
@@ -213,35 +219,34 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
// Reading ADC value is automatically combined with an floating averaging
|
||||
uint32_t average = 0;
|
||||
int loopCounter;
|
||||
for (loopCounter = self->channel; loopCounter < self->parent->numberOfUsedChannels * ADC_AVERAGE_DEPTH; loopCounter = loopCounter + self->parent->numberOfUsedChannels)
|
||||
if (self->initialized)
|
||||
{
|
||||
average = average + self->parent->channelValue[loopCounter];
|
||||
// Reading ADC value is automatically combined with an floating averaging
|
||||
uint32_t average = 0;
|
||||
int loopCounter;
|
||||
for (loopCounter = self->channel; loopCounter < self->parent->numberOfUsedChannels * ADC_AVERAGE_DEPTH; loopCounter = loopCounter + self->parent->numberOfUsedChannels)
|
||||
{
|
||||
average = average + self->parent->channelValue[loopCounter];
|
||||
}
|
||||
*value = average / ADC_AVERAGE_DEPTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
*value = average / ADC_AVERAGE_DEPTH;
|
||||
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
|
||||
static uint32_t channelRead(const struct ADCDevice* self)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
(void)length;
|
||||
|
||||
uint16_t adcValue = 0;
|
||||
returnValue = ADCChannel_read((struct AdcChannel*)self, &adcValue);
|
||||
|
||||
buffer[0] = adcValue >> 8;
|
||||
buffer[1] = adcValue;
|
||||
|
||||
*actualLength = 2;
|
||||
|
||||
uint32_t returnValue = 0;
|
||||
uint16_t value;
|
||||
if (ADCChannel_read((struct AdcChannel*)self, &value) == SUCCESS)
|
||||
{
|
||||
returnValue = (((1 << ADC_RESOLUTION_IN_BITS) - 1) & value);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "Logger.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "CathodeMCP.h"
|
||||
#include "gpio.h"
|
||||
#include "Interlock.h"
|
||||
#include "internalADC.h"
|
||||
@@ -792,6 +793,7 @@ static ErrorStatus initPlatformDevices (void)
|
||||
/* NewHavenDispplay 04 20 */
|
||||
/* --------------------------------------------------------------------*/
|
||||
returnValue = NHD0420_construct(nhd0420, &spiDisplay->device);
|
||||
// returnValue = NHD0420_construct(nhd0420, &uart1->device);
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
|
||||
Reference in New Issue
Block a user