optimation temp & adc

This commit is contained in:
Noah Piqué
2021-11-17 14:34:41 +01:00
parent 04d2bab659
commit cb3449f487
7 changed files with 51 additions and 40 deletions

View File

@ -58,15 +58,16 @@
#define INT_ADC_REF_LO (0.0f) // LO int. reference voltage for conversion
#define INT_ADC_REF (INT_ADC_REF_HI-INT_ADC_REF_LO)// int. reference voltage for conversion
#define BUFFER_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR * 2
#define BUFFER_HALF_SIZE NR_OF_ADCS * ANPI_OVERSAMPLING_FACTOR
#define BUFFER_SIZE NR_OF_ADCS * 2
#define BUFFER_HALF_SIZE NR_OF_ADCS
#define ANPI_ADC_HALF_COMPLETE ((U32)1<<0)
#define ANPI_ADC_FULL_COMPLETE ((U32)1<<1)
#define ANPI_FLAGS_ALL ( ANPI_ADC_HALF_COMPLETE | ANPI_ADC_FULL_COMPLETE )
#define OFFSET 1.026f
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
//=================================================================================================
// Section: MACROS
@ -270,8 +271,6 @@ VOID ANPI_vTask( PVOID arg )
{
u32Flags = osEventFlagsWait( m_pstEventID, ANPI_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
DIPO_vSetOutput(DIPO_eLED);
if( u32Flags & ANPI_ADC_FULL_COMPLETE )
{
u16Offset = BUFFER_HALF_SIZE;
@ -284,29 +283,30 @@ VOID ANPI_vTask( PVOID arg )
// reset the sum for calculating the mean
memset( m_au32ADCRawData, 0, sizeof(m_au32ADCRawData) );
// calculate the mean of the samples to get a better result
// build the sum of the values...
for(U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
{
m_au32ADCRawData[ u16Cnt % NR_OF_ADCS ] += m_au16ADCDataBuffer[eADC1][u16Cnt + u16Offset];
//m_au32ADCRawData[ u16Cnt % NR_OF_ADCS ] = m_au16ADCDataBuffer[eADC1][u16Cnt + u16Offset];
}
// ... multiply by the conversion factor and add the offset
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
// save the values in the buffer...
for(U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
{
m_au32ADCRawData[ u16Cnt ] = m_au16ADCDataBuffer[eADC1][u16Cnt + u16Offset];
}
// ... multiply by the conversion factor and add the offset
for(U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
{
m_aflValues[u16Cnt] = ((((FLOAT)m_au32ADCRawData[u16Cnt] / (FLOAT)ANPI_OVERSAMPLING_FACTOR * OFFSET) - (FLOAT)m_aflOffset1[u16Cnt] ) *
if(u16Cnt == ANPI_eOutputVoltage){
m_aflValues[u16Cnt] = 0.0f;
continue;
}
m_aflValues[u16Cnt] = ((((FLOAT)m_au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR) - (FLOAT)m_aflOffset1[u16Cnt] ) *
(FLOAT)m_aflConversionFactor[u16Cnt]) - (FLOAT)m_aflOffset2[u16Cnt];
//m_aflValues[u16Cnt] = (FLOAT)m_au32ADCRawData[u16Cnt];
}
osMutexRelease( m_pstMutexID ); // release mutex
DIPO_vResetOutput(DIPO_eLED);
}
}