workable STS_Weight_scale, STS-R6
This commit is contained in:
parent
23c229372e
commit
bd2cd43b7a
Core
LoRaWAN/Target
STM32CubeIDE
STS/Core/Src
|
@ -313,8 +313,8 @@ void Error_Handler(void);
|
|||
|
||||
#define HX711_SCK_PIN GPIO_PIN_6
|
||||
#define HX711_DOUT_PIN GPIO_PIN_7
|
||||
#define HX711_SCK_PORT GPIOB
|
||||
#define HX711_DOUT_PORT GPIOB
|
||||
#define HX711_SCK_PORT GPIOA
|
||||
#define HX711_DOUT_PORT GPIOA
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#elif defined(L8)
|
||||
#include "app_tof.h"
|
||||
#endif
|
||||
#include "sts_weight_scale.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -102,7 +103,7 @@ int main(void)
|
|||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
|
||||
PME_ON;
|
||||
#if 0
|
||||
if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
|
||||
{
|
||||
|
@ -118,10 +119,13 @@ int main(void)
|
|||
#endif
|
||||
MX_LoRaWAN_Init();
|
||||
}
|
||||
//PME_ON;
|
||||
//WATER_LEAKAGE_ENABLE;
|
||||
|
||||
sts_weight_scale_init();
|
||||
|
||||
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
//MX_USART2_UART_Init();
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
@ -129,7 +133,6 @@ int main(void)
|
|||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
MX_LoRaWAN_Process();
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
|
|
@ -19,63 +19,17 @@
|
|||
*/
|
||||
/* USER CODE END Header */
|
||||
#include "sts_weight_scale.h"
|
||||
|
||||
#include <stdio.h>
|
||||
uint32_t HX711_Buffer=0;
|
||||
volatile uint32_t gross_weight;
|
||||
uint32_t net_weight;
|
||||
int32_t net_weight;
|
||||
uint8_t Flag_Error;
|
||||
volatile uint32_t last_net_weight=0;
|
||||
volatile sts_sensor_t sts_sensor_data;
|
||||
volatile uint32_t sts_weight_scale_value_g = 0, sts_weight_tare_g=0;
|
||||
void sts_weight_scale_init(void)
|
||||
{
|
||||
HX711_Init();
|
||||
Get_GrossWeight();
|
||||
HAL_Delay(10);
|
||||
Get_GrossWeight();
|
||||
}
|
||||
|
||||
void sts_weight_scale(void)
|
||||
{
|
||||
|
||||
float sum_tmp_net_weight=0.0;
|
||||
|
||||
for (uint8_t cnt=0;cnt<20;cnt++)
|
||||
{
|
||||
Get_NetWeight();
|
||||
sum_tmp_net_weight += net_weight;
|
||||
}
|
||||
net_weight = (float)sum_tmp_net_weight/20.0;
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "Average Net Weight = %d g \r\n", net_weight);
|
||||
|
||||
sts_weight_scale_value_g = net_weight;
|
||||
volatile unsigned long sts_weight_scale_value_g = 0, sts_weight_tare_g=0;
|
||||
|
||||
|
||||
|
||||
// re-calibrate or Zero if changes > 100g
|
||||
if ((fabs(last_net_weight - net_weight) > 100) && (net_weight > 100))
|
||||
{
|
||||
Get_GrossWeight();
|
||||
HAL_Delay(100);
|
||||
Get_GrossWeight();
|
||||
//HAL_Delay(2000);
|
||||
Get_NetWeight();
|
||||
}
|
||||
|
||||
last_net_weight = net_weight;
|
||||
|
||||
//HAL_Delay(2000);
|
||||
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
uint8_t Flag_Error = 0;
|
||||
|
||||
//校准参数
|
||||
//因为不同的传感器特性曲线不是很一致,因此,每一个传感器需要矫正这里这个参数才能使测量值很准确。
|
||||
//当发现测试出来的重量偏大时,增加该数值。
|
||||
|
@ -87,8 +41,58 @@ uint8_t Flag_Error = 0;
|
|||
//#define GapValue 106.5 // for 20kg bar
|
||||
//#define GapValue 101.5 // for 20kg bar
|
||||
//#define GapValue 99.08 // for 20kg bar
|
||||
#define GapValue 384.0 // for 5kg bar
|
||||
//#define GapValue 384.0 // for 5kg bar
|
||||
//#define GapValue 430.0 // for 5kg 4 pcs sensor
|
||||
#define GapValue 276.2394 // for 5kg 4 pcs MINI sensor CLIP, 2024 DEC 01
|
||||
|
||||
void sts_weight_scale_init(void)
|
||||
{
|
||||
HX711_Init();
|
||||
Get_GrossWeight();
|
||||
}
|
||||
|
||||
void sts_weight_scale(void)
|
||||
{
|
||||
//PME_ON;
|
||||
//HAL_Delay(500);
|
||||
Get_NetWeight();
|
||||
sts_weight_scale_value_g = net_weight;
|
||||
|
||||
#if 0
|
||||
for (uint8_t cnt=0;cnt<20;cnt++)
|
||||
{
|
||||
Get_NetWeight();
|
||||
sum_tmp_net_weight += net_weight;
|
||||
}
|
||||
net_weight = (uint32_t)((float)sum_tmp_net_weight/20.0);
|
||||
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Net Weight = %d g \r\n", net_weight);
|
||||
|
||||
sts_weight_scale_value_g = net_weight;
|
||||
|
||||
// re-calibrate or Zero if changes > 100g
|
||||
if ((fabs(last_net_weight - net_weight) > 100) && (net_weight > 100))
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Zero ...Get Gross weight\r\n");
|
||||
Get_GrossWeight();
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Zero ...done Gross=%d \r\n",gross_weight);
|
||||
//HAL_Delay(2000);
|
||||
//Get_NetWeight();
|
||||
}
|
||||
#endif
|
||||
last_net_weight = net_weight;
|
||||
|
||||
//HAL_Delay(2000);
|
||||
|
||||
//PME_OFF;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
uint8_t Flag_Error = 0;
|
||||
|
||||
void HX711_Init(void)
|
||||
{
|
||||
|
@ -130,8 +134,15 @@ uint32_t HX711_Read(void) //增益128
|
|||
count=0;
|
||||
|
||||
//while(HX711_DOUT);
|
||||
while(HAL_GPIO_ReadPin(HX711_DOUT_PORT, HX711_DOUT_PIN)==GPIO_PIN_SET);
|
||||
|
||||
// while(HAL_GPIO_ReadPin(HX711_DOUT_PORT, HX711_DOUT_PIN)==GPIO_PIN_SET);
|
||||
#if 1
|
||||
uint16_t timer=0;
|
||||
do {
|
||||
if (HAL_GPIO_ReadPin(HX711_DOUT_PORT, HX711_DOUT_PIN)==GPIO_PIN_SET)
|
||||
delay_us(1);
|
||||
else break;
|
||||
}while (timer++<500000);
|
||||
#endif
|
||||
delay_us(1);
|
||||
|
||||
for(i=0;i<24;i++)
|
||||
|
@ -170,8 +181,8 @@ void Get_GrossWeight(void)
|
|||
{
|
||||
gross_weight = HX711_Read();
|
||||
|
||||
gross_weight = KalmanFilter(gross_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Gross Weight HX711_read =%d < \r\n",gross_weight);
|
||||
//gross_weight = KalmanFilter(gross_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Gross Weight =%d <<<<<< \r\n",gross_weight);
|
||||
|
||||
}
|
||||
|
||||
|
@ -181,8 +192,8 @@ void Get_GrossWeight(void)
|
|||
void Get_NetWeight(void)
|
||||
{
|
||||
HX711_Buffer = HX711_Read();
|
||||
|
||||
if(HX711_Buffer > gross_weight)
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ----- Get Netweight =%d while last gross weight=%d \r\n", HX711_Buffer, gross_weight);
|
||||
if(HX711_Buffer >= gross_weight)
|
||||
{
|
||||
net_weight = HX711_Buffer;
|
||||
net_weight = net_weight - gross_weight; //获取实物的AD采样数值。
|
||||
|
@ -191,9 +202,12 @@ void Get_NetWeight(void)
|
|||
//因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的GapValue这个除数。
|
||||
//当发现测试出来的重量偏大时,增加该数值。
|
||||
|
||||
net_weight = KalmanFilter(net_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Get Net Weight =%d \r\n", net_weight);//如果测试出来的重量偏小时,减小改数值。
|
||||
//net_weight = KalmanFilter(net_weight);
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ##### Get Net Weight =%d \r\n", (int)net_weight);//如果测试出来的重量偏小时,减小改数值。
|
||||
|
||||
} else {
|
||||
net_weight = 0;
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n ----- less than gross weight\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ extern "C" {
|
|||
* - CHANNEL_PLAN_GROUP_AS923_4 (Freq offset = -5.90 MHz / Freq range = 917-920MHz)
|
||||
* - CHANNEL_PLAN_GROUP_AS923_1_JP (Freq offset = 0.0 MHz / Freq range = 920.6-923.4MHz)
|
||||
*/
|
||||
#define REGION_AS923_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_GROUP_AS923_1_JP
|
||||
#define REGION_AS923_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_GROUP_AS923_1
|
||||
|
||||
/*!
|
||||
* @brief Limits the number usable channels by default for AU915, CN470 and US915 regions
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1048471218779752885" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1581009204476899933" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="1048471218779752885" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1581009204476899933" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||
</provider>
|
||||
|
|
Binary file not shown.
|
@ -21,6 +21,7 @@ RM := rm -rf
|
|||
-include Application/User/STS/TOF/vl53l1x_uld/subdir.mk
|
||||
-include Application/User/STS/TOF/Target/subdir.mk
|
||||
-include Application/User/STS/TOF/App/subdir.mk
|
||||
-include Application/User/STS/RSS/subdir.mk
|
||||
-include Application/User/STS/Core/Src/subdir.mk
|
||||
-include Application/User/LoRaWAN/Target/subdir.mk
|
||||
-include Application/User/LoRaWAN/App/subdir.mk
|
||||
|
|
|
@ -26,6 +26,7 @@ Application/User/Core \
|
|||
Application/User/LoRaWAN/App \
|
||||
Application/User/LoRaWAN/Target \
|
||||
Application/User/STS/Core/Src \
|
||||
Application/User/STS/RSS \
|
||||
Application/User/STS/TOF/App \
|
||||
Application/User/STS/TOF/Target \
|
||||
Application/User/STS/TOF/vl53l1x_uld \
|
||||
|
|
|
@ -570,11 +570,11 @@ void STS_YunhornSTSEventP8_Process(void)
|
|||
*/
|
||||
void STS_YunhornSTSEventP9_Process(void)
|
||||
{
|
||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n P9 Weight Scale Process\r\n");
|
||||
APP_LOG(TS_OFF, VLEVEL_M, "\r\n P9 Weight Scale Process\r\n");
|
||||
|
||||
#if defined(STS_R6)
|
||||
|
||||
sts_weight_scale_init();
|
||||
//sts_weight_scale_init();
|
||||
sts_weight_scale();
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue