#include "stdio.h"
#define U_over_value 230
#define U_under_value 210
typedef enum
{
u_Normal = 0, // 正常
u_Over = 1, // 过压
u_Under = 3, // 欠压
}u_state;
typedef struct
{
u_state V_limit_state[3]; // 电压状态
}z_state;
z_state UA_state;
int Ux[3];
int main(void)
{
while(1)
{
for(uint8_t i; i <3; i++)
{
Ux[i] = 200;
}
for(uint8_t i=0; i <3; i++)
{
UA_state.V_limit_state[i] = Get_V_state(Ux[i],i);
}
}
}
static u_state Get_V_state(uint16_t data, uint8_t phase)
{
static uint8_t cnt_OK[3] = {0};
static uint8_t cnt_Error[3] = {0};
if((data > U_over_value ) || (data < U_under_value )) // 采集到的电压数据已放大100倍
{
cnt_Error[phase]++;
cnt_OK[phase] = 0;
}
else
{
cnt_OK[phase]++;
cnt_Error[phase] = 0;
}
if(cnt_Error[phase] > 3) //滤波:三次
{
cnt_Error[phase] = 0;
if(data >= U_over_value)
return u_Over;
else
return u_Under;
}
else if(cnt_OK[phase] > 3)
{
return u_Normal;
}
else
{
return UA_state.V_limit_state[phase];
}
}
三相电压,三次过压,才算过压,电压状态判断
最新推荐文章于 2024-09-14 19:49:31 发布
这篇文章展示了如何使用C语言定义枚举、结构体以及函数来监控和处理电压状态。程序中定义了电压正常、过压和欠压状态,并通过Get_V_state函数实时检查输入的电压值并进行错误计数和滤波。
摘要由CSDN通过智能技术生成