Fertirrega_v6 all scaled to 4096 counts

This commit is contained in:
2026-07-30 15:52:49 +01:00
parent c90139bd57
commit 6f39aaccb0
20 changed files with 11855 additions and 13746 deletions
+39 -86
View File
@@ -13,7 +13,6 @@
#define INC_AD5934_DRIVER_H_
#include "stm32f1xx_hal.h"
#include "flash_manager.h"
#include "main.h"
#include <math.h>
#include <stdlib.h>
@@ -123,32 +122,6 @@ extern "C" {
/**************************** General Defines ********************************/
/*****************************************************************************/
/*
#define AD5934_CH_REF_100R 0x10
#define AD5934_CH_REF_1K 0x11
#define AD5934_CH_REF_10K 0x12
#define AD5934_CH_PT100 0x00
#define AD5934_CH_PT1000 0x01
#define AD5934_CH_EC_10MS 0x21
#define AD5934_CH_EC_5MS 0x22
*/
/*
#define AD5934_CH_REF100R_LOW_GAIN 0x09
#define AD5934_CH_REF100R_MID_GAIN 0x0A
#define AD5934_CH_REF100R_HIGH_GAIN 0x0C
#define AD5934_CH_REF1K_LOW_GAIN 0x11
#define AD5934_CH_REF1K_MID_GAIN 0x12
#define AD5934_CH_REF1K_HIGH_GAIN 0x14
#define AD5934_CH_REF10K_LOW_GAIN 0x21
#define AD5934_CH_REF10K_MID_GAIN 0x22
#define AD5934_CH_REF10K_HIGH_GAIN 0x24
#define AD5934_CH_RTD_LOW_GAIN 0x41
#define AD5934_CH_RTD_MID_GAIN 0x42
#define AD5934_CH_RTD_HIGH_GAIN 0x44
#define AD5934_CH_EC_LOW_GAIN 0x81
#define AD5934_CH_EC_MID_GAIN 0x82
#define AD5934_CH_EC_HIGH_GAIN 0x84
*/
#define AD5934_LOW_GAIN_BASE 0x01
#define AD5934_MID_GAIN_BASE 0x02
#define AD5934_HIGH_GAIN_BASE 0x04
@@ -196,14 +169,8 @@ extern "C" {
#define AD5934_BURST_SIZE 5
#define AD5934_TRIM_COUNT 1
#define AD5934_HISTORY_SIZE 6
#define AD5934_IIR_ALPHA 0.4f
#define AD5934_EC_FLOAT_SCALE_MIN 0.0f
#define AD5934_EC_FLOAT_SCALE_MAX 15000.0f
#define AD5934_EC_OUT_SCALE_MIN 0
#define AD5934_EC_OUT_SCALE_MAX 4096
#define AD5934_HISTORY_SIZE 5
#define AD5934_IIR_ALPHA 0.55f
#define AD5934_REF_FLOAT_SCALE_MIN 1850.0f
#define AD5934_REF_FLOAT_SCALE_MAX 2450.0f
@@ -215,6 +182,15 @@ extern "C" {
#define AD5934_RTD_OUT_SCALE_MIN 0
#define AD5934_RTD_OUT_SCALE_MAX 4096
#define AD5934_EC5_FLOAT_SCALE_MIN 0.0f
#define AD5934_EC5_FLOAT_SCALE_MAX 20500.0f
#define AD5934_EC5_OUT_SCALE_MIN 0
#define AD5934_EC5_OUT_SCALE_MAX 4096
#define AD5934_EC10_FLOAT_SCALE_MIN 0.0f
#define AD5934_EC10_FLOAT_SCALE_MAX 15000.0f
#define AD5934_EC10_OUT_SCALE_MIN 0
#define AD5934_EC10_OUT_SCALE_MAX 4096
@@ -320,9 +296,9 @@ static const float AD5934_Scale_Float_Min[AD5934_CH_MAX] = {
AD5934_RTD_FLOAT_SCALE_MIN,
AD5934_RTD_FLOAT_SCALE_MIN,
AD5934_RTD_FLOAT_SCALE_MIN,
AD5934_EC_FLOAT_SCALE_MIN,
AD5934_EC_FLOAT_SCALE_MIN,
AD5934_EC_FLOAT_SCALE_MIN
AD5934_EC10_FLOAT_SCALE_MIN,
AD5934_EC10_FLOAT_SCALE_MIN,
AD5934_EC5_FLOAT_SCALE_MIN
};
static const float AD5934_Scale_Float_Max[AD5934_CH_MAX] = {
@@ -338,9 +314,9 @@ static const float AD5934_Scale_Float_Max[AD5934_CH_MAX] = {
AD5934_RTD_FLOAT_SCALE_MAX,
AD5934_RTD_FLOAT_SCALE_MAX,
AD5934_RTD_FLOAT_SCALE_MAX,
AD5934_EC_FLOAT_SCALE_MAX,
AD5934_EC_FLOAT_SCALE_MAX,
AD5934_EC_FLOAT_SCALE_MAX
AD5934_EC10_FLOAT_SCALE_MAX,
AD5934_EC10_FLOAT_SCALE_MAX,
AD5934_EC5_FLOAT_SCALE_MAX
};
static const uint16_t AD5934_Scale_Out_Min[AD5934_CH_MAX] = {
@@ -356,40 +332,29 @@ static const uint16_t AD5934_Scale_Out_Min[AD5934_CH_MAX] = {
AD5934_RTD_OUT_SCALE_MIN,
AD5934_RTD_OUT_SCALE_MIN,
AD5934_RTD_OUT_SCALE_MIN,
AD5934_EC_OUT_SCALE_MIN,
AD5934_EC_OUT_SCALE_MIN,
AD5934_EC_OUT_SCALE_MIN
AD5934_EC10_OUT_SCALE_MIN,
AD5934_EC10_OUT_SCALE_MIN,
AD5934_EC5_OUT_SCALE_MIN
};
static const uint16_t AD5934_Scale_Out_Max[AD5934_CH_MAX] = {
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_EC_OUT_SCALE_MAX,
AD5934_EC_OUT_SCALE_MAX,
AD5934_EC_OUT_SCALE_MAX
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_REF_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_RTD_OUT_SCALE_MAX,
AD5934_EC10_OUT_SCALE_MAX,
AD5934_EC10_OUT_SCALE_MAX,
AD5934_EC5_OUT_SCALE_MAX
};
extern int16_t temperature_dut_samples[2][AD5934_TEMP_AVERAGES];
extern int16_t temperature_ref_samples[2][AD5934_TEMP_AVERAGES];
extern float temperature_display[AD5934_TEMP_AVERAGES];
extern int16_t ec_dut_samples[2][AD5934_EC_AVERAGES];
extern int16_t ec_ref1_samples[2][AD5934_EC_AVERAGES];
extern int16_t ec_ref2_samples[2][AD5934_EC_AVERAGES];
extern float ec_display[AD5934_EC_AVERAGES];
extern float ec_temp_dut[AD5934_EC_AVERAGES];
extern I2C_HandleTypeDef hi2c2;
@@ -409,12 +374,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);
uint32_t AD5934_Sweep(void);
void AD5934_RestartSweep(void);
void AD5934_Repeat_Sweep(void);
@@ -423,26 +384,20 @@ void AD5934_StopSweep(void);
float AD5934_Get_Ref_Resistance(void);
float AD5934_GetTemperature(float mag_ref);
float AD5934_Calculate_Temperature(float mag_ref, float mag_dut);
float AD5934_GetImpedance(float temperature_dut);
float AD5934_EC_Compensate_Magnitude_To_25C(float mag_dut, float temperature_dut);
float AD5934_EC_Calibrate_Temperature(float temp_C);
float AD5934_GetMagnitude(void);
void AD5934_Wait_For_Data_Valid(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);
float AD5934_EC_Compensate_To_25C(float ec_raw_uScm, float temp_C);
float AD5934_EC_Calibrate_Temperature(float temp_C);
void AD5934_Process_System(void);
void AD5934_Sort_Array(float *v, uint8_t n);
@@ -461,11 +416,9 @@ void AD5934_Reference_NewSample(float raw);
void ADG715_SetRegisterValue(char value);
void ADG715_SetChannels(uint8_t ch1, uint8_t ch2);
void ADG715_ResetChannels(void);
void ADG715_Update(uint8_t channel);
void ADG715_SetChannels(AD5934_Channel_t channel);
#ifdef __cplusplus
}
+10 -17
View File
@@ -125,13 +125,18 @@ extern "C" {
* MODE=1b (single-shot/power-down), DR[2:0]=100b (1600SPS, ajustar se necessário),
* COMP_QUE[1:0]=11b (comparador desabilitado, ALERT/RDY em alta impedância)
*/
#define ADS1015_CONFIG_START_SINGLE (ADS1015_REG_CONFIG_OS_SINGLE | ADS1015_REG_CONFIG_MUX_DIFF_0_1 | ADS1015_REG_CONFIG_PGA_0_256V | ADS1015_REG_CONFIG_MODE_SINGLE | ADS1015_REG_CONFIG_DR_128SPS | ADS1015_REG_CONFIG_CMODE_TRAD | ADS1015_REG_CONFIG_CPOL_ACTVLOW | ADS1015_REG_CONFIG_CLAT_NONLAT | ADS1015_REG_CONFIG_CQUE_NONE) // 0x8583 // valor de reset já tem OS=1, então só precisa garantir MODE=1b
#define ADS1015_CONFIG_START_SINGLE (ADS1015_REG_CONFIG_OS_SINGLE | ADS1015_REG_CONFIG_MUX_DIFF_0_1 | ADS1015_REG_CONFIG_PGA_1_024V | ADS1015_REG_CONFIG_MODE_SINGLE | ADS1015_REG_CONFIG_DR_128SPS | ADS1015_REG_CONFIG_CMODE_TRAD | ADS1015_REG_CONFIG_CPOL_ACTVLOW | ADS1015_REG_CONFIG_CLAT_NONLAT | ADS1015_REG_CONFIG_CQUE_NONE) // 0x8583 // valor de reset já tem OS=1, então só precisa garantir MODE=1b
#define ADS1015_BURST_SIZE 5
#define ADS1015_TRIM_COUNT 1
#define ADS1015_HISTORY_SIZE 6
#define ADS1015_IIR_ALPHA 0.4f
#define ADS1015_HISTORY_SIZE 5
#define ADS1015_IIR_ALPHA 0.55f
#define ADS1015_PH_FLOAT_SCALE_MIN 1000.0f
#define ADS1015_PH_FLOAT_SCALE_MAX 3000.0f
#define ADS1015_PH_OUT_SCALE_MIN 0
#define ADS1015_PH_OUT_SCALE_MAX 4096
@@ -147,7 +152,6 @@ typedef enum {
extern I2C_HandleTypeDef hi2c1;
extern float ph_dut_samples[ADS1015_PH_AVERAGES];
typedef struct {
uint16_t m_i2cAddress; ///< the I2C address
@@ -187,24 +191,13 @@ extern ADS1015_filter_t g_ph_filter;
extern volatile uint32_t g_ms_counter; // Increment each 1ms Timer
void ADS1015_Init(void);
uint16_t ADSreadADC_SingleEnded(ADS1015_I2C* i2c, uint8_t channel);
int16_t ADSreadADC_Differential_0_1(ADS1015_I2C* i2c);
int16_t ADSreadADC_Differential_2_3(ADS1015_I2C* i2c);
void ADSstartComparator_SingleEnded(ADS1015_I2C* i2c, uint8_t channel, int16_t threshold);
int16_t ADSgetLastConversionResults();
void ADSsetGain(ADS1015_I2C* i2c, adsGain_t gain);
adsGain_t ADSgetGain(ADS1015_I2C* i2c);
void ADS1015_Process_System(void);
void ADS1015_Sort_Array(float *v, uint8_t n);
float ADS1015_Trimmed_Mean(float *buffer, uint8_t n, uint8_t trim);
void ADS1015_Process_Sample(ADS1015_filter_t *ch, float raw);
void ADS1015_pH_NewSample(float raw);
uint16_t ADS1015_Compress_To_IntScale(float value);
float ADSCalculate_ph_mV(void);
float ADSCalculate_ph_Compensated(float temp_dut);
float ADSCalculate_ph_Uncompensated(void);
float ADSinterpolate_ph(float temp_dut, uint8_t row_index);
float ADSRound_Float_Precision(float value, uint8_t number_of_decimals);
#endif /* INC_ADS1015_DRIVER_H_ */
+70 -397
View File
@@ -20,19 +20,12 @@ uint8_t current_hw_mux_connection = ADG715_Channel_Map[AD5934_CH_RTD_LOW_GAIN];
uint8_t sweep_count = 0; /* Conta quantos sweeps foram feitos no canal atual (0 a 7) */
int16_t temperature_dut_samples[2][AD5934_TEMP_AVERAGES]={{0},{0}};
int16_t temperature_ref_samples[2][AD5934_TEMP_AVERAGES]={{0},{0}};
float temperature_display[AD5934_TEMP_AVERAGES] = {0};
int16_t ec_dut_samples[2][AD5934_EC_AVERAGES]={{0},{0}};
float ec_display[AD5934_EC_AVERAGES] = {0};
AD5934_filter_t g_rtd_filter = {0};
AD5934_filter_t g_ec_filter = {0};
AD5934_filter_t g_ref_filter = {0};
uint8_t is_new_channel = 1;
/******************************************************************************
* @brief Set an AD5934 internal register value.
*
@@ -96,51 +89,10 @@ uint32_t AD5934_GetRegisterValue(uint8_t registerAddress, uint8_t numberOfBytes)
}
/*
AD5934_value.byte[0] = (uint16_t)(AD5934_reg.number & 0x0000FFFF) + 2048;
AD5934_value.ints[1] = (uint16_t)((AD5934_reg.number & 0xFFFF0000)>>16) + 2048;
*/
return AD5934_reg.number;
}
/************************************************************************************
* @brief Lê um registrador do AD5934 usando a abstração Mem_Read (mais segura).
*
* @param regAddr Endereço do registrador no AD5934.
* @return uint32_t Valor lido do registrador.
***********************************************************************************/
uint32_t AD5934_ReadRegister(uint8_t regAddr, uint8_t numberOfBytes)
{
uint32_t registerValue = 0;
uint8_t readData[4] = {0,0,0,0}; // Buffer para receber 16 bits (AD5934 usa regs de 16-bit)
uint8_t writeData[2] = {AD5934_ADDR_POINTER,regAddr};
HAL_StatusTypeDef status;
//Limit buffer size to prevent stack overflow (AD5934 regs are max 4 bytes) */
if (numberOfBytes > 4)
{
return 0xFFFFFFFF;
}
status = HAL_I2C_Master_Transmit(&hi2c2, AD5934_I2C_ADDRESS, writeData, 2, 5);
HAL_Delay(1);
// Usamos Mem_Read que faz: START -> ADDR+W -> REG_ADDR -> REPEATED_START -> ADDR+R -> DATA -> STOP
status = HAL_I2C_Mem_Read(&hi2c2, AD5934_I2C_ADDRESS, AD5934_BLOCK_READ, I2C_MEMADD_SIZE_8BIT, readData, numberOfBytes, 5);
/* 5. Reconstruct value from Big-Endian buffer */
for (uint8_t i = 0; i < numberOfBytes; i++)
{
registerValue = (registerValue << 8) | readData[i];
}
return registerValue;
}
/******************************************************************************
* @brief Configure and Start the AD5934 frequency sweep parameters.
*
@@ -193,15 +145,6 @@ void AD5934_RestartSweep(void)
// Configure Range Output, PGA gain andPlace AD5934 in sweep
AD5934_SetRegisterValue(AD5934_CONTROL_REG_HB, (AD5934_CONTROL_FUNCTION(AD5934_START_FREQ_SWEEP) | AD5934_CONTROL_RANGE(AD5934_400mVpp_RANGE) | AD5934_PGA_GAIN(AD5934_PGA_GAIN_X1)), 1);
// Wait for data to be valid
//AD5934_Wait_For_Data_Valid();
// Power Down
//AD5934_SetRegisterValue(AD5934_CONTROL_REG_HB, (AD5934_CONTROL_FUNCTION(AD5934_POWER_DOWN) | AD5934_CONTROL_RANGE(AD5934_400mVpp_RANGE) | AD5934_PGA_GAIN(AD5934_PGA_GAIN_X1)), 1);
// Place AD5934 in standby (instead of power down)
//AD5934_SetRegisterValue(AD5934_CONTROL_REG_HB, (AD5934_CONTROL_FUNCTION(AD5934_STANDBY) | AD5934_CONTROL_RANGE(AD5934_400mVpp_RANGE) | AD5934_PGA_GAIN(AD5934_PGA_GAIN_X1)), 1);
}
/******************************************************************************
@@ -234,170 +177,6 @@ void AD5934_StopSweep(void)
}
/******************************************************************************
* @brief Start the AD5934 frequency sweep parameters.
*
* @param: none
*
* @return Real(int16) and Imaginary(int16) numbers into a int32.
******************************************************************************/
uint32_t AD5934_Sweep(void)
{
int16_t real_value, imag_value;
uint32_t value=0;
// Restart Sweeping
AD5934_RestartSweep();
real_value = ((AD5934_GetRegisterValue(AD5934_REAL_REG_LB,2)));
imag_value = ((AD5934_GetRegisterValue(AD5934_IMG_REG_LB,2)));
// Get Real (16-bit) and Imaginary (16-bit) values into an unsigned 32-bit
value = ((((uint16_t)(imag_value))<<16) | ((uint16_t)(real_value)));
return value;
}
/******************************************************************************
* @brief Get Reference Resistance on Board.
*
* @param channel - AD5934_CH_PT100 or AD5934_CH_PT1000.
*
* @return impedance.
******************************************************************************/
float AD5934_Get_Ref_Resistance(void)
{
uint8_t i;
uint32_t sample;
int32_t ref_sum[2];
float real_ref,imag_ref, real_dut, mag_ref;
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7) == GPIO_PIN_SET) // OFF = PT1000, ON = PT100, PA7 has internal pull-up and switch connects to GND
ADG715_Update(AD5934_CH_REF100R_LOW_GAIN); // Set the Reference Resistor on board in the Analog Mux
else
ADG715_Update(AD5934_CH_REF1K_MID_GAIN); // Set the Reference Resistor on board in the Analog Mux
sample = AD5934_Sweep(); // Get Reference Resistor Values from ADC
// Move values in the vectors
for (i = (AD5934_TEMP_AVERAGES-1); i > 0; i--)
{
temperature_ref_samples[0][i] = temperature_ref_samples[0][i-1]; //real
temperature_ref_samples[1][i] = temperature_ref_samples[1][i-1]; //imag
}
// Read real and imaginary data
temperature_ref_samples[0][0] = (int16_t)(sample & 0x0000FFFF); //real
//temperature_ref_samples[1][0] = 0xFFFF-(((sample & 0xFFFF0000)>>16)); //imag
temperature_ref_samples[1][0] = (int16_t)((sample & 0xFFFF0000)>>16); //imag
// Sum values in the vectors
for (i = 0, ref_sum[0]=0, ref_sum[1]=0; i < AD5934_TEMP_AVERAGES; i++)
{
ref_sum[0] += (int32_t)temperature_ref_samples[0][i]; //real
ref_sum[1] += (int32_t)temperature_ref_samples[1][i]; //imag
}
real_ref = ((float)ref_sum[0])/((float)AD5934_TEMP_AVERAGES);
imag_ref = ((float)ref_sum[1])/((float)AD5934_TEMP_AVERAGES);
// Calculate gain factor impedance
mag_ref = sqrtf((real_ref * real_ref) + (imag_ref * imag_ref));
return mag_ref;
}
/******************************************************************************
* @brief Calculate Temperature.
*
* @param channel - Magnitude of the Reference Resistor.
*
* @return impedance.
******************************************************************************/
float AD5934_GetTemperature(float mag_ref)
{
uint8_t i, ch_ref;
uint32_t sample;
int32_t dut_sum[2];
float real_dut, imag_dut, ratio, discriminant, mag_dut, ratio_mag, impedance_dut, temperature_sum, gain_factor, temp_result;
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7) == GPIO_PIN_SET) // OFF = PT1000, ON = PT100, PA7 has internal pull-up and switch connects to GND
{
ch_ref = AD5934_CH_RTD_LOW_GAIN; //PT100
gain_factor = AD5934_GAIN_FACTOR_100R;
}
else
{
ch_ref = AD5934_CH_RTD_MID_GAIN; //PT1000
gain_factor = AD5934_GAIN_FACTOR_1K;
}
ADG715_Update(ch_ref);
sample = AD5934_Sweep(); // Get PT100/PT1000 Values from ADC
for (i = (AD5934_TEMP_AVERAGES-1); i > 0; i--)
{
temperature_dut_samples[0][i] = temperature_dut_samples[0][i-1]; //real
temperature_dut_samples[1][i] = temperature_dut_samples[1][i-1]; //imag
}
// Read real and imaginary data
temperature_dut_samples[0][0] = (int16_t)(sample & 0x0000FFFF); //real
//temperature_dut_samples[0][1] = 0xFFFF-(((sample & 0xFFFF0000)>>16)); //imag
temperature_dut_samples[1][0] = (int16_t)((sample & 0xFFFF0000)>>16); //imag
for (i = 0, dut_sum[0]=0, dut_sum[1]=0; i < AD5934_TEMP_AVERAGES; i++)
{
dut_sum[0] += (int32_t)temperature_dut_samples[0][i]; //real
dut_sum[1] += (int32_t)temperature_dut_samples[1][i]; //imag
}
real_dut = ((float)dut_sum[0])/((float)AD5934_TEMP_AVERAGES);
imag_dut = ((float)dut_sum[1])/((float)AD5934_TEMP_AVERAGES);
// Calculate magnitude
mag_dut = sqrtf((real_dut * real_dut) + (imag_dut * imag_dut));
//for (i = (AD5934_TEMP_AVERAGES-1); i > 0; i--)
//temperature_display[i] = temperature_display[i-1];
ratio_mag = mag_ref / mag_dut;
if(ch_ref==AD5934_CH_REF100R_LOW_GAIN) // only for PT100
impedance_dut = AD5934_Linear_Correction(gain_factor * ratio_mag);
else
impedance_dut = gain_factor * ratio_mag;
// Calculate impedance ratio with the Reference Resistor
ratio = impedance_dut / gain_factor;
// Calculate impedance discriminant with the ratio
discriminant = (AD5934_RTD_A*AD5934_RTD_A)-(4.0f * AD5934_RTD_B * (1.0f - ratio));
//temp_result = (-AD5934_RTD_A + sqrtf(discriminant)/(2.0f * AD5934_RTD_B));
return (AD5934_Round_Float_Precision(((-AD5934_RTD_A + sqrtf(discriminant))/(2.0f * AD5934_RTD_B)),2));
//return (AD5934_Round_Float_Precision(temp_result,1));
// Calculate new temperature with the discriminant
//temperature_display[0] = (-AD5934_RTD_A + sqrtf(discriminant))/(2.0f * AD5934_RTD_B);
// Sum of all temperatures
// for (i = 0, temperature_sum=0.0f; i < AD5934_TEMP_AVERAGES; i++)
// temperature_sum += temperature_display[i];
// Is the temperature stable?
//if(temperature_display[0]>0.0f && (abs(temperature_display[0]-temperature_display[AD5934_TEMP_AVERAGES-1])/temperature_display[0])<0.1f)
//return(AD5934_Round_Float_Precision(temperature_sum/((float)AD5934_TEMP_AVERAGES),1)); // Sum / number of averages
//else
//return 0.0f; //instable values return always 0
}
/******************************************************************************
* @brief Check if PT100 or PT1000 to Calculate Temperature.
@@ -441,82 +220,67 @@ float AD5934_Calculate_Temperature(float mag_ref, float mag_dut)
}
/**
* @brief Calculates impedance and converts it to conductivity using a 2-point
* temperature-compensated model.
* @brief Compensate magnitude to a value in 25C.
*
* @param mag_dut The current Magnitude of the DUT (Device Under Test).
* @param temperature_dut The current temperature of the DUT (Device Under Test).
* @return float Calculated conductivity in uS/cm.
*
* @return The value of the Magnitude of the dut when it in 25C.
*/
float AD5934_GetImpedance(float temperature_dut)
float AD5934_EC_Compensate_Magnitude_To_25C(float mag_dut, float temperature_dut)
{
uint8_t i, ec_gain;
uint32_t sample_dut;
int32_t dut_sum[2] = {0, 0};
float real_avg, imag_avg, mag_dut, slope, target_cond;
float factor = 1.0f + AD5934_EC_ALPHA_PER_C * (temperature_dut - AD5934_EC_TEMP_REF_C);
/* 1. Hardware Setup: Gain Selection (PA6) */
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6) == GPIO_PIN_SET)
ec_gain = AD5934_CH_EC_HIGH_GAIN;
else
ec_gain = AD5934_CH_EC_MID_GAIN;
if((ec_gain != flash_data.EC10mS_EC5mS_switch) && (main_state != STATE_PH4_DRY_EC_CALIBRATION || main_state != STATE_PH7_WET_EC_CALIBRATION))
return -1.0f; // Fatal error because the gain used in calibration is different
ADG715_Update(ec_gain);
//HAL_Delay(5);
/* 2. Data Acquisition */
sample_dut = AD5934_Sweep();
// Shift buffer for moving average
for (i = (AD5934_EC_AVERAGES - 1); i > 0; i--)
{
ec_dut_samples[0][i] = ec_dut_samples[0][i-1];
ec_dut_samples[1][i] = ec_dut_samples[1][i-1];
}
// Deconstruct 32-bit sample into Real and Imaginary components
ec_dut_samples[0][0] = (float)(int16_t)(sample_dut & 0xFFFF);
ec_dut_samples[1][0] = (float)(int16_t)((sample_dut >> 16) & 0xFFFF);
/* 3. Compute Averages */
for (i = 0; i < AD5934_EC_AVERAGES; i++)
{
dut_sum[0] += (int32_t)ec_dut_samples[0][i];
dut_sum[1] += (int32_t)ec_dut_samples[1][i];
}
real_avg = (float)dut_sum[0] / (float)AD5934_EC_AVERAGES;
imag_avg = (float)dut_sum[1] / (float)AD5934_EC_AVERAGES;
/* 4. Magnitude Calculation */
mag_dut = sqrtf((real_avg * real_avg) + (imag_avg * imag_avg));
/* 5. Calibration Logic Implementation */
// Mode: CALIBRATION SETUP (User is defining the reference magnitude)
if(main_state == STATE_PH4_DRY_EC_CALIBRATION || main_state == STATE_PH7_WET_EC_CALIBRATION)
{
return mag_dut;
}
// Mode: MEASUREMENT (Applying temperature compensation)
else if(flash_data.ec0_mag != flash_data.ec1413_mag)
{
slope = (AD5934_GAIN_FACTOR_1413US/(flash_data.ec1413_mag-flash_data.ec0_mag));
return(AD5934_GAIN_FACTOR_1413US + (AD5934_EC_Compensate_To_25C(mag_dut,temperature_dut) - flash_data.ec1413_mag) * slope);
}
else
return 0.0f; // Calibration error fallback
if (factor < 0.1f)
factor = 0.1f;
return (mag_dut / factor);
}
/**
* @brief Calibrates EC sensor reading to 25°C reference point
* @param temp_C Temperature of the liquid in Celsius
* @return Temperature-compensated Correction factor value at 25°C reference
*/
float AD5934_EC_Calibrate_Temperature(float temp_C)
{
// Calibration data points for standard solution (1413 uS/cm)
const float temps[] = {5, 10, 15, 18, 20, 22, 25, 30, 35, 40, 45, 50};
const float conductivities[] = {893, 1018, 1149, 1225, 1278, 1329, 1413, 1552, 1691, 1843, 1988, 2145};
// Find the two nearest temperature points for interpolation
int32_t temp_index = -1;
for (int i = 0; i < 12; i++)
{
if (temps[i] >= temp_C)
{
temp_index = i;
break;
}
}
// Handle boundary cases
if (temp_index == -1) {
// Temperature higher than max point (50°C)
temp_index = 10;
} else if (temp_index == 0) {
// Temperature lower than min point (5°C)
temp_index = 0;
}
// Interpolate conductivity at measured temperature
float temp1 = temps[temp_index - 1];
float temp2 = temps[temp_index];
float cond1 = conductivities[temp_index - 1];
float cond2 = conductivities[temp_index];
// Linear interpolation to get conductivity at measured temperature
float interpolated_cond = cond1 + (cond2 - cond1) * (temp_C - temp1) / (temp2 - temp1);
// Return real conductivity at the temperature
return(interpolated_cond/1413.0f);
}
/******************************************************************************
* @brief Get Real and Imaginary values and calculate Magnitude.
@@ -542,37 +306,6 @@ float AD5934_GetMagnitude(void)
}
/**
* @brief Monitora o status com TIMEOUT para evitar travamento do sistema.
*/
void AD5934_Wait_For_Data_Valid(void)
{
uint32_t timeout_counter = 0;
const uint32_t MAX_TIMEOUT = 10000; // Limite de tentativas
uint8_t status;
while (1)
{
status = (uint8_t)AD5934_GetRegisterValue(AD5934_STATUS_REG, 1);
if ((status & AD5934_STATUS_DATA_VALID) != 0)
{
break; // Sucesso!
}
timeout_counter++;
if (timeout_counter >= MAX_TIMEOUT)
{
// TRATAMENTO DE ERRO: O sistema não travou, mas o chip falhou.
break;
}
HAL_Delay(1); // Pequeno delay para não sobrecarregar o barramento I2C
}
}
/**
* @brief Converte um valor float em uma escala de FLOAT_MIN a FLOAT_MAX para uint16_t em escala de UINT16_MIN a UINT16_MAX
*
@@ -646,69 +379,6 @@ float AD5934_Linear_Correction(float raw_value)
return (raw_value * slope) + offset;
}
/**
* @brief Temperature compensation with drift equal to 2%
* @param admittance raw in uS/cm
* @param temperature_celsius Temperature in degrees Celsius
* @return admittance compensated
*/
float AD5934_EC_Compensate_To_25C(float ec_raw_uScm, float temp_C)
{
float factor = 1.0f + AD5934_EC_ALPHA_PER_C * (temp_C - AD5934_EC_TEMP_REF_C);
if (factor < 0.1f)
factor = 0.1f;
return (ec_raw_uScm / factor);
}
/**
* @brief Calibrates EC sensor reading to 25°C reference point
* @param temp_C Temperature of the liquid in Celsius
* @return Temperature-compensated Correction factor value at 25°C reference
*/
float AD5934_EC_Calibrate_Temperature(float temp_C)
{
// Calibration data points for standard solution (1413 uS/cm)
const float temps[] = {5, 10, 15, 18, 20, 22, 25, 30, 35, 40, 45, 50};
const float conductivities[] = {893, 1018, 1149, 1225, 1278, 1329, 1413, 1552, 1691, 1843, 1988, 2145};
// Find the two nearest temperature points for interpolation
int32_t temp_index = -1;
for (int i = 0; i < 12; i++)
{
if (temps[i] >= temp_C)
{
temp_index = i;
break;
}
}
// Handle boundary cases
if (temp_index == -1) {
// Temperature higher than max point (50°C)
temp_index = 10;
} else if (temp_index == 0) {
// Temperature lower than min point (5°C)
temp_index = 0;
}
// Interpolate conductivity at measured temperature
float temp1 = temps[temp_index - 1];
float temp2 = temps[temp_index];
float cond1 = conductivities[temp_index - 1];
float cond2 = conductivities[temp_index];
// Linear interpolation to get conductivity at measured temperature
float interpolated_cond = cond1 + (cond2 - cond1) * (temp_C - temp1) / (temp2 - temp1);
// Return real conductivity at the temperature
return(interpolated_cond/1413.0f);
}
/**
* @brief Calibrate AD5934 using dry probe and standard solution
*
@@ -733,7 +403,13 @@ float AD5934_Calibrate(float dry_probe_real, float dry_probe_imag, float standar
return calibration_factor;
}
/**
* @brief State Machine to process values from AD5934 without blocking delays
*
* @param none
*
* @return none
*/
void AD5934_Process_System(void)
{
static uint32_t state_timer = 0;
@@ -742,7 +418,7 @@ void AD5934_Process_System(void)
switch (ad5934_state)
{
case AD5934_IDLE:
ADG715_Update(current_mux_channel); // Starts changing the mux channel
ADG715_SetChannels(current_mux_channel); // Starts changing the mux channel
is_new_channel = 1; // Forces first channel
state_timer = g_ms_counter;
ad5934_state = AD5934_WAIT_MUX;
@@ -846,7 +522,7 @@ void AD5934_Process_System(void)
current_hw_mux_connection = AD5934_CH_REF1K_MID_GAIN; // 1K Reference Resistor
break;
}
ADG715_Update(current_hw_mux_connection); // Change the analog mux
ADG715_SetChannels(current_hw_mux_connection); // Change the analog mux
is_new_channel = 1; // Channel Switched
state_timer = g_ms_counter; // Reload timer to wait for stability
ad5934_state = AD5934_WAIT_MUX; // Next State
@@ -1007,10 +683,13 @@ void ADG715_SetRegisterValue(char value)
return;
}
void ADG715_SetChannels(uint8_t ch1, uint8_t ch2)
{
ADG715_SetRegisterValue(ch1+ch2);
}
/******************************************************************************
* @brief Disconnect all Channels on the ADG715.
*
* @param: channel
*
* @return none.
******************************************************************************/
void ADG715_ResetChannels(void)
{
@@ -1018,13 +697,13 @@ void ADG715_ResetChannels(void)
}
/******************************************************************************
* @brief Update Channels on the ADG715 and stop-start AD5934.
* @brief Set Channels on the ADG715.
*
* @param: channel = AD5934_CH_REF_100R, AD5934_CH_REF_1K, AD5934_CH_REF_10K, AD5934_CH_PT100, AD5934_CH_PT1000, AD5934_CH_EC, ...
* @param: channel
*
* @return none.
******************************************************************************/
void ADG715_Update(AD5934_Channel_t channel)
void ADG715_SetChannels(AD5934_Channel_t channel)
{
// Garante que o índice recebido não ultrapassa os limites do vetor
if (channel >= AD5934_CH_MAX)
@@ -1033,12 +712,6 @@ void ADG715_Update(AD5934_Channel_t channel)
// Envia o byte combinado via I2C (Make-before-break nativo por barramento)
ADG715_SetRegisterValue(ADG715_Channel_Map[channel]);
// Gestão inteligente do delay de acomodação
/* if (channel >= AD5934_CH_EC_LOW_GAIN)
HAL_Delay(20); // Canais de Condutividade Elétrica (CE) necessitam de maior estabilização química
else
HAL_Delay(10); // Resistores puros e RTD estabilizam mais rapidamente
*/
}
+28 -382
View File
@@ -10,8 +10,6 @@
#include "ads1015_driver.h"
ADS1015_I2C i2c_ads1015;
float ph_dut_samples[ADS1015_PH_AVERAGES]={0};
ADS1015_filter_t g_ph_filter = {0};
@@ -31,24 +29,6 @@ static uint16_t readRegister(ADS1015_I2C *i2c, uint8_t reg) {
return ((pData[0] << 8) | pData[1]);
}
// Check if we have correct connection.
static void ADSbegin(ADS1015_I2C *i2c) {
if (HAL_I2C_IsDeviceReady(i2c->hi2c, i2c->m_i2cAddress, 10, 10) != HAL_OK)
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET); // This MUST have GPIO PA5 ready to use - ERROR I2C - Wrong address
}
// Declare an ADS1015 structure
void ADS1015_Init(void)
{
i2c_ads1015.hi2c = &hi2c1;
i2c_ads1015.m_i2cAddress = ADS1015_ADDR_GND; // It's Important to shift the address << 1
i2c_ads1015.m_conversionDelay = ADS1015_CONVERSIONDELAY;
i2c_ads1015.m_bitShift = 4;
i2c_ads1015.m_gain = GAIN_SIXTEEN; /* +/- 6.144V range (limited to VDD +0.3V max!) */
//ADSbegin(i2c); //Ready is not used
}
/*
* // The ADC input range (or gain) can be changed via the following
@@ -64,223 +44,42 @@ void ADS1015_Init(void)
// ADSsetGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ADSsetGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
*/
void ADSsetGain(ADS1015_I2C *i2c, adsGain_t gain) {
i2c->m_gain = gain;
// Declare an ADS1015 structure
void ADS1015_Init(void)
{
i2c_ads1015.hi2c = &hi2c1;
i2c_ads1015.m_i2cAddress = ADS1015_ADDR_GND; // It's Important to shift the address << 1
i2c_ads1015.m_conversionDelay = ADS1015_CONVERSIONDELAY;
i2c_ads1015.m_bitShift = 4;
i2c_ads1015.m_gain = GAIN_FOUR; /* 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV */
}
// Get the gain
adsGain_t ADSgetGain(ADS1015_I2C *i2c) {
return i2c->m_gain;
}
// Gets a single-ended ADC reading from the specified channel
uint16_t ADSreadADC_SingleEnded(ADS1015_I2C *i2c, uint8_t channel) {
if (channel > 3) {
return 0;
}
// Start with default values
uint16_t config =
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
// Set PGA/voltage range
config |= i2c->m_gain;
// Set single-ended input channel
switch (channel) {
case (0):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
break;
case (1):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
break;
case (2):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
break;
case (3):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
break;
}
// Set 'start single-conversion' bit
config |= ADS1015_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC
writeRegister(i2c, ADS1015_REG_POINTER_CONFIG, config);
// Wait for the conversion to complete
HAL_Delay(i2c->m_conversionDelay);
// Read the conversion results
// Shift 12-bit results right 4 bits for the ADS1015
return readRegister(i2c, ADS1015_REG_POINTER_CONVERT) >> i2c->m_bitShift;
}
/*
* Reads the conversion results, measuring the voltage
* difference between the P (AIN0) and N (AIN1) input. Generates
* a signed value since the difference can be either positive or negative.
/**
* @brief Converte um valor float em uma escala de FLOAT_MIN a FLOAT_MAX para uint16_t em escala de UINT16_MIN a UINT16_MAX
*
* @param value Valor float entre FLOAT_MIN e FLOAT_MAX
*
* @return uint16_t Valor convertido na escala de UINT16_MIN a UINT16_MAX
*/
int16_t ADSreadADC_Differential_0_1(ADS1015_I2C *i2c) {
// Start with default values
uint16_t config =
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1015_REG_CONFIG_DR_250SPS | // 128 samples per second (default)
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
uint16_t ADS1015_Compress_To_IntScale(float value)
{
// Verifica limites do valor de entrada
if (value < ADS1015_PH_FLOAT_SCALE_MIN)
return ADS1015_PH_OUT_SCALE_MIN;
else if (value > ADS1015_PH_FLOAT_SCALE_MAX)
return ADS1015_PH_OUT_SCALE_MAX;
// Set PGA/voltage range
config |= i2c->m_gain;
// Converte o valor usando a fórmula: ((value - FLOAT_MIN) / (FLOAT_MAX - FLOAT_MIN)) * (UINT16_MAX - UINT16_MIN) + UINT16_MIN
uint16_t result = (uint16_t)(((value - ADS1015_PH_FLOAT_SCALE_MIN) / (ADS1015_PH_FLOAT_SCALE_MAX - ADS1015_PH_FLOAT_SCALE_MIN)) * ((float)ADS1015_PH_OUT_SCALE_MAX - (float)ADS1015_PH_OUT_SCALE_MIN) + (float)ADS1015_PH_OUT_SCALE_MIN);
// Set channels
config |= ADS1015_REG_CONFIG_MUX_DIFF_0_1; // AIN0 = P, AIN1 = N
// Garante que o resultado não exceda o limite superior
if (result > ADS1015_PH_OUT_SCALE_MAX)
return (ADS1015_PH_OUT_SCALE_MAX);
// Set 'start single-conversion' bit
config |= ADS1015_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC
writeRegister(i2c, ADS1015_REG_POINTER_CONFIG, config);
// Wait for the conversion to complete
HAL_Delay(i2c->m_conversionDelay);
// Read the conversion results
uint16_t res = readRegister(i2c, ADS1015_REG_POINTER_CONVERT) >> i2c->m_bitShift;
if (i2c->m_bitShift == 0) {
return (int16_t) res;
} else {
// Shift 12-bit results right 4 bits for the ADS1015,
// making sure we keep the sign bit intact
if (res > 0x07FF) {
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t) res;
}
return result;
}
/*
* Reads the conversion results, measuring the voltage
* difference between the P (AIN2) and N (AIN3) input. Generates
* a signed value since the difference can be either positive or negative.
*/
int16_t ADSreadADC_Differential_2_3(ADS1015_I2C *i2c) {
// Start with default values
uint16_t config =
ADS1015_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val)
ADS1015_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
ADS1015_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
// Set PGA/voltage range
config |= i2c->m_gain;
// Set channels
config |= ADS1015_REG_CONFIG_MUX_DIFF_2_3; // AIN2 = P, AIN3 = N
// Set 'start single-conversion' bit
config |= ADS1015_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC
writeRegister(i2c, ADS1015_REG_POINTER_CONFIG, config);
// Wait for the conversion to complete
HAL_Delay(i2c->m_conversionDelay);
// Read the conversion results
uint16_t res = readRegister(i2c, ADS1015_REG_POINTER_CONVERT) >> i2c->m_bitShift;
if (i2c->m_bitShift == 0) {
return (int16_t) res;
} else {
// Shift 12-bit results right 4 bits for the ADS1015,
// making sure we keep the sign bit intact
if (res > 0x07FF) {
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t) res;
}
}
/*
* Sets up the comparator to operate in basic mode, causing the
* ALERT/RDY pin to assert (go from high to low) when the ADC
* value exceeds the specified threshold.
* This will also set the ADC in continuous conversion mode.
*/
void ADSstartComparator_SingleEnded(ADS1015_I2C *i2c, uint8_t channel, int16_t threshold) {
// Start with default values
uint16_t config =
ADS1015_REG_CONFIG_CQUE_1CONV | // Comparator enabled and asserts on 1 match
ADS1015_REG_CONFIG_CLAT_LATCH | // Latching mode
ADS1015_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1015_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1015_REG_CONFIG_DR_1600SPS | // 1600 samples per second (default)
ADS1015_REG_CONFIG_MODE_CONTIN | // Continuous conversion mode
ADS1015_REG_CONFIG_MODE_CONTIN; // Continuous conversion mode
// Set PGA/voltage range
config |= i2c->m_gain;
// Set single-ended input channel
switch (channel) {
case (0):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_0;
break;
case (1):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_1;
break;
case (2):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_2;
break;
case (3):
config |= ADS1015_REG_CONFIG_MUX_SINGLE_3;
break;
}
// Set the high threshold register
// Shift 12-bit results left 4 bits for the ADS1015
writeRegister(i2c, ADS1015_REG_POINTER_HITHRESH, threshold << i2c->m_bitShift);
// Write config register to the ADC
writeRegister(i2c, ADS1015_REG_POINTER_CONFIG, config);
}
/*
* In order to clear the comparator, we need to read the conversion results.
* This function reads the last conversion results without changing the config value.
*/
int16_t ADSgetLastConversionResults(ADS1015_I2C *i2c) {
// Wait for the conversion to complete
HAL_Delay(i2c->m_conversionDelay);
// Read the conversion results
uint16_t res = readRegister(i2c, ADS1015_REG_POINTER_CONVERT) >> i2c->m_bitShift;
if (i2c->m_bitShift == 0) {
return (int16_t) res;
} else {
// Shift 12-bit results right 4 bits for the ADS1015,
// making sure we keep the sign bit intact
if (res > 0x07FF) {
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t) res;
}
}
void ADS1015_Process_System(void)
{
static uint32_t state_timer = 0;
@@ -332,7 +131,7 @@ void ADS1015_Process_System(void)
int16_t raw = (int16_t)readRegister(&i2c_ads1015, ADS1015_REG_POINTER_CONVERT);
raw >>= 4; // remove os 4 bits reservados (D[3:0]), resultado = 12 bits signed
float value = (float)(4096 - raw); // ((float)raw * ADS1015_ADC_VREF) / ADS1015_ADC_MAX; // usa FSR configurado no PGA
float value = (float)(2048 - raw); // ((float)raw * ADS1015_ADC_VREF) / ADS1015_ADC_MAX; // usa FSR configurado no PGA
ADS1015_pH_NewSample(value);
@@ -479,159 +278,6 @@ void ADS1015_pH_NewSample(float raw)
float ADSCalculate_ph_mV(void) // pH in mV
{
float ph_dut_sum;
uint8_t i;
for (i = (ADS1015_PH_AVERAGES-1); i > 0; i--)
ph_dut_samples[i] = ph_dut_samples[i-1];
ph_dut_samples[0] = (((float)(ADSreadADC_Differential_0_1(&i2c_ads1015)) * ADS1015_ADC_VREF) / ADS1015_ADC_MAX); // 1. Converter leitura bruta do ADC para tensão real (mV)
for (i = 0, ph_dut_sum=0; i < ADS1015_PH_AVERAGES; i++)
ph_dut_sum += ph_dut_samples[i];
return (ADSRound_Float_Precision((ph_dut_sum/ADS1015_PH_AVERAGES),2));
}
/**
* @brief Calcula o valor de pH compensado pela temperatura.
*
* @param adc_raw Valor bruto lido do ADC (0 a 4095).
* @param temp_dut Temperatura atual medida em Celsius.
*
* @return float Valor de pH calculado (0.0 a 14.0).
*/
float ADSCalculate_ph_Compensated(float temp_dut)
{
float dut_mV = ADSCalculate_ph_mV();
float t_cal_k = flash_data.ph_temperature + 273.15f;
float t_dut_k = temp_dut + 273.15f;
float slope_dut = flash_data.ph_slope_mV * (t_dut_k / t_cal_k);
float ph_result = (flash_data.ph7_real + ((dut_mV - flash_data.ph7_mV) / slope_dut));
return (ADSRound_Float_Precision(ph_result,2));
}
/**
* @brief Calculates the pH value without temperature compensation.
*
* This version ignores the current temperature (temp_dut) and assumes
* the electrode slope remains constant as calibrated.
*
* @param temp_dut Unused in this non-compensated version.
* @return float Calculated pH value [0.0, 14.0]. Returns 0.0 if calibration error detected.
*/
float ADSCalculate_ph_Uncompensated(void)
{
/*
* 1. Convert raw ADC reading to actual voltage (Volts).
* Note: The subtraction of 2048 assumes a differential configuration
* where the midpoint is at the mid-scale of the ADS1015.
*/
float v_measured = ((float)(ADSreadADC_Differential_0_1(&i2c_ads1015)) * ADS1015_ADC_VREF) / ADS1015_ADC_MAX;
/*
* 2. Calculate the original Slope (measured during calibration).
* PH_DELTA_CALIB is a constant representing the pH difference between
* calibration points (e.g., |7.0 - 4.0| = 3.0).
*/
float delta_v_calib = flash_data.ph7_mV - flash_data.ph4_mV;
/* Safety check: Prevent division by zero if calibration data is invalid */
if (delta_v_calib == 0.0f)
{
return 0.0f;
}
/* Slope = Delta pH / Delta Voltage */
float slope_at_calib = PH_DELTA_CALIB / delta_v_calib;
/*
* 3. Final pH Calculation (Non-compensated)
* Formula: pH = pH_ref + (V_measured - V_ref_7) * Slope
* Where pH_ref is 7.0.
*/
float ph_result = 7.0f + ((v_measured - flash_data.ph7_mV) * slope_at_calib);
/* 4. Clamping (Ensure physical limits of the pH scale) */
if (ph_result < 0.0f)
{
ph_result = 0.0f;
}
else if (ph_result > 14.0f)
{
ph_result = 14.0f;
}
return ph_result;
}
/**
* @brief Performs linear interpolation for a given temperature within the LUT.
*
* @param temp_target The target temperature to interpolate for.
* @param row_index Index of the buffer row (1 for pH4, 2 for pH7).
* @return float Interpolated value from the matrix.
*/
float ADSinterpolate_ph(float temp_target, uint8_t row_index)
{
/* Matrix with {Temperature, Ph 4 Buffer, Ph 7 Buffer} */
const float lut_matrix_buffer_ph[ADS1015_INTERPOLATION_ROWS][ADS1015_PH_TEMP_INTER_POINTS] = {
{0.0f, 5.0f, 10.0f, 15.0f, 20.0f, 25.0f, 30.0f, 35.0f, 40.0f, 45.0f, 50.0f, 55.0f}, // Temperature
{4.01f, 4.00f, 4.00f, 4.00f, 4.00f, 4.01f, 4.01f, 4.02f, 4.03f, 4.05f, 4.06f, 4.10f}, // Buffer ph 4
{7.12f, 7.07f, 7.05f, 7.03f, 7.01f, 7.00f, 6.98f, 6.97f, 6.96f, 6.96f, 6.96f, 6.96f},}; // Buffer ph 7
uint8_t i = 0;
/* Boundary Check: Clamp to first or last index if out of range */
if (temp_target <= lut_matrix_buffer_ph[0][0])
return lut_matrix_buffer_ph[row_index][0];
if (temp_target >= lut_matrix_buffer_ph[0][ADS1015_PH_TEMP_INTER_POINTS-1])
return lut_matrix_buffer_ph[row_index][ADS1015_PH_TEMP_INTER_POINTS-1];
/* Find interpolation interval */
while (i < (ADS1015_PH_TEMP_INTER_POINTS-1) && lut_matrix_buffer_ph[0][i+1] < temp_target)
{
i++;
}
float x0 = lut_matrix_buffer_ph[0][i];
float x1 = lut_matrix_buffer_ph[0][i+1];
float y0 = lut_matrix_buffer_ph[row_index][i];
float y1 = lut_matrix_buffer_ph[row_index][i+1];
/* Linear Interpolation: y = y0 + (x - x0) * ((y1 - y_0) / (x1 - x0)) */
return y0 + (temp_target - x0) * ((y1 - y0) / (x1 - x0));
}
/**
* @brief Reduz a precisão decimal de um float através de truncamento.
*
* @param valor O valor float original.
* @param casas_decimais Quantidade de casas que devem permanecer após a vírgula.
* @return float O valor com as casas decimais excedentes removidas.
*/
float ADSRound_Float_Precision(float value, uint8_t number_of_decimals)
{
float multiply = 1.0f;
for (uint8_t i = 0; i < number_of_decimals; i++)
multiply *= 10.0f;
return roundf(value * multiply) / multiply;
}
@@ -51,7 +51,7 @@ void digital_outputs_init(void)
HAL_GPIO_Init(output_pins[i].port, &GPIO_InitStruct);
// Force initial state to LOW (Reset)
HAL_GPIO_WritePin(output_pins[i].port, output_pins[i].pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(output_pins[i].port, output_pins[i].pin, GPIO_PIN_SET);
pin_states[i] = 0;
}
}
@@ -72,10 +72,10 @@ void digital_outputs_set_state(digital_output_pin_t pin, uint8_t state)
uint16_t pin_mask = output_pins[pin].pin;
if (state) {
HAL_GPIO_WritePin(port, pin_mask, GPIO_PIN_SET);
HAL_GPIO_WritePin(port, pin_mask, GPIO_PIN_RESET);
pin_states[pin] = 1;
} else {
HAL_GPIO_WritePin(port, pin_mask, GPIO_PIN_RESET);
HAL_GPIO_WritePin(port, pin_mask, GPIO_PIN_SET);
pin_states[pin] = 0;
}
}
+117 -149
View File
@@ -59,16 +59,6 @@
/* USER CODE BEGIN PV */
uint8_t rx_buffer[256]; /*!< Buffer for received data */
uint8_t tx_data[] = "Hello RS-485 Broadcast!"; /*!< Data to send */
uint8_t adc_text[6];
uint8_t real_text[6];
uint8_t imag_text[6];
uint8_t rs485_text[6];
uint8_t newline[]={'\r','\n'};
uint8_t doubleSpace[]={'_','_','\0'};
uint8_t newline_ph[]={'_','p','H','\n','\0'};
@@ -84,11 +74,13 @@ uint8_t tm_t[]={'T','M',':',' ','\0'};
uint8_t main_state = STATE_RUNNING_OK;
uint8_t rs485_address=0;
/*
uint16_t AD_RES[2];
uint8_t UpdateEvent = 0;
float Temperature, Temp_Sum, V_Sense, V_Ref;
float Temp_Samples[STM32_TEMPERATURE_AVERAGES]={0};
*/
/* USER CODE END PV */
@@ -112,87 +104,64 @@ void FloatToString(uint8_t * buf, double val);
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE BEGIN 1 */
HAL_StatusTypeDef status0,status1;
// Variables to store previous LED states
uint8_t previous_green_state = 0;
uint8_t previous_red_state = 0;
uint8_t mux_connection = 0;
// Variables for timing
uint32_t previous_millis_green = 0;
uint32_t previous_millis_red = 0;
uint32_t current_millis;
float temperature_RTD, admittance_EC, refResistance, update_value, ph7_interp, ph4_interp, ph_compensated;
/*! Temporary variables */
uint8_t tempString[15] = {0};
uint8_t i;
uint8_t mux_connection = 0;
/* USER CODE END 1 */
// Variables for timing
uint32_t previous_millis_green = 0;
uint32_t previous_millis_red = 0;
uint32_t current_millis;
/* MCU Configuration--------------------------------------------------------*/
//float temperature_RTD, admittance_EC, refResistance, update_value, ph7_interp, ph4_interp, ph_compensated;
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE END 1 */
/* USER CODE BEGIN Init */
/* MCU Configuration--------------------------------------------------------*/
/* USER CODE END Init */
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN Init */
/* USER CODE BEGIN SysInit */
/* USER CODE END Init */
/* USER CODE END SysInit */
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_I2C1_Init();
MX_I2C2_Init();
MX_USART1_UART_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_I2C1_Init();
MX_I2C2_Init();
MX_USART1_UART_Init();
MX_TIM3_Init();
Flash_Load_Page(&flash_data);
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);
HAL_TIM_Base_Start_IT(&htim3);
/*
TempSensor_Init(&hadc1);
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)AD_RES, 2); // Internal Temperature conversion
*/
//TempSensor_Init(&hadc1);
/*
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)AD_RES, 2); // Internal Temperature conversion
*/
digital_outputs_init();
rs485_init();
ADS1015_Init(); // Initializes pH Measurement
AD5934_Init(); // Initializes CE and RTD Measurement
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); // LED Green Off
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); // LED Red Off
digital_outputs_init();
rs485_init();
ADS1015_Init(); // Initializes pH Measurement
AD5934_Init(); // Initializes CE and RTD Measurement
/* USER CODE END 2 */
@@ -279,18 +248,16 @@ int main(void)
{
AD5934_Process_System();
ADS1015_Process_System();
AD5934_Process_System();
ADS1015_Process_System();
current_millis = g_ms_counter;
current_millis = g_ms_counter;
if((current_millis % 100) == 0) // Send data each 50ms
{
if((current_millis % 100) == 0) // Send data each 50ms
{
if (g_ref_filter.value_valid) // Reference Resistor on Board: 100 Ohms or 1000 Ohms
{
if (g_ref_filter.value_valid) // Reference Resistor on Board: 100 Ohms or 1000 Ohms
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7) == GPIO_PIN_SET) // OFF = PT1000, ON = PT100, PA7 has internal pull-up and switch connects to GND
mux_connection = AD5934_CH_REF100R_LOW_GAIN; // 100 Ohms Reference Resistor
else
@@ -299,28 +266,28 @@ int main(void)
uint16_t reference_final = AD5934_REF_OUT_SCALE_MAX - AD5934_Compress_To_IntScale(g_ref_filter.filtered_value, mux_connection);
intToStr(reference_final, tempString);
// float ref_final = g_ref_filter.filtered_value;
//FloatToString(tempString, ref_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
//FloatToString(tempString, ref_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
if (g_ec_filter.value_valid) // EC
{
if (g_ec_filter.value_valid) // EC
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_6) == GPIO_PIN_SET) // Hardware Setup: Gain Selection (PA6)
mux_connection = AD5934_CH_EC_HIGH_GAIN;
mux_connection = AD5934_CH_EC_HIGH_GAIN; // 5mS
else
mux_connection = AD5934_CH_EC_MID_GAIN;
mux_connection = AD5934_CH_EC_MID_GAIN; // 10mS
uint16_t ec_final = AD5934_Compress_To_IntScale(g_ec_filter.filtered_value, mux_connection);
intToStr(ec_final, tempString);
/* float ec_final = g_ec_filter.filtered_value;
FloatToString(tempString, ec_final);*/
// float ec_final = g_ec_filter.filtered_value;
// FloatToString(tempString, ec_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
}
if (g_rtd_filter.value_valid) // PT100 or PT1000 in °C
{
if (g_rtd_filter.value_valid) // PT100 or PT1000 in °C
{
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7) == GPIO_PIN_SET) // OFF = PT1000, ON = PT100, PA7 has internal pull-up and switch connects to GND
mux_connection = AD5934_CH_RTD_LOW_GAIN; //PT100
else
@@ -328,41 +295,42 @@ int main(void)
uint16_t rtd_final = AD5934_RTD_OUT_SCALE_MAX - AD5934_Compress_To_IntScale(g_rtd_filter.filtered_value, mux_connection);
intToStr(rtd_final, tempString);
// float rtd_final = g_rtd_filter.filtered_value;
// FloatToString(tempString, rtd_final);
//float rtd_final = g_rtd_filter.filtered_value;
//FloatToString(tempString, rtd_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
}
if (g_ph_filter.value_valid) // pH
{
float ph_final = g_ph_filter.filtered_value;
FloatToString(tempString, ph_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
if (g_ph_filter.value_valid) // pH
{
uint16_t ph_final = ADS1015_Compress_To_IntScale(g_ph_filter.filtered_value);
intToStr(ph_final, tempString);
//float ph_final = g_ph_filter.filtered_value;
//FloatToString(tempString, ph_final);
rs485_send_broadcast(tempString, (strlen((uint8_t*)tempString)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
rs485_send_broadcast(newline, (strlen((uint8_t*)newline)));
}
}
// Piscar LED verde em PB4 a cada 1 segundo
if ((current_millis - previous_millis_green) >= 1000)
{
previous_millis_green = current_millis;
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
// Piscar LED verde em PB5 a cada 0,5 segundos
if ((current_millis - previous_millis_green) >= 500)
{
previous_millis_green = current_millis;
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
}
}
// Piscar LED vermelho em PB4 a cada 1 segundo
if ((current_millis - previous_millis_red) >= 1000)
/*
// Piscar LED vermelho em PB5 a cada 0,5 segundos
if ((current_millis - previous_millis_red) >= 500)
{
previous_millis_red = current_millis;
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_4);
}
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
}*/
/*
if(UpdateEvent) // Internal Temperature
@@ -408,40 +376,40 @@ int main(void)
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSE;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV8;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
@@ -1,32 +1,25 @@
../Core/Src/ad5934_driver.c:47:6:AD5934_SetRegisterValue 2
../Core/Src/ad5934_driver.c:75:10:AD5934_GetRegisterValue 3
../Core/Src/ad5934_driver.c:114:10:AD5934_ReadRegister 3
../Core/Src/ad5934_driver.c:151:6:AD5934_Init 1
../Core/Src/ad5934_driver.c:182:6:AD5934_RestartSweep 1
../Core/Src/ad5934_driver.c:214:6:AD5934_Repeat_Sweep 1
../Core/Src/ad5934_driver.c:227:6:AD5934_StopSweep 1
../Core/Src/ad5934_driver.c:244:10:AD5934_Sweep 1
../Core/Src/ad5934_driver.c:270:7:AD5934_Get_Ref_Resistance 4
../Core/Src/ad5934_driver.c:321:7:AD5934_GetTemperature 5
../Core/Src/ad5934_driver.c:411:7:AD5934_Calculate_Temperature 3
../Core/Src/ad5934_driver.c:452:7:AD5934_GetImpedance 10
../Core/Src/ad5934_driver.c:528:7:AD5934_GetMagnitude 1
../Core/Src/ad5934_driver.c:549:6:AD5934_Wait_For_Data_Valid 3
../Core/Src/ad5934_driver.c:584:10:AD5934_Compress_To_IntScale 5
../Core/Src/ad5934_driver.c:614:7:AD5934_Round_Float_Precision 2
../Core/Src/ad5934_driver.c:639:7:AD5934_Linear_Correction 1
../Core/Src/ad5934_driver.c:656:7:AD5934_EC_Compensate_To_25C 2
../Core/Src/ad5934_driver.c:672:7:AD5934_EC_Calibrate_Temperature 5
../Core/Src/ad5934_driver.c:721:7:AD5934_Calibrate 1
../Core/Src/ad5934_driver.c:737:6:AD5934_Process_System 24
../Core/Src/ad5934_driver.c:862:6:AD5934_Sort_Array 4
../Core/Src/ad5934_driver.c:884:7:AD5934_Trimmed_Mean 3
../Core/Src/ad5934_driver.c:910:7:AD5934_History_Average 2
../Core/Src/ad5934_driver.c:924:6:AD5934_Process_Sample 4
../Core/Src/ad5934_driver.c:970:6:AD5934_RTD_NewSample 1
../Core/Src/ad5934_driver.c:977:6:AD5934_EC_NewSample 1
../Core/Src/ad5934_driver.c:984:6:AD5934_Reference_NewSample 1
../Core/Src/ad5934_driver.c:1000:6:ADG715_SetRegisterValue 1
../Core/Src/ad5934_driver.c:1010:6:ADG715_SetChannels 1
../Core/Src/ad5934_driver.c:1015:6:ADG715_ResetChannels 1
../Core/Src/ad5934_driver.c:1027:6:ADG715_Update 2
../Core/Src/ad5934_driver.c:40:6:AD5934_SetRegisterValue 2
../Core/Src/ad5934_driver.c:68:10:AD5934_GetRegisterValue 3
../Core/Src/ad5934_driver.c:103:6:AD5934_Init 1
../Core/Src/ad5934_driver.c:134:6:AD5934_RestartSweep 1
../Core/Src/ad5934_driver.c:157:6:AD5934_Repeat_Sweep 1
../Core/Src/ad5934_driver.c:170:6:AD5934_StopSweep 1
../Core/Src/ad5934_driver.c:190:7:AD5934_Calculate_Temperature 3
../Core/Src/ad5934_driver.c:231:7:AD5934_EC_Compensate_Magnitude_To_25C 2
../Core/Src/ad5934_driver.c:246:7:AD5934_EC_Calibrate_Temperature 5
../Core/Src/ad5934_driver.c:292:7:AD5934_GetMagnitude 1
../Core/Src/ad5934_driver.c:317:10:AD5934_Compress_To_IntScale 5
../Core/Src/ad5934_driver.c:347:7:AD5934_Round_Float_Precision 2
../Core/Src/ad5934_driver.c:372:7:AD5934_Linear_Correction 1
../Core/Src/ad5934_driver.c:391:7:AD5934_Calibrate 1
../Core/Src/ad5934_driver.c:413:6:AD5934_Process_System 24
../Core/Src/ad5934_driver.c:538:6:AD5934_Sort_Array 4
../Core/Src/ad5934_driver.c:560:7:AD5934_Trimmed_Mean 3
../Core/Src/ad5934_driver.c:586:7:AD5934_History_Average 2
../Core/Src/ad5934_driver.c:600:6:AD5934_Process_Sample 4
../Core/Src/ad5934_driver.c:646:6:AD5934_RTD_NewSample 1
../Core/Src/ad5934_driver.c:653:6:AD5934_EC_NewSample 1
../Core/Src/ad5934_driver.c:660:6:AD5934_Reference_NewSample 1
../Core/Src/ad5934_driver.c:676:6:ADG715_SetRegisterValue 1
../Core/Src/ad5934_driver.c:694:6:ADG715_ResetChannels 1
../Core/Src/ad5934_driver.c:706:6:ADG715_SetChannels 2
+1 -2
View File
@@ -28,7 +28,7 @@ Core/Src/ad5934_driver.o: ../Core/Src/ad5934_driver.c \
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h \
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h \
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h \
../Core/Inc/flash_manager.h ../Core/Inc/main.h
../Core/Inc/main.h
../Core/Inc/ad5934_driver.h:
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h:
../Core/Inc/stm32f1xx_hal_conf.h:
@@ -58,5 +58,4 @@ Core/Src/ad5934_driver.o: ../Core/Src/ad5934_driver.c \
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h:
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h:
../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h:
../Core/Inc/flash_manager.h:
../Core/Inc/main.h:
Binary file not shown.
+25 -32
View File
@@ -1,32 +1,25 @@
../Core/Src/ad5934_driver.c:47:6:AD5934_SetRegisterValue 32 static
../Core/Src/ad5934_driver.c:75:10:AD5934_GetRegisterValue 40 static
../Core/Src/ad5934_driver.c:114:10:AD5934_ReadRegister 48 static
../Core/Src/ad5934_driver.c:151:6:AD5934_Init 8 static
../Core/Src/ad5934_driver.c:182:6:AD5934_RestartSweep 8 static
../Core/Src/ad5934_driver.c:214:6:AD5934_Repeat_Sweep 8 static
../Core/Src/ad5934_driver.c:227:6:AD5934_StopSweep 8 static
../Core/Src/ad5934_driver.c:244:10:AD5934_Sweep 16 static
../Core/Src/ad5934_driver.c:270:7:AD5934_Get_Ref_Resistance 48 static
../Core/Src/ad5934_driver.c:321:7:AD5934_GetTemperature 72 static
../Core/Src/ad5934_driver.c:411:7:AD5934_Calculate_Temperature 40 static
../Core/Src/ad5934_driver.c:452:7:AD5934_GetImpedance 56 static
../Core/Src/ad5934_driver.c:528:7:AD5934_GetMagnitude 24 static
../Core/Src/ad5934_driver.c:549:6:AD5934_Wait_For_Data_Valid 24 static
../Core/Src/ad5934_driver.c:584:10:AD5934_Compress_To_IntScale 32 static
../Core/Src/ad5934_driver.c:614:7:AD5934_Round_Float_Precision 24 static
../Core/Src/ad5934_driver.c:639:7:AD5934_Linear_Correction 24 static
../Core/Src/ad5934_driver.c:656:7:AD5934_EC_Compensate_To_25C 24 static
../Core/Src/ad5934_driver.c:672:7:AD5934_EC_Calibrate_Temperature 152 static
../Core/Src/ad5934_driver.c:721:7:AD5934_Calibrate 48 static
../Core/Src/ad5934_driver.c:737:6:AD5934_Process_System 16 static
../Core/Src/ad5934_driver.c:862:6:AD5934_Sort_Array 24 static
../Core/Src/ad5934_driver.c:884:7:AD5934_Trimmed_Mean 32 static
../Core/Src/ad5934_driver.c:910:7:AD5934_History_Average 24 static
../Core/Src/ad5934_driver.c:924:6:AD5934_Process_Sample 32 static
../Core/Src/ad5934_driver.c:970:6:AD5934_RTD_NewSample 16 static
../Core/Src/ad5934_driver.c:977:6:AD5934_EC_NewSample 16 static
../Core/Src/ad5934_driver.c:984:6:AD5934_Reference_NewSample 16 static
../Core/Src/ad5934_driver.c:1000:6:ADG715_SetRegisterValue 32 static
../Core/Src/ad5934_driver.c:1010:6:ADG715_SetChannels 16 static
../Core/Src/ad5934_driver.c:1015:6:ADG715_ResetChannels 8 static
../Core/Src/ad5934_driver.c:1027:6:ADG715_Update 16 static
../Core/Src/ad5934_driver.c:40:6:AD5934_SetRegisterValue 32 static
../Core/Src/ad5934_driver.c:68:10:AD5934_GetRegisterValue 40 static
../Core/Src/ad5934_driver.c:103:6:AD5934_Init 8 static
../Core/Src/ad5934_driver.c:134:6:AD5934_RestartSweep 8 static
../Core/Src/ad5934_driver.c:157:6:AD5934_Repeat_Sweep 8 static
../Core/Src/ad5934_driver.c:170:6:AD5934_StopSweep 8 static
../Core/Src/ad5934_driver.c:190:7:AD5934_Calculate_Temperature 40 static
../Core/Src/ad5934_driver.c:231:7:AD5934_EC_Compensate_Magnitude_To_25C 24 static
../Core/Src/ad5934_driver.c:246:7:AD5934_EC_Calibrate_Temperature 152 static
../Core/Src/ad5934_driver.c:292:7:AD5934_GetMagnitude 24 static
../Core/Src/ad5934_driver.c:317:10:AD5934_Compress_To_IntScale 32 static
../Core/Src/ad5934_driver.c:347:7:AD5934_Round_Float_Precision 24 static
../Core/Src/ad5934_driver.c:372:7:AD5934_Linear_Correction 24 static
../Core/Src/ad5934_driver.c:391:7:AD5934_Calibrate 48 static
../Core/Src/ad5934_driver.c:413:6:AD5934_Process_System 16 static
../Core/Src/ad5934_driver.c:538:6:AD5934_Sort_Array 24 static
../Core/Src/ad5934_driver.c:560:7:AD5934_Trimmed_Mean 32 static
../Core/Src/ad5934_driver.c:586:7:AD5934_History_Average 24 static
../Core/Src/ad5934_driver.c:600:6:AD5934_Process_Sample 32 static
../Core/Src/ad5934_driver.c:646:6:AD5934_RTD_NewSample 16 static
../Core/Src/ad5934_driver.c:653:6:AD5934_EC_NewSample 16 static
../Core/Src/ad5934_driver.c:660:6:AD5934_Reference_NewSample 16 static
../Core/Src/ad5934_driver.c:676:6:ADG715_SetRegisterValue 32 static
../Core/Src/ad5934_driver.c:694:6:ADG715_ResetChannels 8 static
../Core/Src/ad5934_driver.c:706:6:ADG715_SetChannels 16 static
@@ -1,22 +1,10 @@
../Core/Src/ads1015_driver.c:21:13:writeRegister 1
../Core/Src/ads1015_driver.c:27:17:readRegister 1
../Core/Src/ads1015_driver.c:35:13:ADSbegin 2
../Core/Src/ads1015_driver.c:42:6:ADS1015_Init 1
../Core/Src/ads1015_driver.c:67:6:ADSsetGain 1
../Core/Src/ads1015_driver.c:72:11:ADSgetGain 1
../Core/Src/ads1015_driver.c:77:10:ADSreadADC_SingleEnded 6
../Core/Src/ads1015_driver.c:129:9:ADSreadADC_Differential_0_1 3
../Core/Src/ads1015_driver.c:174:9:ADSreadADC_Differential_2_3 3
../Core/Src/ads1015_driver.c:220:6:ADSstartComparator_SingleEnded 5
../Core/Src/ads1015_driver.c:262:9:ADSgetLastConversionResults 3
../Core/Src/ads1015_driver.c:284:6:ADS1015_Process_System 10
../Core/Src/ads1015_driver.c:367:6:ADS1015_Sort_Array 4
../Core/Src/ads1015_driver.c:389:7:ADS1015_Trimmed_Mean 3
../Core/Src/ads1015_driver.c:415:7:ADS1015_History_Average 2
../Core/Src/ads1015_driver.c:429:6:ADS1015_Process_Sample 4
../Core/Src/ads1015_driver.c:474:6:ADS1015_pH_NewSample 1
../Core/Src/ads1015_driver.c:482:7:ADSCalculate_ph_mV 3
../Core/Src/ads1015_driver.c:511:7:ADSCalculate_ph_Compensated 1
../Core/Src/ads1015_driver.c:537:7:ADSCalculate_ph_Uncompensated 4
../Core/Src/ads1015_driver.c:589:7:ADSinterpolate_ph 5
../Core/Src/ads1015_driver.c:627:7:ADSRound_Float_Precision 2
../Core/Src/ads1015_driver.c:19:13:writeRegister 1
../Core/Src/ads1015_driver.c:25:17:readRegister 1
../Core/Src/ads1015_driver.c:48:6:ADS1015_Init 1
../Core/Src/ads1015_driver.c:65:10:ADS1015_Compress_To_IntScale 4
../Core/Src/ads1015_driver.c:83:6:ADS1015_Process_System 10
../Core/Src/ads1015_driver.c:166:6:ADS1015_Sort_Array 4
../Core/Src/ads1015_driver.c:188:7:ADS1015_Trimmed_Mean 3
../Core/Src/ads1015_driver.c:214:7:ADS1015_History_Average 2
../Core/Src/ads1015_driver.c:228:6:ADS1015_Process_Sample 4
../Core/Src/ads1015_driver.c:273:6:ADS1015_pH_NewSample 1
Binary file not shown.
+10 -22
View File
@@ -1,22 +1,10 @@
../Core/Src/ads1015_driver.c:21:13:writeRegister 32 static
../Core/Src/ads1015_driver.c:27:17:readRegister 32 static
../Core/Src/ads1015_driver.c:35:13:ADSbegin 16 static
../Core/Src/ads1015_driver.c:42:6:ADS1015_Init 4 static
../Core/Src/ads1015_driver.c:67:6:ADSsetGain 16 static
../Core/Src/ads1015_driver.c:72:11:ADSgetGain 16 static
../Core/Src/ads1015_driver.c:77:10:ADSreadADC_SingleEnded 24 static
../Core/Src/ads1015_driver.c:129:9:ADSreadADC_Differential_0_1 24 static
../Core/Src/ads1015_driver.c:174:9:ADSreadADC_Differential_2_3 24 static
../Core/Src/ads1015_driver.c:220:6:ADSstartComparator_SingleEnded 24 static
../Core/Src/ads1015_driver.c:262:9:ADSgetLastConversionResults 24 static
../Core/Src/ads1015_driver.c:284:6:ADS1015_Process_System 16 static
../Core/Src/ads1015_driver.c:367:6:ADS1015_Sort_Array 24 static
../Core/Src/ads1015_driver.c:389:7:ADS1015_Trimmed_Mean 32 static
../Core/Src/ads1015_driver.c:415:7:ADS1015_History_Average 24 static
../Core/Src/ads1015_driver.c:429:6:ADS1015_Process_Sample 32 static
../Core/Src/ads1015_driver.c:474:6:ADS1015_pH_NewSample 16 static
../Core/Src/ads1015_driver.c:482:7:ADSCalculate_ph_mV 16 static
../Core/Src/ads1015_driver.c:511:7:ADSCalculate_ph_Compensated 48 static
../Core/Src/ads1015_driver.c:537:7:ADSCalculate_ph_Uncompensated 24 static
../Core/Src/ads1015_driver.c:589:7:ADSinterpolate_ph 192 static
../Core/Src/ads1015_driver.c:627:7:ADSRound_Float_Precision 24 static
../Core/Src/ads1015_driver.c:19:13:writeRegister 32 static
../Core/Src/ads1015_driver.c:25:17:readRegister 32 static
../Core/Src/ads1015_driver.c:48:6:ADS1015_Init 4 static
../Core/Src/ads1015_driver.c:65:10:ADS1015_Compress_To_IntScale 24 static
../Core/Src/ads1015_driver.c:83:6:ADS1015_Process_System 16 static
../Core/Src/ads1015_driver.c:166:6:ADS1015_Sort_Array 24 static
../Core/Src/ads1015_driver.c:188:7:ADS1015_Trimmed_Mean 32 static
../Core/Src/ads1015_driver.c:214:7:ADS1015_History_Average 24 static
../Core/Src/ads1015_driver.c:228:6:ADS1015_Process_Sample 32 static
../Core/Src/ads1015_driver.c:273:6:ADS1015_pH_NewSample 16 static
+6 -6
View File
@@ -1,6 +1,6 @@
../Core/Src/main.c:113:5:main 11
../Core/Src/main.c:409:6:SystemClock_Config 4
../Core/Src/main.c:460:6:FloatToString 8
../Core/Src/main.c:522:6:intToStr 12
../Core/Src/main.c:580:6:HAL_TIM_PeriodElapsedCallback 2
../Core/Src/main.c:604:6:Error_Handler 1
../Core/Src/main.c:105:5:main 10
../Core/Src/main.c:377:6:SystemClock_Config 4
../Core/Src/main.c:428:6:FloatToString 8
../Core/Src/main.c:490:6:intToStr 12
../Core/Src/main.c:548:6:HAL_TIM_PeriodElapsedCallback 2
../Core/Src/main.c:572:6:Error_Handler 1
Binary file not shown.
+6 -6
View File
@@ -1,6 +1,6 @@
../Core/Src/main.c:113:5:main 56 static
../Core/Src/main.c:409:6:SystemClock_Config 88 static
../Core/Src/main.c:460:6:FloatToString 104 static
../Core/Src/main.c:522:6:intToStr 32 static
../Core/Src/main.c:580:6:HAL_TIM_PeriodElapsedCallback 16 static
../Core/Src/main.c:604:6:Error_Handler 4 static,ignoring_inline_asm
../Core/Src/main.c:105:5:main 48 static
../Core/Src/main.c:377:6:SystemClock_Config 88 static
../Core/Src/main.c:428:6:FloatToString 104 static
../Core/Src/main.c:490:6:intToStr 32 static
../Core/Src/main.c:548:6:HAL_TIM_PeriodElapsedCallback 16 static
../Core/Src/main.c:572:6:Error_Handler 4 static,ignoring_inline_asm
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff