/* * amplif.c * * Created on: Oct 25, 2017 * Author: toporov */ #include "my.h" #include "main.h" #include "tim.h" #include "adc.h" #include "math.h" #define __ADCMAX 18500UL #define __UMAX 0.790f extern char RouteName[40]; extern __IO uint32_t RouteIndex, MaxRouteIndex; extern __IO uint8_t CALC_FREQ; extern __IO bool WARNING, ALARM; extern __IO float32_t MEAN; extern __IO bool FLAG_CALC_MEAN; extern __IO float64_t REC_MEAN; extern __IO uint32_t CNT_MEAN; extern __IO uint16_t timerStatus; extern __IO uint32_t STATUS; extern __IO bool DrawStatus; extern volatile bool HISTORY; extern LTDC_HandleTypeDef hLtdcHandler; extern SPI_HandleTypeDef hspi1; extern TIM_HandleTypeDef htim2; extern TIM_HandleTypeDef htim7; extern TIM_HandleTypeDef htim10; extern uint8_t aRxBuffer[4]; volatile uint8_t NeedKmDown = 0; volatile uint8_t NeedKmUp = 0; volatile uint32_t TimeKmDown = 0; volatile uint32_t TimeKmUp = 0; volatile bool FirstGain = false; volatile uint32_t AvgCnt = 0; volatile uint32_t AvgVal = 0; volatile bool SeeResults = false; volatile uint32_t timeRelax = 0; volatile uint32_t RELAX = 0; __IO bool AUTOKU = true; extern float32_t MultRec; extern __IO bool OVERDRIVE; extern __IO uint8_t CURR_POINT, NUM_OPERANDS; extern __IO uint16_t timerRefreshScreen; extern volatile uint32_t MeanClbr; extern float32_t MeanKcorr; extern __IO uint32_t TimeRec; extern volatile bool Recording; extern volatile uint64_t RiffLen; extern __IO uint32_t NR; extern __IO uint32_t Vup; extern __IO uint32_t Vdn; extern volatile bool AutoStop; extern float32_t skzDB[3], skz[3]; extern float32_t ValFran[3]; extern float32_t FreqFran; extern volatile uint32_t NumHarmonics; extern volatile int32_t IndexFran; extern volatile float32_t medA[N_MED_MEAS]; extern volatile float32_t medV[N_MED_MEAS]; extern volatile float32_t medS[N_MED_MEAS]; extern uint32_t frq[LEN_M_BUF]; extern uint32_t okf; extern uint32_t kf; extern uint32_t faseF; extern float32_t operand[4]; extern uint8_t CounterA, CounterV, CounterS; extern volatile uint32_t NUMPOINTS; extern volatile uint8_t CardState; //extern volatile uint16_t AdcBuff[SIZE_ADC_BUFF]; //extern __attribute__ ((aligned (32))) DTCM uint16_t AdcBuff[SIZE_ADC_BUFF]; extern volatile bool NeedOff; extern __IO bool USBConnected; extern volatile float32_t CorrKk[3]; extern volatile UserData_TypeDef pardata, pardata_old; extern volatile bool screen, clbr; extern volatile uint8_t menu, menupos, oldmenupos; extern volatile uint8_t LAST_KU; extern float32_t MAXIMUM, MINIMUM; volatile uint32_t MAX_CNT_ADC = SIZE_ADC_BUFF; __IO bool ADC_Started = false; __IO bool NeedFreq = false; __IO bool NeedFreqTacho = false; extern __IO uint32_t CNT_MEAN_FREQ; extern __IO float32_t MEAN_FREQ; volatile uint16_t lastADCn[3] = {0, 0, 0}; volatile uint16_t cntFs = 0; volatile uint16_t faseADC = 0; volatile uint16_t cntADC = 0; volatile uint32_t Ns; volatile uint32_t Fs; volatile uint16_t Nr; volatile uint8_t ADC_VALUE[3] = {0, 0, 0}; volatile uint8_t ADC_VALUE_CNT = 0; volatile uint8_t Flag_Set_KU = 0; volatile uint8_t READY = 0; volatile uint16_t cntmeas = 0; volatile uint16_t cntmeas1 = 0; volatile uint16_t lastcntmeas = 0; volatile uint32_t NSamples = 0; volatile uint16_t measlen = 0; volatile bool READY_TO_SEE = false; volatile bool NeedMeas = false; volatile uint32_t cntOkt = 0; float32_t rms8, rms4, rms2, rms1, rms0_8, rms1_25, rms1_6, rms2_5, rms3_15, rms5, rms6_3, rms10; volatile bool firstOkt = false; volatile float32_t dBi = 0; volatile float32_t dBc = 0; volatile float32_t dBm = 0; volatile float32_t dBN = 0; //volatile float32_t dBm_MAX = 0; extern __IO uint8_t stage; extern __IO uint8_t faseUdar; extern float32_t maxdBm, maxdBc; volatile uint32_t Stability = 0; volatile bool RepeatKm = false; volatile bool firstmeas = false; volatile bool FirstTime = false; volatile bool measuring = false; volatile bool Recording = false; volatile bool Threshold = false; volatile bool FIRST = false; volatile bool IS_ROUTE = false; volatile bool FIRST_RECORD = false; volatile uint32_t MeanCnt = 0; volatile uint32_t adcThr = 0, _adcThr = 0; volatile uint32_t StateThr = 0xffffffff; volatile uint32_t ZeroThr = 0; float32_t rmsAVS[4]; float32_t peakAVS[4]; void SetKU(void) { __IO uint32_t timeout; __IO uint8_t ku = 0; } void initAmplif(void) { uint8_t k, m, ku; __IO float32_t f, f1, fm; if(clbr) { } } void Off(void) { NeedOff = false; BSP_LCD_DisplayOff(); HAL_GPIO_WritePin(DISP_ON_GPIO_Port, DISP_ON_Pin, GPIO_PIN_SET); // BACKLIGHT_OFF wrPar(); while(HAL_GPIO_ReadPin(OFF_GPIO_Port, OFF_Pin) == GPIO_PIN_SET); HAL_GPIO_WritePin(ON_GPIO_Port, ON_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(ON1_GPIO_Port, ON1_Pin, GPIO_PIN_RESET); HAL_Delay(300); while(1); } float64_t get_log_unit_value(float64_t lin_unit_value, float64_t base, float64_t k, float64_t c) { return (c * logl(lin_unit_value) / logl(base) + k); } float64_t get_d_log_unit_value(float64_t d) { static const float64_t base = 0.5921510231527015, k = -3.015055963296224, c = -0.9111115009540; return (get_log_unit_value(d, base, k, c)); } float64_t get_rpm_log_unit_value(float64_t rpm) { static const float64_t base = 6.69896278136537, k = -0.008927920952982967, c = 3.3041976536011; return (get_log_unit_value(rpm, base, k, c)); } float64_t Calc_dBi(float64_t d, float64_t rpm) { static const float64_t a = 3.135283064375708, b = 4.999746694992378, k = -58.16048390995372; return (a * get_d_log_unit_value(d) + b * get_rpm_log_unit_value(rpm) + k); }