// #include "project.h" #include "adc_tools.h" // #include "xp_project.h" #include "IQmathLib.h" #include "math.h" #include "my_filter.h" #include "params.h" // #include "params_protect.h" #include "vector.h" // #include "xp_adc.h" // #include "TuneUpPlane.h" //Ìîðãàíèå ñâåòîäèîäîì // #include "log_to_memory.h" // #include "errors.h" // #define COUNT_ARR_ADC_BUF 2 #define Shift_Filter 1 //2 #define BTR_ENABLED #define R_ADC_DEFAULT { 1180 ,1180 , 256, 256, 256, 256, 256, 1180, 1180, 256, 256, 256, 256, 256, 256, 256, 256, 256 } #define K_LEM_ADC_DEFAULT { 60000,60000,5000, 5000,5000,5000,5000,60000,60000,5000,5000,5000,5000,5000,5000,5000,5000,5000 } //#define LOG_ACP_TO_BUF int ADC_f[COUNT_ARR_ADC_BUF][16]; int ADC_sf[COUNT_ARR_ADC_BUF][16]; #define ZERO_ADC_DEFAULT {2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048, 2048} _iq19 iq19_zero_ADC[18] = ZERO_ADC_DEFAULT; int zero_ADC[18] = ZERO_ADC_DEFAULT; _iq iq_k_norm_ADC[18]; _iq19 iq19_k_norm_ADC[18]; _iq iq_norm_ADC[18]; unsigned int const R_ADC[18] = R_ADC_DEFAULT; unsigned int const K_LEM_ADC[18] = K_LEM_ADC_DEFAULT; //#pragma DATA_SECTION(analog,".fast_vars"); ANALOG_VALUE analog; //#pragma DATA_SECTION(filter,".fast_vars"); ANALOG_VALUE filter; ANALOG_RAW_DATA rawData = ANALOG_RAW_DATA_DEFAULT; _iq koef_Ud_long_filter=0; _iq koef_Ud_fast_filter=0; _iq koef_Im_filter=0; _iq koef_Iabc_filter=0; _iq koef_Wlong=0; void calc_norm_ADC(void); void analog_values_calc(void); _iq im_calc( _iq ia, _iq ib, _iq ic); void read_adc(ANALOG_RAW_DATA *data) { ADC_f[0][0] = data->U1_1; ADC_f[0][1] = data->U1_2; ADC_f[0][2] = data->Izpt1_1; ADC_f[0][3] = data->Izpt1_2; ADC_f[0][4] = data->Ia1; ADC_f[0][5] = data->Ib1; ADC_f[0][6] = data->Ic1; ADC_f[0][7] = 0; ADC_f[0][8] = data->U2_1; ADC_f[0][9] = data->U2_2; ADC_f[0][10] = data->Izpt2_1; ADC_f[0][11] = data->Izpt2_2; ADC_f[0][12] = data->Ia2; ADC_f[0][13] = data->Ib2; ADC_f[0][14] = data->Ic2; ADC_f[0][15] = 0; ADC_sf[0][0] += (ADC_f[0][0] - ADC_sf[0][0]) >> Shift_Filter; ADC_sf[0][1] += (ADC_f[0][1] - ADC_sf[0][1]) >> Shift_Filter; ADC_sf[0][2] += (ADC_f[0][2] - ADC_sf[0][2]) >> Shift_Filter; ADC_sf[0][3] += (ADC_f[0][3] - ADC_sf[0][3]) >> Shift_Filter; ADC_sf[0][4] += (ADC_f[0][4] - ADC_sf[0][4]) >> Shift_Filter; ADC_sf[0][5] += (ADC_f[0][5] - ADC_sf[0][5]) >> Shift_Filter; ADC_sf[0][6] += (ADC_f[0][6] - ADC_sf[0][6]) >> Shift_Filter; ADC_sf[0][7] += (ADC_f[0][7] - ADC_sf[0][7]) >> Shift_Filter; ADC_sf[0][8] += (ADC_f[0][8] - ADC_sf[0][8]) >> Shift_Filter; ADC_sf[0][9] += (ADC_f[0][9] - ADC_sf[0][9]) >> Shift_Filter; ADC_sf[0][10] += (ADC_f[0][10] - ADC_sf[0][10]) >> Shift_Filter; ADC_sf[0][11] += (ADC_f[0][11] - ADC_sf[0][11]) >> Shift_Filter; ADC_sf[0][12] += (ADC_f[0][12] - ADC_sf[0][12]) >> Shift_Filter; ADC_sf[0][13] += (ADC_f[0][13] - ADC_sf[0][13]) >> Shift_Filter; ADC_sf[0][14] += (ADC_f[0][14] - ADC_sf[0][14]) >> Shift_Filter; ADC_sf[0][15] += (ADC_f[0][15] - ADC_sf[0][15]) >> Shift_Filter; ADC_f[1][0] = 0; ADC_f[1][1] = 0; ADC_f[1][2] = 0; ADC_f[1][3] = 0; ADC_sf[1][0] += (ADC_f[1][0] - ADC_sf[1][0]) >> Shift_Filter; ADC_sf[1][1] += (ADC_f[1][1] - ADC_sf[1][1]) >> Shift_Filter; ADC_sf[1][2] += (ADC_f[1][2] - ADC_sf[1][2]) >> Shift_Filter; ADC_sf[1][3] += (ADC_f[1][3] - ADC_sf[1][3]) >> Shift_Filter; } void acp_Handler(void) { // read_adc(); calc_norm_ADC(); analog_values_calc(); // Read_Fast_Errors(); } #define COUNT_DETECT_ZERO 500 // void detect_zero_analog() // { // int i, k; // double tmp_buff[2][16] = {0}; // // _iq koef_zero_ADC_filter = 1; // for(i = 0; i < 16; tmp_buff[0][i++] = 0); // for(i = 0; i < 16; tmp_buff[1][i++] = 0); // i = 0; // for (i = 0; i err_level_adc_on_go ? 1 : 0; // mask |= filter.iqU_2_long > err_level_adc_on_go ? 1 << 1: 0; // } // else // { // mask |= filter.iqU_1_long > err_level_adc ? 1 : 0; // mask |= filter.iqU_2_long > err_level_adc ? 1 << 1: 0; // } // #ifdef NEW_I_ZPT_REZISTORS // mask |= ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 2: 0; // mask |= ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 3: 0; // #else // mask |= ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS? 1 << 2: 0; // mask |= ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS? 1 << 3: 0; // #endif // mask |= ADC_sf[0][4] < ERR_LEVEL_I_FAZA_PLUS? 1 << 4: 0; // mask |= ADC_sf[0][5] < ERR_LEVEL_I_FAZA_PLUS? 1 << 5: 0; // mask |= ADC_sf[0][6] < ERR_LEVEL_I_FAZA_PLUS? 1 << 6: 0; // if(f.Go) // { // mask |= filter.iqU_3_long > err_level_adc_on_go ? 1 << 8: 0; // mask |= filter.iqU_4_long > err_level_adc_on_go ? 1 << 9: 0; // } // else // { // mask |= (filter.iqU_3_long > err_level_adc) ? 1 << 8: 0; // mask |= (filter.iqU_4_long > err_level_adc) ? 1 << 9: 0; // } // #ifdef NEW_I_ZPT_REZISTORS // mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 10: 0; // mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS_REZ_249? 1 << 11: 0; // #else // mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS? 1 << 10: 0; // mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS? 1 << 11: 0; // #endif // mask |= ADC_sf[0][12] < ERR_LEVEL_I_FAZA_PLUS? 1 << 12: 0; // mask |= ADC_sf[0][13] < ERR_LEVEL_I_FAZA_PLUS? 1 << 13: 0; // mask |= ADC_sf[0][14] < ERR_LEVEL_I_FAZA_PLUS? 1 << 14: 0; // //Calculate values for BTR // #ifdef BTR_ENABLED // mask |= ADC_sf[1][0] < ERR_LEVEL_BREAK_REZ? 1 << 7: 0; //BTR1pos // mask |= ADC_sf[1][2] < ERR_LEVEL_BREAK_REZ? 1 << 15: 0; //BTR1neg // #endif //BTR_ENABLED // /* */ // result = mask & prev_mask; // prev_mask |= mask; // // // // if(mask == 0) { prev_mask = 0xFFFF;} // return result; // } // unsigned int detect_protect_ACP_minus() // { // unsigned int mask = 0, result = 0; // static unsigned int prev_mask = 0xFCFC; // // /* */ // if(f.Ready2) // { // // mask |= (ADC_sf[0] > ERR_LEVEL_ADC_MINUS_6) ? 1: 0; // // mask |= (ADC_sf[1] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 1: 0; // } // #ifdef NEW_I_ZPT_REZISTORS // mask |= (ADC_sf[0][2] > ERR_LEVEL_I_ZPT_MINUS_REZ_249)? 1 << 2: 0; // mask |= (ADC_sf[0][3] > ERR_LEVEL_I_ZPT_MINUS_REZ_249)? 1 << 3: 0; // #else // mask |= (ADC_sf[0][2] < ERR_LEVEL_I_ZPT_PLUS)? 1 << 2: 0; // mask |= (ADC_sf[0][3] < ERR_LEVEL_I_ZPT_PLUS)? 1 << 3: 0; // #endif // mask |= ADC_sf[0][4] > ERR_LEVEL_I_FAZA_MINUS? 1 << 4: 0; // mask |= ADC_sf[0][5] > ERR_LEVEL_I_FAZA_MINUS? 1 << 5: 0; // mask |= ADC_sf[0][6] > ERR_LEVEL_I_FAZA_MINUS? 1 << 6: 0; // /* */ // /* if(f.Ready2) // { // mask |= (ADC_sf[0][7] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 8: 0; // mask |= (ADC_sf[0][8] > ERR_LEVEL_ADC_MINUS_6) ? 1 << 9: 0; // } */ // #ifdef NEW_I_ZPT_REZISTORS // mask |= ADC_sf[0][10] > ERR_LEVEL_I_ZPT_MINUS_REZ_249? 1 << 10: 0; // mask |= ADC_sf[0][11] > ERR_LEVEL_I_ZPT_MINUS_REZ_249? 1 << 11: 0; // #else // mask |= ADC_sf[0][10] < ERR_LEVEL_I_ZPT_PLUS? 1 << 10: 0; // mask |= ADC_sf[0][11] < ERR_LEVEL_I_ZPT_PLUS? 1 << 11: 0; // #endif // mask |= ADC_sf[0][12] > ERR_LEVEL_I_FAZA_MINUS? 1 << 12: 0; // mask |= ADC_sf[0][13] > ERR_LEVEL_I_FAZA_MINUS? 1 << 13: 0; // mask |= ADC_sf[0][14] > ERR_LEVEL_I_FAZA_MINUS? 1 << 14: 0; // //Calculate values for BTR // #ifdef BTR_ENABLED // mask |= ADC_sf[1][1] < ERR_LEVEL_BREAK_REZ? 1 << 7: 0; //BTR2pos // mask |= ADC_sf[1][3] < ERR_LEVEL_BREAK_REZ? 1 << 15: 0; //BTR2neg // #endif //BTR_ENABLED // /* */ // result = mask & prev_mask; // prev_mask |= mask; // // // // if(mask == 0) { prev_mask = 0xFFFF;} // return result; // } // #pragma CODE_SECTION(fillADClogs,".fast_run"); // void fillADClogs(void) // { // logpar.log1 = (int16)_IQtoIQ15(analog.iqU_1); // logpar.log2 = (int16)_IQtoIQ15(analog.iqU_2); // logpar.log3 = (int16)_IQtoIQ15(analog.iqIin_1); // logpar.log4 = (int16)_IQtoIQ15(analog.iqIin_2); // logpar.log5 = (int16)_IQtoIQ15(analog.iqIa1_1); // logpar.log6 = (int16)_IQtoIQ15(analog.iqIb1_1); // logpar.log7 = (int16)_IQtoIQ15(analog.iqIc1_1); // logpar.log8 = (int16)_IQtoIQ15(analog.iqU_3); // logpar.log9 = (int16)_IQtoIQ15(analog.iqU_4); // logpar.log10 = (int16)_IQtoIQ15(analog.iqIin_3); // logpar.log11 = (int16)_IQtoIQ15(analog.iqIin_4); // logpar.log12 = (int16)_IQtoIQ15(analog.iqIa2_1); // logpar.log13 = (int16)_IQtoIQ15(analog.iqIb2_1); // logpar.log14 = (int16)_IQtoIQ15(analog.iqIc2_1); // // logpar.log15 = (int16)_IQtoIQ15(filter.iqU_1_fast); // // logpar.log16 = (int16)_IQtoIQ15(filter.iqU_1_long); // } /********************************************************************/ /* Расчет модулy тока из показаний трех фаз */ /********************************************************************/ _iq SQRT_32 = _IQ(0.8660254037844); _iq CONST_23 = _IQ(2.0/3.0); _iq CONST_15 = _IQ(1.5); _iq im_calc( _iq ia, _iq ib, _iq ic) { _iq isa,isb, t; isa = _IQmpy(CONST_15,ia); isb = _IQmpy(SQRT_32,ib-ic ); // ( _IQ19mpy(SQRT_32, _IQ15toIQ19(ib)) - _IQ15mpy(SQRT_32, _IQ15toIQ19(ic)) ); // t = _IQmag(isa,isb); t = _IQsqrt(_IQmpy(isa, isa) + _IQmpy(isb, isb)); t = _IQmpy(CONST_23,t); return (t); }