optimation temp & adc
This commit is contained in:
parent
04d2bab659
commit
cb3449f487
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
Debug/**
|
||||
Debug/
|
||||
/Release/
|
||||
|
@ -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;
|
||||
@ -285,28 +284,29 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,6 @@ extern "C" {
|
||||
// Description: Definition of global constants (visible by all modules).
|
||||
//=================================================================================================
|
||||
|
||||
// attention: perhaps you have to change the ADC sample time in ANPI_AnalogPortsIn.c
|
||||
//#define ANPI_OVERSAMPLING_FACTOR 64
|
||||
#define ANPI_OVERSAMPLING_FACTOR 64
|
||||
|
||||
#if( ANPI_OVERSAMPLING_FACTOR % 2 != 0 )
|
||||
//#error "ANPI_OVERSAMPLING_FACTOR must be power of 2!"
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
|
@ -82,6 +82,8 @@
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
|
||||
BOOL boEnableOutput = FALSE;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: LOCAL CONSTANTS
|
||||
@ -164,11 +166,22 @@ BOOL PECO_boSetTemperature( S16 Temperature ){
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_Enable
|
||||
// Description: Enables the Peltier Controller Output
|
||||
// Parameters: BOOL Enable
|
||||
// Parameters: BOOL boEnable
|
||||
// Returns: None
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
VOID PECO_Enable( BOOL Enable ){
|
||||
DIPO_vSetState(DIPO_eEN, Enable);
|
||||
VOID PECO_Enable( BOOL boEnable ){
|
||||
DIPO_vSetState(DIPO_eEN, boEnable);
|
||||
boEnableOutput = boEnable;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: PECO_isEnabled
|
||||
// Description: Returns true if the Output is enabled
|
||||
// Parameters: None
|
||||
// Returns: BOOL boEnableOutput
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
BOOL PECO_isEnabled( VOID ){
|
||||
return boEnableOutput;
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
|
@ -241,12 +241,13 @@ PRIVATE VOID vTempTask( PVOID arg )
|
||||
|
||||
//if( u32Flags & EVENT_REFRESH )
|
||||
//{
|
||||
|
||||
boOK &= ADCD_dReadData(ADCD_eHot, &error, &u16ADC_data[ADCD_eHot]);
|
||||
if( boOK )
|
||||
{
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever );
|
||||
DIPO_vSetOutput(DIPO_eLED);
|
||||
m_flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
|
||||
DIPO_vResetOutput(DIPO_eLED);
|
||||
//temp = flConvertADCData( u16ADC_data[ADCD_eHot] ); // for debugging
|
||||
//VARH_vSetVariableData( VARH_eTempHeatSink + u8Channel, (VARH_UVariable)(FLOAT)m_dbTempData[u8Channel] );
|
||||
osMutexRelease( m_pstMutexID );
|
||||
@ -266,6 +267,8 @@ PRIVATE VOID vTempTask( PVOID arg )
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
|
||||
osDelay(REFRESH_MS);
|
||||
|
||||
|
||||
@ -321,15 +324,14 @@ PRIVATE VOID vTempTask( PVOID arg )
|
||||
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
|
||||
{
|
||||
|
||||
/*u16RTemp = u16RTemp / 1000;
|
||||
FLOAT u16R = u16RTemp / 8192.0f;
|
||||
|
||||
FLOAT flT = 9.9714f * u16RTemp;
|
||||
FLOAT flT = 9.9714f * u16R;
|
||||
flT += 235.904f;
|
||||
flT *= u16RTemp;
|
||||
flT += -245.876f;*/
|
||||
flT *= u16R;
|
||||
flT += -245.876f;
|
||||
|
||||
|
||||
FLOAT flZ1, flZ2, flZ3, flZ4, flRt, flTemp, flRpoly;
|
||||
/*DOUBLE flZ1, flZ2, flZ3, flZ4, flRt, flTemp, flRpoly;
|
||||
flRt = u16RTemp;
|
||||
flRt /= 32768;
|
||||
flRt *= R_REF;
|
||||
@ -354,7 +356,9 @@ PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
|
||||
flRpoly *= flRt; // ^4
|
||||
flTemp -= 2.8183e-8 * flRpoly;
|
||||
flRpoly *= flRt; // ^5
|
||||
flTemp += 1.5243e-10 * flRpoly;
|
||||
flTemp += 1.5243e-10 * flRpoly;*/
|
||||
|
||||
return( flTemp );
|
||||
|
||||
|
||||
return( flT );
|
||||
}
|
||||
|
@ -251,8 +251,8 @@ static void MX_ADC1_Init(void)
|
||||
hadc1.Init.DMAContinuousRequests = ENABLE;
|
||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc1.Init.OversamplingMode = ENABLE;
|
||||
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_64;
|
||||
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_2;
|
||||
hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_256;
|
||||
hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_4;
|
||||
hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
|
||||
hadc1.Init.Oversampling.OversamplingStopReset = ADC_REGOVERSAMPLING_CONTINUED_MODE;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
|
@ -21,8 +21,8 @@ ADC1.Rank-1\#ChannelRegularConversion=2
|
||||
ADC1.Rank-2\#ChannelRegularConversion=3
|
||||
ADC1.Rank-3\#ChannelRegularConversion=4
|
||||
ADC1.Rank-4\#ChannelRegularConversion=5
|
||||
ADC1.Ratio=ADC_OVERSAMPLING_RATIO_64
|
||||
ADC1.RightBitShift=ADC_RIGHTBITSHIFT_2
|
||||
ADC1.Ratio=ADC_OVERSAMPLING_RATIO_256
|
||||
ADC1.RightBitShift=ADC_RIGHTBITSHIFT_4
|
||||
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5
|
||||
ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5
|
||||
ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_640CYCLES_5
|
||||
|
Loading…
x
Reference in New Issue
Block a user