matlab_23550/Inu/Src2/main/calc_rms_vals.h

67 lines
1.7 KiB
C

/*
* calc_rms_vals.h
*
* Created on: 14 äåê. 2020 ã.
* Author: star
*/
#ifndef SRC_MAIN_CALC_RMS_VALS_H_
#define SRC_MAIN_CALC_RMS_VALS_H_
#include <params_pwm24.h>
#include "IQmathLib.h"
#define RMS_BUFFER_SIZE (FREQ_PWM * 2 / 50)
//#define RMS_BUFFER_SIZE 18 //For FREQ_PWM 450 and signal frequency 50 Hz
typedef struct {
_iq values[RMS_BUFFER_SIZE];
int array_size;
int position;
} RMS_BUFFER;
#define RMS_BUFFER_DEFAULTS {{0}, RMS_BUFFER_SIZE, 0}
#define RMS_THINNING_BUFFER_SIZE 40 //äîëæíî ïîëó÷èòüñÿ îêîëî 30 ýëåìåíòîâ íà ïåðèîä ñèãíàëà
#define RMS_THINNING_PERIOD (RMS_THINNING_BUFFER_SIZE * 3 / 4)
typedef struct {
_iq val; //in
_iq16 values[RMS_THINNING_BUFFER_SIZE];
int array_size;
int position;
int elements_in_period; // Ñêîëüêî ýëåìåíòîâ â ìàññèâå çàíèìàåò 1 ïåðèîä èçìåðÿåìîãî ñèãíàëà
int freq_pwm; //in
_iq signal_freq; //in
int use_teta; //Îïðåäåëÿòü ïåðèîä ñèãíàëà ñ ïîìîùüþ teta
_iq teta; //in
struct {
int miss_write_counter;
int teta_period_counter;
_iq teta_prev;
int zero_teta_period;
// int zero_teta_counter_prev;
} internal;
void (*add_value)();
} RMS_BUFFER_WITH_THINNING;
#define RMS_BUFFER_WITH_THINNING_DEFAULTS {0, {0}, RMS_THINNING_BUFFER_SIZE,0, \
RMS_THINNING_PERIOD,\
(FREQ_PWM * 2),0,0,0, {0,0,0,0}, \
fill_rms_array_IQ15}
void fill_rms_array_IQ15(RMS_BUFFER_WITH_THINNING *v);
void fill_RMS_buff_interrupt(_iq teta_ch1, _iq teta_ch2);
void calc_RMS_values_main();
void init_Uin_rms(void);
void test_calc_rms (_iq teta);
#endif /* SRC_MAIN_CALC_RMS_VALS_H_ */