Fertirrega v6 with internal temperature (but slow)

This commit is contained in:
2026-07-16 16:49:58 +01:00
parent 08709213d9
commit 8d1bb4fadb
121 changed files with 35137 additions and 12048 deletions
+32 -2
View File
@@ -13,6 +13,8 @@
#define INC_AD5934_DRIVER_H_
#include "stm32f1xx_hal.h"
#include "flash_manager.h"
#include "main.h"
#include <math.h>
#include <stdlib.h>
@@ -111,6 +113,7 @@ extern "C" {
#define ADG715_SW7 0x40 //RTD Input
#define ADG715_SW8 0x80 //CE Input
/*
#define AD5934_CH_REF_100R 0x10
#define AD5934_CH_REF_1K 0x11
#define AD5934_CH_REF_10K 0x12
@@ -118,6 +121,32 @@ extern "C" {
#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
#define AD5934_REF100R_BASE 0x08
#define AD5934_REF1K_BASE 0x10
#define AD5934_REF10K_BASE 0x20
#define AD5934_RTD_BASE 0x40
#define AD5934_CE_BASE 0x80
#define AD5934_CH_DELTA 0x10
@@ -126,6 +155,9 @@ extern "C" {
#define AD5934_GAIN_FACTOR_1K 1000.0f
#define AD5934_GAIN_FACTOR_10K 10000.0f
#define AD5934_GAIN_FACTOR_1413US 1413.0f
#define AD5934_GAIN_FACTOR_12880US 12880.0f
#define AD5934_RTD_A 3.9083e-3f
#define AD5934_RTD_B (-5.775e-7f)
@@ -160,8 +192,6 @@ extern int16_t ec_ref1_samples[AD5934_EC_AVERAGES][2];
extern int16_t ec_ref2_samples[AD5934_EC_AVERAGES][2];
extern float ec_display[AD5934_EC_AVERAGES];
extern float ec_temp_dut[AD5934_EC_AVERAGES];
extern float ec_temp_ref1[AD5934_EC_AVERAGES];
extern float ec_temp_ref2[AD5934_EC_AVERAGES];
extern I2C_HandleTypeDef hi2c2;
+6 -2
View File
@@ -13,7 +13,9 @@
#define INC_ADS1015_DRIVER_H_
#include <stdint.h>
#include "main.h" // Assuming HAL is included via main.h
#include "stm32f1xx_hal.h"
#include "flash_manager.h"
#ifdef __cplusplus
extern "C" {
@@ -124,6 +126,7 @@ extern "C" {
#define ADS1015_KELVIN_OFFSET 273.15f // Constante de conversão Kelvin
#define ADS1015_ADC_MAX 4095.0f
#define ADS1015_ADC_VREF 3.3f
#define ADS1015_PH_AVERAGES 8
/*=========================================================================*/
@@ -146,8 +149,9 @@ typedef struct {
I2C_HandleTypeDef* hi2c; // Handle for I2C
}ADS1015_I2C;
extern float temp_calib, ph_compensated, v_ph4, v_ph7;
extern float ph_averages[ADS1015_PH_AVERAGES];
extern ADS1015_I2C i2c;
void ADS1015(ADS1015_I2C* i2c, I2C_HandleTypeDef* hi2c, uint8_t i2cAddress);
uint16_t ADSreadADC_SingleEnded(ADS1015_I2C* i2c, uint8_t channel);
@@ -157,7 +161,7 @@ void ADSstartComparator_SingleEnded(ADS1015_I2C* i2c, uint8_t channel, int16_t
int16_t ADSgetLastConversionResults();
void ADSsetGain(ADS1015_I2C* i2c, adsGain_t gain);
adsGain_t ADSgetGain(ADS1015_I2C* i2c);
float ADSCalculate_ph_Volts(int16_t adc_raw);
float ADSCalculate_ph_Volts(void);
float ADSCalculate_ph_Compensated(int16_t adc_raw, float temp_dut);
#endif /* INC_ADS1015_DRIVER_H_ */
+52
View File
@@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __DMA_H__ */
+11 -6
View File
@@ -25,14 +25,19 @@
* @brief Estrutura de 1KB alinhada e preenchida.
* O uso de padding manual garante que não haja surpresas com o compilador.
*/
typedef struct __attribute__((packed, aligned(4))) {
uint32_t magic_number; // 4 bytes (Validação)
float calibration_offset; // 4 bytes
uint16_t sensor_threshold; // 2 bytes
uint8_t status_flag; // 1 byte
uint8_t reserved[1013]; // Preenchimento para completar 1024 bytes (1KB)
typedef struct __attribute__((packed, aligned(4)))
{
uint32_t magic_number; // 4 bytes (Validação)
float ph4_value; // 4 bytes
float ph7_value; // 4 bytes
float ec1413_value; // 4 bytes
float ec12880_value; // 4 bytes
float temperature_value;// 4 bytes
uint8_t reserved[1000]; // Preenchimento para completar 1024 bytes (1KB)
} FlashPage_t;
extern FlashPage_t flash_data;
/* Protótipos */
HAL_StatusTypeDef Flash_Save_Page(FlashPage_t *pPage);
HAL_StatusTypeDef Flash_Load_Page(FlashPage_t *pDest);
+8 -1
View File
@@ -127,8 +127,15 @@ void Error_Handler(void);
/* USER CODE BEGIN Private defines */
#define STATE_RUNNING_OK 0x00
#define STATE_SETUP_CALIBRATION 0x01
#define STATE_RS485_SUPPLY_FAULT 0x02
#define STATE_PH_SUPPLY_FAULT 0x03
#define STATE_EC_RTD_SUPPLY_FAULT 0x04
#define STATE_NO_SETUP_CALIBRATION 0x05
#define STATE_HIGH_AMBIENT_TEMPERATURE 0x06
extern uint8_t main_state;
/* USER CODE END Private defines */
#ifdef __cplusplus
+2 -2
View File
@@ -42,7 +42,7 @@
/*#define HAL_CORTEX_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_DMA_MODULE_ENABLED */
#define HAL_DMA_MODULE_ENABLED
/*#define HAL_ETH_MODULE_ENABLED */
/*#define HAL_FLASH_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
@@ -64,7 +64,7 @@
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_SRAM_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
+1
View File
@@ -56,6 +56,7 @@ void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void EXTI3_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
void USART1_IRQHandler(void);
/* USER CODE BEGIN EFP */
+52
View File
@@ -0,0 +1,52 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.h
* @brief This file contains all the function prototypes for
* the tim.c file
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TIM_H__
#define __TIM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern TIM_HandleTypeDef htim3;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_TIM3_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __TIM_H__ */