matlab_23550/Inu/Src/main_matlab/adc_tools.h
2024-12-27 10:50:32 +03:00

446 lines
13 KiB
C

#ifndef _ADC_TOOLS
#define _ADC_TOOLS
#include "IQmathLib.h"
#include "xp_project.h"
#define COUNT_DETECT_ZERO 3000
#define COUNT_ARR_ADC_BUF_FAST_POINT 10
#define NORMA_ACP 3000.0
#define NORMA_ACP_RMS 2127.66
#define NORMA_ACP_TEMPER_MILL_AMP 100.0 //
#ifndef PROJECT_SHIP
#error Íå óñòàíîâëåí PROJECT_SHIP â predifine Name
#else
#if (PROJECT_SHIP == 1)
#define NORMA_ACP_TEMPER 100.0 // äëÿ 23550.1
#endif
#if (PROJECT_SHIP == 2)
#define NORMA_ACP_TEMPER 200.0 // äëÿ 23550.3
#endif
#if (PROJECT_SHIP== 3)
#define NORMA_ACP_TEMPER 200.0 // äëÿ 23550.3
#endif
#endif
#define DELTA_ACP_TEMPER 0.0 // äàò÷èêè áëîêè pt100 äàåþò ïîñòîÿííîå ñìåùåíèå 0.0 ãðàäóñîâ, òàê íàñòðîåí áëîê SG3013
#define NORMA_ACP_P 100.0
#define ADC_READ_FROM_PARALLEL_BUS 1
#define DEFAULT_ZERO_ADC 2048
#ifndef USE_INTERNAL_ADC
#define USE_INTERNAL_ADC 0
#endif
#if (USE_INTERNAL_ADC==1)
#define COUNT_ARR_ADC_BUF (C_adc_number+1)
#else
#define COUNT_ARR_ADC_BUF C_adc_number
#endif
#define COUNT_ARR_ADC_BUF_EXTERNAL C_adc_number
// 23550.3
#if(C_adc_number>=1)
#define R_ADC_DEFAULT_0 { 271, 271, 876, 876, 876, 876, 876, 876, 249, 249, 301, 301, 301, 301, 301, 301 }
#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 }
#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP }
#endif
#if(C_adc_number>=2)
#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 }
#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 }
#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_TEMPER_MILL_AMP, NORMA_ACP_P, NORMA_ACP }
#endif
#if(C_adc_number>=3)
#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 }
#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 }
#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP }
#endif
// 23550.1
//#if(C_adc_number>=1)
//#define R_ADC_DEFAULT_0 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 312, 312, 312, 312, 309, 309 }
//#define K_LEM_ADC_DEFAULT_0 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 8400, 8400, 8400, 8400, 5000, 5000 }
//#define NORMA_ADC_DEFAULT_0 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP }
//#endif
//
//#if(C_adc_number>=2)
//#define R_ADC_DEFAULT_1 { 1, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190, 6190 }
//#define K_LEM_ADC_DEFAULT_1 { 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1 }
//#define NORMA_ADC_DEFAULT_1 { NORMA_ACP, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_TEMPER, NORMA_ACP_P, NORMA_ACP }
//#endif
//
//#if(C_adc_number>=3)
//#define R_ADC_DEFAULT_2 { 271, 271, 887, 887, 887, 887, 887, 887, 250, 250, 3125, 3125, 3125, 3125, 309, 309 }
//#define K_LEM_ADC_DEFAULT_2 { 7200, 7200, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 5000, 60000, 60000, 60000, 60000, 5000, 5000 }
//#define NORMA_ADC_DEFAULT_2 { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP }
//#endif
#if (USE_INTERNAL_ADC==1)
#define R_ADC_DEFAULT_INTERNAL { 100,100,100,100,100,100,100,100,1248,1248,1248,100,100,100,100,100 }
#define K_LEM_ADC_DEFAULT_INTERNAL { 30,30,30,30,10,10,10,10,621,621,621,100,10,10,10,10 }
#define NORMA_ADC_DEFAULT_INTERNAL { NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP, NORMA_ACP }
#endif
/*
//awa3
//14 êàíàë out1
0 - 11 êðèâûå äàò÷èêè
//15 êàíàë out2
0 - 11 êðèâûå äàò÷èêè
//8 êàíàë
0 - 20 ìÀ | 0 ãðàä - 200 ãðàä / ëèíåéíûé
0V - 1.5V / 0 ãðàä - 200 ãðàä / ëèíåéíûé
//9 êàíàë
0 - 20 ìÀ | 0 ãðàä - 200 ãðàä / ëèíåéíûé
0V - 1.5V / 0 ãðàä - 200 ãðàä / ëèíåéíûé
//10 êàíàë
0 - 20 ìÀ | 0 ãðàä - 200 ãðàä / ëèíåéíûé
0V - 1.5V / 0 ãðàä - 200 ãðàä / ëèíåéíûé
//11 êàíàë
0 - 20 ìÀ | 0 ãðàä - 200 ãðàä / ëèíåéíûé
0V - 1.5V / 0 ãðàä - 200 ãðàä / ëèíåéíûé
//12 êàíàë
4 - 20 ìÀ | 0 áàð - 10 áàð / ëèíåéíûé
0.3V - 1.5V / 0 áàð - 10 áàð / ëèíåéíûé
//13 êàíàë
4 - 20 ìÀ | 0 áàð - 10 áàð / ëèíåéíûé
0.3V - 1.5V / 0 áàð - 10 áàð / ëèíåéíûé
*/
typedef union
{
struct
{
unsigned int c0_plus : 1; /* 0 äàò÷èê+ */
unsigned int c1_plus : 1; /* 0 äàò÷èê+ */
unsigned int c2_plus : 1; /* 0 äàò÷èê+ */
unsigned int c3_plus : 1; /* 0 äàò÷èê+ */
unsigned int c4_plus : 1; /* 0 äàò÷èê+ */
unsigned int c5_plus : 1; /* 0 äàò÷èê+ */
unsigned int c6_plus : 1; /* 0 äàò÷èê+ */
unsigned int c7_plus : 1; /* 0 äàò÷èê+ */
unsigned int c8_plus : 1; /* 0 äàò÷èê+ */
unsigned int c9_plus : 1; /* 0 äàò÷èê+ */
unsigned int c10_plus : 1; /* 0 äàò÷èê+ */
unsigned int c11_plus : 1; /* 0 äàò÷èê+ */
unsigned int c12_plus : 1; /* 0 äàò÷èê+ */
unsigned int c13_plus : 1; /* 0 äàò÷èê+ */
unsigned int c14_plus : 1; /* 0 äàò÷èê+ */
unsigned int c15_plus : 1; /* 0 äàò÷èê+ */
} bit; /* Îøèáêè ïîáèòíî */
unsigned long all; /* Îøèáêè âìåñòå */
} ERR_ADC_PLUS_PROTECT;
typedef union
{
struct
{
unsigned int c0_minus : 1; /* 0 äàò÷èê- */
unsigned int c1_minus : 1; /* 0 äàò÷èê- */
unsigned int c2_minus : 1; /* 0 äàò÷èê- */
unsigned int c3_minus : 1; /* 0 äàò÷èê- */
unsigned int c4_minus : 1; /* 0 äàò÷èê- */
unsigned int c5_minus : 1; /* 0 äàò÷èê- */
unsigned int c6_minus : 1; /* 0 äàò÷èê- */
unsigned int c7_minus : 1; /* 0 äàò÷èê- */
unsigned int c8_minus : 1; /* 0 äàò÷èê- */
unsigned int c9_minus : 1; /* 0 äàò÷èê- */
unsigned int c10_minus : 1; /* 0 äàò÷èê- */
unsigned int c11_minus : 1; /* 0 äàò÷èê- */
unsigned int c12_minus : 1; /* 0 äàò÷èê- */
unsigned int c13_minus : 1; /* 0 äàò÷èê- */
unsigned int c14_minus : 1; /* 0 äàò÷èê- */
unsigned int c15_minus : 1; /* 0 äàò÷èê- */
} bit; /* Îøèáêè ïîáèòíî */
unsigned int all; /* Îøèáêè âìåñòå */
} ERR_ADC_MINUS_PROTECT;
typedef struct
{
ERR_ADC_PLUS_PROTECT plus;
ERR_ADC_MINUS_PROTECT minus;
} ERR_ADC_PROTECT;
/* Ãëîáàëüíày ñòðóêòóðà çíà÷åíèé òîêîâ è íàïðyæåíèé ÀÈÍ */
typedef struct
{
_iq iqU_1;
_iq iqU_2;
_iq iqU_1_fast;
_iq iqU_2_fast;
_iq iqU_1_long;
_iq iqU_2_long;
_iq iqIu_1;
_iq iqIv_1;
_iq iqIw_1;
_iq iqIu_2;
_iq iqIv_2;
_iq iqIw_2;
_iq iqIu_1_rms;
_iq iqIv_1_rms;
_iq iqIw_1_rms;
_iq iqIu_2_rms;
_iq iqIv_2_rms;
_iq iqIw_2_rms;
_iq iqIu;
_iq iqIv;
_iq iqIw;
_iq iqIin_1;
_iq iqIin_2;
_iq iqUin_A1B1;
_iq iqUin_B1C1;
_iq iqUin_C1A1;
_iq iqUin_A2B2;
_iq iqUin_B2C2;
_iq iqUin_C2A2;
_iq iqUin_A1B1_rms;
_iq iqUin_B1C1_rms;
_iq iqUin_C1A1_rms;
_iq iqUin_A2B2_rms;
_iq iqUin_B2C2_rms;
_iq iqUin_C2A2_rms;
_iq iqUin_m1;
_iq iqUin_m2;
_iq iqIbreak_1;
_iq iqIbreak_2;
_iq T_U01;
_iq T_U02;
_iq T_U03;
_iq T_U04;
_iq T_U05;
_iq T_U06;
_iq T_U07;
_iq T_Water_external;
_iq T_Water_internal;
_iq T_Air_01;
_iq T_Air_02;
_iq T_Air_03;
_iq T_Air_04;
_iq P_Water_internal;
_iq iqI_vozbud;
_iq iqIin_sum;
_iq iqIm_1;
_iq iqIm_2;
_iq iqIm;
_iq iqM;
_iq PowerScalar;
_iq PowerScalarFilter2;
_iq PowerFOC;
_iq iqU_1_imit;
/*
_iq iqUzpt_1_2; //uzpt1 bs2
_iq iqUzpt_2_2; //uzpt2 bs2
_iq iqUzpt_1_2_fast; //uzpt1 bs2
_iq iqUzpt_2_2_fast; //uzpt2 bs2
_iq iqUzpt_1_2_long; //uzpt1 bs2
_iq iqUzpt_2_2_long; //uzpt2 bs2
_iq iqIin_1_1; //Iin AF1 BS1
_iq iqIin_2_1; //Iin AF2 BS1
_iq iqIin_3_1; //Iin AF3 BS1
_iq iqIin_4_1; //Iin AF4 BS1
_iq iqIin_5_1; //Iin AF5 BS1
_iq iqIin_6_1; //Iin AF6 BS1
_iq iqIin_1_2; //Iin AF1 BS2
_iq iqIin_2_2; //Iin AF2 BS2
_iq iqIin_3_2; //Iin AF3 BS2
_iq iqIin_4_2; //Iin AF4 BS2
_iq iqIin_5_2; //Iin AF5 BS2
_iq iqIin_6_2; //Iin AF6 BS2
_iq iqUin_AB; //Âõîäíîå ëèíåéíîå íàïðßæåíèå AB
_iq iqUin_BC; //Âõîäíîå ëèíåéíîå íàïðßæåíèå BC
_iq iqUin_CA; //Âõîäíîå ëèíåéíîå íàïðßæåíèå CA
_iq iqUin_AB_sf; //Âõîäíîå ëèíåéíîå íàïðßæåíèå AB
_iq iqUin_BC_sf; //Âõîäíîå ëèíåéíîå íàïðßæåíèå BC
_iq iqUin_CA_sf; //Âõîäíîå ëèíåéíîå íàïðßæåíèå CA
_iq iqT_WATER_in; // Òåìïåðàòóðà âîäû íà âõîäå Ï×
_iq iqT_WATER_out; // Òåìïåðàòóðà âîäû íà âûõîäå Ï×
_iq iqT_AIR_in_up; // Òåìïåðàòóðà âîçäóõà íà âõîäå Ï× (âåðõ)
_iq iqT_AIR_in_down;// Òåìïåðàòóðà âîçäóõà íà âõîäå Ï× (íèç)
_iq iqP_WATER_in; // Äàâëåíèå âîäû íà âõîäå Ï×
_iq iqP_WATER_out; // Äàâëåíèå âîäû íà âûõîäå Ï×
_iq iqT_BK1_BK12; // Òåêóùåå ïîêàçàíèå îäíîãî èç äàò÷èêîâ BK1_BK12
_iq iqT_BK13_BK24; // Òåêóùåå ïîêàçàíèå îäíîãî èç äàò÷èêîâ BK13_BK24
_iq iqUin_m1; //Àìïëèòóäà Âõîäíîå ëèíåéíîå íàïðßæåíèå
_iq iqIu_1_1; //Iu AF1 BS1
_iq iqIu_1_2; //Iu AF2 BS1
_iq iqIv_1_1; //Iv AF3 BS1
_iq iqIv_1_2; //Iv AF4 BS1
_iq iqIw_1_1; //Iw AF5 BS1
_iq iqIw_1_2; //Iw AF6 BS1
_iq iqIu_2_1; //Iu AF1 BS2
_iq iqIu_2_2; //Iu AF2 BS2
_iq iqIv_2_1; //Iv AF3 BS2
_iq iqIv_2_2; //Iv AF4 BS2
_iq iqIw_2_1; //Iw AF5 BS2
_iq iqIw_2_2; //Iw AF6 BS2
_iq iqIm_1;
_iq iqIm_2;
_iq iqWexp;
_iq iqWout;
_iq iqM;
*/
} ANALOG_VALUE;
typedef struct {
float U1_1;
float U1_2;
float Izpt1_1;
float Izpt1_2;
float Ia1;
float Ib1;
float Ic1;
float U2_1;
float U2_2;
float Izpt2_1;
float Izpt2_2;
float Ia2;
float Ib2;
float Ic2;
void (*read_adc)();
} ANALOG_RAW_DATA;
#define ANALOG_VALUE_DEFAULT {0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0, 0}
/* Ãëîáàëüíày ñòðóêòóðà çíà÷åíèé òîêîâ è íàïðyæåíèé ÀÈÍ */
#define ERR_LEVEL_ADC_PLUS 3950 //+1270A //2950 // +650A //3467 // 3367 //3367 //3267 // 0xfff-0x29c
#define ERR_LEVEL_ADC_MINUS 150 //-1270A //1150 //-650A // 267 //367
#define ERR_LEVEL_ADC_PLUS_6 3800 //3783 //3623~1150 // 3462 ~ 1050 A // 3320 ~ 960A //3680 //3267 // 0xfff-0x29c
#define ERR_LEVEL_ADC_MINUS_6 1000 //267 //367
#define MIN_DETECT_UD_ZERO 2300
#define level_err_ADC_PLUS_default {ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\
ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\
ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,\
ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS,ERR_LEVEL_ADC_PLUS}
#define level_err_ADC_MINUS_default {ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\
ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\
ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,\
ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS,ERR_LEVEL_ADC_MINUS}
extern ANALOG_VALUE analog;
extern ANALOG_VALUE filter;
extern ANALOG_VALUE analog_zero;
extern ANALOG_RAW_DATA rawData;
extern _iq iq_norm_ADC[COUNT_ARR_ADC_BUF][16];
//void calc_norm_ADC(int fast);
void calc_norm_ADC_0(int run_norma);
void calc_norm_ADC_1(int run_norma);
void Init_Adc_Variables(void);
void norma_adc_nc(int nc);
void init_Adc_Variables(void);
void detect_zero_analog(int nc);
extern int ADC_f[COUNT_ARR_ADC_BUF][16];
extern int zero_ADC[COUNT_ARR_ADC_BUF][16];
extern ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF], mask_err_adc_protect[COUNT_ARR_ADC_BUF];
extern unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16];
extern unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16];
extern float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16];
//void norma_all_adc(void);
void detect_zero_analog(int nc);
#if (USE_INTERNAL_ADC==1)
void Init_Internal_Adc(void);
#endif
#endif // end _ADC_TOOLS