From 9ec74ad0fb18bfb584b7199cbd1c6df7d05edd55 Mon Sep 17 00:00:00 2001 From: nelolik Date: Mon, 15 Feb 2021 15:01:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D1=87=D1=91=D1=82=20=D0=B8=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D1=83=20=D0=BF=D0=BE=2026=20?= =?UTF-8?q?=D0=B8=2027=20=D0=B0=D0=B4=D1=80=D0=B5=D1=81=D0=B0=D0=BC=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BF=D1=80=D0=BE=D1=82=D0=B8=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=BE=D0=BB=D1=8F=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D0=9C=D0=BE=20=D1=8510.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/ice.bin | Bin 31284 -> 32724 bytes isolatio.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++++++++ isolatio.h | 26 ++++++ main.c | 2 + 4 files changed, 291 insertions(+) diff --git a/bin/ice.bin b/bin/ice.bin index 2ae21aa418bbc18852f25ca9adf2190a11c1746a..088acb6384d42274eb70fe4bf47789f205f40da6 100644 GIT binary patch delta 4493 zcmbtXe^AuN72nH8hK?*UleePG6|`L-a67B~nC`4$&^+%CEV| zj0lC*trM+n6D>K~Qq`wdlW3 z^7gV2;fa>~F?Ryp)6k;t3TfG2fKdxG{}Loyft9N8PSNMjL=)9lwZ_K*=wR*gU; zSv*DCG|tSeL8H6?rMIWc)v8hU2uXg)Rw&xq`%z&J)y1Tdw@(IV#S9bj=N_t!J50{@ z&|`7AAc7ypwPVuJ6WpzpFahVc63!DeL>m*g62J~8=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pv6PQ;v@Cu;TBIwI_f$;& zX?m(P9v0CIn`ij6zM5LicH6-W2=-EbPM?S=;x9GF6)2^rX^>1 zKk~o}z=#&$#Hu}K%UTOXRwohCsDZUidi19IpokX#xlx$KBsDYrCrc!6c>K@Qj6*!n zXropl`B3qpRcoA=-UE4ZgytEt{a}*XJfrPMmflgx+mapEtc1?*QIj(VV_KVMik5rB z8tj4d;7iV32#RRsG|Rhp>H^Ige1f~-j+LLfLcp1dpm4fj23Q(quDA;zH1*0n=HiOm z3AFbM^{mUEd?Hz$HOw&Wm6aXzfd=FUhZ4g&+{y2`&$41HLz*c4s05n1cKwV0=*bitcS0eAZ%aa zf!I*D3(>wOL-l{B=P6!nXopI-!xl&9$e`%wC$ZZ>;u}l&^Yl%zJLrWFM@Aa^4kXZ< zris&9z!ym}mcTPQMZRNFcO+_b=Is;BwLvw!_PPcsf^pVV>h+q0+p4^`zb7n!`D=d!xjx=dy89Hpvq n1U%%JIK|8w&g;9FPI{Mt-c@vD=wj{|mT6mt+2Y|}ok0HuJCdt{ diff --git a/isolatio.c b/isolatio.c index ae46038..8305c00 100644 --- a/isolatio.c +++ b/isolatio.c @@ -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; + } +} +*/ + + + diff --git a/isolatio.h b/isolatio.h index 1b2e1ad..2d63e29 100644 --- a/isolatio.h +++ b/isolatio.h @@ -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 // Гц + diff --git a/main.c b/main.c index d574b57..228fa6d 100644 --- a/main.c +++ b/main.c @@ -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;