Fixed error from 0.5 to 0.1 Celsius Degree
This commit is contained in:
@@ -87,12 +87,24 @@ extern "C" {
|
||||
|
||||
// Values for frequency counts = (freq*2^27)/(1MHz/16)
|
||||
#define AD5934_FREQ_4K882HZ 0x009FF92F // 4.882kHz
|
||||
#define AD5934_FREQ_3K761HZ 0x007B3D8E // 3.761kHZ
|
||||
#define AD5934_FREQ_2K599HZ 0x005529FE // 2.599kHz
|
||||
#define AD5934_FREQ_2K5HZ 0x0051EB86 // 2.5kHz
|
||||
#define AD5934_FREQ_2K293HZ 0x004B2314 // 2.293kHz
|
||||
#define AD5934_FREQ_2K018HZ 0x00422036 // 2.018kHz
|
||||
#define AD5934_FREQ_1K953HZ 0x003FFEF3 // 1.953kHz
|
||||
#define AD5934_FREQ_1K865HZ 0x003D1CC1 // 1.865kHz
|
||||
#define AD5934_FREQ_1K590HZ 0x003419E3 // 1.59kHz
|
||||
#define AD5934_FREQ_0HZ 0x00000000 // 0Hz
|
||||
#define AD5934_STEP_FREQ_0 0x0000 // 0 passos
|
||||
#define AD5934_SETTLING_TIME_23 0x0017 // 17 ciclos
|
||||
#define AD5934_SETTLING_TIME_32 0x0020 // 32 ciclos
|
||||
#define AD5934_SETTLING_TIME_48 0x0030 // 48 ciclos
|
||||
#define AD5934_SETTLING_TIME_64 0x0040 // 64 ciclos
|
||||
#define AD5934_SETTLING_TIME_90 0x0060 // 90 ciclos
|
||||
#define AD5934_SETTLING_TIME_117 0x0075 // 117 ciclos
|
||||
#define AD5934_SETTLING_TIME_160 0x00A0 // 160 ciclos
|
||||
#define AD5934_SETTLING_TIME_191 0x00BF // 191 ciclos
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -116,7 +128,7 @@ extern "C" {
|
||||
#define ADG715_SW7 0x40 //RTD Input
|
||||
#define ADG715_SW8 0x80 //CE Input
|
||||
|
||||
|
||||
#define ADG715_SWOFF 0x00 //Dummy
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** General Defines ********************************/
|
||||
@@ -141,6 +153,9 @@ extern "C" {
|
||||
#define AD5934_GAIN_FACTOR_1413US 1413.0f
|
||||
#define AD5934_GAIN_FACTOR_12880US 12880.0f
|
||||
|
||||
// Aproximação linear do coeficiente PT100/PT1000 (α), usada abaixo de 0°C
|
||||
// R(T) ≈ R0 * (1 + ALPHA * T) → T ≈ (R/R0 - 1) / ALPHA
|
||||
#define AD5934_RTD_ALPHA 0.00385f // ohms/ohm/°C, padrão IEC 60751
|
||||
#define AD5934_RTD_A 3.9083e-3f
|
||||
#define AD5934_RTD_B (-5.775e-7f)
|
||||
|
||||
@@ -150,27 +165,22 @@ extern "C" {
|
||||
#define AD5934_EC_ALPHA_PER_C 0.02f
|
||||
#define AD5934_EC_TEMP_REF_C 25.0f
|
||||
|
||||
// Values for sample timming sync
|
||||
#define AD5934_SYNC_PER_SWEEP 60 // 60 ms between sweeps
|
||||
#define AD5934_SYNC_MUX_SETTLING 5 // 5 ms to wait before read after change ADG715 channels
|
||||
|
||||
//Mux Set to Read...
|
||||
#define AD5934_ID_RTD 0
|
||||
#define AD5934_ID_EC 1
|
||||
#define AD5934_ID_REF 2
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**************************** Filtering Defines *****************************/
|
||||
/*****************************************************************************/
|
||||
#define AD5934_TIME_PER_SWEEP 60 // 60 ms entre o início de cada sweep
|
||||
#define AD5934_TIME_MUX_SETTLING 10 // 10 ms de espera após trocar o MUX
|
||||
#define AD5934_TIME_PER_SWEEP 10 // 60 ms entre o início de cada sweep
|
||||
#define AD5934_SYNC_MUX_SETTLING 40 // 10 ms to wait before read after change ADG715 channels
|
||||
|
||||
#define AD5934_BURST_SIZE 5
|
||||
#define AD5934_TRIM_COUNT 1
|
||||
#define AD5934_HISTORY_SIZE 5
|
||||
#define AD5934_IIR_ALPHA 0.55f
|
||||
#define AD5934_BURST_SIZE 1 // Number of Repeated Sweeps on the same channel before change the Mux
|
||||
#define AD5934_TRIM_COUNT 0
|
||||
#define AD5934_HISTORY_SIZE 8
|
||||
#define AD5934_IIR_ALPHA 0.10f
|
||||
|
||||
#define AD5934_REF_FLOAT_SCALE_MIN 1850.0f
|
||||
#define AD5934_REF_FLOAT_SCALE_MAX 2450.0f
|
||||
@@ -241,12 +251,12 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
AD5934_IDLE,
|
||||
AD5934_WAIT_MUX,
|
||||
AD5934_START_CONVERSION,
|
||||
AD5934_WAIT_CONVERSION,
|
||||
AD5934_READ_DATA,
|
||||
AD5934_WAIT_NEXT_SWEEP,
|
||||
AD5934_SWITCH_MUX,
|
||||
AD5934_WAIT_MUX
|
||||
AD5934_SWITCH_MUX
|
||||
} AD5934_State_t;
|
||||
|
||||
|
||||
@@ -263,6 +273,14 @@ typedef struct {
|
||||
uint8_t value_valid;
|
||||
} AD5934_filter_t;
|
||||
|
||||
typedef struct {
|
||||
float buffer[AD5934_HISTORY_SIZE];
|
||||
float sum;
|
||||
uint8_t index;
|
||||
uint8_t count; // quantas amostras já foram inseridas (até encher o buffer)
|
||||
float average;
|
||||
} AD5934_AvgFilter_t;
|
||||
|
||||
static const uint8_t ADG715_Channel_Map[AD5934_CH_MAX] = {
|
||||
[AD5934_CH_REF100R_LOW_GAIN] = (ADG715_SW1 | ADG715_SW4),
|
||||
[AD5934_CH_REF100R_MID_GAIN] = (ADG715_SW2 | ADG715_SW4),
|
||||
@@ -357,12 +375,14 @@ static const uint16_t AD5934_Scale_Out_Max[AD5934_CH_MAX] = {
|
||||
AD5934_EC5_OUT_SCALE_MAX
|
||||
};
|
||||
|
||||
|
||||
extern I2C_HandleTypeDef hi2c2;
|
||||
|
||||
extern float reference_resistor, temperature_RTD, thermal_compensaded_EC;
|
||||
|
||||
extern volatile AD5934_State_t ad5934_state;
|
||||
extern volatile uint32_t g_ms_counter; // Increment each 1ms Timer
|
||||
extern volatile uint32_t state_timer;
|
||||
|
||||
extern uint8_t current_mux_channel;
|
||||
extern uint8_t sweep_count; // Count how many sweeps done at the same channel now (0 a 7)
|
||||
@@ -373,6 +393,9 @@ extern uint8_t current_ref_mux;
|
||||
|
||||
extern AD5934_filter_t g_rtd_filter, g_ec_filter, g_ref_filter;
|
||||
|
||||
extern int16_t rtd_now, ref_now, ec_now;
|
||||
extern int16_t rtd_now_i, ref_now_i, ec_now_i;
|
||||
|
||||
/*****************************************************************************/
|
||||
/************************ Functions Declarations *****************************/
|
||||
/*****************************************************************************/
|
||||
@@ -380,6 +403,8 @@ void AD5934_SetRegisterValue(uint8_t registerAddress, uint32_t registerValue, ui
|
||||
|
||||
uint32_t AD5934_GetRegisterValue(uint8_t registerAddress, uint8_t numberOfBytes);
|
||||
|
||||
uint32_t AD5934_ReadRegister(uint8_t regAddr, uint8_t numberOfBytes);
|
||||
|
||||
void AD5934_Init(void);
|
||||
|
||||
void AD5934_RestartSweep(void);
|
||||
@@ -398,12 +423,20 @@ float AD5934_EC_Calibrate_Temperature(float temp_C);
|
||||
|
||||
float AD5934_GetMagnitude(void);
|
||||
|
||||
float AD5934_GetImpedance(float mag_ref, float mag_dut);
|
||||
|
||||
uint32_t AD5934_Get_Real_Imag_Numbers(void);
|
||||
|
||||
uint16_t AD5934_Compress_To_IntScale(float value, uint8_t scale);
|
||||
|
||||
float AD5934_Round_Float_Precision(float value, uint8_t number_of_decimals);
|
||||
|
||||
float AD5934_Linear_Correction(float raw_value);
|
||||
|
||||
void AD5934_MovingAvg_Init(AD5934_AvgFilter_t *filt);
|
||||
|
||||
void AD5934_MovingAvg_Process(AD5934_AvgFilter_t *filt, float new_sample);
|
||||
|
||||
void AD5934_Process_System(void);
|
||||
|
||||
void AD5934_Sort_Array(float *v, uint8_t n);
|
||||
@@ -416,10 +449,22 @@ void AD5934_Process_Sample(AD5934_filter_t *ch, float raw);
|
||||
|
||||
void AD5934_RTD_NewSample(float raw);
|
||||
|
||||
void AD5934_RTD_Real_NewSample(float raw);
|
||||
|
||||
void AD5934_RTD_Imag_NewSample(float raw);
|
||||
|
||||
void AD5934_EC_NewSample(float raw);
|
||||
|
||||
void AD5934_EC_Real_NewSample(float raw);
|
||||
|
||||
void AD5934_EC_Imag_NewSample(float raw);
|
||||
|
||||
void AD5934_Reference_NewSample(float raw);
|
||||
|
||||
void AD5934_Reference_Real_NewSample(float raw);
|
||||
|
||||
void AD5934_Reference_Imag_NewSample(float raw);
|
||||
|
||||
void ADG715_SetRegisterValue(char value);
|
||||
|
||||
void ADG715_ResetChannels(void);
|
||||
|
||||
Reference in New Issue
Block a user