with hardware oversampling
This commit is contained in:
@ -38,6 +38,7 @@
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
@ -49,11 +50,11 @@
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
#define ADC_RES (4096) // ADC resolution: 12 bits
|
||||
#define ADC_RES (4096) // ADC resolution: 12 bits
|
||||
#define NR_OF_ADCS 5 // number of internal adc channels
|
||||
|
||||
// definitions of internal adc
|
||||
#define INT_ADC_REF_HI (3.28f) // HI int. reference voltage for conversion
|
||||
#define INT_ADC_REF_HI (3.3f) // HI int. reference voltage for conversion
|
||||
#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
|
||||
|
||||
@ -269,6 +270,8 @@ 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;
|
||||
@ -288,6 +291,7 @@ VOID ANPI_vTask( PVOID arg )
|
||||
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
|
||||
@ -297,9 +301,12 @@ VOID ANPI_vTask( PVOID arg )
|
||||
{
|
||||
m_aflValues[u16Cnt] = ((((FLOAT)m_au32ADCRawData[u16Cnt] / (FLOAT)ANPI_OVERSAMPLING_FACTOR * OFFSET) - (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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,6 +330,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, ANPI_ADC_HALF_COMPLETE );
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
@ -7,7 +7,7 @@
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Project: Peltier Controller V2
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
// Author: Noah Piqu<71> (noah.pique@psi.ch)
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
//
|
||||
@ -41,10 +41,11 @@ extern "C" {
|
||||
//=================================================================================================
|
||||
|
||||
// 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!"
|
||||
//#error "ANPI_OVERSAMPLING_FACTOR must be power of 2!"
|
||||
#endif
|
||||
|
||||
//=================================================================================================
|
||||
|
@ -159,7 +159,7 @@ BOOL ANPO_boSetVoltage( FLOAT Voltage ){
|
||||
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
|
||||
U32 RawData;
|
||||
|
||||
RawData = Voltage * 4095 / 3.28;
|
||||
RawData = Voltage * 4095 / 3.3;
|
||||
|
||||
return RawData;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
#define RTD_A 3.9083e-3
|
||||
#define RTD_B -5.775e-7
|
||||
|
||||
#define R_REF 3900
|
||||
#define R_REF 4000
|
||||
#define R_NOMINAL 1000
|
||||
|
||||
//=================================================================================================
|
||||
|
Reference in New Issue
Block a user