Добавил расчёт и отправку по 26 и 27 адресам сопротивления изоляции в Мо х10.

This commit is contained in:
nelolik 2021-02-15 15:01:02 +03:00
parent b8a0477c5c
commit 9ec74ad0fb
4 changed files with 291 additions and 0 deletions

Binary file not shown.

View File

@ -13,6 +13,12 @@
OPTOCANAL opt[2];
ISOLATION isolation1 = ISOLATION_DEFAULT;
ISOLATION isolation2 = ISOLATION_DEFAULT;
static void calibrateIsolation();
void init_isolation_struct(void);
void DCLK(int i, int x)
{
x=!x;
@ -66,6 +72,9 @@ interrupt void cpu_timer1_isr_ISOL(void)
else set_READY();
}
isolation1.pause_counter += 1;
isolation2.pause_counter += 1;
for(i=0;i<2;i++)
{
if(sens_error[i].bit.Bypas)
@ -110,6 +119,11 @@ interrupt void cpu_timer1_isr_ISOL(void)
Modbus[i*2+0x10].all = (int)(numb & 0xFFFF);
Modbus[i*2+0x11].all = (int)(numb>>16);
if (i == 0) {
isolation1.adc_value = numb;
} else {
isolation2.adc_value = numb;
}
Riso=numb;
Riso = Riso/256; // ïðåäïîëîæèì
Modbus[i+DATASTART].all = Riso;
@ -145,4 +159,253 @@ void timer_Init()
period_ready = TELE_FREQ / (READY_FREQ * 2);
init_isolation_struct();
}
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
#define COEFF_ACP_TO_MOMx10_NEW 1033584219L
#define COEFF_ACP_TO_MOMx10_OLD 1644429312L
//#define COEFF_ACP_TO_MOMx10 1604321280L //Ïîëó÷àåòñè èç ðàçðéàäíîñòè ÀÖÏ, êîýôô. óñèëåí., èçìåðèòåëüíîãî ñîïðîòèâëåíèþ
#define COEFF_ACP_TO_MOMx10_1 COEFF_ACP_TO_MOMx10_NEW //ÀÖÏ 24-áèòíûé, 15 çíà÷àùèé ðàçðéàäîâ
//R = 5100 Om
#define COEFF_ACP_TO_MOMx10_2 COEFF_ACP_TO_MOMx10_NEW //COEFF_ACP_TO_MOMx10_OLD //; 32 - 1668494131L
int calibration1 = 0; //Ï× 31 - 0; 32 - (-2); 21 - 1
int calibration2 = 0; //Ï× 31 - 3; 32 - (-4); //21 - 1
void init_isolation_struct(void)
{
int* pint = (int*)&isolation1;
int i = 0;
int size = sizeof(isolation1)/sizeof(int);
for(i = 0; i < size; i++)
{
*(pint + i) = 0;
}
pint = (int*)&isolation2;
size = sizeof(isolation2)/sizeof(int);
for(i = 0; i < size; i++)
{
*(pint + i) = 0;
}
isolation1.f_not_ready = 1;
isolation2.f_not_ready = 1;
isolation1.pause_time = 12400;
isolation2.pause_time = 12400;
}
#define iso_time_pause 6200
void isolation_calc(void)
{
volatile unsigned long int acp_val1_l, acp_val2_l;
long int tmp_delta;
int acp_val1, acp_val2, k, l, m;
int buff[IS_BUFF_SIZE];
// calibrateIsolation();
if(isolation1.pause_counter > isolation1.pause_time) //Ïîñêîëüêó âñ¸ ìåäëåííî, ñîõðàíÿþ çíà÷åíèÿ ðàç 3 ñåêóíäû
{ //÷òîáû íåìüøå îòñ÷¸òîâ ïîïàäàëî, íàâûáðîñû
isolation1.pause_counter = 0;
acp_val1_l = isolation1.adc_value;
acp_val1 = (int)(acp_val1_l >> 10); //Óìåíüøàþ ðàçìåð, äàáû íå èìåòü äåëî ñ long
if(acp_val1)
{
isolation1.buff[isolation1.buff_position++] = acp_val1;
}
else
{
if (isolation1.buff_position > 0) {
isolation1.buff[isolation1.buff_position] = isolation1.buff[isolation1.buff_position - 1];
} else {
isolation1.buff[isolation1.buff_position] = isolation1.buff[IS_BUFF_SIZE - 1];
}
++isolation1.buff_position;
}
if(isolation1.buff_position >= IS_BUFF_SIZE)
{
isolation1.buff_position -= IS_BUFF_SIZE;
isolation1.f_not_ready = 0;
// if (isolation1.max_val || isolation1.min_val) {
// }
}
for (k = 0; k < IS_BUFF_SIZE; k++) {
buff[k] = 0x8000; //minimal int
}
k = 0;
l = 0;
while (k < IS_BUFF_SIZE) {
l = 0;
while ((l < IS_BUFF_SIZE) && (isolation1.buff[k] < buff[l])) {
l++;
}
if (l < IS_BUFF_SIZE) {
for (m = IS_BUFF_SIZE - 1; (m > l) && (m > 0); m--) {
buff[m] = buff[m - 1];
}
}
buff[l] = isolation1.buff[k];
k++;
}
isolation1.max_val = buff[5];
isolation1.min_val = buff[IS_BUFF_SIZE - 5];
k = 0;
// while(k < IS_BUFF_SIZE)
// {
// if((isolation1.buff[(k + 1) % IS_BUFF_SIZE] - isolation1.buff[k]) > 1500)
// {
// isolation1.max_val = isolation1.buff[(k + 7) % IS_BUFF_SIZE];
// isolation1.min_val = isolation1.buff[(k) % IS_BUFF_SIZE];
// break;
// }
// k++;
// }
tmp_delta = isolation1.max_val - isolation1.min_val;
if(!isolation1.f_not_ready)
{
isolation1.row_MOms = tmp_delta ? COEFF_ACP_TO_MOMx10_1 / (tmp_delta << 10) - 200 + calibration1
: isolation1.row_MOms;
if (isolation1.row_MOms > isolation1.MOms_x_10) {
isolation1.MOms_x_10 += 2; //isolation1.row_MOms;
}
else if (isolation1.row_MOms < isolation1.MOms_x_10) {isolation1.MOms_x_10 -= 1;}
} else {
isolation1.MOms_x_10 = tmp_delta ? COEFF_ACP_TO_MOMx10_1 / (tmp_delta << 10) - 200 + calibration1
: isolation1.MOms_x_10;
}
if (isolation1.MOms_x_10 > 50) { isolation1.MOms_x_10 = 50;}
if (isolation1.MOms_x_10 < 0) { isolation1.MOms_x_10 = 0;}
if (isolation1.f_not_ready == 0) {
Modbus[26].all = isolation1.MOms_x_10;
}
}
//Âòîé êàíàë
if(isolation2.pause_counter > isolation2.pause_time)
{
isolation2.pause_counter = 0;
acp_val2_l = isolation2.adc_value;
acp_val2 = (int)(acp_val2_l >> 10);
if(acp_val2)
{
isolation2.buff[isolation2.buff_position++] = acp_val2;
}
else
{
if (isolation2.buff_position > 0) {
isolation2.buff[isolation2.buff_position] = isolation2.buff[isolation2.buff_position - 1];
} else {
isolation2.buff[isolation2.buff_position] = isolation2.buff[IS_BUFF_SIZE - 1];
}
++isolation2.buff_position;
}
if(isolation2.buff_position >= IS_BUFF_SIZE)
{
isolation2.buff_position -= IS_BUFF_SIZE;
isolation2.f_not_ready = 0;
// if (isolation2.max_val || isolation2.min_val) {
// }
}
for (k = 0; k < IS_BUFF_SIZE; k++) {
buff[k] = 0x8000;
}
k = 0;
l = 0;
while (k < IS_BUFF_SIZE) {
l = 0;
while ((l < IS_BUFF_SIZE) && (isolation2.buff[k] < buff[l])) {
l++;
}
if (l < IS_BUFF_SIZE) {
for (m = IS_BUFF_SIZE - 1; (m > l) && (m > 0); m--) {
buff[m] = buff[m - 1];
}
}
buff[l] = isolation2.buff[k];
k++;
}
isolation2.max_val = buff[5];
isolation2.min_val = buff[IS_BUFF_SIZE - 5];
//
// k = 0;
// while(k < IS_BUFF_SIZE)
// {
// if((isolation2.buff[(k + 1) % IS_BUFF_SIZE] - isolation2.buff[k]) > 1500)
// {
// isolation2.max_val = isolation2.buff[(k + 7) % IS_BUFF_SIZE];
// break;
// }
// k++;
// }
// k = 0;
// while(k < IS_BUFF_SIZE)
// {
// if((isolation2.buff[(k + 1) % IS_BUFF_SIZE] - isolation2.buff[k]) < -1500)
// {
// isolation2.min_val = isolation2.buff[(k + 7) % IS_BUFF_SIZE];
// break;
// }
// k++;
// }
tmp_delta = isolation2.max_val - isolation2.min_val;
if(!isolation2.f_not_ready) {
isolation2.row_MOms = tmp_delta ? (COEFF_ACP_TO_MOMx10_2) / (tmp_delta << 10) - 200 + calibration2 //1668494131L
: isolation2.row_MOms;
if (isolation2.row_MOms > isolation2.MOms_x_10 ) {
isolation2.MOms_x_10 += 2; // isolation2.row_MOms;
}
else if (isolation2.row_MOms < isolation2.MOms_x_10 ) {isolation2.MOms_x_10 -= 1; }
} else {
isolation2.MOms_x_10 = tmp_delta ? (COEFF_ACP_TO_MOMx10_2) / (tmp_delta << 10) - 200 + calibration2
: isolation2.MOms_x_10;
}
if (isolation2.MOms_x_10 > 50) { isolation2.MOms_x_10 = 50;}
if (isolation2.MOms_x_10 < 0) { isolation2.MOms_x_10 = 0;}
if (isolation2.f_not_ready == 0) {
Modbus[27].all = isolation2.MOms_x_10;
}
}
}
/*
void calibrateIsolation() {
switch (modbus_table_in[280].all) {
case 12:
calibration1 = 0;
calibration2 = 0;
break;
case 21:
calibration1 = -4;
calibration2 = -1;
break;
case 22:
calibration1 = -5;
calibration2 = -5;
break;
case 31:
calibration1 = -5;
calibration2 = -1;
break;
case 32:
calibration1 = 0;
calibration2 = -2;
break;
}
}
*/

View File

@ -10,4 +10,30 @@ typedef struct
unsigned long Numb;
} OPTOCANAL;
#define IS_BUFF_SIZE 16
typedef struct {
int buff[IS_BUFF_SIZE];
int min_val;
int max_val;
unsigned int buff_position;
int MOms_x_10;
int row_MOms;
unsigned int sample_time;
unsigned int f_not_ready;
unsigned int pause_counter;
unsigned int pause_time;
unsigned long adc_value;
}ISOLATION;
extern ISOLATION isolation1;
extern ISOLATION isolation2;
#define ISOLATION_DEFAULT {{0,0,0,0,0,0,0,0}, 0, 0, 0, 0, 0, 0, 0, 0}
void isolation_calc(void);
#define TELE_FREQ 2000 // Ãö

2
main.c
View File

@ -150,6 +150,8 @@ void main()
Modbus[23].all = Inputs.wrd.word_0;
}
isolation_calc();
for(i=0;i<2;i++)
{
if(i) rs = &rs_a;