Compare commits

...

2 Commits

46 changed files with 687 additions and 9474 deletions

205
Inu/MCU.c Normal file
View File

@ -0,0 +1,205 @@
/**
**************************************************************************
* @file MCU.c
* @brief Исходный код S-Function.
**************************************************************************
@details
Данный файл содержит функции S-Function, который вызывает MATLAB.
**************************************************************************
@note
Описание функций по большей части сгенерировано MATLAB'ом, поэтому на английском
**************************************************************************/
/**
* @addtogroup WRAPPER_SFUNC S-Function funtions
* @ingroup MCU_WRAPPER
* @brief Дефайны и функции блока S-Function
* @details Здесь собраны функции, с которыми непосредственно работает S-Function
* @note Описание функций по большей части сгенерировано MATLAB'ом, поэтому на английском
* @{
*/
#define S_FUNCTION_NAME wrapper_inu
#define S_FUNCTION_LEVEL 2
#include "mcu_wrapper_conf.h"
#define MDL_UPDATE ///< для подключения mdlUpdate()
/**
* @brief Update S-Function at every step of simulation
* @param S - pointer to S-Function (library struct from "simstruc.h")
* @details Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S)
{
// get time of simulation
time_T TIME = ssGetT(S);
//---------------SIMULATE MCU---------------
MCU_Step_Simulation(S, TIME); // SIMULATE MCU
//------------------------------------------
}//end mdlUpdate
/**
* @brief Writting outputs of S-Function
* @param S - pointer to S-Function (library struct from "simstruc.h")
* @details Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector(s),
* ssGetOutputPortSignal.
*/
static void mdlOutputs(SimStruct *S)
{
SIM_writeOutputs(S);
}//end mdlOutputs
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlCheckParameters(SimStruct *S)
{
int i;
// Проверяем и принимаем параметры и разрешаем или запрещаем их менять
// в процессе моделирования
for (i=0; i<1; i++)
{
// Input parameter must be scalar or vector of type double
if (!mxIsDouble(ssGetSFcnParam(S,i)) || mxIsComplex(ssGetSFcnParam(S,i)) ||
mxIsEmpty(ssGetSFcnParam(S,i)))
{
ssSetErrorStatus(S,"Input parameter must be of type double");
return;
}
// Параметр м.б. только скаляром, вектором или матрицей
if (mxGetNumberOfDimensions(ssGetSFcnParam(S,i)) > 2)
{
ssSetErrorStatus(S,"Параметр м.б. только скаляром, вектором или матрицей");
return;
}
// sim_dt = mxGetPr(ssGetSFcnParam(S,0))[0];
// Parameter not tunable
// ssSetSFcnParamTunable(S, i, SS_PRM_NOT_TUNABLE);
// Parameter tunable (we must create a corresponding run-time parameter)
ssSetSFcnParamTunable(S, i, SS_PRM_TUNABLE);
// Parameter tunable only during simulation
// ssSetSFcnParamTunable(S, i, SS_PRM_SIM_ONLY_TUNABLE);
}//for (i=0; i<NPARAMS; i++)
}//end mdlCheckParameters
#endif //MDL_CHECK_PARAMETERS
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 1);
// Кол-во ожидаемых и фактических параметров должно совпадать
if(ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S))
{
// Проверяем и принимаем параметры
mdlCheckParameters(S);
}
else
{
return;// Parameter mismatch will be reported by Simulink
}
// set up discrete states
ssSetNumContStates(S, 0); // number of continuous states
ssSetNumDiscStates(S, DISC_STATES_WIDTH); // number of discrete states
// set up input port
if (!ssSetNumInputPorts(S, 1)) return;
for (int i = 0; i < IN_PORT_NUMB; i++)
ssSetInputPortWidth(S, i, IN_PORT_WIDTH);
ssSetInputPortDirectFeedThrough(S, 0, 0);
ssSetInputPortRequiredContiguous(S, 0, 1); // direct input signal access
// set up output port
if (!ssSetNumOutputPorts(S, OUT_PORT_NUMB)) return;
for (int i = 0; i < OUT_PORT_NUMB; i++)
ssSetOutputPortWidth(S, i, OUT_PORT_WIDTH);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork( S, 5); // number of real work vector elements
ssSetNumIWork( S, 5); // number of integer work vector elements
ssSetNumPWork( S, 0); // number of pointer work vector elements
ssSetNumModes( S, 0); // number of mode work vector elements
ssSetNumNonsampledZCs( S, 0); // number of nonsampled zero crossings
ssSetRuntimeThreadSafetyCompliance(S, RUNTIME_THREAD_SAFETY_COMPLIANCE_TRUE);
/* Take care when specifying exception free code - see sfuntmpl.doc */
ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}
#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
/**
* @brief Initialize S-Function at start of simulation
* @param S - pointer to S-Function (library struct from "simstruc.h")
* @details Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
static void mdlStart(SimStruct *S)
{
SIM_Initialize_Simulation();
}
#endif // MDL_START
/**
* @brief Initialize Sample Time of Simulation
* @param S - pointer to S-Function (library struct from "simstruc.h")
* @details Abstract:
* This function is used to specify the sample time(s) for your
* S-function. You must register the same number of sample times as
* specified in ssSetNumSampleTimes.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
// Шаг дискретизации
hmcu.SimSampleTime = mxGetPr(ssGetSFcnParam(S,NPARAMS-1))[0];
// Register one pair for each sample time
ssSetSampleTime(S, 0, hmcu.SimSampleTime);
ssSetOffsetTime(S, 0, 0.0);
}
/**
* @brief Terminate S-Function at the end of simulation
* @param S - pointer to S-Function (library struct from "simstruc.h")
* @details Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{
hmcu.fMCU_Stop = 1;
ResumeThread(hmcu.hMCUThread);
WaitForSingleObject(hmcu.hMCUThread, 10000);
SIM_deInitialize_Simulation();
mexUnlock();
}
/** WRAPPER_SFUNC
* @}
*/
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a
MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration
function */
#endif

View File

@ -1,4 +0,0 @@
#include "DSP2833x_Device.h"
//#define int16 int
#define interrupt

View File

@ -1 +0,0 @@

View File

@ -1 +0,0 @@

View File

@ -1,687 +0,0 @@
//#define __IQMATHLIB_H_INCLUDED__
/**
* Èììèòàöèÿ áèáëèîòåêè IQmath äëÿ òåñòèðîâàíèÿ â MATLAB
*
*/
#ifndef IQ_MATH_LIB
#define IQ_MATH_LIB
#ifndef GLOBAL_Q
#define GLOBAL_Q 24
#endif
typedef long _iq;
typedef long _iq30;
typedef long _iq29;
typedef long _iq28;
typedef long _iq27;
typedef long _iq26;
typedef long _iq25;
typedef long _iq24;
typedef long _iq23;
typedef long _iq22;
typedef long _iq21;
typedef long _iq20;
typedef long _iq19;
typedef long _iq18;
typedef long _iq17;
typedef long _iq16;
typedef long _iq15;
typedef long _iq14;
typedef long _iq13;
typedef long _iq12;
typedef long _iq11;
typedef long _iq10;
typedef long _iq9;
typedef long _iq8;
typedef long _iq7;
typedef long _iq6;
typedef long _iq5;
typedef long _iq4;
typedef long _iq3;
typedef long _iq2;
typedef long _iq1;
//---------------------------------------------------------------------------
#define _IQmpy2(A) ((A)<<1)
#define _IQmpy4(A) ((A)<<2)
#define _IQmpy8(A) ((A)<<3)
#define _IQmpy16(A) ((A)<<4)
#define _IQmpy32(A) ((A)<<5)
#define _IQmpy64(A) ((A)<<6)
#define _IQdiv2(A) ((A)>>1)
#define _IQdiv4(A) ((A)>>2)
#define _IQdiv8(A) ((A)>>3)
#define _IQdiv16(A) ((A)>>4)
#define _IQdiv32(A) ((A)>>5)
#define _IQdiv64(A) ((A)>>6)
//---------------------------------------------------------------------------
#define _IQ30(A) (long) ((A) * 1073741824.0L)
#define _IQ29(A) (long) ((A) * 536870912.0L)
#define _IQ28(A) (long) ((A) * 268435456.0L)
#define _IQ27(A) (long) ((A) * 134217728.0L)
#define _IQ26(A) (long) ((A) * 67108864.0L)
#define _IQ25(A) (long) ((A) * 33554432.0L)
#define _IQ24(A) (long) ((A) * 16777216.0L)
#define _IQ23(A) (long) ((A) * 8388608.0L)
#define _IQ22(A) (long) ((A) * 4194304.0L)
#define _IQ21(A) (long) ((A) * 2097152.0L)
#define _IQ20(A) (long) ((A) * 1048576.0L)
#define _IQ19(A) (long) ((A) * 524288.0L)
#define _IQ18(A) (long) ((A) * 262144.0L)
#define _IQ17(A) (long) ((A) * 131072.0L)
#define _IQ16(A) (long) ((A) * 65536.0L)
#define _IQ15(A) (long) ((A) * 32768.0L)
#define _IQ14(A) (long) ((A) * 16384.0L)
#define _IQ13(A) (long) ((A) * 8192.0L)
#define _IQ12(A) (long) ((A) * 4096.0L)
#define _IQ11(A) (long) ((A) * 2048.0L)
#define _IQ10(A) (long) ((A) * 1024.0L)
#define _IQ9(A) (long) ((A) * 512.0L)
#define _IQ8(A) (long) ((A) * 256.0L)
#define _IQ7(A) (long) ((A) * 128.0L)
#define _IQ6(A) (long) ((A) * 64.0L)
#define _IQ5(A) (long) ((A) * 32.0L)
#define _IQ4(A) (long) ((A) * 16.0L)
#define _IQ3(A) (long) ((A) * 8.0L)
#define _IQ2(A) (long) ((A) * 4.0L)
#define _IQ1(A) (long) ((A) * 2.0L)
#if GLOBAL_Q == 30
#define _IQ(A) _IQ30(A)
#endif
#if GLOBAL_Q == 29
#define _IQ(A) _IQ29(A)
#endif
#if GLOBAL_Q == 28
#define _IQ(A) _IQ28(A)
#endif
#if GLOBAL_Q == 27
#define _IQ(A) _IQ27(A)
#endif
#if GLOBAL_Q == 26
#define _IQ(A) _IQ26(A)
#endif
#if GLOBAL_Q == 25
#define _IQ(A) _IQ25(A)
#endif
#if GLOBAL_Q == 24
#define _IQ(A) _IQ24(A)
#endif
#if GLOBAL_Q == 23
#define _IQ(A) _IQ23(A)
#endif
#if GLOBAL_Q == 22
#define _IQ(A) _IQ22(A)
#endif
#if GLOBAL_Q == 21
#define _IQ(A) _IQ21(A)
#endif
#if GLOBAL_Q == 20
#define _IQ(A) _IQ20(A)
#endif
#if GLOBAL_Q == 19
#define _IQ(A) _IQ19(A)
#endif
#if GLOBAL_Q == 18
#define _IQ(A) _IQ18(A)
#endif
#if GLOBAL_Q == 17
#define _IQ(A) _IQ17(A)
#endif
#if GLOBAL_Q == 16
#define _IQ(A) _IQ16(A)
#endif
#if GLOBAL_Q == 15
#define _IQ(A) _IQ15(A)
#endif
#if GLOBAL_Q == 14
#define _IQ(A) _IQ14(A)
#endif
#if GLOBAL_Q == 13
#define _IQ(A) _IQ13(A)
#endif
#if GLOBAL_Q == 12
#define _IQ(A) _IQ12(A)
#endif
#if GLOBAL_Q == 11
#define _IQ(A) _IQ11(A)
#endif
#if GLOBAL_Q == 10
#define _IQ(A) _IQ10(A)
#endif
#if GLOBAL_Q == 9
#define _IQ(A) _IQ9(A)
#endif
#if GLOBAL_Q == 8
#define _IQ(A) _IQ8(A)
#endif
#if GLOBAL_Q == 7
#define _IQ(A) _IQ7(A)
#endif
#if GLOBAL_Q == 6
#define _IQ(A) _IQ6(A)
#endif
#if GLOBAL_Q == 5
#define _IQ(A) _IQ5(A)
#endif
#if GLOBAL_Q == 4
#define _IQ(A) _IQ4(A)
#endif
#if GLOBAL_Q == 3
#define _IQ(A) _IQ3(A)
#endif
#if GLOBAL_Q == 2
#define _IQ(A) _IQ2(A)
#endif
#if GLOBAL_Q == 1
#define _IQ(A) _IQ1(A)
#endif
//---------------------------------------------------------------------------
#define _IQ30toF(A) ((float) ((A) / 1073741824.0L))
#define _IQ29toF(A) ((float) ((A) / 536870912.0L))
#define _IQ28toF(A) ((float) ((A) / 268435456.0L))
#define _IQ27toF(A) ((float) ((A) / 134217728.0L))
#define _IQ26toF(A) ((float) ((A) / 67108864.0L))
#define _IQ25toF(A) ((float) ((A) / 33554432.0L))
#define _IQ24toF(A) ((float) ((A) / 16777216.0L))
#define _IQ23toF(A) ((float) ((A) / 8388608.0L))
#define _IQ22toF(A) ((float) ((A) / 4194304.0L))
#define _IQ21toF(A) ((float) ((A) / 2097152.0L))
#define _IQ20toF(A) ((float) ((A) / 1048576.0L))
#define _IQ19toF(A) ((float) ((A) / 524288.0L))
#define _IQ18toF(A) ((float) ((A) / 262144.0L))
#define _IQ17toF(A) ((float) ((A) / 131072.0L))
#define _IQ16toF(A) ((float) ((A) / 65536.0L))
#define _IQ15toF(A) ((float) ((A) / 32768.0L))
#define _IQ14toF(A) ((float) ((A) / 16384.0L))
#define _IQ13toF(A) ((float) ((A) / 8192.0L))
#define _IQ12toF(A) ((float) ((A) / 4096.0L))
#define _IQ11toF(A) ((float) ((A) / 2048.0L))
#define _IQ10toF(A) ((float) ((A) / 1024.0L))
#define _IQ9toF(A) ((float) ((A) / 512.0L))
#define _IQ8toF(A) ((float) ((A) / 256.0L))
#define _IQ7toF(A) ((float) ((A) / 128.0L))
#define _IQ6toF(A) ((float) ((A) / 64.0L))
#define _IQ5toF(A) ((float) ((A) / 32.0L))
#define _IQ4toF(A) ((float) ((A) / 16.0L))
#define _IQ3toF(A) ((float) ((A) / 8.0L))
#define _IQ2toF(A) ((float) ((A) / 4.0L))
#define _IQ1toF(A) ((float) ((A) / 2.0L))
#if GLOBAL_Q == 30
#define _IQtoF(A) _IQ30toF(A)
#endif
#if GLOBAL_Q == 29
#define _IQtoF(A) _IQ29toF(A)
#endif
#if GLOBAL_Q == 28
#define _IQtoF(A) _IQ28toF(A)
#endif
#if GLOBAL_Q == 27
#define _IQtoF(A) _IQ27toF(A)
#endif
#if GLOBAL_Q == 26
#define _IQtoF(A) _IQ26toF(A)
#endif
#if GLOBAL_Q == 25
#define _IQtoF(A) _IQ25toF(A)
#endif
#if GLOBAL_Q == 24
#define _IQtoF(A) _IQ24toF(A)
#endif
#if GLOBAL_Q == 23
#define _IQtoF(A) _IQ23toF(A)
#endif
#if GLOBAL_Q == 22
#define _IQtoF(A) _IQ22toF(A)
#endif
#if GLOBAL_Q == 21
#define _IQtoF(A) _IQ21toF(A)
#endif
#if GLOBAL_Q == 20
#define _IQtoF(A) _IQ20toF(A)
#endif
#if GLOBAL_Q == 19
#define _IQtoF(A) _IQ19toF(A)
#endif
#if GLOBAL_Q == 18
#define _IQtoF(A) _IQ18toF(A)
#endif
#if GLOBAL_Q == 17
#define _IQtoF(A) _IQ17toF(A)
#endif
#if GLOBAL_Q == 16
#define _IQtoF(A) _IQ16toF(A)
#endif
#if GLOBAL_Q == 15
#define _IQtoF(A) _IQ15toF(A)
#endif
#if GLOBAL_Q == 14
#define _IQtoF(A) _IQ14toF(A)
#endif
#if GLOBAL_Q == 13
#define _IQtoF(A) _IQ13toF(A)
#endif
#if GLOBAL_Q == 12
#define _IQtoF(A) _IQ12toF(A)
#endif
#if GLOBAL_Q == 11
#define _IQtoF(A) _IQ11toF(A)
#endif
#if GLOBAL_Q == 10
#define _IQtoF(A) _IQ10toF(A)
#endif
#if GLOBAL_Q == 9
#define _IQtoF(A) _IQ9toF(A)
#endif
#if GLOBAL_Q == 8
#define _IQtoF(A) _IQ8toF(A)
#endif
#if GLOBAL_Q == 7
#define _IQtoF(A) _IQ7toF(A)
#endif
#if GLOBAL_Q == 6
#define _IQtoF(A) _IQ6toF(A)
#endif
#if GLOBAL_Q == 5
#define _IQtoF(A) _IQ5toF(A)
#endif
#if GLOBAL_Q == 4
#define _IQtoF(A) _IQ4toF(A)
#endif
#if GLOBAL_Q == 3
#define _IQtoF(A) _IQ3toF(A)
#endif
#if GLOBAL_Q == 2
#define _IQtoF(A) _IQ2toF(A)
#endif
#if GLOBAL_Q == 1
#define _IQtoF(A) _IQ1toF(A)
#endif
#define _IQsat(A, Pos, Neg) ((A > Pos) ? Pos : (A < Neg) ? Neg : A)
//---------------------------------------------------------------------------
#define _IQtoIQ30(A) ((long) (A) << (30 - GLOBAL_Q))
#define _IQ30toIQ(A) ((long) (A) >> (30 - GLOBAL_Q))
#if (GLOBAL_Q >= 29)
#define _IQtoIQ29(A) ((long) (A) >> (GLOBAL_Q - 29))
#define _IQ29toIQ(A) ((long) (A) << (GLOBAL_Q - 29))
#else
#define _IQtoIQ29(A) ((long) (A) << (29 - GLOBAL_Q))
#define _IQ29toIQ(A) ((long) (A) >> (29 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 28)
#define _IQtoIQ28(A) ((long) (A) >> (GLOBAL_Q - 28))
#define _IQ28toIQ(A) ((long) (A) << (GLOBAL_Q - 28))
#else
#define _IQtoIQ28(A) ((long) (A) << (28 - GLOBAL_Q))
#define _IQ28toIQ(A) ((long) (A) >> (28 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 27)
#define _IQtoIQ27(A) ((long) (A) >> (GLOBAL_Q - 27))
#define _IQ27toIQ(A) ((long) (A) << (GLOBAL_Q - 27))
#else
#define _IQtoIQ27(A) ((long) (A) << (27 - GLOBAL_Q))
#define _IQ27toIQ(A) ((long) (A) >> (27 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 26)
#define _IQtoIQ26(A) ((long) (A) >> (GLOBAL_Q - 26))
#define _IQ26toIQ(A) ((long) (A) << (GLOBAL_Q - 26))
#else
#define _IQtoIQ26(A) ((long) (A) << (26 - GLOBAL_Q))
#define _IQ26toIQ(A) ((long) (A) >> (26 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 25)
#define _IQtoIQ25(A) ((long) (A) >> (GLOBAL_Q - 25))
#define _IQ25toIQ(A) ((long) (A) << (GLOBAL_Q - 25))
#else
#define _IQtoIQ25(A) ((long) (A) << (25 - GLOBAL_Q))
#define _IQ25toIQ(A) ((long) (A) >> (25 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 24)
#define _IQtoIQ24(A) ((long) (A) >> (GLOBAL_Q - 24))
#define _IQ24toIQ(A) ((long) (A) << (GLOBAL_Q - 24))
#else
#define _IQtoIQ24(A) ((long) (A) << (24 - GLOBAL_Q))
#define _IQ24toIQ(A) ((long) (A) >> (24 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 23)
#define _IQtoIQ23(A) ((long) (A) >> (GLOBAL_Q - 23))
#define _IQ23toIQ(A) ((long) (A) << (GLOBAL_Q - 23))
#else
#define _IQtoIQ23(A) ((long) (A) << (23 - GLOBAL_Q))
#define _IQ23toIQ(A) ((long) (A) >> (23 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 22)
#define _IQtoIQ22(A) ((long) (A) >> (GLOBAL_Q - 22))
#define _IQ22toIQ(A) ((long) (A) << (GLOBAL_Q - 22))
#else
#define _IQtoIQ22(A) ((long) (A) << (22 - GLOBAL_Q))
#define _IQ22toIQ(A) ((long) (A) >> (22 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 21)
#define _IQtoIQ21(A) ((long) (A) >> (GLOBAL_Q - 21))
#define _IQ21toIQ(A) ((long) (A) << (GLOBAL_Q - 21))
#else
#define _IQtoIQ21(A) ((long) (A) << (21 - GLOBAL_Q))
#define _IQ21toIQ(A) ((long) (A) >> (21 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 20)
#define _IQtoIQ20(A) ((long) (A) >> (GLOBAL_Q - 20))
#define _IQ20toIQ(A) ((long) (A) << (GLOBAL_Q - 20))
#else
#define _IQtoIQ20(A) ((long) (A) << (20 - GLOBAL_Q))
#define _IQ20toIQ(A) ((long) (A) >> (20 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 19)
#define _IQtoIQ19(A) ((long) (A) >> (GLOBAL_Q - 19))
#define _IQ19toIQ(A) ((long) (A) << (GLOBAL_Q - 19))
#else
#define _IQtoIQ19(A) ((long) (A) << (19 - GLOBAL_Q))
#define _IQ19toIQ(A) ((long) (A) >> (19 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 18)
#define _IQtoIQ18(A) ((long) (A) >> (GLOBAL_Q - 18))
#define _IQ18toIQ(A) ((long) (A) << (GLOBAL_Q - 18))
#else
#define _IQtoIQ18(A) ((long) (A) << (18 - GLOBAL_Q))
#define _IQ18toIQ(A) ((long) (A) >> (18 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 17)
#define _IQtoIQ17(A) ((long) (A) >> (GLOBAL_Q - 17))
#define _IQ17toIQ(A) ((long) (A) << (GLOBAL_Q - 17))
#else
#define _IQtoIQ17(A) ((long) (A) << (17 - GLOBAL_Q))
#define _IQ17toIQ(A) ((long) (A) >> (17 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 16)
#define _IQtoIQ16(A) ((long) (A) >> (GLOBAL_Q - 16))
#define _IQ16toIQ(A) ((long) (A) << (GLOBAL_Q - 16))
#else
#define _IQtoIQ16(A) ((long) (A) << (16 - GLOBAL_Q))
#define _IQ16toIQ(A) ((long) (A) >> (16 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 15)
#define _IQtoIQ15(A) ((long) (A) >> (GLOBAL_Q - 15))
#define _IQ15toIQ(A) ((long) (A) << (GLOBAL_Q - 15))
#define _IQtoQ15(A) ((long) (A) >> (GLOBAL_Q - 15))
#define _Q15toIQ(A) ((long) (A) << (GLOBAL_Q - 15))
#else
#define _IQtoIQ15(A) ((long) (A) << (15 - GLOBAL_Q))
#define _IQ15toIQ(A) ((long) (A) >> (15 - GLOBAL_Q))
#define _IQtoQ15(A) ((long) (A) << (15 - GLOBAL_Q))
#define _Q15toIQ(A) ((long) (A) >> (15 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 14)
#define _IQtoIQ14(A) ((long) (A) >> (GLOBAL_Q - 14))
#define _IQ14toIQ(A) ((long) (A) << (GLOBAL_Q - 14))
#define _IQtoQ14(A) ((long) (A) >> (GLOBAL_Q - 14))
#define _Q14toIQ(A) ((long) (A) << (GLOBAL_Q - 14))
#else
#define _IQtoIQ14(A) ((long) (A) << (14 - GLOBAL_Q))
#define _IQ14toIQ(A) ((long) (A) >> (14 - GLOBAL_Q))
#define _IQtoQ14(A) ((long) (A) << (14 - GLOBAL_Q))
#define _Q14toIQ(A) ((long) (A) >> (14 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 13)
#define _IQtoIQ13(A) ((long) (A) >> (GLOBAL_Q - 13))
#define _IQ13toIQ(A) ((long) (A) << (GLOBAL_Q - 13))
#define _IQtoQ13(A) ((long) (A) >> (GLOBAL_Q - 13))
#define _Q13toIQ(A) ((long) (A) << (GLOBAL_Q - 13))
#else
#define _IQtoIQ13(A) ((long) (A) << (13 - GLOBAL_Q))
#define _IQ13toIQ(A) ((long) (A) >> (13 - GLOBAL_Q))
#define _IQtoQ13(A) ((long) (A) << (13 - GLOBAL_Q))
#define _Q13toIQ(A) ((long) (A) >> (13 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 12)
#define _IQtoIQ12(A) ((long) (A) >> (GLOBAL_Q - 12))
#define _IQ12toIQ(A) ((long) (A) << (GLOBAL_Q - 12))
#define _IQtoQ12(A) ((long) (A) >> (GLOBAL_Q - 12))
#define _Q12toIQ(A) ((long) (A) << (GLOBAL_Q - 12))
#else
#define _IQtoIQ12(A) ((long) (A) << (12 - GLOBAL_Q))
#define _IQ12toIQ(A) ((long) (A) >> (12 - GLOBAL_Q))
#define _IQtoQ12(A) ((long) (A) << (12 - GLOBAL_Q))
#define _Q12toIQ(A) ((long) (A) >> (12 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 11)
#define _IQtoIQ11(A) ((long) (A) >> (GLOBAL_Q - 11))
#define _IQ11toIQ(A) ((long) (A) << (GLOBAL_Q - 11))
#define _IQtoQ11(A) ((long) (A) >> (GLOBAL_Q - 11))
#define _Q11toIQ(A) ((long) (A) << (GLOBAL_Q - 11))
#else
#define _IQtoIQ11(A) ((long) (A) << (11 - GLOBAL_Q))
#define _IQ11toIQ(A) ((long) (A) >> (11 - GLOBAL_Q))
#define _IQtoQ11(A) ((long) (A) << (11 - GLOBAL_Q))
#define _Q11toIQ(A) ((long) (A) >> (11 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 10)
#define _IQtoIQ10(A) ((long) (A) >> (GLOBAL_Q - 10))
#define _IQ10toIQ(A) ((long) (A) << (GLOBAL_Q - 10))
#define _IQtoQ10(A) ((long) (A) >> (GLOBAL_Q - 10))
#define _Q10toIQ(A) ((long) (A) << (GLOBAL_Q - 10))
#else
#define _IQtoIQ10(A) ((long) (A) << (10 - GLOBAL_Q))
#define _IQ10toIQ(A) ((long) (A) >> (10 - GLOBAL_Q))
#define _IQtoQ10(A) ((long) (A) << (10 - GLOBAL_Q))
#define _Q10toIQ(A) ((long) (A) >> (10 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 9)
#define _IQtoIQ9(A) ((long) (A) >> (GLOBAL_Q - 9))
#define _IQ9toIQ(A) ((long) (A) << (GLOBAL_Q - 9))
#define _IQtoQ9(A) ((long) (A) >> (GLOBAL_Q - 9))
#define _Q9toIQ(A) ((long) (A) << (GLOBAL_Q - 9))
#else
#define _IQtoIQ9(A) ((long) (A) << (9 - GLOBAL_Q))
#define _IQ9toIQ(A) ((long) (A) >> (9 - GLOBAL_Q))
#define _IQtoQ9(A) ((long) (A) << (9 - GLOBAL_Q))
#define _Q9toIQ(A) ((long) (A) >> (9 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 8)
#define _IQtoIQ8(A) ((long) (A) >> (GLOBAL_Q - 8))
#define _IQ8toIQ(A) ((long) (A) << (GLOBAL_Q - 8))
#define _IQtoQ8(A) ((long) (A) >> (GLOBAL_Q - 8))
#define _Q8toIQ(A) ((long) (A) << (GLOBAL_Q - 8))
#else
#define _IQtoIQ8(A) ((long) (A) << (8 - GLOBAL_Q))
#define _IQ8toIQ(A) ((long) (A) >> (8 - GLOBAL_Q))
#define _IQtoQ8(A) ((long) (A) << (8 - GLOBAL_Q))
#define _Q8toIQ(A) ((long) (A) >> (8 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 7)
#define _IQtoIQ7(A) ((long) (A) >> (GLOBAL_Q - 7))
#define _IQ7toIQ(A) ((long) (A) << (GLOBAL_Q - 7))
#define _IQtoQ7(A) ((long) (A) >> (GLOBAL_Q - 7))
#define _Q7toIQ(A) ((long) (A) << (GLOBAL_Q - 7))
#else
#define _IQtoIQ7(A) ((long) (A) << (7 - GLOBAL_Q))
#define _IQ7toIQ(A) ((long) (A) >> (7 - GLOBAL_Q))
#define _IQtoQ7(A) ((long) (A) << (7 - GLOBAL_Q))
#define _Q7toIQ(A) ((long) (A) >> (7 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 6)
#define _IQtoIQ6(A) ((long) (A) >> (GLOBAL_Q - 6))
#define _IQ6toIQ(A) ((long) (A) << (GLOBAL_Q - 6))
#define _IQtoQ6(A) ((long) (A) >> (GLOBAL_Q - 6))
#define _Q6toIQ(A) ((long) (A) << (GLOBAL_Q - 6))
#else
#define _IQtoIQ6(A) ((long) (A) << (6 - GLOBAL_Q))
#define _IQ6toIQ(A) ((long) (A) >> (6 - GLOBAL_Q))
#define _IQtoQ6(A) ((long) (A) << (6 - GLOBAL_Q))
#define _Q6toIQ(A) ((long) (A) >> (6 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 5)
#define _IQtoIQ5(A) ((long) (A) >> (GLOBAL_Q - 5))
#define _IQ5toIQ(A) ((long) (A) << (GLOBAL_Q - 5))
#define _IQtoQ5(A) ((long) (A) >> (GLOBAL_Q - 5))
#define _Q5toIQ(A) ((long) (A) << (GLOBAL_Q - 5))
#else
#define _IQtoIQ5(A) ((long) (A) << (5 - GLOBAL_Q))
#define _IQ5toIQ(A) ((long) (A) >> (5 - GLOBAL_Q))
#define _IQtoQ5(A) ((long) (A) << (5 - GLOBAL_Q))
#define _Q5toIQ(A) ((long) (A) >> (5 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 4)
#define _IQtoIQ4(A) ((long) (A) >> (GLOBAL_Q - 4))
#define _IQ4toIQ(A) ((long) (A) << (GLOBAL_Q - 4))
#define _IQtoQ4(A) ((long) (A) >> (GLOBAL_Q - 4))
#define _Q4toIQ(A) ((long) (A) << (GLOBAL_Q - 4))
#else
#define _IQtoIQ4(A) ((long) (A) << (4 - GLOBAL_Q))
#define _IQ4toIQ(A) ((long) (A) >> (4 - GLOBAL_Q))
#define _IQtoQ4(A) ((long) (A) << (4 - GLOBAL_Q))
#define _Q4toIQ(A) ((long) (A) >> (4 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 3)
#define _IQtoIQ3(A) ((long) (A) >> (GLOBAL_Q - 3))
#define _IQ3toIQ(A) ((long) (A) << (GLOBAL_Q - 3))
#define _IQtoQ3(A) ((long) (A) >> (GLOBAL_Q - 3))
#define _Q3toIQ(A) ((long) (A) << (GLOBAL_Q - 3))
#else
#define _IQtoIQ3(A) ((long) (A) << (3 - GLOBAL_Q))
#define _IQ3toIQ(A) ((long) (A) >> (3 - GLOBAL_Q))
#define _IQtoQ3(A) ((long) (A) << (3 - GLOBAL_Q))
#define _Q3toIQ(A) ((long) (A) >> (3 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 2)
#define _IQtoIQ2(A) ((long) (A) >> (GLOBAL_Q - 2))
#define _IQ2toIQ(A) ((long) (A) << (GLOBAL_Q - 2))
#define _IQtoQ2(A) ((long) (A) >> (GLOBAL_Q - 2))
#define _Q2toIQ(A) ((long) (A) << (GLOBAL_Q - 2))
#else
#define _IQtoIQ2(A) ((long) (A) << (2 - GLOBAL_Q))
#define _IQ2toIQ(A) ((long) (A) >> (2 - GLOBAL_Q))
#define _IQtoQ2(A) ((long) (A) << (2 - GLOBAL_Q))
#define _Q2toIQ(A) ((long) (A) >> (2 - GLOBAL_Q))
#endif
#if (GLOBAL_Q >= 1)
#define _IQtoQ1(A) ((long) (A) >> (GLOBAL_Q - 1))
#define _Q1toIQ(A) ((long) (A) << (GLOBAL_Q - 1))
#else
#define _IQtoQ1(A) ((long) (A) << (1 - GLOBAL_Q))
#define _Q1toIQ(A) ((long) (A) >> (1 - GLOBAL_Q))
#endif
#define _IQtoIQ1(A) ((long) (A) >> (GLOBAL_Q - 1))
#define _IQ1toIQ(A) ((long) (A) << (GLOBAL_Q - 1))
/////////////////////////////////////////////////////////////
long multiply(long x, long y);
long long multiply_fixed_base_select(long long x, long long y, int base);
long divide(long num, long den);
long divide19(long num, long den);
long divideN(long num, long den, unsigned int d);
long sin_fixed(long x);
long cos_fixed(long x);
long sqrt_fixed(long x);
long exp_fixed(long x);
long exp_fixedN(long x, unsigned int n);
#define _IQabs(A) ((A) > 0 ? (A): -(A))
#define _IQmpy(A,B) multiply(A,B)
#define _IQ19mpy(A,B) multiply_fixed_base_select(A,B,19)
#define _IQ18mpy(A,B) multiply_fixed_base_select(A,B,18)
#define _IQdiv(A,B) divide(A,B)
#define _IQ19div(A,B) divide19(A,B)
#define _IQ18div(A,B) divideN(A,B,18)
#define _IQ22div(A,B) divideN(A,B,22)
#define _IQsin(A) sin_fixed(A)
#define _IQcos(A) cos_fixed(A)
#define _IQsinPU(A) sin_fixed(A)
#define _IQcosPU(A) cos_fixed(A)
#define _IQsqrt(A) sqrt_fixed(A)
#define _IQexp(A) exp_fixed(A)
#define _IQ18exp(A) exp_fixedN(A,18)
#define _IQmpyI32(A,B) ((A)*(B))
#define PI 3.1415926535897932384626433832795
#define PI_2 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#ifndef ONE_24
#define ONE_24 16777216
#endif
#ifndef ONE_27
#define ONE_27 134217728
#endif
#ifndef ONE_28
#define ONE_28 268435456
#endif
// #ifndef FIXED_PI
// #define FIXED_PI 52707179
// #endif
// #ifndef FIXED_2PI
// #define FIXED_2PI 105414357
// #endif
#ifndef FIXED_PI_30
#define FIXED_PI_30 3373259426
#endif
#ifndef FIXED_2PI_30
#define FIXED_2PI_30 6746518852
#endif
#ifndef FIXED_3PIna2
#define FIXED_3PIna2 79060768
#endif
#ifndef FIXED_PIna3
#define FIXED_PIna3 17569059
#endif
#ifndef FIXED_PIna6
#define FIXED_PIna6 8784529
#endif
//###########################################################################
// If FLOAT_MATH is used, the IQmath library function are replaced by
// equivalent floating point operations:
//===========================================================================
#define _IQ15sqrt(A) sqrt(A)
#endif //IQ_MATH_LIB

View File

@ -1,237 +0,0 @@
#include "IQmathLib.h"
#include <math.h>
// Преобразование числа с плавающей точкой в число с фиксированной точкой
#define float_to_fixed(A) (long)((A)*(1 << (GLOBAL_Q)) + (A > 0 ? 0.5: -0.5))
// Преобразование числа с плавающей точкой в число с фиксированной точкой с выбором числа бит, отдаваемых под дробную часть
#define float_to_fixed_base_select(A, F_BITS) (long)((A)*(1 << (F_BITS)) + (A > 0 ? 0.5: -0.5))
// Преобразование целого числа в число с фиксированной точкой
#define int_to_fixed(A) (long)((A) << (GLOBAL_Q))
// Преобразование целого числа в число с фиксированной точкой с выбором числа бит, отдаваемых под дробную часть
#define int_to_fixed_base_select(A, F_BITS) (long)((A) << (F_BITS))
//Преобразование числа с фиксированной точкой в число с плавающей точкой
#define fixed_to_float(A) ((double)A / (1 << GLOBAL_Q))
//Перобразование числа с фиксированной точкой в целое число
#define fixed_to_int(A) ((int)(A >> GLOBAL_Q) )
long _IQmag(long a, long b)
{
return _IQsqrt(_IQmpy(a, a) + _IQmpy(b, b));
}
long multiply(long x, long y)
{
long long z = (long long)x * (long long)y;
return (long)(z >> GLOBAL_Q);
}
//служебная функция. Умножает числа с 27 битами, отданными под дробную часть
static inline long multiply_27(long x, long y)
{
long long z = (long long)x * (long long)y;
return z & 0x4000000 ? (long)(z >> 27) + 1 : (long)(z >> 27);
}
long long multiply_fixed_base_select(long long x, long long y, int base)
{
long long z = (long long)x * (long long)y;
return z & (1 << base) ? (z >> base) + 1 : (z >> base);
}
long divide(long num, long den)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << GLOBAL_Q) / den;
return (long)quotient;
}
long divide19(long num, long den)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << 19) / den;
return (long)quotient;
}
long divideN(long num, long den, unsigned int d)
{
if (den == 0)
return 0;
long long numLong = (long long)num;
long long quotient = (numLong << d) / den;
return (long)quotient;
}
//
static inline long long divide_fixed_base_select(long long num, long long den, int base)
{
if (den == 0)
return 0;
long long quotient = ((long long)num << base) / den;
return quotient;
}
#define div_def(A,B) (long)(((long long)(A) << 24)/(B))
#define div_mod(A,B) (A)%(B)
#define mult_def(A,B) (long)((((long long)(A))*((long long)(B))) >> 24)
#define abs_def(A) ((A) > 0 ? (A): -(A))
long sin_fixed(long x)
{
//Константы сделал ститическими, что бы они вычислялись во время запуска программы, а не исполнения
static long FIXED_2PI = float_to_fixed(TWO_PI);
static long FIXED_PI = float_to_fixed(PI);
static long FIXED_PIna2 = float_to_fixed(PI_2);
//Здесть так же что бы не производить операции деления посчитал констаны ряда Тейлора
static long one_110 = float_to_fixed_base_select(1./110, 27);
static long one_72 = float_to_fixed_base_select(1./72, 27);
static long one_42 = float_to_fixed_base_select(1./42, 27);
static long one_20= float_to_fixed_base_select(1./20, 27);
static long one_6 = float_to_fixed_base_select(1./6, 27);
long long xx, tmp ;
while(x >= FIXED_2PI) { x -= FIXED_2PI;} //Помещаю аргумент в диапазон 2 ПИ
while(x <= -FIXED_2PI) { x += FIXED_2PI;}
//Так как ряды быстрее сходнятся при малых значениях, помещаю значение аргумента
//в ближайшие к нулю области
if(x > FIXED_PI)
{
x -= FIXED_2PI;
}
else if(x < -FIXED_PI)
{
x += FIXED_2PI;
}
if(x < -FIXED_PIna2)
{
x = -FIXED_PI - x;
}
else if(x > FIXED_PIna2)
{
x = FIXED_PI - x;
}
//проверяю угол на значения, при которых синус раве 0 или 1
if(x == 0) return 0;
if(x == FIXED_PIna2) return int_to_fixed(1);
if(x == -FIXED_PIna2) return int_to_fixed(-1);
//Перевожу в формат с максимальной точностью для возможного дипазано значений
x <<= (27 - GLOBAL_Q);
//Считаю ряд фурье
xx = multiply_27(x, x);
tmp = ONE_27 - multiply_27(one_110, xx);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_72);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_42);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_20);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_6);
tmp = multiply_27(x, tmp);
return tmp >> (27 - GLOBAL_Q); //Перед возвращением из функции преобразую в первоначальный формат
}
long cos_fixed(long x)
{
//Константы сделал ститическими, что бы они вычислялись во время запуска программы, а не исполнения
static long FIXED_2PI = float_to_fixed(TWO_PI);
static long FIXED_PI = float_to_fixed(PI);
static long FIXED_PIna2 = float_to_fixed(PI_2);
//Здесть так же что бы не производить операции деления посчитал констаны ряда Тейлора
static long one_132 = float_to_fixed_base_select(1./132, 27);
static long one_90 = float_to_fixed_base_select(1./90, 27);
static long one_56 = float_to_fixed_base_select(1./56, 27);
static long one_30 = float_to_fixed_base_select(1./30, 27);
static long one_12 = float_to_fixed_base_select(1./12, 27);
long xx, tmp, counter = 0;
while(x >= FIXED_2PI) { x -= FIXED_2PI;} //Помещаю аргумент в диапазон 2 ПИ
while(x < 0) { x += FIXED_2PI;}
x = _IQabs(x); //Так как косинус симметричен относительно нуля, нахожу его модуль
//проверяю угол на значения, при которых синус раве 0 или 1
if(x == 0) return 1 << GLOBAL_Q;
if(x == FIXED_PI) return -(1 << GLOBAL_Q);
if(x == (FIXED_PIna2) || (x == FIXED_3PIna2))return 0;
//Так как ряды быстрее сходнятся при малых значениях, помещаю значение аргумента
//в ближайшие к нулю области
while(x > FIXED_PIna2)
{
x -= FIXED_PIna2;
counter++;
}
if(counter == 1 || counter == 3) { x = FIXED_PIna2 - x;}
//Перевожу в формат с максимальной точностью для возможного дипазона значений
x <<= (27 - GLOBAL_Q);
//Считаю ряд фурье
xx = multiply_27(x, x);
tmp = ONE_27 - multiply_27(xx, one_132);
tmp= multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(xx, one_90);
tmp= multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_56);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_30);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - multiply_27(tmp, one_12);
tmp = multiply_27(xx, tmp);
tmp = ONE_27 - (tmp >> 1);
tmp >>= (27 - GLOBAL_Q);
return (counter == 0) || (counter == 3) ? tmp : -tmp;
}
long sqrt_fixed(long x)
{
int variable_size_bits = sizeof(x) << 3;
long average_val, prev_avg_val;
if(x <= 0) return 0;
while(!(x & (1 << --variable_size_bits))); //Нахожу старший значащий бит
//Нахожу приближение корня сдвгом на половину числа бит между старшим значащим битом
//и положением точки
if(variable_size_bits > GLOBAL_Q)
{
average_val = x >> ((variable_size_bits - GLOBAL_Q) >> 1);
}
else
{
average_val = x << ((GLOBAL_Q - variable_size_bits) >> 1);
}
prev_avg_val = divide(x, average_val); //Нахожу 1/А
//В цикле нахожу среднее арифметическое между А и 1/А, пока число не перестанет меняться
while(_IQabs(prev_avg_val - average_val) > 1)
{
prev_avg_val = average_val;
average_val = (average_val + divide(x, average_val)) >> 1;
}
return average_val;
}
long exp_fixed(long x)
{
// static long FIXED_2PI = float_to_fixed(TWO_PI);
float f = _IQtoF(x);
float r1 = exp(f);
if (r1>127) r1=127;
if (r1<-127) r1=-127;
long r2 = _IQ(r1);
return r2;
}
long exp_fixedN(long x, unsigned int n)
{
if (n==18)
{
float f = _IQ18toF(x);
float r1 = exp(f);
if (r1>8100) r1=8100;
if (r1<-8100) r1=-8100;
long r2 = _IQ(r1);
return r2;
}
}

View File

@ -1,32 +0,0 @@
/* =================================================================================
File name: DMCTYPE.H
Originator: Digital Control Systems Group
Texas Instruments
Description: DMC data type definition file.
=====================================================================================
History:
-------------------------------------------------------------------------------------
04-15-2005 Version 3.20
------------------------------------------------------------------------------*/
#ifndef DMCTYPE
#define DMCTYPE
//---------------------------------------------------------------------------
// For Portability, User Is Recommended To Use Following Data Type Size
// Definitions For 16-bit and 32-Bit Signed/Unsigned Integers:
//
#ifndef DSP28_DATA_TYPES
#define DSP28_DATA_TYPES
typedef int int16;
typedef long int32;
typedef unsigned int Uint16;
typedef unsigned long Uint32;
typedef float float32;
typedef long double float64;
#endif
#endif // DMCTYPE

View File

@ -1,719 +0,0 @@
#include <math.h>
#include <stdlib.h>
//#include "project.h"
#include "IQmathLib.h"
//#include "f281xpwm.h"
//
////#include "SpaceVectorPWM.h"
//#include "MemoryFunctions.h"
//#include "PWMTools.h"
//#include "pwm_vector_regul.h"
//#include "PWMTMSHandle.h"
//#include "TuneUpPlane.h"
//#include "RS_Functions.h"
//#include "CAN_setup.h"
//#include "global_time.h"
#include "params.h"
#include "vector.h"
//#include "rmp_cntl_my1.h"
//#include "vhzprof.h"
//#include "adc_tools.h"
//#include "v_pwm24.h"
//#include "break_regul.h"
//#include "break_tools.h"
//#include "detect_phase.h"
//#include "mathlib.h"
//#include "project.h"
//#include "log_to_memory.h"
//#include "rotation_speed.h"
//#include "detect_overload.h"
//#include "xp_write_xpwm_time.h"
//#include "errors.h"
//#include "sync_tools.h"
//#include "optical_bus.h"
//#include "IQmathLib.h"
#define DEF_FREQ_PWM_XTICS (3750000 / FREQ_PWM / 2)
#define DEF_PERIOD_MIN_XTICS 400 //375 ~ 100mks //315 ~ 84 mks //460//(3750000 * mks / 1000000)
#define DEF_PERIOD_MIN_BR_XTICS 165
#define DEF_FREQ_PWM_XTICS_MIN = 4261
#define DEF_FREQ_PWM_XTICS_MAX = 4687
#define STOP_ROTOR_LIMIT 27962 //2 rpm
#define STOP_ROTOR_MIN_CURRENT 4194304 //750A //3355443 //600A
#define K_MODUL_MAX 15770583 //13421772 //80% //10066329 //60% //5033164 //30% 15099494 ~ 90% //15435038 ~ 0.92%
//15770583 ~ 0.94%
#define MIN_Fsl_WHEN_STOPED 41943 //0.05 //67108 //0.08Hz
#define PWM_ONE_INTERRUPT_RUN 1
#define PWM_TWICE_INTERRUPT_RUN 0
//4464
// ×àñòîòà ØÈÌ â xilinx òèêàõ (60000000 / 16 / FREQ_PWM = 3750000 / FREQ_PWM)
#pragma DATA_SECTION(VAR_FREQ_PWM_XTICS,".fast_vars1");
int VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS;
// Ìèíèìàëüíîå çíà÷åíèå ØÈÌà â xilinx òèêàõ
#pragma DATA_SECTION(VAR_PERIOD_MAX_XTICS,".fast_vars1");
int VAR_PERIOD_MAX_XTICS = DEF_FREQ_PWM_XTICS - DEF_PERIOD_MIN_XTICS;
// Ìèíèìàëüíîå çíà÷åíèå ØÈÌà â xilinx òèêàõ (mintime+deadtime) (Fïèëû * Tìèí.êëþ÷à.ñåê = (60 / 16 / 2) * Tìêñ = (60 * Tìêñ / 16 / 2))
#pragma DATA_SECTION(VAR_PERIOD_MIN_XTICS,".fast_vars1");
int VAR_PERIOD_MIN_XTICS = DEF_PERIOD_MIN_XTICS;//
// Ìèíèìàëüíîå çíà÷åíèå ØÈÌà â xilinx òèêàõ äëÿ òîðìîçíûõ êëþ÷åé (mintime) (Fïèëû * Tìèí.êëþ÷à.ñåê = (60 / 16 / 2) * Tìêñ = (60 * Tìêñ / 16 / 2))
#pragma DATA_SECTION(VAR_PERIOD_MIN_BR_XTICS,".fast_vars1");
int VAR_PERIOD_MIN_BR_XTICS = DEF_PERIOD_MIN_BR_XTICS;//
#pragma DATA_SECTION(freq1,".fast_vars1");
_iq freq1;
#pragma DATA_SECTION(k1,".fast_vars1");
_iq k1 = 0;
RMP_MY1 rmp_freq = RMP_MY1_DEFAULTS;
//VHZPROF vhz1 = VHZPROF_DEFAULTS;
// WINDING a;
// FLAG f;
#define COUNT_SAVE_LOG_OFF 100 //Ñêîëüêî òàêòîâ ØÈÌ ñîõðàíÿåòñÿ ïîñëå îñòàíîâêè
#define COUNT_START_IMP 2
int i = 0;
/*void InitPWM()
{
WriteMemory(ADR_PWM_MODE_0, 0x0000); //Âûáèðàåì â êà÷åñòâå èñòî÷íèêà ØÈÌ TMS
}*/
static void write_swgen_pwm_times();
void write_swgen_pwm_times_split_eages(unsigned int mode_reload);
void fix_pwm_freq_synchro_ain();
void detect_level_interrupt(void);
void detect_current_saw_val(void);
void InitXPWM(void)
{
#ifdef XPWMGEN
/* Start of PWM Generator initialization*/
for(i = 0; i < 16; i++) // Îáíóëÿåì
{
WriteMemory(ADR_PWM_KEY_NUMBER, i);
WriteMemory(ADR_PWM_TIMING, 0);
}
WriteMemory(ADR_PWM_DIRECT, 0xffff);
WriteMemory(ADR_PWM_DRIVE_MODE, 0); //Choose PWM sourse PWMGenerator on Spartan 200e
WriteMemory(ADR_PWM_DEAD_TIME, 360); //Dead time in tics. 1 tic = 16.67 nsec
#ifndef _test_without_power
// OFF WDOG
WriteMemory(ADR_PWM_WDOG, 0x8005); //TODO turn on
#else
// ON WDOG
WriteMemory(ADR_PWM_WDOG, 0x0005); //TODO turn on
#endif
WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec
WriteMemory(ADR_PWM_SAW_DIRECT, 0x0555);
WriteMemory(ADR_TK_MASK_0, 0);
WriteMemory(ADR_TK_MASK_1, 0xffff); //Turn off additional 16 tk lines
#if C_PROJECT_TYPE == PROJECT_BALZAM
WriteMemory(ADR_PWM_IT_TYPE, 1); //1 interrupt per PWM period
#else
WriteMemory(ADR_PWM_IT_TYPE, 0); //interrupt on each counter twist
#endif
// WriteMemory(ADR_PWM_WDOG, 0x8008);//ðàçðåøåíèå îøèáêè ïî PWM
#endif
#ifdef TMSPWMGEN
WriteMemory(ADR_PWM_MODE_0, 0x0000); //Âûáèðàåì â êà÷åñòâå èñòî÷íèêà ØÈÌ TMS
#endif
/* End îf PWM Gen init */
}
void initPWM_Variables(void)
{
//Äëÿ ïåðâîé ïèëû çàêðûòî, êîãäà âûøå çàäàííîãî óðîâíÿ, äëÿ âòîðîé íèæå
// xpwm_time.Tclosed_0 = 0;
// xpwm_time.Tclosed_1 = VAR_FREQ_PWM_XTICS + 1;
// xpwm_time.pwm_tics = VAR_FREQ_PWM_XTICS;
// xpwm_time.saw_direct.all = 0;//0x0555;
// xpwm_time.one_or_two_interrupts_run = PWM_TWICE_INTERRUPT_RUN;
init_alpha_pwm24(VAR_FREQ_PWM_XTICS);
InitVariablesSvgen(VAR_FREQ_PWM_XTICS);
init_DQ_pid();
break_resistor_managment_init();
rmp_freq.RampLowLimit = _IQ(-4); //0
rmp_freq.RampHighLimit = _IQ(4);
rmp_freq.RampPlus = _IQ(0.00005); //_IQ(0.0002);_IQ(0.000005);
rmp_freq.RampMinus = _IQ(-0.00005); //_IQ(-0.000005);
rmp_freq.DesiredInput = 0;
rmp_freq.Out = 0;
a.k = 0;
a.k1 = 0;
a.k2 = 0;
k1 = 0;
freq1 = 0;
}
#pragma CODE_SECTION(start_PWM24,".fast_run2")
void start_PWM24(int O1, int O2)
{
if ((O1 == 1) && (O2 == 1))
{
start_pwm();
}
else
{
if ((O1 == 0) && (O2 == 1))
{
start_pwm_b();
}
if ((O1 == 1) && (O2 == 0))
{
start_pwm_a();
}
}
}
inline void init_regulators()
{
if(f.Mode != 0)
{
pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor,
rotor.iqFout, f.Mode, 1, 1);
}
}
#define select_working_channels(go_a, go_b) go_a = !f.Obmotka1; \
go_b = !f.Obmotka2;
void PWM_interrupt()
{
static unsigned int pwm_run = 0;
static _iq Uzad1, Fzad, Uzad2;
static int count_step=0;
static int count_step_ram_off = 0;
static int count_start_impuls = 0;
static int flag_record_log = 0;
static int log_saved_to_const_mem = 0;
static int prevGo = -1;
static volatile unsigned int go_a = 0;
static volatile unsigned int go_b = 0;
static int stop_rotor_counter = 0;
static int prev_go_a = 1;
static int prev_go_b = 1;
int pwm_enable_calc_main = 0;
int start_int_xtics = 0, end_int_xtics = 0;
// i_led1_on_off(1);
if (pwm_run == 1)
{
// stop_pwm();
// errors.slow_stop.bit.PWM_interrupt_to_long |= 1;
return;
}
pwm_run = 1;
// detect_level_interrupt();
// start_int_xtics = xpwm_time.current_period;
if (xpwm_time.where_interrupt == PWM_LOW_LEVEL_INTERRUPT
|| xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN)
{
pwm_enable_calc_main = 1;
if (f.flag_second_PCH) {
fix_pwm_freq_synchro_ain();
}
}
else {
// i_sync_pin_on();
pwm_enable_calc_main = 0;
}
// project.cds_in[0].read_pbus(&project.cds_in[0]); //read direction
// project.read_all_pbus();
// optical_bus_read();
update_rot_sensors();
global_time.calc(&global_time);
//
inc_RS_timeout_cicle();
inc_CAN_timeout_cicle();
detect_I_M_overload();
DetectI_Out_BreakFase();
Rotor_measure();
if ((f.Go == 1) && (f.Stop == 0)
&& (f.rotor_stopped == 0)
// && (faults.faults5.bit.rotor_stopped == 0)
/* && (f.Ready2 == 1)*/)
{
if (f.Ready2) {f.flag_turn_On_Pump = 1;} //Íà âñ-êèé ñëó÷àé
if (f.Go != prevGo) {
set_start_mem(FAST_LOG);
// clear_mem(FAST_LOG);
// count_start_impuls = 0;
count_step = 0;
count_step_ram_off = COUNT_SAVE_LOG_OFF;
init_regulators();
stop_rotor_counter = 0;
} else {
if (f.Mode == 0) {
rmp_freq.DesiredInput = freq1;
rmp_freq.calc(&rmp_freq);
// Fzad = rmp_freq.Out;
Fzad = freq1;
// if(k1 < 87772)
// { k1 = 87772;}
Uzad1 = k1;
Uzad2 = k1;
}
select_working_channels(go_a, go_b);
if (go_a == 0 && prev_go_a != go_a) {
stop_pwm_a();
}
if (go_a == 1 && prev_go_a != go_a) {
start_pwm_a();
}
if (go_b == 0 && prev_go_b != go_b) {
stop_pwm_b();
}
if (go_b == 1 && prev_go_b != go_b) {
start_pwm_b();
}
prev_go_a = go_a;
prev_go_b = go_b;
if (count_start_impuls < COUNT_START_IMP) {
count_start_impuls++;
Fzad = 0;
rmp_freq.Out = 0;
// set_start_mem(FAST_LOG);
// set_start_mem(SLOW_LOG);
} else {
if (count_start_impuls==2)
{
if (go_a == 1 && go_b == 1) {
// òóò âûñòàâëåíî middle ñîñòîÿíèå êëþ÷åé ïåðåä ðàçðåøåíèåì âûõîäîâ pwm
// start_pwm(); äîëæåí âûçâàòüñÿ îäèí ðàç çà èçìåíåíèå f.Go
start_pwm();
} else if (go_a == 1) {
write_swgen_pwm_times(); //TODO: Check with new PWM
start_pwm_a();
} else if (go_b == 1) {
write_swgen_pwm_times();
start_pwm_b();
}
} // end if (count_start_impuls==1)
count_start_impuls++;
if (count_start_impuls > 2 * COUNT_START_IMP) {
count_start_impuls = 2 * COUNT_START_IMP;
}
}
}
flag_record_log = 1;
log_saved_to_const_mem = 0;
} else {
if (f.Discharge
&& (errors.slow_stop2.bit.Break_Resistor == 0)
&& (errors.plains_and_others.bit.er0_setted == 0)
&& (errors.umu_errors.bit.Voltage380_BSU_Off == 0))
// && !f.Stop)
{
start_break_pwm();
break_resistor_managment_calc();
} else {
//Do not stop, when come for the first time, to write to xilinx times to close keys.
//Otherwise mintime error can occure.
//Also we do not stop pwm wile break_resistor keys working
if (!count_start_impuls) {
// ýòî ïðîèçîéäåò òîëüêî íà âòîðîì òàêòå âûêëþ÷åíèÿ
stop_pwm();
}
break_resistor_set_closed();
}
if (count_step_ram_off > 0) {
count_step_ram_off--;
flag_record_log = 1;
} else {
flag_record_log = 0;
}
pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor,
rotor.iqFout, 0, 1, 1);
if (count_start_impuls > 0) {
count_start_impuls -= 1;
} else {
count_start_impuls = 0;
}
Uzad1 = 87772; //0.5%
Uzad2 = 87772;
k1 = Uzad1;
svgen_pwm24_1.Gain = Uzad1;
svgen_pwm24_2.Gain = Uzad1;
svgen_dq_1.Ualpha = 0;
svgen_dq_1.Ubeta = 0;
svgen_dq_2.Ualpha = 0;
svgen_dq_2.Ubeta = 0;
a.iqk = Uzad1;
}
// a.iqk1 = Uzad1;
// a.iqk2 = Uzad2;
// a.iqk = (a.iqk1 + a.iqk2) >> 1;
// a.iqf = Fzad;
prevGo = f.Go;
break_resistor_recup_calc();
break_resistor_managment_update();
if (count_start_impuls >= (2 * COUNT_START_IMP) ) {
if (f.Mode == 0) {
// test_calc_pwm24(Uzad1, Uzad2, Fzad);
if (pwm_enable_calc_main) {
test_calc_simple_dq_pwm24(Uzad1, Uzad2, Fzad, Fzad, K_MODUL_MAX);
}
analog_dq_calc_const();
} else {
if ((_IQabs(rotor.iqFout) < STOP_ROTOR_LIMIT)
&& (_IQabs(analog.iqIq1) > STOP_ROTOR_MIN_CURRENT)) {
if ((stop_rotor_counter >= 2520)) {
stop_rotor_counter = 2520;
// faults.faults5.bit.rotor_stopped |= 1;
f.rotor_stopped |= 1;
} else {
stop_rotor_counter += 1;
}
if (_IQabs(analog.Fsl) < MIN_Fsl_WHEN_STOPED) {
// faults.faults5.bit.rotor_stopped |= 1;
f.rotor_stopped |= 1;
}
} else {
if (stop_rotor_counter > 0) {
stop_rotor_counter -= 1;
} else {
stop_rotor_counter = 0;
}
}
pwm_vector_model_titov(f.iq_p_zad, f.iq_fzad, rotor.direct_rotor,
rotor.iqFout, f.Mode, 0, pwm_enable_calc_main);
}
} else {
// òóò îïÿòü middle ñîñòîÿíèå ïåðåä âûêëþ÷åíèåì êëþ÷åé
if (count_start_impuls)
{
// svgen_set_time_keys_closed(&svgen_pwm24_1);
// svgen_set_time_keys_closed(&svgen_pwm24_2);
svgen_set_time_middle_keys_open(&svgen_pwm24_1);
svgen_set_time_middle_keys_open(&svgen_pwm24_2);
}
else
// à òóò ìû óæå âûêëþ÷èëèñü
{
svgen_set_time_keys_closed(&svgen_pwm24_1);
svgen_set_time_keys_closed(&svgen_pwm24_2);
//Ñíèìàåì çàïðåò ØÈÌà
// if (faults.faults5.bit.rotor_stopped == 1) {
if (f.rotor_stopped == 1) {
if (stop_rotor_counter > 0) {
stop_rotor_counter -= 1;
} else {
// faults.faults5.bit.rotor_stopped = 0;
f.rotor_stopped = 0;
stop_rotor_counter = 0;
}
} else {
stop_rotor_counter = 0;
}
}
}
if (f.Mode) {
a.iqf = analog.iqFstator;
} else {
a.iqf = Fzad;
analog.iqFstator = Fzad;
a.iqk1 = _IQsqrt(_IQmpy(svgen_dq_1.Ualpha, svgen_dq_1.Ualpha) + _IQmpy(svgen_dq_1.Ubeta, svgen_dq_1.Ubeta)); //For output Kmodul to terminal
a.iqk2 = _IQsqrt(_IQmpy(svgen_dq_2.Ualpha, svgen_dq_2.Ualpha) + _IQmpy(svgen_dq_2.Ubeta, svgen_dq_2.Ubeta)); //end counting Uout
}
a.iqk = (a.iqk1 + a.iqk2) / 2;
// write_swgen_pwm_times();
if (xpwm_time.one_or_two_interrupts_run == PWM_ONE_INTERRUPT_RUN)
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE);
else
{
if (f.Go == 1)
{
if (count_start_impuls == (2 * COUNT_START_IMP))
{
if (pwm_enable_calc_main)
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_HIGH);
else
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_LOW);
}
else
// if (pwm_enable_calc_main)
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE);
}
else
{
if (count_start_impuls == (2 * COUNT_START_IMP) - 1)
{
if (pwm_enable_calc_main)
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_HIGH);
else
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_LOW);
}
else
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_FORCE);
}
// if (pwm_enable_calc_main)
// prev_run_calc_uf = run_calc_uf;
}
// logs recording
// if ((flag_record_log && !f.stop_Log) || f.Startstoplog)
// //if (f.Log1_Log2 == 1)// && f.Go == 1 && (!f.Stop))
// //if(f.Go == 1)
// {
// test_mem_limit(FAST_LOG, !f.Ciclelog);
// count_step++;
//
// if (count_step >= 0) {
// fillADClogs();
//// logpar.log13 = flag_record_log;
//// logpar.log14 = count_start_impuls;
//// logpar.log10 = (int16)_IQtoIQ15(analog.iqIq1_filter);
//// logpar.log11 = (int16)_IQtoIQ15(rotor.iqFrotFromOptica);
// logpar.log15 = (int16) _IQtoIQ15(analog.iqIq2);
// logpar.log16 = (int16) _IQtoIQ15(a.iqk1);
// logpar.log17 = (int16) _IQtoIQ15(analog.iqId1);
// logpar.log18 = (int16) _IQtoIQ15(analog.iqIq1);
//
//// logpar.log24 = (int16) break_result_1;
//// logpar.log25 = (int16) break_result_2;
// logpar.log27 = (int16)(_IQtoIQ15(analog.iqIbtr1_1));
// logpar.log28 = (int16)(_IQtoIQ15(analog.iqIbtr2_1));
//
// getFastLogs(!f.Ciclelog);
// count_step = 0;
// }
// } else {
// if (f.Stop && log_saved_to_const_mem == 0) {
// logpar.copy_log_to_const_memory = 1;
// log_saved_to_const_mem = 1;
// }
// }
// optical_bus_write();
// detect_current_saw_val();
end_int_xtics = xpwm_time.current_period;
f.PWMcounterVal = labs(start_int_xtics - end_int_xtics);
pwm_run = 0;
i_sync_pin_off();
// i_led1_on_off(0);
}
void slow_vector_update()
{
_iq iqKzad = 0;
freq1 = _IQ (f.fzad/F_STATOR_MAX);//f.iqFRotorSetHz;
iqKzad = _IQ(f.kzad);
k1 = zad_intensiv_q(30000, 30000, k1, iqKzad); //20000
}
//#pragma CODE_SECTION(write_swgen_pwm_times,".fast_run");
//void write_swgen_pwm_times()
//{
// xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0.Ti;
// xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1.Ti;
// xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0.Ti;
// xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1.Ti;
// xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0.Ti;
// xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1.Ti;
//
// xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0.Ti;
// xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1.Ti;
// xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0.Ti;
// xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1.Ti;
// xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0.Ti;
// xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1.Ti;
//
// xpwm_time.Tbr0_0 = break_result_1;
// xpwm_time.Tbr0_1 = break_result_2;
// xpwm_time.Tbr1_0 = break_result_3;
// xpwm_time.Tbr1_1 = break_result_4;
//
// xpwm_time.write_1_2_winding_break_times(&xpwm_time);
//
//
//// logpar.log29 = xpwm_time.Ta0_0;
//// logpar.log30 = xpwm_time.Ta0_1;
//// logpar.log10 = xpwm_time.Tb0_0;
//// logpar.log11 = xpwm_time.Tb0_1;
//// logpar.log12 = xpwm_time.Tc0_0;
//// logpar.log13 = xpwm_time.Tc0_1;
//// logpar.log7 = _IQtoIQ12(svgen_pwm24_1.Alpha);
//// logpar.log8 = xpwm_time.Ta0_0 - xpwm_time.Tb0_0;
//// logpar.log9 = xpwm_time.Ta0_1 - xpwm_time.Tb0_1;
//// logpar.log10 = xpwm_time.Tb0_0 - xpwm_time.Tc0_0;
//// logpar.log11 = xpwm_time.Tb0_1 - xpwm_time.Tc0_1;
//// logpar.log12 = xpwm_time.Tc0_0 - xpwm_time.Ta0_0;
//// logpar.log13 = xpwm_time.Tc0_1 - xpwm_time.Ta0_1;
//
//}
//#pragma CODE_SECTION(write_swgen_pwm_times_split_eages,".fast_run2");
//void write_swgen_pwm_times_split_eages(unsigned int mode_reload)
//{
//
// xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Tc_0.Ti;
// xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Tc_1.Ti;
// xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0.Ti;
// xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1.Ti;
// xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Ta_0.Ti;
// xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Ta_1.Ti;
//
// xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Tc_0.Ti;
// xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Tc_1.Ti;
// xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0.Ti;
// xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1.Ti;
// xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Ta_0.Ti;
// xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Ta_1.Ti;
//
// xpwm_time.Tbr0_0 = break_result_1;
// xpwm_time.Tbr0_1 = break_result_2;
// xpwm_time.Tbr1_0 = break_result_3;
// xpwm_time.Tbr1_1 = break_result_4;
//
// xpwm_time.mode_reload = mode_reload;
//
// xpwm_time.write_1_2_winding_break_times_split(&xpwm_time);
//}
#define CONST_IQ_1 16777216 //1
//#pragma CODE_SECTION(fix_pwm_freq_synchro_ain,".fast_run");
//void fix_pwm_freq_synchro_ain()
//{
//// if (f.Sync_input_or_output == SYNC_INPUT)
// {
// sync_inc_error();
//
// if (f.disable_sync || f.sync_ready == 0)
// {
//
//
// return;
// }
//
// if (f.pwm_freq_plus_minus_zero==1)
// {
//
//
// //Increment xtics
// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS + 1;
// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec
//
// change_freq_pwm(VAR_FREQ_PWM_XTICS);
//
//
// }
//
// if (f.pwm_freq_plus_minus_zero==-1)
// {
// //4464
// //Decrement xtics
// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS - 1;
// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS); // Saw period in tics. 1 tic = 16.67 nsec
//
// change_freq_pwm(VAR_FREQ_PWM_XTICS);
//
// }
//
// if (f.pwm_freq_plus_minus_zero==0)
// {
// VAR_FREQ_PWM_XTICS = DEF_FREQ_PWM_XTICS - 1;
// WriteMemory(ADR_PWM_PERIOD, VAR_FREQ_PWM_XTICS);
// change_freq_pwm(VAR_FREQ_PWM_XTICS);
// }
//
// }
//
//
//
//}
//void detect_level_interrupt(void)
//{
//
// WriteMemory(ADR_SAW_REQUEST, 0x8000);
// xpwm_time.current_period = ReadMemory(ADR_SAW_VALUE);
//
// if (xpwm_time.current_period<xpwm_time.pwm_tics/2)
// xpwm_time.where_interrupt = PWM_LOW_LEVEL_INTERRUPT;
//
// if (xpwm_time.current_period>xpwm_time.pwm_tics/2)
// xpwm_time.where_interrupt = PWM_HIGH_LEVEL_INTERRUPT;
//
//}
//
//void detect_current_saw_val(void)
//{
// WriteMemory(ADR_SAW_REQUEST, 0x8000);
// xpwm_time.current_period = ReadMemory(ADR_SAW_VALUE);
//}

View File

@ -1,445 +0,0 @@
#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

View File

@ -1,748 +0,0 @@
// #include "project.h"
#include "adc_tools.h"
// #include "xp_project.h"
#include "IQmathLib.h"
#include "math.h"
#include "filter_v1.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
#if (USE_INTERNAL_ADC==1)
#if(C_adc_number==1)
unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0,R_ADC_DEFAULT_INTERNAL };
unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_INTERNAL };
float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_INTERNAL };
#endif
#if(C_adc_number==2)
unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1,R_ADC_DEFAULT_INTERNAL };
unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_INTERNAL };
float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_INTERNAL };
#endif
#if(C_adc_number==3)
unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2,R_ADC_DEFAULT_INTERNAL };
unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2, K_LEM_ADC_DEFAULT_INTERNAL };
float const K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2, NORMA_ADC_DEFAULT_INTERNAL };
#endif
#else
#if(C_adc_number==1)
#pragma DATA_SECTION(R_ADC,".slow_vars")
unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0 };
#pragma DATA_SECTION(K_LEM_ADC,".slow_vars")
unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0 };
#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars")
float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0 };
#endif
#if(C_adc_number==2)
#pragma DATA_SECTION(R_ADC,".slow_vars")
unsigned int const R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1 };
#pragma DATA_SECTION(K_LEM_ADC,".slow_vars")
unsigned int const K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1 };
#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars")
float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1 };
#endif
#if(C_adc_number==3)
#pragma DATA_SECTION(R_ADC,".slow_vars")
unsigned int R_ADC[COUNT_ARR_ADC_BUF][16] = { R_ADC_DEFAULT_0, R_ADC_DEFAULT_1, R_ADC_DEFAULT_2 };
#pragma DATA_SECTION(K_LEM_ADC,".slow_vars")
unsigned int K_LEM_ADC[COUNT_ARR_ADC_BUF][16] = { K_LEM_ADC_DEFAULT_0, K_LEM_ADC_DEFAULT_1, K_LEM_ADC_DEFAULT_2 };
#pragma DATA_SECTION(K_NORMA_ADC,".slow_vars")
float K_NORMA_ADC[COUNT_ARR_ADC_BUF][16] = { NORMA_ADC_DEFAULT_0, NORMA_ADC_DEFAULT_1, NORMA_ADC_DEFAULT_2 };
#endif
#endif
#pragma DATA_SECTION(ADC_f,".fast_vars");
int ADC_f[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(ADC_fast,".fast_vars");
int ADC_fast[COUNT_ARR_ADC_BUF][16][COUNT_ARR_ADC_BUF_FAST_POINT];
#pragma DATA_SECTION(ADC_sf,".fast_vars");
int ADC_sf[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(analog,".fast_vars");
ANALOG_VALUE analog = ANALOG_VALUE_DEFAULT;
#pragma DATA_SECTION(filter,".fast_vars");
ANALOG_VALUE filter = ANALOG_VALUE_DEFAULT;
#pragma DATA_SECTION(analog_zero,".fast_vars");
ANALOG_VALUE analog_zero = ANALOG_VALUE_DEFAULT;
unsigned int const level_err_ADC_PLUS[16] = level_err_ADC_PLUS_default;
unsigned int const level_err_ADC_MINUS[16] = level_err_ADC_MINUS_default;
#pragma DATA_SECTION(err_adc_protect,".fast_vars");
#pragma DATA_SECTION(mask_err_adc_protect,".fast_vars");
ERR_ADC_PROTECT err_adc_protect[COUNT_ARR_ADC_BUF], mask_err_adc_protect[COUNT_ARR_ADC_BUF];
_iq koef_Im_filter = 0;
_iq koef_Power_filter = 0;
_iq koef_Power_filter2 = 0;
#pragma DATA_SECTION(k_norm_ADC,".slow_vars")
_iq19 k_norm_ADC[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(iq19_zero_ADC,".fast_vars");
_iq19 iq19_zero_ADC[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(zero_ADC,".slow_vars")
int zero_ADC[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(iq19_k_norm_ADC,".fast_vars");
_iq19 iq19_k_norm_ADC[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(iq_norm_ADC,".fast_vars");
_iq iq_norm_ADC[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(iq_norm_ADC_sf,".fast_vars");
_iq iq_norm_ADC_sf[COUNT_ARR_ADC_BUF][16];
#pragma DATA_SECTION(koef_Uzpt_long_filter,".fast_vars");
_iq koef_Uzpt_long_filter = 0;
#pragma DATA_SECTION(koef_Uzpt_fast_filter,".fast_vars");
_iq koef_Uzpt_fast_filter = 0;
#pragma DATA_SECTION(koef_Uin_filter,".fast_vars");
_iq koef_Uin_filter = 0;
ANALOG_RAW_DATA rawData = {0};
void calc_norm_ADC(void);
void analog_values_calc(void);
_iq im_calc( _iq ia, _iq ib, _iq ic);
#define Shift_Filter 1 //2
void read_adc()
{
static unsigned int adr_adc = 0;
if(project.adc[0].status == component_Ready)
{
project.adc->read_pbus(&project.adc[0]);
ADC_f[0][0] = project.adc[0].read.pbus.adc_value[0];
ADC_f[0][1] = project.adc[0].read.pbus.adc_value[1];
ADC_f[0][2] = project.adc[0].read.pbus.adc_value[2];
ADC_f[0][3] = project.adc[0].read.pbus.adc_value[3];
ADC_f[0][4] = project.adc[0].read.pbus.adc_value[4];
ADC_f[0][5] = project.adc[0].read.pbus.adc_value[5];
ADC_f[0][6] = project.adc[0].read.pbus.adc_value[6];
ADC_f[0][7] = project.adc[0].read.pbus.adc_value[7];
ADC_f[0][8] = project.adc[0].read.pbus.adc_value[8];
ADC_f[0][9] = project.adc[0].read.pbus.adc_value[9];
ADC_f[0][10] = project.adc[0].read.pbus.adc_value[10];
ADC_f[0][11] = project.adc[0].read.pbus.adc_value[11];
ADC_f[0][12] = project.adc[0].read.pbus.adc_value[12];
ADC_f[0][13] = project.adc[0].read.pbus.adc_value[13];
ADC_f[0][14] = project.adc[0].read.pbus.adc_value[14];
ADC_f[0][15] = project.adc[0].read.pbus.adc_value[15];
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;
}
if(project.adc[1].status == component_Ready)
{
project.adc->read_pbus(&project.adc[1]);
// adr_adc = project.adc[1].adr_pbus.adr_table[0];
ADC_f[1][0] = project.adc[1].read.pbus.adc_value[0];
ADC_f[1][1] = project.adc[1].read.pbus.adc_value[1];
ADC_f[1][2] = project.adc[1].read.pbus.adc_value[2];
ADC_f[1][3] = project.adc[1].read.pbus.adc_value[3];
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;
/* Not used
ADC_sf[1][4] += (ADC_f[1][4] - ADC_sf[1][4]) >> Shift_Filter;
ADC_sf[1][5] += (ADC_f[1][5] - ADC_sf[1][5]) >> Shift_Filter;
ADC_sf[1][6] += (ADC_f[1][6] - ADC_sf[1][6]) >> Shift_Filter;
ADC_sf[1][7] += (ADC_f[1][7] - ADC_sf[1][7]) >> Shift_Filter;
ADC_sf[1][8] += (ADC_f[1][8] - ADC_sf[1][8]) >> Shift_Filter;
ADC_sf[1][9] += (ADC_f[1][9] - ADC_sf[1][9]) >> Shift_Filter;
ADC_sf[1][10] += (ADC_f[1][10] - ADC_sf[1][10]) >> Shift_Filter;
ADC_sf[1][11] += (ADC_f[1][11] - ADC_sf[1][11]) >> Shift_Filter;
ADC_sf[1][12] += (ADC_f[1][12] - ADC_sf[1][12]) >> Shift_Filter;
ADC_sf[1][13] += (ADC_f[1][13] - ADC_sf[1][13]) >> Shift_Filter;
ADC_sf[1][14] += (ADC_f[1][14] - ADC_sf[1][14]) >> Shift_Filter;
ADC_sf[1][15] += (ADC_f[1][15] - ADC_sf[1][15]) >> Shift_Filter;
*/
}
}
void acp_Handler(void)
{
//read_adc();
calc_norm_ADC_0(0);
//analog_values_calc();
// Read_Fast_Errors();
}
//#define COUNT_DETECT_ZERO 500
void init_Adc_Variables(void)
{
unsigned int k, i, j;
int* panalog, * pfilter;
volatile float k_f;
for (i = 0; i < COUNT_ARR_ADC_BUF; i++)
{
for (k = 0; k < 16; k++)
{
ADC_f[i][k] = 0;
ADC_sf[i][k] = 0;
for (j = 0; j < COUNT_ARR_ADC_BUF_FAST_POINT; j++)
ADC_fast[i][k][j] = 0;
k_f = K_LEM_ADC[i][k] * 2.5 / R_ADC[i][k] / 4096.0;
k_norm_ADC[i][k] = _IQ19(k_f);
k_f = K_LEM_ADC[i][k] * 250.0 / R_ADC[i][k] / K_NORMA_ADC[i][k] / 4096.0;
iq19_k_norm_ADC[i][k] = _IQ19(k_f);
zero_ADC[i][k] = DEFAULT_ZERO_ADC;//1835;
iq19_zero_ADC[i][k] = _IQ19(zero_ADC[i][k]); //_IQ19(2030);//_IQ19(1770);
}
}
panalog = (int*)&analog;
pfilter = (int*)&filter;
for (k = 0; k < sizeof(ANALOG_VALUE) / sizeof(int); k++)
{
*(panalog + k) = 0;
*(pfilter + k) = 0;
}
for (i = 0; i < COUNT_ARR_ADC_BUF; i++)
{
if (project.adc[i].status >= component_Ready)
detect_zero_analog(i);
}
// zero_ADC[1][2] = 2010;//1976; // uab
// zero_ADC[1][3] = 2010;//1989; // ubc
// zero_ADC[1][4] = 2010;//1994; // uca
zero_ADC[0][0] = zero_ADC[0][2];//2042;//1992;//1835; //uzpt
zero_ADC[0][1] = zero_ADC[0][2];//2042;//1992;//1835; //uzpt
#if (COUNT_ARR_ADC_BUF>1)
zero_ADC[1][1] = zero_ADC[1][15];
zero_ADC[1][2] = zero_ADC[1][15];
zero_ADC[1][3] = zero_ADC[1][15];
zero_ADC[1][4] = zero_ADC[1][15];
zero_ADC[1][5] = zero_ADC[1][15];
zero_ADC[1][6] = zero_ADC[1][15];
zero_ADC[1][7] = zero_ADC[1][15];
zero_ADC[1][8] = zero_ADC[1][15];
zero_ADC[1][9] = zero_ADC[1][15];
zero_ADC[1][10] = zero_ADC[1][15];
zero_ADC[1][11] = zero_ADC[1][15];
zero_ADC[1][12] = zero_ADC[1][15];
zero_ADC[1][13] = zero_ADC[1][15];
zero_ADC[1][14] = zero_ADC[1][15];
#endif
for (k = 0; k < 16; k++)
{
for (i = 0; i < COUNT_ARR_ADC_BUF; i++)
{
if ((zero_ADC[i][k] > 2200) || (zero_ADC[i][k] < 1900))
zero_ADC[i][k] = DEFAULT_ZERO_ADC;
}
}
for (k = 0; k < 16; k++)
{
for (i = 0; i < COUNT_ARR_ADC_BUF; i++)
{
iq19_zero_ADC[i][k] = _IQ19(zero_ADC[i][k]);//_IQ19(1770);
}
}
// koef_allADC_filter = _IQ19(0.00002/0.00003185);//koef_ADC_filter[0];
// koef_zero_ADC_filter=_IQ19(0.00002/0.0003185);
koef_Uzpt_long_filter = _IQ(0.001 / 0.016666);
koef_Uzpt_fast_filter = _IQ(0.001 / 0.002); //_IQ(0.001/0.00131);
koef_Uin_filter = _IQ(0.001 / 0.00931);
// koef_Im_filter = _IQ(0.001/0.006);
koef_Im_filter = _IQ(0.001 / 0.065);
koef_Power_filter = _IQ(0.001 / 0.065);
koef_Power_filter2 = _IQ(0.001 / 0.2);
// koef_Iabc_filter = _IQ(0.001/0.006);
filter.iqU_1_fast = 0;
filter.iqU_1_long = 0;
filter.iqU_2_fast = 0;
filter.iqU_2_long = 0;
filter.iqUin_m1 = 0;
filter.iqUin_m2 = 0;
// filter.iqU_3_fast = 0;
// filter.iqU_4_fast = 0;
// filter.iqU_1_long = 0;
// filter.iqU_2_long = 0;
// filter.iqU_3_long = 0;
// filter.iqU_4_long = 0;
// filter.iqIin_1 = 0;
// filter.iqIin_2 = 0;
filter.iqIm_1 = 0;
filter.iqIm_2 = 0;
// filter.iqUin_m1 = 0;
// filter.iqUin_m2 = 0;
for (i = 0; i < COUNT_ARR_ADC_BUF; i++)
{
mask_err_adc_protect[i].plus.all = 0;
mask_err_adc_protect[i].minus.all = 0x0;
err_adc_protect[i].plus.all = 0;
err_adc_protect[i].minus.all = 0x0;
}
#if (USE_INTERNAL_ADC==1)
Init_Internal_Adc();
#endif
}
inline _iq norma_adc(int plane, int chan, int n_norm)
{
// return _IQ19toIQ(_IQ19mpy((iq19_zero_ADC[n_norm] - ((long)ADC_sf[plane][chan]<<19) ),iq19_k_norm_ADC[n_norm]));
// return _IQ19toIQ(_IQ19mpy((((long)ADC_sf[plane][chan]<<19) - iq19_zero_ADC[n_norm]),iq19_k_norm_ADC[n_norm]));
return _IQ19toIQ(_IQ19mpy((((long)ADC_sf[plane][chan]<<19)),iq19_k_norm_ADC[n_norm]));
}
////////////////////////////////////////////////////////////////////
#pragma CODE_SECTION(norma_adc_nc,".fast_run");
#define SDVIG_K_FILTER_S 2 //1//(27.08.2009) //3
void norma_adc_nc(int nc)
{
int k;
// int bb;
for (k = 0; k < 16; k++)
{
ADC_f[nc][k] = project.adc[nc].read.pbus.adc_value[k];
ADC_sf[nc][k] += (((int)(ADC_f[nc][k] - ADC_sf[nc][k])) >> SDVIG_K_FILTER_S);
iq_norm_ADC[nc][k] = _IQ19toIQ(_IQ19mpy((-iq19_zero_ADC[nc][k] + ((long)ADC_f[nc][k] << 19)), iq19_k_norm_ADC[nc][k]));
}
}
////////////////////////////////////////////////////////////////////
#pragma CODE_SECTION(calc_norm_ADC_0,".fast_run");
void calc_norm_ADC_0(int run_norma)
{
_iq a1, a2, a3;
#if (USE_ADC_0)
if (run_norma)
norma_adc_nc(0);
#if (_FLOOR6)
analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit;
analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit;
#else
analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1;
analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2;
#endif
analog.iqIu_1 = iq_norm_ADC[0][2];
analog.iqIv_1 = iq_norm_ADC[0][3];
analog.iqIw_1 = iq_norm_ADC[0][4];
analog.iqIu_2 = iq_norm_ADC[0][5];
analog.iqIv_2 = iq_norm_ADC[0][6];
analog.iqIw_2 = iq_norm_ADC[0][7];
analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут
analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут
analog.iqUin_A1B1 = iq_norm_ADC[0][10];
// два варианта подключения датчиков 23550.1 более правильный - по схеме
// 23550.1
analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1
analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1
// 23550.3 bs1 bs2
// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3
// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3
//
analog.iqUin_B2C2 = iq_norm_ADC[0][13];
analog.iqIbreak_1 = iq_norm_ADC[0][14];
analog.iqIbreak_2 = iq_norm_ADC[0][15];
#else
analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 =
analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 =
analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2
= 0;
#endif
analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1);
analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2);
filter.iqU_1_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_1_long, analog.iqU_1);
filter.iqU_2_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_2_long, analog.iqU_2);
// analog.iqU_1_fast = filter_U1_3point(analog.iqU_1_fast);
filter.iqU_1_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_1_fast, analog.iqU_1);
filter.iqU_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_2_fast, analog.iqU_2);
// filter.iqUzpt_2_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqUzpt_2_2_fast, analog.iqUzpt_2_2);
//15
analog.iqIm_1 = im_calc(analog.iqIu_1, analog.iqIv_1, analog.iqIw_1);
analog.iqIm_2 = im_calc(analog.iqIu_2, analog.iqIv_2, analog.iqIw_2);
analog.iqIu = analog.iqIu_1 + analog.iqIu_2;
analog.iqIv = analog.iqIv_1 + analog.iqIv_2;
analog.iqIw = analog.iqIw_1 + analog.iqIw_2;
analog.iqIm = im_calc(analog.iqIu, analog.iqIv, analog.iqIw);
analog.iqIin_sum = analog.iqIin_1 + analog.iqIin_2;
// analog.iqIm_3 = im_calc(analog.iqIa1_1_fir_n+analog.iqIa2_1_fir_n, analog.iqIb1_1_fir_n+analog.iqIb2_1_fir_n, analog.iqIc1_1_fir_n+analog.iqIc2_1_fir_n);
analog.iqUin_m1 = im_calc(analog.iqUin_A1B1, analog.iqUin_B1C1, analog.iqUin_C1A1);
analog.iqUin_m2 = im_calc(analog.iqUin_A2B2, analog.iqUin_B2C2, analog.iqUin_C2A2);
// analog.iqUin_m2 = im_calc(analog.UinA2, analog.UinB2, analog.UinC2);
filter.iqUin_m1 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m1, analog.iqUin_m1);
filter.iqUin_m2 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m2, analog.iqUin_m2);
// i_led1_on_off(0);
// i_led1_on_off(1);
//1
filter.iqIm_1 = exp_regul_iq(koef_Im_filter, filter.iqIm_1, analog.iqIm_1);
filter.iqIm_2 = exp_regul_iq(koef_Im_filter, filter.iqIm_2, analog.iqIm_2);
filter.iqIm = exp_regul_iq(koef_Im_filter, filter.iqIm, analog.iqIm);
filter.iqIin_sum = exp_regul_iq(koef_Im_filter, filter.iqIin_sum, analog.iqIin_sum);
//3
// filter_batter2_Iin.InpVarCurr = (analog.iqIin_1)-ZERO_I_IN;
// filter_batter2_Iin.calc(&filter_batter2_Iin);
// filter.iqIin = _IQmpy(filter_batter2_Iin.Out,_IQ_09);
filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1);
filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2);
a1 = analog.iqU_1 + analog.iqU_2;
a2 = analog.iqIin_1;
a3 = _IQmpy(a1, a2);
analog.PowerScalar = a3;
// filter.Power = analog.iqU_1+analog.iqU_2;
filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar);
filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar);
}
////////////////////////////////////////////////////////////////////
void analog_values_calc(void)
{
//#if (USE_ADC_0)
//
//#if (_FLOOR6)
// analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1 + analog.iqU_1_imit;
// analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2 + analog.iqU_1_imit;
//#else
// analog.iqU_1 = iq_norm_ADC[0][0] - analog_zero.iqU_1;
// analog.iqU_2 = iq_norm_ADC[0][1] - analog_zero.iqU_2;
//#endif
// analog.iqIu_1 = iq_norm_ADC[0][2];
// analog.iqIv_1 = iq_norm_ADC[0][3];
// analog.iqIw_1 = iq_norm_ADC[0][4];
//
// analog.iqIu_2 = iq_norm_ADC[0][5];
// analog.iqIv_2 = iq_norm_ADC[0][6];
// analog.iqIw_2 = iq_norm_ADC[0][7];
//
// analog.iqIin_1 = -iq_norm_ADC[0][9]; // датчик перевернут
// analog.iqIin_2 = -iq_norm_ADC[0][9]; // датчик перевернут
//
// analog.iqUin_A1B1 = iq_norm_ADC[0][10];
//
// // два варианта подключения датчиков 23550.1 более правильный - по схеме
// // 23550.1
//
// analog.iqUin_B1C1 = iq_norm_ADC[0][11]; // 23550.1
// analog.iqUin_A2B2 = iq_norm_ADC[0][12]; // 23550.1
//
//// 23550.3 bs1 bs2
//
//// analog.iqUin_B1C1 = iq_norm_ADC[0][12]; // 23550.3
//// analog.iqUin_A2B2 = iq_norm_ADC[0][11]; // 23550.3
////
// analog.iqUin_B2C2 = iq_norm_ADC[0][13];
//
// analog.iqIbreak_1 = iq_norm_ADC[0][14];
// analog.iqIbreak_2 = iq_norm_ADC[0][15];
//
// #else
// analog.iqU_1 = analog.iqIu_1 = analog.iqIu_2 = analog.iqIv_1 = analog.iqIv_2 =
// analog.iqIw_1 = analog.iqIw_2 = analog.iqIin_1 = analog.iqIin_2 = analog.iqUin_A1B1 =
// analog.iqUin_B1C1 = analog.iqUin_A2B2 = analog.iqUin_B2C2 = analog.iqIbreak_1 = analog.iqIbreak_2
// = 0;
// #endif
//
// analog.iqUin_C1A1 = -(analog.iqUin_A1B1 + analog.iqUin_B1C1);
// analog.iqUin_C2A2 = -(analog.iqUin_A2B2 + analog.iqUin_B2C2);
//
//
//
// filter.iqU_1_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_1_long, analog.iqU_1);
// filter.iqU_2_long = exp_regul_iq(koef_Uzpt_long_filter, filter.iqU_2_long, analog.iqU_2);
//
//
// // analog.iqU_1_fast = filter_U1_3point(analog.iqU_1_fast);
// filter.iqU_1_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_1_fast, analog.iqU_1);
// filter.iqU_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqU_2_fast, analog.iqU_2);
//
//
// // filter.iqUzpt_2_2_fast = exp_regul_iq(koef_Uzpt_fast_filter, filter.iqUzpt_2_2_fast, analog.iqUzpt_2_2);
//
//
//
// //15
//
//
// analog.iqIm_1 = im_calc(analog.iqIu_1, analog.iqIv_1, analog.iqIw_1);
// analog.iqIm_2 = im_calc(analog.iqIu_2, analog.iqIv_2, analog.iqIw_2);
//
// analog.iqIu = analog.iqIu_1 + analog.iqIu_2;
// analog.iqIv = analog.iqIv_1 + analog.iqIv_2;
// analog.iqIw = analog.iqIw_1 + analog.iqIw_2;
//
// analog.iqIm = im_calc(analog.iqIu, analog.iqIv, analog.iqIw);
//
//
// analog.iqIin_sum = analog.iqIin_1 + analog.iqIin_2;
//
// // analog.iqIm_3 = im_calc(analog.iqIa1_1_fir_n+analog.iqIa2_1_fir_n, analog.iqIb1_1_fir_n+analog.iqIb2_1_fir_n, analog.iqIc1_1_fir_n+analog.iqIc2_1_fir_n);
//
// analog.iqUin_m1 = im_calc(analog.iqUin_A1B1, analog.iqUin_B1C1, analog.iqUin_C1A1);
// analog.iqUin_m2 = im_calc(analog.iqUin_A2B2, analog.iqUin_B2C2, analog.iqUin_C2A2);
//
// // analog.iqUin_m2 = im_calc(analog.UinA2, analog.UinB2, analog.UinC2);
//
// filter.iqUin_m1 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m1, analog.iqUin_m1);
// filter.iqUin_m2 = exp_regul_iq(koef_Uin_filter, filter.iqUin_m2, analog.iqUin_m2);
//
//
//
// // i_led1_on_off(0);
// // i_led1_on_off(1);
//
// //1
//
// filter.iqIm_1 = exp_regul_iq(koef_Im_filter, filter.iqIm_1, analog.iqIm_1);
// filter.iqIm_2 = exp_regul_iq(koef_Im_filter, filter.iqIm_2, analog.iqIm_2);
// filter.iqIm = exp_regul_iq(koef_Im_filter, filter.iqIm, analog.iqIm);
//
// filter.iqIin_sum = exp_regul_iq(koef_Im_filter, filter.iqIin_sum, analog.iqIin_sum);
//
// //3
// // filter_batter2_Iin.InpVarCurr = (analog.iqIin_1)-ZERO_I_IN;
// // filter_batter2_Iin.calc(&filter_batter2_Iin);
//
// // filter.iqIin = _IQmpy(filter_batter2_Iin.Out,_IQ_09);
//
//
// filter.iqIin_1 = exp_regul_iq(koef_Im_filter, filter.iqIin_1, analog.iqIin_1);
// filter.iqIin_2 = exp_regul_iq(koef_Im_filter, filter.iqIin_2, analog.iqIin_2);
//
// a1 = analog.iqU_1 + analog.iqU_2;
// a2 = analog.iqIin_1;
// a3 = _IQmpy(a1, a2);
// analog.PowerScalar = a3;
// // filter.Power = analog.iqU_1+analog.iqU_2;
// filter.PowerScalar = exp_regul_iq(koef_Power_filter, filter.PowerScalar, analog.PowerScalar);
// filter.PowerScalarFilter2 = exp_regul_iq(koef_Power_filter2, filter.PowerScalarFilter2, filter.PowerScalar);
}
#define CONST_IQ_11PI6 96629827 //11Pi/6
#define CONST_IQ_PI6 8784529 // Pi/6
/********************************************************************/
/* Определение нулy показаний АЦП */
/********************************************************************/
#pragma DATA_SECTION(acp_zero,".slow_vars")
_iq19 acp_zero[16];
#pragma DATA_SECTION(acp_summ,".slow_vars")
long acp_summ[16];
void detect_zero_analog(int nc)
{
long i, k;
_iq koef_zero_ADC_filter = _IQ19(0.00002 / 0.0003185);
for (k = 0; k < 16; k++)
{
acp_zero[k] = 0;
acp_summ[k] = 0;
}
for (i = 0; i < COUNT_DETECT_ZERO; i++)
{
// norma_all_adc();
norma_adc_nc(nc);
// norma_adc_nc(1);
for (k = 0; k < 16; k++)
{
acp_zero[k] = exp_regul_iq(koef_zero_ADC_filter, acp_zero[k], ((long)ADC_f[nc][k] << 19));
acp_summ[k] = acp_summ[k] + ADC_f[nc][k];
}
pause_1000(1000);
}
// 16 и 7 канал пропускаем т.к. это канал напрениy
for (k = 0; k < 16; k++)
{
// if ((k==15))
// {
// if (ADC_sf[k]<MIN_DETECT_UD_ZERO)
// iq19_zero_ADC[k] = acp_zero[k];
// }
// else
{
iq19_zero_ADC[nc][k] = acp_zero[k];
}
// zero_ADC[k] =_IQ19toF(acp_zero[k]);
zero_ADC[nc][k] = acp_summ[k] / COUNT_DETECT_ZERO;//_IQ19toF(acp_zero[k]);
}
}
unsigned int detect_protect_ACP_plus()
{
}
unsigned int detect_protect_ACP_minus()
{
}

View File

@ -1,25 +0,0 @@
#include "DSP281x_Device.h"
//#include "errors.h"
// #include "adc_tools.h"
// #include "can_watercool.h"
// #include "xp_project.h"
// #include "x_basic_types.h"
// #include "CAN_Setup.h"
// #include "vector.h"
// #include "PWMTMSHandle.h"
// #include "params.h"
// #include "params_protect.h"
// //#include "all_main_stuff.h"
// #include "global_time.h"
// #include "errors_temperature.h"
// #include "PWMTMSHandle.h"
// #include "rotation_speed.h"
// #include "io_verbal_names.h"
// #include "isolation.h"
// #include "global_time.h"
// #include "regul_power.h"
//ERRORS errors = ERRORS_DEFAULTS;
//FAULTS faults = {0,0,0};

View File

@ -1,73 +0,0 @@
#ifndef _IO_VERBAL_NAMES
#define _IO_VERBAL_NAMES
//#include "xp_project.h"
#define CHANNEL_IS_ON_IN1 1
#define CHANNEL_IS_ON_IN2 0
#define CHANNEL_IS_OFF 1
// //IN0
// #define IN_OIL_PUMP_IS_READY project.cds_in[0].read.pbus.data_in.bit.in4
// #define IN_LOCAL_CONTROL project.cds_in[0].read.pbus.data_in.bit.in9
// //IN0 UKSS READY
// #define IN_READY_BV1 project.cds_in[0].read.pbus.ready_in.bit.in5
// #define IN_READY_BV2 project.cds_in[0].read.pbus.ready_in.bit.in7
// #define IN_READY_UKSI project.cds_in[0].read.pbus.ready_in.bit.in10
// #define IN_READY_BI1 project.cds_in[0].read.pbus.ready_in.bit.in11
// #define IN_READY_BI2 project.cds_in[0].read.pbus.ready_in.bit.in13
// #define IN_READY_UMU project.cds_in[0].read.pbus.ready_in.bit.in15
// //IN1
// #define IN_EMERGENCY_STOP project.cds_in[1].read.pbus.data_in.bit.in0
// #define IN_PCH_IS_BLOCKED project.cds_in[1].read.pbus.data_in.bit.in1
// #define IN_PROTECTION_ERROR project.cds_in[1].read.pbus.data_in.bit.in2
// #define IN_BTR_IS_OFF project.cds_in[1].read.pbus.data_in.bit.in3
// #define IN_RESERVED_TO_INV2_1 project.cds_in[1].read.pbus.data_in.bit.in4
// #define IN_RECEIVED_TASK_FROM_SVU project.cds_in[1].read.pbus.data_in.bit.in5
// #define IN_QTV22_IS_ON project.cds_in[1].read.pbus.data_in.bit.in6
// #define IN_ERROR_PAIR_INV project.cds_in[1].read.pbus.data_in.bit.in8
// #define IN_BREAKING_K1 project.cds_in[1].read.pbus.data_in.bit.in9
// #define IN_ALARM_K2 project.cds_in[1].read.pbus.data_in.bit.in10
// #define IN_TURNDOWN_K4 project.cds_in[1].read.pbus.data_in.bit.in11 //îòêàç
// #define IN_BWC_NO_24VOLT_ERROR project.cds_in[1].read.pbus.data_in.bit.in12
// #define IN_BWC_AUTO_MODE project.cds_in[1].read.pbus.data_in.bit.in13
// #define IN_BSU_DOORS_ARE_CLOSED project.cds_in[1].read.pbus.data_in.bit.in15
// //IN2
// #define IN_PCH_IS_LEADING project.cds_in[2].read.pbus.data_in.bit.in0
// #define IN_PCH_IS_LEADING_2 project.cds_in[2].read.pbus.data_in.bit.in2
// #define IN_TEST_LAMPS project.cds_in[2].read.pbus.data_in.bit.in3
// #define IN_EMERGANCY_BUTTON project.cds_in[2].read.pbus.data_in.bit.in4
// #define IN_EMERGENCY_STOP_EXTERNAL project.cds_in[2].read.pbus.data_in.bit.in5
// #define IN_RESET_ERRORS project.cds_in[2].read.pbus.data_in.bit.in6
// #define IN_BSU_DOORS_ARE_BLOCKED project.cds_in[2].read.pbus.data_in.bit.in7
// //OUT0
// #define OUT_READY1 project.cds_out[0].write.sbus.data_out.bit.dout0
// #define OUT_READY2 project.cds_out[0].write.sbus.data_out.bit.dout1
// #define OUT_INVERTOR_ERROR project.cds_out[0].write.sbus.data_out.bit.dout2
// #define OUT_BATTERY_LOADED project.cds_out[0].write.sbus.data_out.bit.dout3
// #define OUT_CHARGE_BLOCKED project.cds_out[0].write.sbus.data_out.bit.dout4
// #define OUT_TURN_ON_BWC project.cds_out[0].write.sbus.data_out.bit.dout5
// #define OUT_OIL_PUMP project.cds_out[0].write.sbus.data_out.bit.dout6
// #define OUT_ALLOW_TURN_ON_QTV22 project.cds_out[0].write.sbus.data_out.bit.dout7
// #define OUT_CHOOSE_CHANNEL project.cds_out[0].write.sbus.data_out.bit.dout8
// #define OUT_RESET_ERRORS project.cds_out[0].write.sbus.data_out.bit.dout9
// #define OUT_TURN_ON_HIDRO_PODPOR project.cds_out[0].write.sbus.data_out.bit.dout10
// #define OUT_RECEIVED_TASK_FROM_SVU project.cds_out[0].write.sbus.data_out.bit.dout11
// #define OUT_RESERV_2 project.cds_out[0].write.sbus.data_out.bit.dout12
// //OUT1
// #define OUT_LAMP_READY1 project.cds_out[1].write.sbus.data_out.bit.dout0
// #define OUT_LAMP_READY2 project.cds_out[1].write.sbus.data_out.bit.dout1
// #define OUT_LAMP_BATTERY_LOADED project.cds_out[1].write.sbus.data_out.bit.dout2
// #define OUT_LAMP_FAULT project.cds_out[1].write.sbus.data_out.bit.dout3
// #define OUT_LAMP_OVERHEAT project.cds_out[1].write.sbus.data_out.bit.dout4
// #define OUT_LAMP_POWER_LIMIT project.cds_out[1].write.sbus.data_out.bit.dout5
// #define OUT_SWITCH_HI_VOLTAGE_TEST_LAMPS project.cds_out[1].write.sbus.data_out.bit.dout6
#endif //_IO_VERBAL_NAMES

View File

@ -1,428 +0,0 @@
#include "rotation_speed.h"
#include "xp_rotation_sensor.h"
#include "IQmathLib.h"
#include "params.h"
#include "adc_tools.h"
#include "rmp_cntl_my1.h"
#include "my_filter.h"
#include "vector.h"
#include "TuneUpPlane.h" //ñâåòîäèîäèê
#include "errors.h"
#include "log_to_memory.h"
#include "DSP281x_Device.h" //for int16
#pragma DATA_SECTION(rotor,".fast_vars1");
ROTOR_VALUE rotor = ROTOR_VALUE_DEFAULTS;
RMP_MY1 rmp_wrot = RMP_MY1_DEFAULTS;
_iq koef_Wout_filter = _IQ(0.2); //_IQ(0.15);
_iq koef_Wout_filter_long = _IQ(0.12);//_IQ(0.03);
static _iq impulses_To_iqF(unsigned int time, unsigned int impulses);
static _iq counter_To_iqF(unsigned int count, unsigned int freq_mode);
static _iq delta_Angle_To_iqF(unsigned long delta, unsigned int period);
static void sort_F_array(_iq *array, unsigned int size);
void rotorInit(void)
{
unsigned int i = 0, size = 0, *pint = 0;
rmp_wrot.RampLowLimit = 0;
rmp_wrot.RampHighLimit = _IQ(1);
rmp_wrot.RampPlus = _IQ(0.0015/NORMA_FROTOR);
rmp_wrot.RampMinus = _IQ(-0.0015/NORMA_FROTOR);
rmp_wrot.DesiredInput = 0;
rmp_wrot.Out = 0;
pint = (unsigned int*)&rotor;
size = sizeof(rotor) / sizeof(unsigned int);
for(i = 0; i < size; i++)
{
*(pint + i) = 0;
}
koef_Wout_filter = _IQ(0.2); //_IQ(0.15);
koef_Wout_filter_long = _IQ(0.001); //_IQ(0.0005);
}
#pragma CODE_SECTION(update_rot_sensors,".fast_run");
void update_rot_sensors()
{
// rotation_sensor.update_registers(&rotation_sensor);
}
#pragma CODE_SECTION(Rotor_measure,".fast_run");
void Rotor_measure(void)
{
static unsigned long PrevAngle1 = 0, PrevAngle2 = 0, PrevAngle3 = 0, PrevAngle4 = 0;
static unsigned int peroid_shim_mks = (unsigned int)(1000000L / FREQ_PWM / 2.0);
static _iq prev_wrot = 0;
static unsigned int prev_wrot_count = 0;
static int direct_accum = 0;
static int sens1_err_count = 0;
static int sens2_err_count = 0;
// unsigned int s_number = 0, begin_data = 0, end_data = 0, i;
// _iq accumulator = 0, deltaF = 0, deltaAngle = 0;
// rotation_sensor.read_sensors(&rotation_sensor);
// if(rotation_sensor.in_plane.read.regs.comand_reg.bit.update_registers)
// {
// rotor.error_update_count ++;
// }
// // logpar.log22 = rotation_sensor.in_plane.out.CountOne1;
// // logpar.log23 = rotation_sensor.in_plane.out.CountZero1;
// if(rotation_sensor.use_sensor1)
// {
// if((rotation_sensor.in_plane.out.CountOne1 <= 200)// && !rotation_sensor.in_plane.out.counter_freq1)
// || rotation_sensor.in_plane.out.CountOne1 == 65535)
// { rotation_sensor.in_plane.out.CountOne1 = 0; }
// if((rotation_sensor.in_plane.out.CountZero1 <= 200)// && !rotation_sensor.in_plane.out.counter_freq1)
// || rotation_sensor.in_plane.out.CountZero1 == 65535)
// { rotation_sensor.in_plane.out.CountZero1 = 0; }
// //Êîãäà èìïóëüñîâ ìàëî ñ÷èòàåì ïî ïåðèîäó
// if (rotation_sensor.in_plane.out.Impulses1 < 5) {
// if(rotation_sensor.in_plane.out.CountOne1) {
// rotor.iqFsensors[s_number++] = counter_To_iqF(rotation_sensor.in_plane.out.CountOne1,
// rotation_sensor.in_plane.out.counter_freq1);
// }
// if(rotation_sensor.in_plane.out.CountZero1) {
// rotor.iqFsensors[s_number++] = counter_To_iqF(rotation_sensor.in_plane.out.CountZero1,
// rotation_sensor.in_plane.out.counter_freq1);
// }
// }
// if(rotation_sensor.in_plane.out.Impulses1 > 2)
// {
// rotor.iqFsensors[s_number++] = impulses_To_iqF(rotation_sensor.in_plane.out.Time1,
// rotation_sensor.in_plane.out.Impulses1);
// // logpar.log11 = (int16) _IQtoIQ15(rotor.iqFsensors[s_number - 1]);
// } else {
// // logpar.log11 = 0;
// }
// if (rotor.iqF > 139810L)//10 rpm
// {
// if (rotation_sensor.in_plane.out.CountOne1 == 0 && rotation_sensor.in_plane.out.CountZero1 == 0
// && rotation_sensor.in_plane.out.Impulses1 == 0) {
// sens1_err_count += 1;
// } else {
// sens1_err_count = 0;
// }
// if (sens1_err_count > 50) {
// sens1_err_count = 50;
// faults.faults4.bit.Speed_Datchik_1_Off |= 1;
// }
// } else {
// sens1_err_count = 0;
// }
// }
// // logpar.log4 = rotation_sensor.in_plane.out.CountOne2;
// // logpar.log20 = rotation_sensor.in_plane.out.CountZero2;
// if(rotation_sensor.use_sensor2)
// {
// if((rotation_sensor.in_plane.out.CountOne2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2)
// || rotation_sensor.in_plane.out.CountOne2 == 65535)
// { rotation_sensor.in_plane.out.CountOne2 = 0; }
// if((rotation_sensor.in_plane.out.CountZero2 <= 200)// && !rotation_sensor.in_plane.out.counter_freq2)
// || rotation_sensor.in_plane.out.CountZero2 == 65535)
// { rotation_sensor.in_plane.out.CountZero2 = 0; }
// //Êîääà èìïóëüñîâ ìàëî, ñ÷èòàåì ïî ïåðèîäó
// if (rotation_sensor.in_plane.out.Impulses2 < 5) {
// if(rotation_sensor.in_plane.out.CountOne2) {
// rotor.iqFsensors[s_number++] = counter_To_iqF(rotation_sensor.in_plane.out.CountOne2,
// rotation_sensor.in_plane.out.counter_freq2);
// }
// if(rotation_sensor.in_plane.out.CountZero2) {
// rotor.iqFsensors[s_number++] = counter_To_iqF(rotation_sensor.in_plane.out.CountZero2,
// rotation_sensor.in_plane.out.counter_freq2);
// }
// }
// if(rotation_sensor.in_plane.out.Impulses2 > 2)
// {
// rotor.iqFsensors[s_number++] = impulses_To_iqF(rotation_sensor.in_plane.out.Time2,
// rotation_sensor.in_plane.out.Impulses2);
// // logpar.log16 = (int16) _IQtoIQ15(rotor.iqFsensors[s_number - 1]);
// }
// if (rotor.iqF > 139810L)//10 rpm
// {
// if (rotation_sensor.in_plane.out.CountOne2 == 0 && rotation_sensor.in_plane.out.CountZero2 == 0
// && rotation_sensor.in_plane.out.Impulses2 == 0) {
// sens2_err_count += 1;
// } else {
// sens2_err_count = 0;
// }
// if (sens2_err_count > 50) {
// sens2_err_count = 50;
// faults.faults4.bit.Speed_Datchik_2_Off |= 1;
// }
// } else {
// sens2_err_count = 0;
// }
// }
// if(rotation_sensor.use_angle_plane && (s_number < SENSORS_NUMBER))
// {
// if(rotation_sensor.rotation_plane.cds_rs->read.sbus.config.bit.channel1_enable && rotor.iqFsensors[0] && (s_number < (SENSORS_NUMBER - 1)))
// {
// if(rotation_sensor.rotation_plane.out.Delta_angle1 < 1500)
// {
// rotor.iqFsensors[s_number++] = delta_Angle_To_iqF(rotation_sensor.rotation_plane.out.Delta_angle1,
// rotation_sensor.rotation_plane.out.survey_time_mks);
// }
// deltaAngle = _IQabs(rotation_sensor.rotation_plane.out.Current_angle1 - PrevAngle1);
// if(deltaAngle > 1500)
// {
// deltaAngle = 262144 - deltaAngle;
// }
// if((deltaAngle < 291) && (deltaAngle >= 0))
// {
// rotor.iqFsensors[s_number++] =
// delta_Angle_To_iqF(deltaAngle, peroid_shim_mks);
// }
// PrevAngle1 = rotation_sensor.rotation_plane.out.Current_angle1;
// }
// // else
// // {
// // rotor.iqFsensors[s_number++] = 0;
// // rotor.iqFsensors[s_number++] = 0;
// // }
// if(rotation_sensor.rotation_plane.cds_rs->read.sbus.config.bit.channel2_enable && (s_number < (SENSORS_NUMBER - 1)))
// {
// rotor.iqFsensors[s_number++] = delta_Angle_To_iqF(rotation_sensor.rotation_plane.out.Delta_angle2,
// rotation_sensor.rotation_plane.out.survey_time_mks);
// rotor.iqFsensors[s_number++] =
// delta_Angle_To_iqF(_IQabs(rotation_sensor.rotation_plane.out.Current_angle2 - PrevAngle2),
// peroid_shim_mks);
// PrevAngle2 = rotation_sensor.rotation_plane.out.Current_angle2;
// }
// if(rotation_sensor.rotation_plane.cds_rs->read.sbus.config.bit.channel3_enable && (s_number < (SENSORS_NUMBER - 1)))
// {
// rotor.iqFsensors[s_number++] = delta_Angle_To_iqF(rotation_sensor.rotation_plane.out.Delta_angle3,
// rotation_sensor.rotation_plane.out.survey_time_mks);
// rotor.iqFsensors[s_number++] =
// delta_Angle_To_iqF(_IQabs(rotation_sensor.rotation_plane.out.Current_angle3 - PrevAngle3),
// peroid_shim_mks);
// PrevAngle3 = rotation_sensor.rotation_plane.out.Current_angle3;
// }
// if(rotation_sensor.rotation_plane.cds_rs->read.sbus.config.bit.channel4_enable && (s_number < (SENSORS_NUMBER - 1)))
// {
// rotor.iqFsensors[s_number++] = delta_Angle_To_iqF(rotation_sensor.rotation_plane.out.Delta_angle4,
// rotation_sensor.rotation_plane.out.survey_time_mks);
// rotor.iqFsensors[s_number++] =
// delta_Angle_To_iqF(_IQabs(rotation_sensor.rotation_plane.out.Current_angle4 - PrevAngle4),
// peroid_shim_mks);
// PrevAngle2 = rotation_sensor.rotation_plane.out.Current_angle4;
// }
// }
// // logpar.log22 = (int16) _IQtoIQ15(rotor.iqFsensors[0]);
// // logpar.log23 = (int16) _IQtoIQ15(rotor.iqFsensors[1]);
// // logpar.log24 = (int16) _IQtoIQ15(rotor.iqFsensors[2]);
// // logpar.log25 = (int16) _IQtoIQ15(rotor.iqFsensors[3]);
// // logpar.log29 = (int16) _IQtoIQ15(rotor.iqFsensors[4]);
// // logpar.log30 = (int16) _IQtoIQ15(rotor.iqFsensors[5]);
// if(s_number > SENSORS_NUMBER_ONLY_IN) {s_number = SENSORS_NUMBER_ONLY_IN;} //TODO set SENSORS_NUMBER when tune angle measure
// if(s_number > 3)
// {
// sort_F_array(rotor.iqFsensors, s_number);
// deltaF = rotor.iqFout >> 2;
// if(deltaF < 43000) // ~3 ob/min
// {
// deltaF = 43000;
// }
// i = 0;
// begin_data = 0;
// end_data = s_number; //TODO test, as usial
// while(i < s_number)
// {
// if(_IQabs(rotor.iqFout - rotor.iqFsensors[i]) >= deltaF)
// {
// i++;
// }
// else
// {
// break;
// }
// }
// if(i < s_number) { begin_data = i; }
// else {begin_data = 0;}
// while((i < s_number) && (_IQabs(rotor.iqFout - rotor.iqFsensors[i]) < deltaF))
// {
// i++;
// }
// if(i <= SENSORS_NUMBER)
// {
// end_data = i;
// }
// else
// {
// end_data = SENSORS_NUMBER;
// }
// }
// else
// {
// begin_data = 0;
// end_data = s_number;
// }
// if (begin_data >= end_data) { //This part to prevent freeze of speed on some level if signal lost
// begin_data = 0;
// end_data = s_number;
// }
// for(i = begin_data; i < end_data; i++)
// {
// accumulator += rotor.iqFsensors[i];
// }
// if(end_data != begin_data)
// {
// rotor.iqF = accumulator / (end_data - begin_data);
// prev_wrot_count = 0;
// }
// else
// {
// rotor.iqF = prev_wrot;
// prev_wrot_count += 1;
// }
// // logpar.log19 = (int16)(_IQtoIQ15(rotor.iqF));
// if (prev_wrot != rotor.iqF || rotor.iqF==0 )
// {
// rmp_wrot.DesiredInput = rotor.iqF;
// rmp_wrot.calc(&rmp_wrot);
// rotor.iqF = rmp_wrot.Out;
// }
// prev_wrot=rotor.iqF;
// //Îò çàâèñàíèÉà ñòàðîãî çíà÷åíèÉà.
// if (prev_wrot_count > 10) {
// prev_wrot = 0;
// prev_wrot_count = 10;
// }
// rotor.iqFout = exp_regul_iq(koef_Wout_filter, rotor.iqFout, rotor.iqF);
// rotor.iqFlong = exp_regul_iq(koef_Wout_filter_long, rotor.iqFlong, rotor.iqF);
// rotor.direct_rotor_in1 = rotation_sensor.in_plane.out.direction1;
// rotor.direct_rotor_in2 = rotation_sensor.in_plane.out.direction2;
// rotor.direct_rotor_angle = rotation_sensor.rotation_plane.out.direction;
// rotor.error.sens_err1 = rotation_sensor.in_plane.read.pbus.direction.bit.sens_err1;
// rotor.error.sens_err2 = rotation_sensor.in_plane.read.pbus.direction.bit.sens_err2;
// // rotor.direct_rotor = (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) > 0 ? 1 : // + rotor.direct_rotor_angle
// // (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) < 0 ? -1 : // + rotor.direct_rotor_angle
// // 0;
// if(rotor.iqFout >139810L) //10ob/min
// {
// if((rotor.direct_rotor_in1 + rotor.direct_rotor_in2) > 0)
// {
// direct_accum++;
// }
// else if((rotor.direct_rotor_in1 + rotor.direct_rotor_in2) < 0)
// {
// direct_accum--;
// }
// else
// {
// if(direct_accum > 0) {direct_accum--;}
// if(direct_accum < 0) {direct_accum++;}
// }
// if(direct_accum > 60) { direct_accum = 60; }
// if(direct_accum < -60) { direct_accum = -60; }
// rotor.direct_rotor = direct_accum > 0 ? 1 :
// direct_accum < 0 ? -1 :
// 0;
// // if (f.flag_second_PCH) {
// // rotor.direct_rotor = - rotor.direct_rotor;
// // }
// }
// else
// {
// rotor.direct_rotor = (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) > 0 ? 1 : // + rotor.direct_rotor_angle
// (rotor.direct_rotor_in1 + rotor.direct_rotor_in2) < 0 ? -1 : // + rotor.direct_rotor_angle
// 0;
// // if (f.flag_second_PCH) {
// // rotor.direct_rotor = - rotor.direct_rotor;
// // }
// direct_accum = rotor.direct_rotor;
// }
// if(rotation_sensor.in_plane.write.regs.comand_reg.bit.set_sampling_time) //Èìïóëüñû êîðîòêèå
// {
// rotation_sensor.in_plane.write.regs.comand_reg.bit.filter_sensitivity = 0x5C;
// }
// else //Èìïóëüñû äëèííûå, ôèëüòð óñèëèâàåì
// {
// rotation_sensor.in_plane.write.regs.comand_reg.bit.filter_sensitivity = 0xA8;
// }
}
#pragma CODE_SECTION(impulses_To_iqF,".fast_run");
_iq impulses_To_iqF(unsigned int time, unsigned int impulses) //time mks. impulses count
{
//Flong = (impulses / time / IMPULSES_PER_TURN) * _IQ(1) / NORMA_FROTOR;
static unsigned long long koeff_to_F = 16777216LL / IMPULSES_PER_TURN * 1000000LL / NORMA_FROTOR;
long long Flong = (long long)impulses * koeff_to_F / time;
return (_iq)Flong;
}
//Frot = Fimp / IMPULSES_PER_TURN / NORMA_FROTOR =
// = counter_freq / counter / 2 / IMPULSES_PER_TURN / NORMA_FROTOR
//äåëþ íà 2, ò.ê. ñ÷èòàåì äëèòåëüíîñòü ïîëîâèíû ïåðèîäà
//äðîìíîæàþ íà (1LL << 24) ÷òîáû ïðèâåñòè ê iq24
#pragma CODE_SECTION(counter_To_iqF,".fast_run");
_iq counter_To_iqF(unsigned int count, unsigned int freq_mode)
{
static long long koeff_to_F = 60000000LL * _IQ(1) / IMPULSES_PER_TURN / 2 / NORMA_FROTOR;
long long Flong = 0;
if(freq_mode == 0) // 60Mhz
{
Flong = koeff_to_F / count / 100;
}
else //600KHz
{
Flong = koeff_to_F / count;
}
return Flong;
}
#pragma CODE_SECTION(delta_Angle_To_iqF,".fast_run");
_iq delta_Angle_To_iqF(unsigned long delta, unsigned int period)
{
// iqF = (delta / ANGLE_RESOLUTION) / (period * 10^-6) * (1LL << 24) / NORMA_FROTOR;
// iqF = delta * 10^6 * (1LL << 24) / ANGLE_RESOLUTION / period / NORMA_FROTOR;
static long long koeff_to_F = 1000000LL * (1LL << 24) / ANGLE_RESOLUTION / NORMA_FROTOR;
return (_iq)(koeff_to_F * delta / period);
}
#pragma CODE_SECTION(sort_F_array,".fast_run2");
void sort_F_array(_iq *array, unsigned int size)
{
unsigned int i, j;
_iq tmp = 0;
for(i = size; i > 0; i--)
{
for(j = 1; j < size; j++)
{
if(array[j - 1] > array[j])
{
tmp = array[j];
array[j] = array[j - 1];
array[j - 1] = tmp;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,190 +0,0 @@
#ifndef _V_PWM24_H
#define _V_PWM24_H
#ifdef __cplusplus
extern "C" {
#endif
#include "IQmathLib.h"
// #include "DSP281x_Device.h"
#include "word_structurs.h"
#include "svgen_dq.h"
//#define COUNT_VAR_FREQ 400
//#define IQ_KP_DELTA_T 134217728//0.004
//#define IQ_KP_DELTA_COMP_I 134217728//0.004
//#define PID_KP_DELTA_T 0.5//1//20//2//0.001//11.18 //0.036 //0.018 //0.18 //0.095 // PID Kp
//#define PID_KI_DELTA_T 0.000005//0.01 //0.08 // 0.008 // PID Ki
//#define PID_KD_DELTA_T 2//5//0.01 //0.08 // 0.008 // PID Ki
//#define PID_KC_DELTA_T 0.005 //0.09 // PID Kc
//#define PID_KP_DELTA_KOMP_I 1//0.12//0.06//5//10
//#define PID_KI_DELTA_KOMP_I 0.005//0//0.005//0.01
//#define PID_KC_DELTA_KOMP_I 0.005//0//0.005//0.01
//#define PID_KD_DELTA_KOMP_I 0//0//0.005//0.01
//#define PID_KD_DELTA_T 0.0000 //*100 // PID Kd
//#define DELTA_T_MAX 1258291//15099494//0.9//8388608//0.5//13421772//0.8 //8388608// 0.5//13421772 // 0.8
//#define DELTA_T_MIN -1258291//-15099494//0.9//-8388608//-0.5//-13421772//0.8 //-8388608// -0.5//-13421772 // -0.8
//#define DELTA_KOMP_I_MAX 1258291//6//1677721//0.1//3355443//0.2//1677721//200 A//4194304// 500 A
//#define DELTA_KOMP_I_MIN -1258291//-6//-1677721//-0.1//-3355443//-0.2//-1677721//-200 A//-4194304// -500 A
//#define INSENSITIVE_LEVEL_DELTA_T 83886 //10 V//167772// 20V //335544//40 V//83886 //10 V//335544//40 V//58720//7V//167772// 20V //83886 //10 V
//#define MAX_LEVEL_DELTA_T 1258291//150V//1677721 //200v//2516582//300 V//4194304//500 V//2516582 // 838860 //100 V
typedef struct { _iq Ti; // Output: reference phase-a switching function (pu)
int up_or_down; // Output: reference phase-b switching function (pu)
int impuls_lenght_max;
int impuls_lenght_min;
int counter_pass_max;
int counter_pass_min;
} SVGEN_PWM24_TIME;
typedef struct {
_iq Gain; // Input: reference gain voltage (pu)
//_iq Offset; // Input: reference offset voltage (pu)
_iq Freq; // Input: reference frequency (pu)
_iq FreqMax; // Parameter: Maximum step angle = 6*base_freq*T (pu)
_iq Alpha; // History: Sector angle (pu)
_iq delta_U;
_iq delta_t;
int XilinxFreq; // Xilinx freq in TIC
unsigned int pwm_minimal_impuls_zero_minus;
unsigned int pwm_minimal_impuls_zero_plus;
WORD_UINT2BITS_STRUCT saw_direct;
int prev_level; // ïðåäûäóùåå ñîñòîÿíèå ØÈÌà, äëÿ ïåðåõîäà èç middle èëè close â ðàáî÷åå
unsigned int Tclosed_high;
unsigned int Tclosed_saw_direct_0;
unsigned int Tclosed_saw_direct_1;
_iq Ia;
_iq Ib;
_iq Ic;
unsigned int number_svgen;
SVGEN_PWM24_TIME Ta_0; // Output: reference phase-a switching function (pu)
SVGEN_PWM24_TIME Ta_1; // Output: reference phase-a switching function (pu)
SVGEN_PWM24_TIME Tb_0; // Output: reference phase-b switching function (pu)
SVGEN_PWM24_TIME Tb_1; // Output: reference phase-b switching function (pu)
SVGEN_PWM24_TIME Tc_0; // Output: reference phase-c switching function (pu)
SVGEN_PWM24_TIME Tc_1; // Output: reference phase-c switching function (pu)
void (*calc)(); // Pointer to calculation function
void (*calc_dq)(); // Pointer to calculation function which don`t calculate angle from freq
} SVGEN_PWM24;
typedef SVGEN_PWM24 *SVGEN_PWM24_handle;
#define SVGEN_PWM24_TIME_DEFAULTS { 0,0,0,0 }
#define SVGEN_PWM24_DEFAULTS { 0,0,0,0,0,0,0,0,0, \
{0}, 0,0,0,0,0,0,0,0,\
SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS, \
SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS,SVGEN_PWM24_TIME_DEFAULTS, \
(void (*)(unsigned int))svgen_pwm24_calc, (void (*)(unsigned int))svgen_pwm24_calc_dq }
// extern int ar_sa_a[3][4][7];
extern SVGEN_PWM24 svgen_pwm24_1;
extern SVGEN_PWM24 svgen_pwm24_2;
extern SVGENDQ svgen_dq_1;
extern SVGENDQ svgen_dq_2;
// extern _iq pidCur_Kp;
// extern _iq pidCur_Ki;
// extern _iq iq_alfa_coef;
// extern _iq iq_koef_mod_korrect_1;
// extern _iq iq_koef_mod_korrect_2;
//extern int freq_array[COUNT_VAR_FREQ];
void svgen_pwm24_calc(SVGEN_PWM24 *vt);
void svgen_pwm24_calc_dq(SVGEN_PWM24 *vt);
void init_alpha_pwm24(int xFreq);
void test_calc_pwm24(_iq uz1, _iq uz2, _iq fz1/*, _iq fz2, int revers*/);
void calc_arr_tph(int sector,int region, _iq iq_ttt0, _iq iq_ttt1,
_iq iq_ttt2, _iq iq_ttt3, _iq iq_ttt4, _iq iq_ttt5, _iq delta_t, unsigned int number_sv,
_iq iqIa, _iq iqIb, _iq iqIc);
_iq calc_delta_t(_iq delta_1, unsigned int number,int region);
//void change_freq_pwm(_iq FreqMax, int freq_pwm_xtics, _iq XilinxFreq);
void change_freq_pwm(_iq freq_pwm_xtics);
//void calc_freq_pwm();
void calc_time_one_tk(_iq gain, _iq teta, _iq delta_U,
_iq Ia, _iq Ib, _iq Ic,
unsigned int number,
SVGEN_PWM24_TIME *tk0,
SVGEN_PWM24_TIME *tk1,
SVGEN_PWM24_TIME *tk2,
SVGEN_PWM24_TIME *tk3,
SVGEN_PWM24_TIME *tk4,
SVGEN_PWM24_TIME *tk5);
void test_calc_pwm24_dq(_iq U_zad1, _iq U_zad2,_iq teta);
void svgen_set_time_keys_closed(SVGEN_PWM24 *vt);
void svgen_set_time_middle_keys_open(SVGEN_PWM24 *vt);
void InitVariablesSvgen(unsigned int freq);
//void init_alpha(void);
_iq correct_balance_uzpt_pwm24(_iq Tinput, _iq Kplus);
void recalc_time_pwm_minimal_2_xilinx_pwm24_l(SVGEN_PWM24 *pwm24,
_iq *T0, _iq *T1,
_iq timpuls_corr );
void test_calc_simple_dq_pwm24(_iq uz1, _iq uz2, _iq fz1, _iq fz2, _iq Uzad_max);
void test_calc_dq_pwm24(_iq Ud, _iq Uq, _iq Ud2, _iq Uq2, _iq tetta,_iq Uzad_max, _iq* maxUq1, _iq* maxUq2, _iq* Uq1Out, _iq* Uq2Out);
//void test_calc_simple_uf_pwm24(_iq uz1, _iq uz2, _iq fz1, _iq fz2,_iq Uzad_max);
//void init_freq_array(void);
typedef union {
unsigned int all;
struct {
unsigned int k0;
unsigned int k1;
unsigned int k2;
unsigned int k3;
unsigned int k4;
unsigned int k5;
unsigned int k6;
unsigned int k7;
unsigned int k8;
unsigned int k9;
unsigned int k10;
unsigned int k11;
unsigned int k12;
unsigned int k13;
unsigned int k14;
unsigned int k15;
}bit;
} UP_OR_DOWN;
extern UP_OR_DOWN up_down;
extern _iq winding_displacement;
#ifdef __cplusplus
}
#endif
#endif /* _V_PWM24_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,183 +0,0 @@
/*
* xp_write_xpwm_time.h
*
* Created on: 03 àïð. 2018 ã.
* Author: stud
*/
#ifndef XP_WRITE_TIME_H_
#define XP_WRITE_TIME_H_
#include "word_structurs.h"
#define PWM_ERROR_LEVEL_INTERRUPT 0 // íå îïðåäåëèëè ãäå ìû, îøèáêà!!!
#define PWM_LOW_LEVEL_INTERRUPT 1 // ìû âíèçó ïèëû
#define PWM_HIGH_LEVEL_INTERRUPT 2 // ìû ââåðõó ïèëû
#define PWM_MODE_RELOAD_FORCE 0 // îáíîâëÿòü âñå çíà÷åíèÿ
#define PWM_MODE_RELOAD_LEVEL_LOW 1 // îáíîâëÿòü çíà÷åíèÿ äëÿ íèçà ïèëû, äëÿ saw_direct=1
#define PWM_MODE_RELOAD_LEVEL_HIGH 2 // îáíîâëÿòü çíà÷åíèÿ äëÿ âåðõà ïèëû, äëÿ saw_direct=0
#define PWM_KEY_NUMBER_A1_PLUS 0
#define PWM_KEY_NUMBER_A1_MINUS 1
#define PWM_KEY_NUMBER_B1_PLUS 2
#define PWM_KEY_NUMBER_B1_MINUS 3
#define PWM_KEY_NUMBER_C1_PLUS 4
#define PWM_KEY_NUMBER_C1_MINUS 5
#define PWM_KEY_NUMBER_A2_PLUS 6
#define PWM_KEY_NUMBER_A2_MINUS 7
#define PWM_KEY_NUMBER_B2_PLUS 8
#define PWM_KEY_NUMBER_B2_MINUS 9
#define PWM_KEY_NUMBER_C2_PLUS 10
#define PWM_KEY_NUMBER_C2_MINUS 11
#define PWM_KEY_NUMBER_BR1_PLUS 12
#define PWM_KEY_NUMBER_BR1_MINUS 13
#define PWM_KEY_NUMBER_BR2_PLUS 14
#define PWM_KEY_NUMBER_BR2_MINUS 15
//////////////////////////////////////////////////////////////////////
#define ENABLE_PWM_BREAK_ALL 0x0fff
#define ENABLE_PWM_BREAK_1 0xcfff
#define ENABLE_PWM_BREAK_2 0x3fff
#define ENABLE_PWM_1 0xffc0
#define ENABLE_PWM_2 0xf03f
#define ENABLE_PWM_1_2 0xf000
#define ENABLE_PWM_ALL 0x0000
//
#define DISABLE_PWM_BREAK_ALL 0xf000
#define DISABLE_PWM_BREAK_1 0x3000
#define DISABLE_PWM_BREAK_2 0xc000
#define DISABLE_PWM_1 0x003f
#define DISABLE_PWM_2 0x0fc0
#define DISABLE_PWM_1_2 0x0fff
#define DISABLE_PWM_ALL 0xffff
///
#define DISABLE_PWM_A1 0x0003
#define DISABLE_PWM_B1 0x000c
#define DISABLE_PWM_C1 0x0030
#define DISABLE_PWM_A2 0x00c0
#define DISABLE_PWM_B2 0x0300
#define DISABLE_PWM_C2 0x0c00
//
//////////////////////////////////////////////////////////////////////
/*
* PWM - Start Stop
* (15) - Soft start-stop m0de 1- soft mode enabled, 0 -disabled. Åñëè âûáðàí ðåæèì ìßãêîé îñòàíîâêè, òî ïðè ïîäà÷å
* ñèãíàëà ñòîï(0)-ðåãèñòð = 0, âûõîäû áëîêèðóþòñß â ìîìåíò ïåðåãèáà ïèëû (ïîñëå ïîäà÷è ñèãíàëà îñòàíîâêè)., åñëè íåò- ñðàçó.
* Àíàëîãè÷íî ïðèìåíßþòñß ìàñêè- ïðè soft mode ìàñêè ïðèìåíßþòñß â ìîìåíò ïåðåãèáà.
* ÂÀÆÍÎ! Äëß ìîìåíòàëüíîé îñòàíîâêè ØÈÌà äàííûé ðåãèñòð äîëæåí áûòü ðàâåí íóëþ.
* (0) - 1 -start, 0 - stop
*/
#define PWM_START_SOFT 0x8001
#define PWM_START_HARD 0x0001
#define PWM_STOP_SOFT 0x8000
#define PWM_STOP_HARD 0x0000
/////////////////////////////////////
/////////////////////////////////////
typedef struct
{
// Winding 1 times
unsigned int Ta0_0;
unsigned int Ta0_1;
unsigned int Tb0_0;
unsigned int Tb0_1;
unsigned int Tc0_0;
unsigned int Tc0_1;
// Winding 2 times
unsigned int Ta1_0;
unsigned int Ta1_1;
unsigned int Tb1_0;
unsigned int Tb1_1;
unsigned int Tc1_0;
unsigned int Tc1_1;
// Break transistors
unsigned int Tbr0_0;
unsigned int Tbr0_1;
unsigned int Tbr1_0;
unsigned int Tbr1_1;
//Level transistors closed
unsigned int Tclosed_0;
unsigned int Tclosed_1;
unsigned int Tclosed_high;
unsigned int pwm_tics;
unsigned int inited;
unsigned int freq_pwm;
unsigned int Tclosed_saw_direct_0;
unsigned int Tclosed_saw_direct_1;
unsigned int current_period;
unsigned int where_interrupt;
unsigned int mode_reload;
unsigned int one_or_two_interrupts_run;
WORD_UINT2BITS_STRUCT saw_direct;
void (*write_1_2_winding_break_times)();
void (*write_1_2_winding_break_times_split)();
} XPWM_TIME;
#define DEFAULT_XPWM_TIME {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}, \
xpwm_write_1_2_winding_break_times_16_lines, \
xpwm_write_1_2_winding_break_times_16_lines_split_eages }
void xpwm_write_1_2_winding_break_times_16_lines();
void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p);
void xpwm_write_zero_winding_break_times_16_lines_split_eages();
void initXpwmTimeStructure(XPWM_TIME *p);
extern XPWM_TIME xpwm_time;
#define write_winding1_fase_a(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 0); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 1); WriteMemory(ADR_PWM_TIMING, T1);
#define write_winding1_fase_b(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 2); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 3); WriteMemory(ADR_PWM_TIMING, T1);
#define write_winding1_fase_c(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 4); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 5); WriteMemory(ADR_PWM_TIMING, T1);
#define write_winding2_fase_a(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 6); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 7); WriteMemory(ADR_PWM_TIMING, T1);
#define write_winding2_fase_b(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 8); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 9); WriteMemory(ADR_PWM_TIMING, T1);
#define write_winding2_fase_c(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 10); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 11); WriteMemory(ADR_PWM_TIMING, T1);
#define write_break_winding1(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 12); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 13); WriteMemory(ADR_PWM_TIMING, T1);
#define write_break_winding2(T0, T1) \
WriteMemory(ADR_PWM_KEY_NUMBER, 14); WriteMemory(ADR_PWM_TIMING, T0); \
WriteMemory(ADR_PWM_KEY_NUMBER, 15); WriteMemory(ADR_PWM_TIMING, T1);
#endif /* XP_WRITE_TIME_H_ */

View File

@ -1,361 +0,0 @@
/*
* xp_write_xpwm_time.c
*
* Created on: 03 àïð. 2018 ã.
* Author: stud
*/
#include "xp_write_xpwm_time.h"
// #include "MemoryFunctions.h"
// #include "Spartan2E_Adr.h"
// #include "PWMTMSHandle.h"
#include "def.h"
// #pragma DATA_SECTION(xpwm_time,".fast_vars1");
XPWM_TIME xpwm_time = DEFAULT_XPWM_TIME;
#define set_default_tclosed(k,b) {if (b) k = p->Tclosed_saw_direct_1; else k = p->Tclosed_saw_direct_0;}
void initXpwmTimeStructure(XPWM_TIME *p) {
p->Ta0_0 = p->Tclosed_0;
p->Ta0_1 = p->Tclosed_1;
p->Tb0_0 = p->Tclosed_0;
p->Tb0_1 = p->Tclosed_1;
p->Tc0_0 = p->Tclosed_0;
p->Tc0_1 = p->Tclosed_1;
p->Ta1_0 = p->Tclosed_0;
p->Ta1_1 = p->Tclosed_1;
p->Tb1_0 = p->Tclosed_0;
p->Tb1_1 = p->Tclosed_1;
p->Tc1_0 = p->Tclosed_0;
p->Tc1_1 = p->Tclosed_1;
p->Tbr0_0 = 0;
p->Tbr0_1 = 0;
p->Tbr1_0 = 0;
p->Tbr1_1 = 0;
}
// Ôóíêöèè çàãëóøêè ÷òîáû êîìïèëèðîâàëîñü â ìàòëàáå
void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p) {
}
// void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p) {
// }
/*
//#pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines,".fast_run1");
void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p)
{
if(!(ReadMemory(ADR_ERRORS_TOTAL_INFO)))
{
WriteMemory(ADR_PWM_KEY_NUMBER, 0);
WriteMemory(ADR_PWM_TIMING, p->Ta0_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 1);
WriteMemory(ADR_PWM_TIMING, p->Ta0_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 2);
WriteMemory(ADR_PWM_TIMING, p->Tb0_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 3);
WriteMemory(ADR_PWM_TIMING, p->Tb0_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 4);
WriteMemory(ADR_PWM_TIMING, p->Tc0_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 5);
WriteMemory(ADR_PWM_TIMING, p->Tc0_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 6);
WriteMemory(ADR_PWM_TIMING, p->Ta1_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 7);
WriteMemory(ADR_PWM_TIMING, p->Ta1_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 8);
WriteMemory(ADR_PWM_TIMING, p->Tb1_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 9);
WriteMemory(ADR_PWM_TIMING, p->Tb1_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 10);
WriteMemory(ADR_PWM_TIMING, p->Tc1_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 11);
WriteMemory(ADR_PWM_TIMING, p->Tc1_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 12);
WriteMemory(ADR_PWM_TIMING, p->Tbr0_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 13);
WriteMemory(ADR_PWM_TIMING, p->Tbr0_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 14);
WriteMemory(ADR_PWM_TIMING, p->Tbr1_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 15);
WriteMemory(ADR_PWM_TIMING, p->Tbr1_1);
}
else
{
WriteMemory(ADR_PWM_KEY_NUMBER, 0);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 1);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 2);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 3);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 4);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 5);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 6);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 7);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 8);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 9);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 10);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_0);
WriteMemory(ADR_PWM_KEY_NUMBER, 11);
WriteMemory(ADR_PWM_TIMING, p->Tclosed_1);
WriteMemory(ADR_PWM_KEY_NUMBER, 12);
WriteMemory(ADR_PWM_TIMING, 0);
WriteMemory(ADR_PWM_KEY_NUMBER, 13);
WriteMemory(ADR_PWM_TIMING, 0);
WriteMemory(ADR_PWM_KEY_NUMBER, 14);
WriteMemory(ADR_PWM_TIMING, 0);
WriteMemory(ADR_PWM_KEY_NUMBER, 15);
WriteMemory(ADR_PWM_TIMING, 0);
}
}
*/
// #pragma CODE_SECTION(xpwm_write_1_2_winding_break_times_16_lines_split_eages,".fast_run1");
void xpwm_write_1_2_winding_break_times_16_lines_split_eages(XPWM_TIME *p)
{
// if (!(i_ReadMemory(ADR_ERRORS_TOTAL_INFO)))
{
//a
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit0==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Ta0_0);
EPwm2Regs.CMPA.half.CMPA = p->Ta0_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit1 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit1==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Ta0_1);
EPwm1Regs.CMPA.half.CMPA = p->Ta0_1;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit2 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit2==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tb0_0);
EPwm4Regs.CMPA.half.CMPA = p->Tb0_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit3 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit3==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tb0_1);
EPwm3Regs.CMPA.half.CMPA = p->Tb0_1;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit4 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit4==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tc0_0);
EPwm6Regs.CMPA.half.CMPA = p->Tc0_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit5 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit5==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tc0_1);
EPwm5Regs.CMPA.half.CMPA = p->Tc0_1;
}
//b
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit6 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit6==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Ta1_0);
EPwm8Regs.CMPA.half.CMPA = p->Ta1_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit7 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit7==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Ta1_1);
EPwm7Regs.CMPA.half.CMPA = p->Ta1_1;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit8 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit8==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tb1_0);
EPwm10Regs.CMPA.half.CMPA = p->Tb1_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit9 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit9==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tb1_1);
EPwm9Regs.CMPA.half.CMPA = p->Tb1_1;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit10 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit10==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tc1_0);
EPwm12Regs.CMPA.half.CMPA = p->Tc1_0;
}
if ((p->mode_reload==PWM_MODE_RELOAD_FORCE)
|| (p->saw_direct.bits.bit11 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_HIGH)
|| (p->saw_direct.bits.bit11==0 && p->mode_reload==PWM_MODE_RELOAD_LEVEL_LOW) )
{
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tc1_1);
EPwm11Regs.CMPA.half.CMPA = p->Tc1_1;
}
//br1 br2
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_0);
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tbr0_1);
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_0);
// i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS);
// i_WriteMemory(ADR_PWM_TIMING, p->Tbr1_1);
}
// else
// {
// // hard_stop_x24_pwm_all();
// // stop_pwm();
// xpwm_write_zero_winding_break_times_16_lines_split_eages(p);
// }
}
/*
// #pragma CODE_SECTION(xpwm_write_zero_1,".fast_run2");
void xpwm_write_zero_1(XPWM_TIME *p)
{
unsigned int tclose;
//a
set_default_tclosed(tclose, p->saw_direct.bits.bit0);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Ta0_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit1);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A1_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Ta0_1 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit2);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tb0_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit3);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B1_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tb0_1 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit4);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tc0_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit5);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C1_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tc0_1 = tclose;
}
// #pragma CODE_SECTION(xpwm_write_zero_2,".fast_run1");
void xpwm_write_zero_2(XPWM_TIME *p)
{
unsigned int tclose;
//b
set_default_tclosed(tclose, p->saw_direct.bits.bit6);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Ta1_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit7);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_A2_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Ta1_1 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit8);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tb1_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit9);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_B2_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tb1_1 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit10);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_PLUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tc1_0 = tclose;
set_default_tclosed(tclose, p->saw_direct.bits.bit11);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_C2_MINUS);
i_WriteMemory(ADR_PWM_TIMING, tclose);
p->Tc1_1 = tclose;
}
// #pragma CODE_SECTION(xpwm_write_zero_break_1,".fast_run2");
void xpwm_write_zero_break_1(XPWM_TIME *p)
{
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_PLUS);
i_WriteMemory(ADR_PWM_TIMING, 0);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR1_MINUS);
i_WriteMemory(ADR_PWM_TIMING, 0);
p->Tbr0_0 = 0;
p->Tbr0_1 = 0;
}
// #pragma CODE_SECTION(xpwm_write_zero_break_2,".fast_run2");
void xpwm_write_zero_break_2(XPWM_TIME *p)
{
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_PLUS);
i_WriteMemory(ADR_PWM_TIMING, 0);
i_WriteMemory(ADR_PWM_KEY_NUMBER, PWM_KEY_NUMBER_BR2_MINUS);
i_WriteMemory(ADR_PWM_TIMING, 0);
p->Tbr1_0 = 0;
p->Tbr1_1 = 0;
}
// #pragma CODE_SECTION(xpwm_write_zero_winding_break_times_16_lines_split_eages,".fast_run2");
void xpwm_write_zero_winding_break_times_16_lines_split_eages(XPWM_TIME *p)
{
xpwm_write_zero_1(p);
xpwm_write_zero_2(p);
xpwm_write_zero_break_1(p);
xpwm_write_zero_break_2(p);
}
*/

View File

@ -1,248 +0,0 @@
/**************************************************************************
Description: Ïðîãðàììà ìîäåëèðóåò ðàáîòó ïðîöåññîðà - îñóùåñòâëÿåò
âûçîâ ôóíêöèé init28335, detcoeff, isr.
Òàêæå ìîäåëèðóåò ðàçëè÷íûå ïåðèôåðèéíûå óñòðîéñòâà ïðîöåññîðà
TMS320F28335/TMS320F28379D (ADC, PWM, QEP è ò.ä.).
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.11.08
**************************************************************************/
#include "simstruc.h"
#include "controller.h"
#include "init28335.h"
#include "param.h"
UMotorMeasure motor;
double dt;
// Äëÿ èìèòàöèè îáìåíà ñ ÏÓ
int j;
unsigned short paramNo;
unsigned short paramNew[PAR_NUMBER];
void processSFunctionIfChanged(SimStruct *S, int_T *iW) {
// îáðàáàòûâàåì ïàðàìåòðû S-Function êàæäûé ðàç, êîãäà îíè èçìåíèëèñü
if ( iW[0] == 1 ) {
iW[0] = 0;
int kkk = 0;
for (int lll = 0; lll < NPARAMS; lll++ ) {
// îïðåäåëÿåì êîë-âî ýëåìåíòîâ â ïàðàìåòðå
int dimen = mxGetNumberOfElements(ssGetSFcnParam(S,lll));
// îáðàáàòûâàåì ïàðàìåòð â çàâèñèìîñòè îò åãî ðàçìåðà
if ( dimen > LEN_PARAM_MATR*2 ) {
ssSetErrorStatus(S,"Â ïàðàìåòðå-ìàññèâå ñëèøêîì ìíîãî ýëåìåíòîâ");
return;
}
else if ( dimen > 1 ) {
// çàïîìèíàåì êîë-âî ýëåìåíòîâ ïàðàìåòðà-ìàòðèöû
paramMatrDimen = dimen;
// çàïîìèíàåì çíà÷åíèÿ ýëåìåíòîâ ïàðàìåòðà-ìàòðèöû
for (int mmm = 0; mmm < dimen; mmm++ )
paramMatr[mmm] = mxGetPr(ssGetSFcnParam(S,lll))[mmm];
}
else {
// çàïîìèíàåì çíà÷åíèÿ ïàðàìåòðîâ-ñêàëÿðîâ
paramScal[kkk++] = mxGetPr(ssGetSFcnParam(S,lll))[0];
}
}
// ÏÀÐÀÌÅÒÐÛ (begin)
int nn = 0;
dt = paramScal[nn++];//øàã äèñêðåòèçàöèè (âñåãäà äîëæåí ïåðåäàâàòüñÿ â S-function ïîñëåäíèì!)
// ÏÀÐÀÌÅÒÐÛ (end)
} //if ( iW[0] == 1 )
}
void initialisationOnStart(int_T *iW) {
// êîå-÷òî âûïîëíÿåì îäèí ðàç ïðè çàïóñêå ìîäåëè
if ( iW[1] == 1 ) {
iW[1] = 0;
Init_Timers();
init28335();
} //if ( iW[1] == 1 )
}
void update_norm_ADC_array()
{
//// Udc1
//if ( udc1_ml > UDC_SENS_MAX )
// udc1_ml = UDC_SENS_MAX;
//else if ( udc1_ml < -UDC_SENS_MAX )
// udc1_ml = -UDC_SENS_MAX;
//iq_norm_ADC[0] = _IQ(udc1_ml/NORMA_ACP);
//// Udc2
//if ( udc2_ml > UDC_SENS_MAX )
// udc2_ml = UDC_SENS_MAX;
//else if ( udc2_ml < -UDC_SENS_MAX )
// udc2_ml = -UDC_SENS_MAX;
//iq_norm_ADC[1] = _IQ(udc2_ml/NORMA_ACP);
//// Udc3
//if ( udc3_ml > UDC_SENS_MAX )
// udc3_ml = UDC_SENS_MAX;
//else if ( udc3_ml < -UDC_SENS_MAX )
// udc3_ml = -UDC_SENS_MAX;
//iq_norm_ADC[7] = _IQ(udc3_ml/NORMA_ACP);
//// Udc4
//if ( udc4_ml > UDC_SENS_MAX )
// udc4_ml = UDC_SENS_MAX;
//else if ( udc4_ml < -UDC_SENS_MAX )
// udc4_ml = -UDC_SENS_MAX;
//iq_norm_ADC[8] = _IQ(udc4_ml/NORMA_ACP);
//// Idc1
//if ( idc1_ml > IDC_SENS_MAX )
// idc1_ml = IDC_SENS_MAX;
//else if ( idc1_ml < -IDC_SENS_MAX )
// idc1_ml = -IDC_SENS_MAX;
//iq_norm_ADC[2] = _IQ(idc1_ml/NORMA_ACP);
//// Idc2
//if ( idc2_ml > IDC_SENS_MAX )
// idc2_ml = IDC_SENS_MAX;
//else if ( idc2_ml < -IDC_SENS_MAX )
// idc2_ml = -IDC_SENS_MAX;
//iq_norm_ADC[3] = _IQ(idc2_ml/NORMA_ACP);
//// Idc3
//if ( idc3_ml > IDC_SENS_MAX )
// idc3_ml = IDC_SENS_MAX;
//else if ( idc3_ml < -IDC_SENS_MAX )
// idc3_ml = -IDC_SENS_MAX;
//iq_norm_ADC[9] = _IQ(idc3_ml/NORMA_ACP);
//// Idc4
//if ( idc4_ml > IDC_SENS_MAX )
// idc4_ml = IDC_SENS_MAX;
//else if ( idc4_ml < -IDC_SENS_MAX )
// idc4_ml = -IDC_SENS_MAX;
//iq_norm_ADC[10] = _IQ(idc4_ml/NORMA_ACP);
//// Ia1
//if ( ia1_ml > IAC_SENS_MAX )
// ia1_ml = IAC_SENS_MAX;
//else if ( ia1_ml < -IAC_SENS_MAX )
// ia1_ml = -IAC_SENS_MAX;
//iq_norm_ADC[4] = _IQ(ia1_ml/NORMA_ACP);
//// Ib1
//if ( ib1_ml > IAC_SENS_MAX )
// ib1_ml = IAC_SENS_MAX;
//else if ( ib1_ml < -IAC_SENS_MAX )
// ib1_ml = -IAC_SENS_MAX;
//iq_norm_ADC[5] = _IQ(ib1_ml/NORMA_ACP);
//// Ic1
//if ( ic1_ml > IAC_SENS_MAX )
// ic1_ml = IAC_SENS_MAX;
//else if ( ic1_ml < -IAC_SENS_MAX )
// ic1_ml = -IAC_SENS_MAX;
//iq_norm_ADC[6] = _IQ(ic1_ml/NORMA_ACP);
//// Ia2
//if ( ia2_ml > IAC_SENS_MAX )
// ia2_ml = IAC_SENS_MAX;
//else if ( ia2_ml < -IAC_SENS_MAX )
// ia2_ml = -IAC_SENS_MAX;
//iq_norm_ADC[11] = _IQ(ia2_ml/NORMA_ACP);
//// Ib2
//if ( ib2_ml > IAC_SENS_MAX )
// ib2_ml = IAC_SENS_MAX;
//else if ( ib2_ml < -IAC_SENS_MAX )
// ib2_ml = -IAC_SENS_MAX;
//iq_norm_ADC[12] = _IQ(ib2_ml/NORMA_ACP);
//// Ic2
//if ( ic2_ml > IAC_SENS_MAX )
// ic2_ml = IAC_SENS_MAX;
//else if ( ic2_ml < -IAC_SENS_MAX )
// ic2_ml = -IAC_SENS_MAX;
//iq_norm_ADC[13] = _IQ(ic2_ml/NORMA_ACP);
//vect_control.off_curr_pi = mst.off_curr_pi;
//vect_control.only_one_km = mst.only_one_km;
//vect_control.enable_compens_iq1_iq2 = mst.enable_compens_iq1_iq2;
}
void simulateAdcAndCallIsr() {
///* Ìîäåëèðóåì ïðåîáðàçîâàíèÿ èçìåðÿåìûõ âåëè÷èí äàò÷èêàìè,
//îïåðàöèîííèêàìè è ÀÖÏ (ñ ïîìîùüþ nAdc ó÷èòûâàåì ñäâèã ïî âðåìåíè
//ìåæäó ÀÖÏ ðàçíûõ ñèãíàëîâ) */
//if ( tAdc < Tadc ) {
// tAdc++;
//}
//else {
// tAdc = 1;
// timers_adc++;
// if (timers_adc>=FREQ_ADC_TIMER)
// timers_adc = 0;
// update_norm_ADC_array();
// // ïîñëå çàâåðøåíèÿ ñåðèè ÀÖÏ âûçûâàåì isr()
// acp_Handler();
// //isr();
// // nAdc++;
// // switch ( nAdc ) {
// // case 5:
//
// // break;
// // case 6:
// // break;
// // case 7:
// // // êàê áû ñ ÏÓ
// // for ( j = FIRST_WRITE_PAR_NUM; j < paramNo; j++ ) {
// // if ( paramNew[j] != param[j] ) {
// // input_param((short)j, paramNew[j]);
// // break;
// // }
// // }
// // // ïîñëå çàâåðøåíèÿ ñåðèè ÀÖÏ âûçûâàåì isr()
// // isr();
// // break;
// // } //switch ( nAdc )
//} //tAdc
// if (calcAlgUpr) {
// // ðåàëèçóåò àëãîðèòì óïðàâëåíèÿ
// upr();
// calcAlgUpr = 0;
// timers_pwm++;
// if (timers_pwm>=FREQ_PWM_TIMER)
// timers_pwm = 0;
// }
}
void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW, int_T *iW) {
readInputParameters(u);
processSFunctionIfChanged(S, iW);
initialisationOnStart(iW);
Simulate_Timers();
simulateAdcAndCallIsr();
writeOutputParameters(xD);
} //void controller(SimStruct ...

View File

@ -1,62 +0,0 @@
#include "DSP281x_Device.h"
#include "wrapper_inu.h"
#include "def.h"
#include "pwm_sim.h"
#include "edrk_main.h"
#include "vector.h"
#include "vector_control.h"
#include "adc_tools.h"
#include "uf_alg_ing.h"
#include "v_rotor.h"
#include "v_rotor_22220.h"
#include "v_pwm24_v2.h"
#include "control_station.h"
#include "control_station_project.h"
#include "CAN_Setup.h"
#include "RS_Functions.h"
#include "master_slave.h"
#include "xp_write_xpwm_time.h"
#include <params.h>
#include <params_alg.h>
#include <params_norma.h>
#include <params_pwm24.h>
#include <params_temper_p.h>
#include <project.h>
#ifndef __WRAPPER_CONTROLLER_H
#define __WRAPPER_CONTROLLER_H
// Ìàêñèìàëüíàÿ äëèíà ïàðàìåòðà-âåêòîðà
#define LEN_PARAM_MATR 21
// Ìàññèâû ñ ïàðàìåòðàìè S_Function
double paramScal[NPARAMS];
double paramMatr[LEN_PARAM_MATR*2];
int paramMatrDimen;
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â controller.c (begin)
//#########################################################################
// Ïàðàìåòðû
//double ;
// Âõîäû
typedef struct
{
double udc1_ml;
double udc2_ml;
double ia1_ml;
double ib1_ml;
double ic1_ml;
double ia2_ml;
double ib2_ml;
double ic2_ml;
double wm_ml;
}UMotorMeasure;
extern UMotorMeasure motor;
#endif //__WRAPPER_CONTROLLER_H

View File

@ -1,242 +0,0 @@
/**************************************************************************
Description: Ôóíêöèÿ âûçûâàåòñÿ îäèí ðàç â íà÷àëå âûïîëíåíèÿ
ïðîãðàììû è ïîäãîòàâëèâàåò äàííûå íåîáõîäèìûå äëÿ å¸ ðàáîòû.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.11.08
**************************************************************************/
#include "def.h"
#include "detcoeff.h"
void process_sgm_parameters(void);
short read_eeprom(void);
short test_param(void);
void detcoeff(void) {
float Tci;
float Tcf;
float Tcs;
float Km;
// äëÿ ñèãíàëèçàöèè
testParamFaultNo = 0;
// ÷òåíèå EEPROM
// ( -> param[])
eprom.readFaultNo = read_eeprom();
if ( eprom.readFaultNo != 0 ) {
faultNo = 1;
state = STATE_SHUTDOWN;
}
else {
// ïðîâåðÿåì ìàññèâ param[]
testParamFaultNo = test_param();
if ( testParamFaultNo != 0 ) {
faultNo = 4;
state = STATE_SHUTDOWN;
}
else {
faultNo = 0;
state = STATE_STOP;
}
}
rf.PsiZ = (float)param[180]*0.001;//%*10 -> o.e.
// ñìåùåíèÿ íóëÿ äàò÷èêîâ, åä. ÀÖÏ
offset.Ia1 = param[200];
offset.Ib1 = param[201];
offset.Ic1 = param[202];
offset.Udc1 = param[203];
offset.Ia2 = param[206];
offset.Ib2 = param[207];
offset.Ic2 = param[208];
offset.Udc2 = param[209];
// ïàðàìåòðû ÀÄ
sgmPar.Rs = (float)param[303]*1e-6;//ìêÎì -> Îì
sgmPar.Lls = (float)param[304]*1e-7;//ìêÃí*10 -> Ãí
sgmPar.Rr = (float)param[305]*1e-6;//ìêÎì -> Îì
sgmPar.Llr = (float)param[306]*1e-7;//ìêÃí*10 -> Ãí
sgmPar.Lm = (float)param[307]*1e-6;//ìêÃí -> Ãí
// ïîëó÷àåì èç ïàðàìåòðîâ ÀÄ âñÿêèå âñïîìîãàòåëüíûå âåëè÷èíû
process_sgm_parameters();
// êîýôôèöèåíòû ðåãóëÿòîðîâ Id è Iq
// ... ïîñòîÿííàÿ âðåìåíè êîíòóðà òîêà, ñ
Tci = TY*3.8;
cc.KpOrig = 0.01*sgmPar.SigmaLs/Tci*I_BAZ*U_2_Y;
cc.Kp = cc.KpOrig*(float)param[210];
cc.KiOrig = 0.01*(sgmPar.Rs + sgmPar.Rr*sgmPar.Kl*sgmPar.Kl)/Tci*I_BAZ*U_2_Y*TY;
cc.Ki = cc.KiOrig*(float)param[211];
// êîýôôèöèåíòû ðåãóëÿòîðà Psi
// ... ïîñòîÿííàÿ âðåìåíè êîíòóðà ïîòîêà, ñ
Tcf = 50e-3;
cf.KpOrig = 0.01*sgmPar.KlInv/(sgmPar.Rr*Tcf)*PSI_BAZ/I_BAZ;
cf.Kp = cf.KpOrig*(float)param[212];
cf.KiOrig = 0.01/(sgmPar.Lm*Tcf)*PSI_BAZ/I_BAZ*TY*DECIM_PSI_WM_PM;
cf.Ki = cf.KiOrig*(float)param[213];
// êîýôôèöèåíòû ðåãóëÿòîðà N
// ... ïîñòîÿííàÿ âðåìåíè êîíòóðà ñêîðîñòè, ñ
Tcs = 200e-3;
// ... êîýôôèöèåíò äëÿ ïåðåñ÷¸òà òîêà â ìîìåíò
Km = 1.5*PP*sgmPar.Kl*PSI_BAZ*rf.PsiZ;
csp.KpOrig = 0.01*J/(Km*Tcs)*WM_BAZ/I_BAZ;
csp.Kp = csp.KpOrig*(float)param[214];
csp.KiOrig = 0.01*J/(Km*Tcs*Tcs*5.)*WM_BAZ/I_BAZ*TY*DECIM_PSI_WM_PM;
csp.Ki = csp.KiOrig*(float)param[215];
// âñÿêèå óñòàâêè
protect.IacMax = (short)(2047.*(float)param[220]*0.01);//% -> åä. ÀÖÏ
protect.IacMin = -protect.IacMax;
protect.UdcMax = (float)param[221]*0.01;//% -> o.e.
IzLim = (float)param[222]*0.01;//% -> o.e.
cf.IdLim = (float)param[223]*0.01;//% -> o.e.
cf.IdLimNeg = cf.IdLim*(-0.4);
csp.IqLim = (float)param[224]*0.01;//% -> o.e.
csp.IqLimNeg = -csp.IqLim;
protect.UdcMin = (float)param[225]*0.01;//% -> o.e.
protect.WmMax = (float)param[226]*0.01;//% -> o.e.
rf.WmNomPsi = (float)param[228]*0.01;//% -> o.e.
rf.YlimPsi = (float)param[229]*0.01*Y_LIM;//% -> åä. ñ÷¸ò÷èêà òàéìåðà
protect.TudcMin = (unsigned short)((float)param[231]*0.001/TY);
protect.TwmMax = (unsigned short)((float)param[233]*0.001/TY);
// äëÿ ðàçíûõ ÇÈ
rs.WlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)param[244]*0.001);
csp.IlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)param[245]*0.001);
rp.PlimIncr = 1.0*TY*DECIM_PSI_WM_PM/((float)param[248]*0.001);
rf.PsizIncr = 1.0*TY*DECIM_PSI_WM_PM/2.0;
// äëÿ êîððåêöèè
KmeCorr = (float)param[269]*0.0001;//%*100 -> o.e.
// äëÿ ðàçíûõ ôèëüòðîâ
Kudc = (TY*10000.)/(float)param[285];
if ( Kudc > 1.0 )
Kudc = 1.0;
Kwm = (TY*10000.)/(float)param[286];
if ( Kwm > 1.0 )
Kwm = 1.0;
rs.Kwmz = (TY*DECIM_PSI_WM_PM*1000.)/(float)param[288];
rf.Kpsiz = (TY*DECIM_PSI_WM_PM*1000.)/(float)param[289];
Kme = (TY*1000.)/(float)param[290];
rp.Kpmz = (TY*DECIM_PSI_WM_PM*1000.)/(float)param[292];
out.K = TY/100e-3;
// âûäåðæêè
protect.Tdi24VSource = (unsigned short)(5.0/TY);
// âñ¸ â èñõîäíîå ïîëîæåíèå
udc1 = 0;
udc2 = 0;
wmNf = 0;
wm = 0;
me = 0;
out.udc1 = 0;
out.udc2 = 0;
out.iac1 = 0;
out.iac2 = 0;
out.wm = 0;
out.me = 0;
out.pm = 0;
protect.tWmMax = 0;
protect.tDI24VSource = 0;
onceShutdown = 0;
onceFaultReset = 0;
stopPause = 1;
mst.pzMode = 0;
mst.faultReset = 0;
mst.start = 0;
mst.wmZz = 0;
mst.pmZz = 0;
mst.wmLim = 0;
mst.pmLim = 0;
mst.pIncrMaxTy = 0;
mst.pDecrMaxTy = 0;
} //void detcoeff(void)
// Âû÷èñëÿåò èç ïàðàìåòðîâ ÀÄ âñÿêèå âñïîìîãàòåëüíûå âåëè÷èíû
void process_sgm_parameters(void) {
// ïîëíàÿ èíäóêòèâíîñòü ôàçû ñòàòîðà, Ãí
sgmPar.Ls = sgmPar.Lm + sgmPar.Lls;
// ïîëíàÿ èíäóêòèâíîñòü ôàçû ðîòîðà, Ãí
sgmPar.Lr = sgmPar.Lm + sgmPar.Llr;
// âñÿêî-ðàçíî
sgmPar.SigmaLs = (1. - sgmPar.Lm*sgmPar.Lm/(sgmPar.Ls*sgmPar.Lr))*sgmPar.Ls;
sgmPar.LmInv = 1.0/sgmPar.Lm;
sgmPar.LrInv = 1.0/sgmPar.Lr;
sgmPar.Kl = sgmPar.Lm*sgmPar.LrInv;
sgmPar.KlInv = 1.0/sgmPar.Kl;
sgmPar.Tr = sgmPar.Lr/sgmPar.Rr;
sgmPar.TrInv = sgmPar.Rr*sgmPar.LrInv;
} //void process_sgm_parameters(void)
// ×èòàåò PAR_NUMBER ïàðàìåòðîâ èç EEPROM è ñîõðàíÿåò â ìàññèâå param[]
// ( -> param[])
short read_eeprom(void) {
return 0;
}
// Ïðîâåðÿåò äîïóñòèìîñòü çíà÷åíèé ïàðàìåòðîâ, ïîëó÷åííûõ èç EEPROM
// (â param.c ó ïàðàìåòðîâ ä.á. òå æå ãðàíèöû äîïóñòèìûõ çíà÷åíèé!)
short test_param(void) {
if ( param[180] > 2000 ) return 180;//rf.PsiZ
if ( (param[200]<1748) || (param[200]>2348) ) return 200;//offset.Ia1
if ( (param[201]<1748) || (param[201]>2348) ) return 201;//offset.Ib1
if ( (param[202]<1748) || (param[202]>2348) ) return 202;//offset.Ic1
if ( (param[203]<1748) || (param[203]>2348) ) return 203;//offset.Udc1
if ( (param[206]<1748) || (param[206]>2348) ) return 206;//offset.Ia2
if ( (param[207]<1748) || (param[207]>2348) ) return 207;//offset.Ib2
if ( (param[208]<1748) || (param[208]>2348) ) return 208;//offset.Ic2
if ( (param[209]<1748) || (param[209]>2348) ) return 209;//offset.Udc2
if ( param[210] > 5000 ) return 210;//cc.Kp
if ( param[211] > 5000 ) return 211;//cc.Ki
if ( param[212] > 5000 ) return 212;//cf.Kp
if ( param[213] > 5000 ) return 213;//cf.Ki
if ( param[214] > 5000 ) return 214;//csp.Kp
if ( param[215] > 5000 ) return 215;//csp.Ki
if ( param[220] > 99 ) return 220;//protect.IacMax
if ( param[221] > 136 ) return 221;//protect.UdcMax
if ( param[222] > 200 ) return 222;//IzLim
if ( param[223] > 200 ) return 223;//cf.IdLim
if ( param[224] > 200 ) return 224;//csp.IqLim
if ( param[225] > 110 ) return 225;//protect.UdcMin
if ( param[226] > 200 ) return 226;//protect.WmMax
if ( param[228] > 200 ) return 228;//rf.WmNomPsi
if ( param[229] > 101 ) return 229;//rf.YlimPsi
if ( (param[231]<1) || (param[231]>8500) ) return 231;//protect.TudcMin
if ( (param[233]<1) || (param[233]>8500) ) return 233;//protect.TwmMax
if ( param[244] < 1 ) return 244;//rs.WlimIncr
if ( param[245] < 1 ) return 245;//csp.IlimIncr
if ( param[248] < 1 ) return 248;//rp.PlimIncr
if ( (param[269]<5000) || (param[269]>20000) ) return 269;//KmeCorr
if ( (param[285]<1) || (param[285]>20000) ) return 285;//Kudc
if ( (param[286]<1) || (param[286]>20000) ) return 286;//Kwm
if ( (param[288]<1) || (param[288]>20000) ) return 288;//rs.Kwmz
if ( (param[289]<1) || (param[289]>20000) ) return 289;//rf.Kpsiz
if ( (param[290]<1) || (param[290]>20000) ) return 290;//Kme
if ( (param[292]<1) || (param[292]>20000) ) return 292;//rp.Kpmz
return 0;
} //short test_param(void)

View File

@ -1,47 +0,0 @@
#ifndef DETCOEFF
#define DETCOEFF
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â detcoeff.c (begin)
//#########################################################################
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â detcoeff.c (end)
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â detcoeff.c (begin)
//#########################################################################
extern short testParamFaultNo;
extern struct Eprom eprom;
extern volatile short faultNo;
extern volatile short state;
extern unsigned short param[];
extern struct Rf rf;
extern struct Offset offset;
extern struct SgmPar sgmPar;
extern struct Cc cc;
extern struct Cf cf;
extern struct Csp csp;
extern float IzLim;
extern struct Protect protect;
extern struct Rs rs;
extern struct Rp rp;
extern float KmeCorr;
extern float Kudc;
extern float Kwm;
extern float Kme;
extern volatile struct Out out;
extern volatile float udc1;
extern volatile float udc2;
extern volatile float wmNf;
extern volatile float wm;
extern volatile float me;
extern short onceShutdown;
extern short onceFaultReset;
extern short stopPause;
extern struct Mst mst;
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â detcoeff.c (end)
#endif //DETCOEFF

BIN
Inu/isr.c

Binary file not shown.

View File

@ -1,72 +0,0 @@
#ifndef ISR
#define ISR
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â isr.c (begin)
//#########################################################################
struct Offset offset;
volatile struct Result result;
volatile short state;
volatile short faultNo;
volatile struct Out out;
// Udc
float Kudc;
volatile float udc1Nf;
volatile float udc1;
volatile float udc2Nf;
volatile float udc2;
// Iac
volatile float ia1Nf;
volatile float ib1Nf;
volatile float ic1Nf;
volatile float ix1;
volatile float iy1;
volatile float iac1Nf;
volatile float ia2Nf;
volatile float ib2Nf;
volatile float ic2Nf;
volatile float ix2;
volatile float iy2;
volatile float iac2Nf;
// Wm
float Kwm;
volatile float wmNf;
volatile float wm;
volatile float wmAbs;
// Me
volatile float kMe;
float KmeCorr;
float Kme;
volatile float meNf;
volatile float me;
// Pm
volatile float pm;
// çàùèòû
struct Protect protect;
volatile struct Emerg emerg;
short csmSuccess;
// óïðàâëÿþùàÿ ëîãèêà
volatile short onceShutdown;
volatile short testParamFaultNo;
volatile short onceFaultReset;
volatile short stopPause;
volatile short inuWork;
// îáìåí
struct Mst mst;
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â isr.c (end)
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â isr.c (begin)
//#########################################################################
extern struct SgmPar sgmPar;
extern unsigned short param[];
extern volatile short onceUpr;
extern volatile float psi;
extern float iq1;
extern float iq2;
extern struct Rp rp;
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â isr.c (end)
#endif //ISR

View File

@ -0,0 +1,3 @@
#include "adc_sim.h"
AdcSimHandle adcsim;

12
Inu/main_matlab/adc_sim.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef PWM_SIM
#define PWM_SIM
// Äëÿ ìîäåëèðîâàíèÿ ADC
typedef struct
{
int tAdc;
int Tadc;
int nAdc;
}AdcSimHandle;
#endif //PWM_SIM

View File

@ -1,7 +1,7 @@
#ifndef INIT28335
#define INIT28335
#include "controller.h"
#include "mcu_wrapper_conf.h"
void init28335(void);

View File

@ -1,4 +1,4 @@
#include "controller.h"
#include "mcu_wrapper_conf.h"
//#include "edrk_main.h"
//#include "vector.h"
//#include "vector_control.h"

View File

@ -6,6 +6,7 @@
**************************************************************************/
#include "param.h"
#include "pwm_sim.h"
int Unites[UNIT_QUA_UNITS][UNIT_LEN];
int CAN_timeout[UNIT_QUA];
@ -31,7 +32,7 @@ void readInputParameters(const real_T *u) {
edrk.Go = u[nn++];
u[nn++];
edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_OBOROTS;
edrk.Mode_ScalarVectorUFConst = ALG_MODE_FOC_POWER;
edrk.zadanie.iq_power_zad = _IQ(0.5);
edrk.zadanie.iq_oborots_zad_hz = _IQ(0.5);

View File

@ -1,5 +1,5 @@
#include "simstruc.h"
#include "controller.h"
#include "mcu_wrapper_conf.h"
#ifndef PARAM
#define PARAM

View File

@ -1,9 +1,4 @@
#include "pwm_sim.h"
#include "xp_write_xpwm_time.h"
#include "main_matlab.h"
#include "wrapper_inu.h"
#include "params_pwm24.h"
#include "def.h"
TimerSimHandle t1sim;
TimerSimHandle t2sim;
@ -36,18 +31,18 @@ void Simulate_Timers(void)
void Init_Timers(void)
{
initSimulateTim(&t1sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t2sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t3sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t4sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t5sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t6sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t7sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t8sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t9sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t10sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t11sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t12sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * dt);
initSimulateTim(&t1sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t2sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t3sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t4sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t5sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t6sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t7sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t8sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t9sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t10sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t11sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
initSimulateTim(&t12sim, FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM, FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.SimSampleTime);
}
@ -58,7 +53,7 @@ void initSimulateTim(TimerSimHandle* tsim, int period, double step)
tsim->dtsim.stateDt = 1;
tsim->TPr = period/2;
tsim->TxCntPlus = step;
tsim->dtsim.DtCntPeriod = (int)(DT / dt);
tsim->dtsim.DtCntPeriod = (int)(DT / hmcu.SimSampleTime);
}
void SimulateMainPWM(TimerSimHandle* tsim, int compare)

View File

@ -1,5 +1,4 @@
#include "DSP281x_Device.h"
#include "v_pwm24_v2.h"
#include "mcu_wrapper_conf.h"
#ifndef PWM_SIM
#define PWM_SIM

43
Inu/mcu_app_includes.h Normal file
View File

@ -0,0 +1,43 @@
/**
**************************************************************************
* @file mcu_app_includes.h
* @brief Заголовочный файл для оболочки МК.
**************************************************************************
@details
Главный заголовочный файл для матлаба. Включает дейфайны для S-Function,
объявляет базовые функции для симуляции МК и подключает базовые библиотеки:
- для симуляции "stm32fxxx_matlab_conf.h"
- для S-Function "simstruc.h"
- для потоков <process.h>
**************************************************************************/
#ifndef _APP_INCLUDES_H_
#define _APP_INCLUDES_H_
// Includes
#include "DSP281x_Device.h"
#include "def.h"
#include "edrk_main.h"
#include "vector.h"
#include "vector_control.h"
#include "adc_tools.h"
#include "uf_alg_ing.h"
#include "v_rotor.h"
#include "v_rotor_22220.h"
#include "v_pwm24_v2.h"
#include "control_station.h"
#include "control_station_project.h"
#include "CAN_Setup.h"
#include "RS_Functions.h"
#include "master_slave.h"
#include "xp_write_xpwm_time.h"
#include <params.h>
#include <params_alg.h>
#include <params_norma.h>
#include <params_pwm24.h>
#include <params_temper_p.h>
#include <project.h>
#endif //_APP_INCLUDES_H_

173
Inu/mcu_wrapper.c Normal file
View File

@ -0,0 +1,173 @@
/**
**************************************************************************
* @file mcu_wrapper.c
* @brief Исходный код оболочки МК.
**************************************************************************
@details
Данный файл содержит функции для симуляции МК в Simulink (S-Function).
**************************************************************************/
#include "mcu_wrapper_conf.h"
#include "init28335.h"
#include "param.h"
#include "pwm_sim.h"
/**
* @addtogroup WRAPPER_CONF
* @{
*/
SIM__MCUHandleTypeDef hmcu; ///< Хендл для управления потоком программы МК
/** MCU_WRAPPER
* @}
*/
//-------------------------------------------------------------//
//-----------------CONTROLLER SIMULATE FUNCTIONS---------------//
/* THREAD FOR MCU APP */
#ifdef RUN_APP_THRREAD
/**
* @brief Главная функция приложения МК.
* @details Функция с которой начинается выполнение кода МК. Выход из данной функции происходит только в конце симуляции @ref mdlTerminate
*/
extern int main(void); // extern while from main.c
/**
* @brief Поток приложения МК.
* @details Поток, который запускает и выполняет код МК (@ref main).
*/
unsigned __stdcall MCU_App_Thread(void) {
main(); // run MCU code
return 0; // end thread
// note: this return will reached only at the end of simulation, when all whiles will be skipped due to @ref sim_while
}
#endif //RUN_APP_THRREAD
/* SIMULATE MCU FOR ONE SIMULATION STEP */
/**
* @brief Симуляция МК на один такт симуляции.
* @param S - указатель на структуру S-Function из "simstruc.h"
* @param time - текущее время симуляции.
* @details Запускает поток, который выполняет код МК и управляет ходом потока:
* Если прошел таймаут, поток прерывается, симулируется периферия
* и на следующем шаге поток возобнавляется.
*
* Вызывается из mdlUpdate()
*/
void MCU_Step_Simulation(SimStruct* S, time_T time)
{
hmcu.SystemClockDouble += hmcu.SystemClock_step; // emulate core clock
hmcu.SystemClock = hmcu.SystemClockDouble;
hmcu.SimTime = time;
MCU_readInputs(S); // считывание портов
MCU_Periph_Simulation(); // simulate peripheral
#ifdef RUN_APP_THRREAD
ResumeThread(hmcu.hMCUThread);
for (int i = DEKSTOP_CYCLES_FOR_MCU_APP; i > 0; i--)
{
}
SuspendThread(hmcu.hMCUThread);
#endif //RUN_APP_THRREAD
MCU_writeOutputs(S); // запись портов (по факту запись в буфер. запись в порты в mdlOutputs)
}
/* SIMULATE MCU PERIPHERAL */
/**
* @brief Симуляция периферии МК
* @details Пользовательский код, который симулирует работу периферии МК.
*/
void MCU_Periph_Simulation(void)
{
Simulate_Timers();
}
/* READ INPUTS S-FUNCTION TO MCU REGS */
/**
* @brief Считывание входов S-Function в порты ввода-вывода.
* @param S - указатель на структуру S-Function из "simstruc.h"
* @details Пользовательский код, который записывает порты ввода-вывода из входов S-Function.
*/
void MCU_readInputs(SimStruct* S)
{
/* Get S-Function inputs */
real_T* IN = ssGetInputPortRealSignal(S, 0);
readInputParameters(IN);
}
/* WRITE OUTPUTS BUFFER S-FUNCTION FROM MCU REGS*/
/**
* @brief Запись портов ввода-вывода в буфер выхода S-Function
* @param S - указатель на структуру S-Function из "simstruc.h"
* @details Пользовательский код, который записывает буфер выходов S-Function из портов ввода-вывода.
*/
void MCU_writeOutputs(SimStruct* S)
{
/* Get S-Function descrete array */
real_T* Out_Buff = ssGetDiscStates(S);
writeOutputParameters(Out_Buff);
}
//-----------------CONTROLLER SIMULATE FUNCTIONS---------------//
//-------------------------------------------------------------//
//-------------------------------------------------------------//
//----------------------SIMULINK FUNCTIONS---------------------//
/* MCU WRAPPER DEINITIALIZATION */
/**
* @brief Инициализация симуляции МК.
* @details Пользовательский код, который создает поток для приложения МК
и настраивает симулятор МК для симуляции.
*/
void SIM_Initialize_Simulation(void)
{
// инициализация потока, который будет выполнять код МК
#ifdef RUN_APP_THRREAD
hmcu.hMCUThread = (HANDLE)CreateThread(NULL, 0, MCU_App_Thread, 0, CREATE_SUSPENDED, &hmcu.idMCUThread);
#endif //RUN_APP_THRREAD
/* user initialization */
Init_Timers();
init28335();
/* wrapper initialization */
hmcu.SystemClock_step = MCU_CORE_CLOCK * hmcu.SimSampleTime; // set system clock step
}
/* MCU WRAPPER DEINITIALIZATION */
/**
* @brief Деинициализация симуляции МК.
* @details Пользовательский код, который будет очищать все структуры после окончания симуляции.
*/
void SIM_deInitialize_Simulation(void)
{
//// simulate structures of peripheral deinitialization
//deInitialize_Periph_Sim();
//// mcu peripheral memory deinitialization
//deInitialize_MCU();
}
/* WRITE OUTPUTS OF S-BLOCK */
/**
* @brief Формирование выходов S-Function.
* @param S - указатель на структуру S-Function из "simstruc.h"
* @details Пользовательский код, который записывает выходы S-Function из буфера.
*/
void SIM_writeOutputs(SimStruct* S)
{
real_T* GPIO;
real_T* Out_Buff = ssGetDiscStates(S);
//-------------WRITTING GPIOS---------------
for (int j = 0; j < OUT_PORT_NUMB; j++)
{
GPIO = ssGetOutputPortRealSignal(S, j);
for (int i = 0; i < OUT_PORT_WIDTH; i++)
{
GPIO[i] = Out_Buff[j * OUT_PORT_WIDTH + i];
Out_Buff[j * OUT_PORT_WIDTH + i] = 0;
}
}
//------------------------------------------
}
//-------------------------------------------------------------//

173
Inu/mcu_wrapper_conf.h Normal file
View File

@ -0,0 +1,173 @@
/**
**************************************************************************
* @dir ../MCU_Wrapper
* @brief <b> Папка с исходным кодом оболочки МК. </b>
* @details
В этой папке содержаться оболочка(англ. wrapper) для запуска и контроля
эмуляции микроконтроллеров в MATLAB (любого МК, не только STM).
Оболочка представляет собой S-Function - блок в Simulink, который работает
по скомпилированому коду. Компиляция происходит с помощью MSVC-компилятора.
**************************************************************************/
/**
**************************************************************************
* @file mcu_wrapper_conf.h
* @brief Заголовочный файл для оболочки МК.
**************************************************************************
@details
Главный заголовочный файл для матлаба. Включает дейфайны для S-Function,
объявляет базовые функции для симуляции МК и подключает базовые библиотеки:
- для симуляции "stm32fxxx_matlab_conf.h"
- для S-Function "simstruc.h"
- для потоков <process.h>
**************************************************************************/
#ifndef _WRAPPER_CONF_H_
#define _WRAPPER_CONF_H_
// Includes
#include "simstruc.h" // For S-Function variables
#include <process.h> // For threads
#include "mcu_app_includes.h"
/**
* @defgroup MCU_WRAPPER MCU Wrapper
* @brief Всякое для оболочки МК
*/
/**
* @addtogroup WRAPPER_CONF Wrapper Configuration
* @ingroup MCU_WRAPPER
* @brief Параметры конфигурации для оболочки МК
* @details Здесь дефайнами задается параметры оболочки, которые определяют как она будет работать
* @{
*/
// Parametrs of MCU simulator
//#define RUN_APP_THRREAD
#define CREATE_SUSPENDED 0x00000004 ///< define from WinBase.h. We dont wanna include "Windows.h" or smth like this, because of HAL there are a lot of redefine errors.
#define DEKSTOP_CYCLES_FOR_MCU_APP 0xFFFF ///< number of for() cycles after which MCU thread would be suspended
// Parameters of S_Function
#define NPARAMS 1 ///< number of input parametrs (only Ts)
#define IN_PORT_WIDTH 20 ///< width of input ports
#define IN_PORT_NUMB 1 ///< number of input ports
#define OUT_PORT_WIDTH 49 ///< width of output ports
#define OUT_PORT_NUMB 1 ///< number of output ports
#define DISC_STATES_WIDTH OUT_PORT_WIDTH*OUT_PORT_NUMB ///< width of discrete states array
#define NPARAMS 1 //кол-во параметров (скаляров и векторов)
#define RWORK_0_WIDTH 5 //width of the real-work vector
#define IWORK_0_WIDTH 5 //width of the integer-work vector
#define MCU_CORE_CLOCK 150000000
/** WRAPPER_CONF
* @}
*/
/**
* @addtogroup MCU_WRAPPER
* @{
*/
typedef void* HANDLE; ///< MCU handle typedef
/**
* @brief MCU handle Structure definition.
* @note Prefixes: h - handle, s - settings, f - flag
*/
typedef struct {
// MCU Thread
HANDLE hMCUThread; ///< Хендл для потока МК
int idMCUThread; ///< id потока МК (unused)
// Flags
unsigned fMCU_Stop : 1; ///< флаг для выхода из потока программы МК
double SimSampleTime; ///< sample time of simulation
double SystemClockDouble; ///< Счетчик в формате double для точной симуляции системных тиков С промежуточными значений
long SystemClock; ///< Счетчик тактов для симуляции системных тиков (в целочисленном формате)
double SystemClock_step; ///< Шаг тиков для их симуляции, в формате double
double SimTime;
}SIM__MCUHandleTypeDef;
extern SIM__MCUHandleTypeDef hmcu; // extern для видимости переменной во всех файлах
//-------------------------------------------------------------//
//------------------ SIMULINK WHILE DEFINES -----------------//
/* DEFINE TO WHILE WITH SIMULINK WHILE */
/**
* @brief Redefine C while statement with sim_while() macro.
* @param _expression_ - expression for while.
* @details Это while который будет использоваться в симулинке @ref sim_while для подробностей.
*/
#define while(_expression_) sim_while(_expression_)
/* SIMULINK WHILE */
/**
* @brief While statement for emulate MCU code in Simulink.
* @param _expression_ - expression for while.
* @details Данный while необходим, чтобы в конце симуляции, завершить поток МК:
* При выставлении флага окончания симуляции, все while будут пропускаться
* и поток сможет дойти до конца функции main и завершить себя.
*/
#define sim_while(_expression_) while((_expression_)&&(hmcu.fMCU_Stop == 0))
/* DEFAULT WHILE */
/**
* @brief Default/Native C while statement.
* @param _expression_ - expression for while.
* @details Данный while - аналог обычного while, без дополнительного функционала.
*/
#define native_while(_expression_) for(; (_expression_); )
/***************************************************************/
//------------------ SIMULINK WHILE DEFINES -----------------//
//-------------------------------------------------------------//
//-------------------------------------------------------------//
//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
/* Step simulation */
void MCU_Step_Simulation(SimStruct *S, time_T time);
/* MCU peripheral simulation */
void MCU_Periph_Simulation(void);
/* Initialize MCU simulation */
void SIM_Initialize_Simulation(void);
/* Deinitialize MCU simulation */
void SIM_deInitialize_Simulation(void);
/* Read inputs S-function */
void MCU_readInputs(SimStruct* S);
/* Write pre-outputs S-function (out_buff states) */
void MCU_writeOutputs(SimStruct* S);
/* Write outputs of block of S-Function*/
void SIM_writeOutput(SimStruct* S);
//---------------- SIMULATE FUNCTIONS PROTOTYPES -------------//
//-------------------------------------------------------------//
/** MCU_WRAPPER
* @}
*/
#endif // _WRAPPER_CONF_H_
//-------------------------------------------------------------//
//---------------------BAT FILE DESCRIBTION--------------------//
/**
* @file run_mex.bat
* @brief Батник для компиляции оболочки МК.
* @details
* Вызывается в матлабе из mexing.m.
*
* Исходный код батника:
* @include F:\Work\Projects\MATLAB\matlab_stm_emulate\MCU_Wrapper\run_mex.bat
*/

974
Inu/upr.c
View File

@ -1,974 +0,0 @@
/**************************************************************************
Description: Ôóíêöèÿ ðåàëèçóåò àëãîðèòì óïðàâëåíèÿ INU
(îòðàáîòêà N è P).
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.11.08
**************************************************************************/
#include "def.h"
#include "upr.h"
#include "pwm_vector_regul.h"
#include "IQmathLib.h"
#include "adc_tools.h"
#include "params.h"
#include "vector.h"
#include "v_pwm24.h"
#include "xp_write_xpwm_time.h"
#include "rotation_speed.h"
#pragma CODE_SECTION(control_current, "ramfuncs");
#pragma CODE_SECTION(control_flux, "ramfuncs");
#pragma CODE_SECTION(control_speed_power, "ramfuncs");
#pragma CODE_SECTION(indirect_vector_control, "ramfuncs");
#pragma CODE_SECTION(ipark, "ramfuncs");
#pragma CODE_SECTION(limit_current, "ramfuncs2");
#pragma CODE_SECTION(pwm, "ramfuncs2");
#pragma CODE_SECTION(reference_flux, "ramfuncs");
#pragma CODE_SECTION(reference_power, "ramfuncs");
#pragma CODE_SECTION(reference_speed, "ramfuncs");
#pragma CODE_SECTION(select_feedback, "ramfuncs");
#pragma CODE_SECTION(upr, "ramfuncs");
void control_current(void);
void control_flux(void);
void control_speed_power(void);
void indirect_vector_control(void);
void ipark(void);
void limit_current(void);
void pwm(void);
void reference_flux(void);
void reference_power(void);
void reference_speed(void);
void select_feedback(void);
void write_swgen_pwm_times_split_eages(void);
void write_CMP_tims(void);
int reset = 1;
extern double wm_ml;
void upr(void) {
static short decim_psi_wm_pm;
static int calcPWMtimes = 0;
if ( onceUpr == 0 ) {
onceUpr = 1;
decim_psi_wm_pm = (short)DECIM_PSI_WM_PM;
psi = 0;
rf.once = 0;
rs.once = 0;
rp.once = 0;
cf.once = 0;
csp.once = 0;
ivc.once = 0;
cc.once = 0;
reset = 1;
init_DQ_pid();
InitVariablesSvgen(FREQ_PWM);
pwm_vector_model_titov(0, 0, 0, 0, 0, 1, calcPWMtimes);
analog.tetta = 0;
} else {
reset = 0;
}
// âíåøíèå êîíòóðû ðåãóëèðîâàíèÿ (ïî ïîòîêó, îáîðîòàì è ìîùíîñòè)
// íå äîëæíû áûòü òàêèìè æå áûñòðûìè êàê âíóòðåííèå (ïî òîêó) (?)
if ( decim_psi_wm_pm < (short)DECIM_PSI_WM_PM ) {
decim_psi_wm_pm++;
calcPWMtimes = 0;
}
else {
decim_psi_wm_pm = 1;
calcPWMtimes = 1;
// çàäàííîå ïîòîêîñöåïëåíèå
// (rf.PsiZ -> rf.psiZ, rf.pPsiZ)
reference_flux();
// çàäàííàÿ ñêîðîñòü
// (mst.wmZz, mst.wmLim -> rs.wmZ, rs.pWmZ)
reference_speed();
// çàäàííàÿ ìîùíîñòü
// (mst.pmZz, mst.pmLim -> rp.pmZ)
reference_power();
// çàäàííûé òîê (idZ, iqZ)
// ... ðåãóëÿòîð ïîòîêîñöåïëåíèÿ
// (rf.psiZ, psi, rf.pPsiZ, cf.IdLim, cf.IdLimNeg -> idZ)
control_flux();
// ... ðåãóëÿòîðû ñêîðîñòè è ìîùíîñòè
// (rs.wmZ, wm, rs.pWmZ, rp.pmZ, mst.wmLim, mst.pmLim, csp.IqLim,
// csp.IqLimNeg -> iqZ, inuWork)
control_speed_power();
// ... îãðàíè÷åíèå ïîëíîãî òîêà
// (idZ, iqZ, IzLim -> idZ, iqZ, csp.iqLimFlag)
limit_current();
} //decim_psi_wm_pm
if ( mst.start == 1 ) {
inuWork = 1;
} else {
inuWork = 0;
}
_iq Pzad = _IQ(rp.pmZ * 1.1);
// _iq Pzad = _IQ(1.1);
_iq Fzad = _IQ(rs.wmZ / (PI2 * 1.1574233675198942802148869545233));
// _iq Frot = _IQ(10.0 / 6.0 / NORMA_FROTOR);
_iq Frot = _IQ(wm_ml / PI2 / NORMA_FROTOR);
int direction = Frot >= 0 ? 1 : -1;
rotor.iqFout = Frot;
int mode = 2;
// int reset = 0;
f.Go = 1;
if (mode != 0) {
limit_mzz_zad_power(Frot);
// set_cos_tetta_calc_params();
pwm_vector_model_titov(Pzad, Fzad, direction, labs(Frot), mode, 0, calcPWMtimes);
} else {
// U/f=Const
#define K_MODUL_MAX 15435038LL
vect_control.iqUqKm1 = _IQ(0.6);
vect_control.iqUqKm2 = _IQ(0.6);
_iq Fconst = IQ_F_STATOR_NOM / 10;
test_calc_simple_dq_pwm24(vect_control.iqUqKm1, vect_control.iqUqKm2, Fconst, Fconst, K_MODUL_MAX);
}
reset = 0;
float theta = _IQtoF(analog.tetta);
sincos(theta, &sinTheta, &cosTheta);
if (calcPWMtimes)
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_HIGH);
else
write_swgen_pwm_times_split_eages(PWM_MODE_RELOAD_LEVEL_LOW);
write_CMP_tims(calcPWMtimes);
// cc.yd1 = _IQtoF(vect_control.iqUdKm1Out) * Y_LIM;
// cc.yq1 = _IQtoF(vect_control.iqUqKm1Out) * Y_LIM;
// cc.yd2 = _IQtoF(vect_control.iqUdKm2Out) * Y_LIM;
// cc.yq2 = _IQtoF(vect_control.iqUqKm2Out) * Y_LIM;
// indirect vector control
// (wmNf, wm, ix1, iy1, ix2, iy2 -> ivc.ws, ivc.sinTheta, ivc.cosTheta,
// ivc.id1, ivc.iq1, ivc.id2, ivc.iq2, ivc.psi)
// indirect_vector_control();
// âûáîð ñèãíàëîâ î.ñ.
// (... -> ws, sinTheta, cosTheta, id1, iq1, id2, iq2, psi)
// select_feedback();
// idZ = 0.1;
// iqZ = 0.2;
// ðåãóëÿòîðû òîêà
// (idZ, iqZ, id1, iq1, id2, iq2, ws, wm, psi ->
// -> cc.yd1, cc.yq1, cc.yd2, cc.yq2)
// control_current();
// ïåðåâîä ñèãíàëîâ óïðàâëåíèÿ èç ñ.ê. d-q â ñ.ê. x-y
// (cc.yd1, cc.yq1, cc.yd2, cc.yq2, sinTheta, cosTheta, ws ->
// -> ip.yx1, ip.yy1, ip.yx2, ip.yy2)
// ipark();
// ØÈÌ
// (ip.yx1, ip.yy1, ip.yx2, ip.yy2 ->
// -> EPwm1Regs.CMPA.half.CMPA, EPwm2Regs.CMPA.half.CMPA,
// EPwm3Regs.CMPA.half.CMPA, EPwm4Regs.CMPA.half.CMPA,
// EPwm5Regs.CMPA.half.CMPA, EPwm6Regs.CMPA.half.CMPA,
// EPwm7Regs.CMPA.half.CMPA, EPwm8Regs.CMPA.half.CMPA,
// EPwm9Regs.CMPA.half.CMPA, EPwm10Regs.CMPA.half.CMPA,
// EPwm11Regs.CMPA.half.CMPA, EPwm12Regs.CMPA.half.CMPA)
// pwm();
} //void upr(void)
// Ðåãóëèðóåò òîê
// (idZ, iqZ, id1, iq1, id2, iq2, ws, wm, psi ->
// -> cc.yd1, cc.yq1, cc.yd2, cc.yq2)
void control_current(void) {
if ( cc.once == 0 ) {
cc.once = 1;
cc.y1LimFlag = 0;
cc.yd1I = 0;
cc.yq1I = 0;
cc.yd1 = 0;
cc.yq1 = 0;
cc.y2LimFlag = 0;
cc.yd2I = 0;
cc.yq2I = 0;
cc.yd2 = 0;
cc.yq2 = 0;
// äëÿ ñîêðàùåíèÿ âû÷èñëåíèé
cc.K1 = sgmPar.SigmaLs*I_BAZ*WE_BAZ*U_2_Y;
cc.K2 = sgmPar.Rr*sgmPar.Lm/(sgmPar.Lr*sgmPar.Lr)*PSI_BAZ*U_2_Y;
cc.K3 = sgmPar.Kl*PSI_BAZ*WE_BAZ*U_2_Y;
}
// äëÿ ñîêðàùåíèÿ âû÷èñëåíèé
cc.Xyff = ws*cc.K1;
cc.yffAux2 = psi*cc.K2;
cc.yffAux3 = psi*wm*cc.K3;
// ðåãóëÿòîð Id1
cc.del = idZ - id1;
cc.yd1P = cc.del*cc.Kp;
if ( (cc.y1LimFlag == 0) || (cc.yd1*cc.del < 0) )
cc.yd1I += cc.del*cc.Ki;
cc.yd1FF = -iq1*cc.Xyff - cc.yffAux2;
cc.yd1 = cc.yd1P + cc.yd1I + cc.yd1FF;
// ðåãóëÿòîð Iq1
cc.del = iqZ - iq1;
cc.yq1P = cc.del*cc.Kp;
if ( (cc.y1LimFlag == 0) || (cc.yq1*cc.del < 0) )
cc.yq1I += cc.del*cc.Ki;
cc.yq1FF = id1*cc.Xyff + cc.yffAux3;
cc.yq1 = cc.yq1P + cc.yq1I + cc.yq1FF;
// îãðàíè÷åíèå
cc.y1 = sqrt(cc.yd1*cc.yd1 + cc.yq1*cc.yq1);
if ( cc.y1 > Y_LIM ) {
cc.kYlim = Y_LIM/cc.y1;
cc.yd1 *= cc.kYlim;
cc.yq1 *= cc.kYlim;
cc.y1LimFlag = 1;
}
else {
cc.y1LimFlag = 0;
}
// ðåãóëÿòîð Id2
cc.del = idZ - id2;
cc.yd2P = cc.del*cc.Kp;
if ( (cc.y2LimFlag == 0) || (cc.yd2*cc.del < 0) )
cc.yd2I += cc.del*cc.Ki;
cc.yd2FF = -iq2*cc.Xyff - cc.yffAux2;
cc.yd2 = cc.yd2P + cc.yd2I + cc.yd2FF;
// ðåãóëÿòîð Iq2
cc.del = iqZ - iq2;
cc.yq2P = cc.del*cc.Kp;
if ( (cc.y2LimFlag == 0) || (cc.yq2*cc.del < 0) )
cc.yq2I += cc.del*cc.Ki;
cc.yq2FF = id2*cc.Xyff + cc.yffAux3;
cc.yq2 = cc.yq2P + cc.yq2I + cc.yq2FF;
// îãðàíè÷åíèå
cc.y2 = sqrt(cc.yd2*cc.yd2 + cc.yq2*cc.yq2);
if ( cc.y2 > Y_LIM ) {
cc.kYlim = Y_LIM/cc.y2;
cc.yd2 *= cc.kYlim;
cc.yq2 *= cc.kYlim;
cc.y2LimFlag = 1;
}
else {
cc.y2LimFlag = 0;
}
} //void control_current(void)
// Ðåãóëèðóåò ïîòîêîñöåïëåíèå
// (rf.psiZ, psi, rf.pPsiZ, cf.IdLim, cf.IdLimNeg -> idZ)
void control_flux(void) {
if ( cf.once == 0 ) {
cf.once = 1;
cf.idLimFlag = 0;
cf.idI = 0;
idZ = 0;
}
// ðåãóëÿòîð Psi
cf.del = rf.psiZ - psi;
cf.idP = cf.del*cf.Kp;
if ( (cf.idLimFlag == 0) || (idZ*cf.del < 0) )
cf.idI += cf.del*cf.Ki;
cf.idFF = (rf.psiZ + rf.pPsiZ*sgmPar.Tr)*sgmPar.LmInv*PSI_BAZ/I_BAZ;
idZ = cf.idP + cf.idI + cf.idFF;
// îãðàíè÷åíèå ïîòîêîîáðàçóþùåãî òîêà
if ( idZ > cf.IdLim ) {
idZ = cf.IdLim;
cf.idLimFlag = 1;
}
else if ( idZ < cf.IdLimNeg ) {
idZ = cf.IdLimNeg;
cf.idLimFlag = 1;
}
else {
cf.idLimFlag = 0;
}
} //void control_flux(void)
// Ðåãóëèðóåò ñêîðîñòü èëè ìîùíîñòü
// (rs.wmZ, wm, rs.pWmZ, rp.pmZ, mst.wmLim, mst.pmLim, csp.IqLim,
// csp.IqLimNeg -> iqZ, inuWork)
void control_speed_power(void) {
if ( csp.once == 0 ) {
csp.once = 1;
csp.wmLimZi = mst.wmLim;
csp.pmLimZi = mst.pmLim;
csp.iqLimFlag = 0;
csp.iqI = 0;
iqZ = 0;
csp.iqLimZi = csp.IqLim;
csp.iqLim = csp.IqLim;
csp.pmZiRampDown = 0;
}
// äëÿ îãðàíè÷åíèÿ ñêîðîñòè
if ( mst.wmLim - csp.wmLimZi > rs.WlimIncr ) {
csp.wmLimZi += rs.WlimIncr;
}
else if ( csp.wmLimZi - mst.wmLim > rs.WlimIncr ) {
csp.wmLimZi -= rs.WlimIncr;
}
else {
csp.wmLimZi = mst.wmLim;
}
// äëÿ îãðàíè÷åíèÿ ìîùíîñòè
if ( mst.pmLim - csp.pmLimZi > rp.PlimIncr ) {
csp.pmLimZi += rp.PlimIncr;
}
else if ( csp.pmLimZi - mst.pmLim > rp.PlimIncr ) {
csp.pmLimZi -= rp.PlimIncr;
}
else {
csp.pmLimZi = mst.pmLim;
}
if ( inuWork == 0 ) {
if ( mst.start == 1 ) {
// ÃÝÄ íàìàãíè÷åí, ìîæíî ïåðåõîäèòü ê îòðàáîòêå N èëè P
//if ( (rf.psiZ > rf.PsiZ*0.97) && (psi > rf.psiZ*0.97) )
inuWork = 1;
}
else {
// âñ¸ âûêëþ÷àåì
inuWork = 2;
}
// ÷òîáû ñòàðòàíóòü áåç áðîñêîâ òîêà
rs.wmZi = rs.wmZ = wm;
rp.pmZi = rp.pmZ = 0;
iqZ = 0;
}
else if ( inuWork == 1 ) {
if ( mst.start == 1 ) {
// ðåãóëÿòîð N --------------
if ( mst.pzMode == 0 ) {
csp.del = rs.wmZ - wm;
csp.iqP = csp.del*csp.Kp;
if ( (csp.iqLimFlag == 0) || (iqZ*csp.del < 0) )
csp.iqI += csp.del*csp.Ki;
csp.iqFF = rs.pWmZ/kMe*(WM_BAZ*J/M_BAZ);
iqZ = csp.iqP + csp.iqI + csp.iqFF;
// îãðàíè÷åíèå òîêà äëÿ îãðàíè÷åíèÿ ìîùíîñòè
if ( wmAbs > WM_MIN ) {
csp.iqLimAux = csp.pmLimZi/(wmAbs*kMe);
}
else {
csp.iqLimAux = csp.pmLimZi/(WM_MIN*kMe);
}
if ( csp.iqLimAux < csp.IqLim ) {
csp.iqLim = csp.iqLimAux;
}
else {
csp.iqLim = csp.IqLim;
}
}
// ðåãóëÿòîð P --------------
else { //if ( mst.pzMode == 1 )
if ( wmAbs <= WM_MIN ) {
iqZ = rp.pmZ/(WM_MIN*kMe);
}
else if ( wmAbs <= rf.WmNomPsi ) {
iqZ = rp.pmZ/(wmAbs*kMe);
csp.kMeNom = kMe;
}
else {
iqZ = rp.pmZ/(wmAbs*csp.kMeNom);
}
// îãðàíè÷åíèå òîêà äëÿ îãðàíè÷åíèÿ îáîðîòîâ
if ( wmAbs < csp.wmLimZi*0.98 ) {
csp.iqLimAux = fabs(iqZ);
}
else if ( wmAbs > csp.wmLimZi*1.02 ) {
csp.iqLimAux = 0;
}
else {
csp.iqLimAux = csp.iqLimZi;
}
// ... ìåíÿåì ñêîðîñòü èçìåíåíèÿ îãðàíè÷åíèÿ òîêà (?)
csp.delWmAbs = fabs(wmAbs - csp.wmLimZi);
if ( csp.delWmAbs > 0.12 )
csp.KizIncr = 10.0;
else if ( csp.delWmAbs < 0.02 )
csp.KizIncr = 0.1;
else
csp.KizIncr = 0.1 + (csp.delWmAbs - 0.02)*(10.0 - 0.1)/(0.12 - 0.02);
// ... ÇÈ
if ( csp.iqLimAux - csp.iqLimZi > csp.IlimIncr*csp.KizIncr )
csp.iqLimZi += csp.IlimIncr*csp.KizIncr;
else if ( csp.iqLimZi - csp.iqLimAux > csp.IlimIncr*csp.KizIncr )
csp.iqLimZi -= csp.IlimIncr*csp.KizIncr;
else
csp.iqLimZi = csp.iqLimAux;
if ( csp.iqLimZi < csp.IqLim ) {
csp.iqLim = csp.iqLimZi;
}
else {
csp.iqLim = csp.IqLim;
}
} //mst.pzMode
// äëÿ ïëàâíîé îñòàíîâêè
csp.pmZiRampDown = rp.pmEqv;
}
else { //if ( mst.start == 0 )
// ñíèæàåì çàäàííóþ ìîùíîñòü
if ( 0 - csp.pmZiRampDown > mst.pDecrMaxTy ) {
csp.pmZiRampDown += mst.pDecrMaxTy;
}
else if ( csp.pmZiRampDown - 0 > mst.pDecrMaxTy ) {
csp.pmZiRampDown -= mst.pDecrMaxTy;
}
else {
csp.pmZiRampDown = 0;
// òîê ñíèæåí - çàâåðøàåì ðàáîòó
inuWork = 2;
}
// ôîðìèðóåì çàäàííûé òîê
if ( wmAbs > WM_MIN ) {
iqZ = csp.pmZiRampDown/(wmAbs*kMe);
}
else {
iqZ = csp.pmZiRampDown/(WM_MIN*kMe);
}
// íà ñëó÷àé, åñëè mst.start âîññòàíîâèòñÿ ðàíüøå
// çàâåðøåíèÿ ðàáîòû (inuWork = 2)
rs.wmZi = rs.wmZ = wm;
csp.iqI = iqZ;
rp.pmZi = rp.pmZ = rp.pmEqv;
} //mst.start
// óñòàâêà îãðàíè÷åíèÿ ñíèçó
if ( -csp.iqLim > csp.IqLimNeg )
csp.iqLimNeg = -csp.iqLim;
else
csp.iqLimNeg = csp.IqLimNeg;
// îãðàíè÷åíèå ìîìåíòîîáðàçóþùåãî òîêà
if ( iqZ > csp.iqLim ) {
iqZ = csp.iqLim;
csp.iqLimFlag = 1;
}
else if ( iqZ < csp.iqLimNeg ) {
iqZ = csp.iqLimNeg;
csp.iqLimFlag = 1;
}
else {
csp.iqLimFlag = 0;
}
// äëÿ ïëàâíîãî ïåðåõîäà
if ( mst.pzMode == 0 ) {
// ... â ðåæèì ðåãóëèðîâàíèÿ P
rp.pmZ = iqZ*kMe*wmAbs;
rp.pmZi = rp.pmZ;
csp.iqLimZi = fabs(iqZ);
}
else {
// ... â ðåæèì ðåãóëèðîâàíèÿ N
csp.iqI = iqZ;
csp.iqFF = 0;
rs.wmZ = wm;
rs.wmZi = rs.wmZ + csp.iqFF*0.05;
}
} //inuWork
} //void control_speed_power(void)
// Ðàñ÷¸òû äëÿ indirect vector control
// (wmNf, wm, ix1, iy1, ix2, iy2 -> ivc.ws, ivc.sinTheta, ivc.cosTheta,
// ivc.id1, ivc.iq1, ivc.id2, ivc.iq2, ivc.psi)
void indirect_vector_control(void) {
static float theta;
if ( ivc.once == 0 ) {
ivc.once = 1;
ivc.im = 0;
ivc.iq1 = 0;
ivc.iq2 = 0;
ivc.wr = 0;
theta = 0;
}
// ÷àñòîòà ðîòîðíîé ÝÄÑ, o.e.
if ( ivc.im > 4e-3 ) {
ivc.wr = (ivc.iq1 + ivc.iq2)*0.5/ivc.im*sgmPar.TrInv*(1.0/WE_BAZ);
}
// ÷àñòîòà ïîëÿ ñòàòîðà, î.å.
ivc.wsNf = wmNf + ivc.wr;
ivc.ws = wm + ivc.wr;
// ýëåêòðè÷åñêèé óãîë, ðàä.
theta += ivc.wsNf*WE_BAZ*TY;
if ( theta > PI2 )
theta -= PI2;
else if ( theta < 0 )
theta += PI2;
vect_control.theta = theta;
// äëÿ êîîðäèíàòíûõ ïðåîáðàçîâàíèé
sincos(theta, &ivc.sinTheta, &ivc.cosTheta);
// park transformations, î.å.
ivc.id1 = ix1*ivc.cosTheta + iy1*ivc.sinTheta;
ivc.iq1 = -ix1*ivc.sinTheta + iy1*ivc.cosTheta;
ivc.id2 = ix2*ivc.cosTheta + iy2*ivc.sinTheta;
ivc.iq2 = -ix2*ivc.sinTheta + iy2*ivc.cosTheta;
// òîê íàìàãíè÷èâàíèÿ, o.e.
ivc.im += ((ivc.id1 + ivc.id2)*0.5 - ivc.im)*sgmPar.TrInv*TY;
// àìïëèòóäà ïîòîêà, o.e.
ivc.psi = ivc.im*sgmPar.Lm*(1.0/L_BAZ);
} //void indirect_vector_control(void)
// Ïåðåâîäèò ñèãíàëû óïðàâëåíèÿ èç ñ.ê. d-q â ñ.ê. x-y
// (cc.yd1, cc.yq1, cc.yd2, cc.yq2, sinTheta, cosTheta, ws ->
// -> ip.yx1, ip.yy1, ip.yx2, ip.yy2)
void ipark(void) {
ip.yx1Aux = cc.yd1*cosTheta - cc.yq1*sinTheta;
ip.yy1Aux = cc.yd1*sinTheta + cc.yq1*cosTheta;
ip.yx2Aux = cc.yd2*cosTheta - cc.yq2*sinTheta;
ip.yy2Aux = cc.yd2*sinTheta + cc.yq2*cosTheta;
// êîððåêöèÿ, ñâÿçàííàÿ ñ äèñêðåòíîñòüþ ÑÓ
ip.theta = ws*WE_BAZ*TY*1.5;//ðàä.
sincos(ip.theta, &ip.sinTheta, &ip.cosTheta);
ip.yx1 = ip.yx1Aux*ip.cosTheta - ip.yy1Aux*ip.sinTheta;
ip.yy1 = ip.yx1Aux*ip.sinTheta + ip.yy1Aux*ip.cosTheta;
ip.yx2 = ip.yx2Aux*ip.cosTheta - ip.yy2Aux*ip.sinTheta;
ip.yy2 = ip.yx2Aux*ip.sinTheta + ip.yy2Aux*ip.cosTheta;
} //void ipark(void)
// Îãðàíè÷èâàåò ïîëíûé òîê
// (idZ, iqZ, IzLim -> idZ, iqZ, csp.iqLimFlag)
void limit_current(void) {
iZ = sqrt(idZ*idZ + iqZ*iqZ);
if ( iZ > IzLim ) {
if ( iqZ >= 0 ) {
iqZ = sqrt(IzLim*IzLim - idZ*idZ);
}
else {
iqZ = -sqrt(IzLim*IzLim - idZ*idZ);
}
csp.iqLimFlag = 1;
}
} //void limit_current(void)
// ØÈÌ
// (ip.yx1, ip.yy1, ip.yx2, ip.yy2 ->
// -> EPwm1Regs.CMPA.half.CMPA, EPwm2Regs.CMPA.half.CMPA,
// EPwm3Regs.CMPA.half.CMPA, EPwm4Regs.CMPA.half.CMPA,
// EPwm5Regs.CMPA.half.CMPA, EPwm6Regs.CMPA.half.CMPA,
// EPwm7Regs.CMPA.half.CMPA, EPwm8Regs.CMPA.half.CMPA,
// EPwm9Regs.CMPA.half.CMPA, EPwm10Regs.CMPA.half.CMPA,
// EPwm11Regs.CMPA.half.CMPA, EPwm12Regs.CMPA.half.CMPA)
void pwm(void) {
static float yAux1;
static float yAux2;
static float ya;
static float yb;
static float yc;
static float yPredm = 0;
static float yaPredm;
static float ybPredm;
static float ycPredm;
// ïåðåâîäèì èç ñ.ê. x-y â ñ.ê. a-b-c
yAux1 = ip.yx1*(-0.5*ISQRT3);
yAux2 = ip.yy1*0.5;
ya = ip.yx1*ISQRT3;
yb = yAux1 + yAux2;
yc = yAux1 - yAux2;
// ïðåäìîäóëèðóþùåå âîçäåéñòâèå
if ((ya >= yb) && (ya <= yc)) {
yPredm = ya*0.5;
}
else if ((yc >= yb) && (yc <= ya)) {
yPredm = yc*0.5;
}
else if ((yb >= yc) && (yb <= ya)) {
yPredm = yb*0.5;
}
else if ((ya >= yc) && (ya <= yb)) {
yPredm = ya*0.5;
}
else if ((yc >= ya) && (yc <= yb)) {
yPredm = yc*0.5;
}
else if ((yb >= ya) && (yb <= yc)) {
yPredm = yb*0.5;
}
yaPredm = (ya + yPredm)*2.;
ybPredm = (yb + yPredm)*2.;
ycPredm = (yc + yPredm)*2.;
// full compare unit compare registers
if (yaPredm >= 0) {
EPwm1Regs.CMPA.half.CMPA = (unsigned short)yaPredm;
EPwm2Regs.CMPA.half.CMPA = 0;
}
else {
EPwm1Regs.CMPA.half.CMPA = 0;
EPwm2Regs.CMPA.half.CMPA = (unsigned short)(-yaPredm);
}
if (ybPredm >= 0) {
EPwm3Regs.CMPA.half.CMPA = (unsigned short)ybPredm;
EPwm4Regs.CMPA.half.CMPA = 0;
}
else {
EPwm3Regs.CMPA.half.CMPA = 0;
EPwm4Regs.CMPA.half.CMPA = (unsigned short)(-ybPredm);
}
if (ycPredm >= 0) {
EPwm5Regs.CMPA.half.CMPA = (unsigned short)ycPredm;
EPwm6Regs.CMPA.half.CMPA = 0;
}
else {
EPwm5Regs.CMPA.half.CMPA = 0;
EPwm6Regs.CMPA.half.CMPA = (unsigned short)(-ycPredm);
}
// ïåðåâîäèì èç ñ.ê. x-y â ñ.ê. a-b-c
#ifndef SHIFT
yAux1 = ip.yx2*(-0.5*ISQRT3);
yAux2 = ip.yy2*0.5;
ya = ip.yx2*ISQRT3;
yb = yAux1 + yAux2;
yc = yAux1 - yAux2;
#else //SHIFT
yAux1 = ip.yx2*0.5;
yAux2 = ip.yy2*0.5*ISQRT3;
ya = yAux1 + yAux2;
yb = -yAux1 + yAux2;
yc = ip.yy2*(-ISQRT3);
#endif //SHIFT
// ïðåäìîäóëèðóþùåå âîçäåéñòâèå
if ((ya >= yb) && (ya <= yc)) {
yPredm = ya*0.5;
}
else if ((yc >= yb) && (yc <= ya)) {
yPredm = yc*0.5;
}
else if ((yb >= yc) && (yb <= ya)) {
yPredm = yb*0.5;
}
else if ((ya >= yc) && (ya <= yb)) {
yPredm = ya*0.5;
}
else if ((yc >= ya) && (yc <= yb)) {
yPredm = yc*0.5;
}
else if ((yb >= ya) && (yb <= yc)) {
yPredm = yb*0.5;
}
yaPredm = (ya + yPredm)*2.;
ybPredm = (yb + yPredm)*2.;
ycPredm = (yc + yPredm)*2.;
#ifdef ML
// full compare unit compare registers
if (yaPredm >= 0) {
EPwm7Regs.CMPA.half.CMPA = (unsigned short)yaPredm;
EPwm8Regs.CMPA.half.CMPA = 0;
}
else {
EPwm7Regs.CMPA.half.CMPA = 0;
EPwm8Regs.CMPA.half.CMPA = (unsigned short)(-yaPredm);
}
if (ybPredm >= 0) {
EPwm9Regs.CMPA.half.CMPA = (unsigned short)ybPredm;
EPwm10Regs.CMPA.half.CMPA = 0;
}
else {
EPwm9Regs.CMPA.half.CMPA = 0;
EPwm10Regs.CMPA.half.CMPA = (unsigned short)(-ybPredm);
}
if (ycPredm >= 0) {
EPwm11Regs.CMPA.half.CMPA = (unsigned short)ycPredm;
EPwm12Regs.CMPA.half.CMPA = 0;
}
else {
EPwm11Regs.CMPA.half.CMPA = 0;
EPwm12Regs.CMPA.half.CMPA = (unsigned short)(-ycPredm);
}
#endif //ML
// ðàçðåøàåì èìïóëüñû
EALLOW;
EPwm1Regs.TZCLR.all = 0x0004;
EPwm2Regs.TZCLR.all = 0x0004;
EPwm3Regs.TZCLR.all = 0x0004;
EPwm4Regs.TZCLR.all = 0x0004;
EPwm5Regs.TZCLR.all = 0x0004;
EPwm6Regs.TZCLR.all = 0x0004;
#ifdef ML
EPwm7Regs.TZCLR.all = 0x0004;
EPwm8Regs.TZCLR.all = 0x0004;
EPwm9Regs.TZCLR.all = 0x0004;
EPwm10Regs.TZCLR.all = 0x0004;
EPwm11Regs.TZCLR.all = 0x0004;
EPwm12Regs.TZCLR.all = 0x0004;
#endif //ML
EDIS;
} //void pwm(void)
// Ôîðìèðóåò çàäàííûé ïîòîê
// (rf.PsiZ -> rf.psiZ, rf.pPsiZ)
void reference_flux(void) {
if ( rf.once == 0 ) {
rf.once = 1;
rf.KpsiSub = TY*DECIM_PSI_WM_PM/6.0;
rf.psiZi = 0;
cc.y1 = 0;
cc.y2 = 0;
rf.psiSub = 0;
rf.psiZ = 0;
rf.psiZPrev1 = 0;
rf.psiZPrev2 = 0;
rf.psiZPrev3 = 0;
}
// ÇÈ
if ( rf.PsiZ - rf.psiZi > rf.PsizIncr ) {
rf.psiZi += rf.PsizIncr;
}
else if ( rf.psiZi - rf.PsiZ > rf.PsizIncr ) {
rf.psiZi -= rf.PsizIncr;
}
else {
rf.psiZi = rf.PsiZ;
}
// êîððåêöèÿ â ñîîòâåòñòâèè ñî ñêîðîñòüþ
if ( wmAbs <= rf.WmNomPsi )
rf.psiZCorr = rf.psiZi;
else
rf.psiZCorr = rf.psiZi*rf.WmNomPsi/wmAbs;
// êîððåêöèÿ â ñîîòâåòñòâèè ñ ïðîòèâîÝÄÑ
if ( (cc.y1 > rf.YlimPsi) || (cc.y2 > rf.YlimPsi) ) {
rf.psiSub += (rf.psiZCorr - rf.psiSub)*rf.KpsiSub;
}
else {
rf.psiSub += (0 - rf.psiSub)*rf.KpsiSub;
}
rf.psiZCorr2 = rf.psiZCorr - rf.psiSub;
// ÷òîáû çàäàíèå ìåíÿëîñü ÷óòü ïëàâíåå
rf.psiZ += (rf.psiZCorr2 - rf.psiZ)*rf.Kpsiz;
// ïðîèçâîäíàÿ çàäàííîãî ïîòîêîñöåïëåíèÿ
rf.pPsiZ = (rf.psiZ - rf.psiZPrev3)/(TY*DECIM_PSI_WM_PM*3.);
rf.psiZPrev3 = rf.psiZPrev2;
rf.psiZPrev2 = rf.psiZPrev1;
rf.psiZPrev1 = rf.psiZ;
} //void reference_flux(void)
// Ôîðìèðóåò çàäàííóþ ìîùíîñòü
// (mst.pmZz, mst.pmLim -> rp.pmZ)
void reference_power(void) {
if ( rp.once == 0 ) {
rp.once = 1;
rp.pmZi = 0;
rp.pmZ = 0;
}
// îãðàíè÷åíèå
if ( fabs(mst.pmZz) > mst.pmLim ) {
if ( mst.pmZz >= 0 )
rp.pmZz = mst.pmLim;
else
rp.pmZz = -mst.pmLim;
}
else {
rp.pmZz = mst.pmZz;
}
// äëÿ îãðàíè÷åíèÿ ïðèðàùåíèÿ ìîùíîñòè (?)
if ( fabs(rp.pmZi - rp.pmEqv) > 0.02 )
rp.KpIncrDecr = 0.10;
else
rp.KpIncrDecr = 1.00;
// ÇÈ
if ( rp.pmZz - rp.pmZi > mst.pIncrMaxTy*rp.KpIncrDecr ) {
rp.pmZi += mst.pIncrMaxTy*rp.KpIncrDecr;
}
else if ( rp.pmZi - rp.pmZz > mst.pDecrMaxTy*rp.KpIncrDecr ) {
rp.pmZi -= mst.pDecrMaxTy*rp.KpIncrDecr;
}
else {
rp.pmZi = rp.pmZz;
}
// ÷òîáû çàäàíèå ìåíÿëîñü ÷óòü ïëàâíåå
// rp.pmZ += (rp.pmZi - rp.pmZ)*rp.Kpmz;
rp.pmZ = rp.pmZz;
} //void reference_power(void)
// Ôîðìèðóåò çàäàííóþ ñêîðîñòü
// (mst.wmZz, mst.wmLim -> rs.wmZ, rs.pWmZ)
void reference_speed(void) {
if ( rs.once == 0 ) {
rs.once = 1;
rs.wmZi = rs.wmZ = wm;
rs.wzIncr = rs.WlimIncr;
rs.wmZPrev1 = rs.wmZ;
rs.wmZPrev2 = rs.wmZ;
rs.wmZPrev3 = rs.wmZ;
rs.tPwmZ = 0;
}
// îãðàíè÷åíèå
if ( fabs(mst.wmZz) > mst.wmLim ) {
if ( mst.wmZz >= 0 )
rs.wmZz = mst.wmLim;
else
rs.wmZz = -mst.wmLim;
}
else {
rs.wmZz = mst.wmZz;
}
// äëÿ îãðàíè÷åíèÿ ïðèðàùåíèÿ ìîùíîñòè (?)
if ( fabs(rs.wmZi) < 0.5 )
rs.wzIncrNf = rs.WlimIncr*3.5;
else if ( fabs(rs.wmZi) < 0.8 )
rs.wzIncrNf = rs.WlimIncr*2.0;
else
rs.wzIncrNf = rs.WlimIncr;
rs.wzIncr += (rs.wzIncrNf - rs.wzIncr)*(TY*DECIM_PSI_WM_PM)/0.25;
// ÇÈ
if ( rs.wmZz - rs.wmZi > rs.wzIncr ) {
rs.wmZi += rs.wzIncr;
}
else if ( rs.wmZi - rs.wmZz > rs.wzIncr ) {
rs.wmZi -= rs.wzIncr;
}
else {
rs.wmZi = rs.wmZz;
}
// ÷òîáû çàäàíèå ìåíÿëîñü ÷óòü ïëàâíåå
// rs.wmZ += (rs.wmZi - rs.wmZ)*rs.Kwmz;
rs.wmZ = rs.wmZz;
// ïðîèçâîäíàÿ çàäàííîé ñêîðîñòè
rs.pWmZ = (rs.wmZ - rs.wmZPrev3)/(TY*DECIM_PSI_WM_PM*3.);
rs.wmZPrev3 = rs.wmZPrev2;
rs.wmZPrev2 = rs.wmZPrev1;
rs.wmZPrev1 = rs.wmZ;
// ... ÷òîáû èçáåæàòü áðîñêîâ ïðè âõîäå â ðàáî÷èé ðåæèì
// if ( (inuWork == 0) || (mst.start == 0) || (mst.pzMode == 1) )
// rs.tPwmZ = 0;
// if ( rs.tPwmZ <= 3 ) {
// rs.tPwmZ++;
// rs.pWmZ = 0;
// }
} //void reference_speed(void)
// Âûáèðàåò î.ñ.
// (... -> ws, sinTheta, cosTheta, id1, iq1, id2, iq2, psi)
void select_feedback(void) {
ws = ivc.ws;
sinTheta = ivc.sinTheta;
cosTheta = ivc.cosTheta;
id1 = ivc.id1;
iq1 = ivc.iq1;
id2 = ivc.id2;
iq2 = ivc.iq2;
psi = ivc.psi;
} //void select_feedback(void)
void write_swgen_pwm_times_split_eages(unsigned int mode_reload) {
xpwm_time.Ta0_0 = (unsigned int) svgen_pwm24_1.Ta_0.Ti;
xpwm_time.Ta0_1 = (unsigned int) svgen_pwm24_1.Ta_1.Ti;
xpwm_time.Tb0_0 = (unsigned int) svgen_pwm24_1.Tb_0.Ti;
xpwm_time.Tb0_1 = (unsigned int) svgen_pwm24_1.Tb_1.Ti;
xpwm_time.Tc0_0 = (unsigned int) svgen_pwm24_1.Tc_0.Ti;
xpwm_time.Tc0_1 = (unsigned int) svgen_pwm24_1.Tc_1.Ti;
xpwm_time.Ta1_0 = (unsigned int) svgen_pwm24_2.Ta_0.Ti;
xpwm_time.Ta1_1 = (unsigned int) svgen_pwm24_2.Ta_1.Ti;
xpwm_time.Tb1_0 = (unsigned int) svgen_pwm24_2.Tb_0.Ti;
xpwm_time.Tb1_1 = (unsigned int) svgen_pwm24_2.Tb_1.Ti;
xpwm_time.Tc1_0 = (unsigned int) svgen_pwm24_2.Tc_0.Ti;
xpwm_time.Tc1_1 = (unsigned int) svgen_pwm24_2.Tc_1.Ti;
// xpwm_time.Tbr0_0 = break_result_1;
// xpwm_time.Tbr0_1 = break_result_2;
// xpwm_time.Tbr1_0 = break_result_3;
// xpwm_time.Tbr1_1 = break_result_4;
xpwm_time.mode_reload = PWM_MODE_RELOAD_FORCE;// mode_reload;
xpwm_time.write_1_2_winding_break_times_split(&xpwm_time);
}
void write_CMP_tims(int calcPWMtimes) {
// if (calcPWMtimes == 0) {
// return;
// }
// EPwm1Regs.CMPA.half.CMPA = xpwm_time.Ta0_1;
// EPwm2Regs.CMPA.half.CMPA = xpwm_time.Ta0_0;
// EPwm3Regs.CMPA.half.CMPA = xpwm_time.Tb0_1;
// EPwm4Regs.CMPA.half.CMPA = xpwm_time.Tb0_0;
// EPwm5Regs.CMPA.half.CMPA = xpwm_time.Tc0_1;
// EPwm6Regs.CMPA.half.CMPA = xpwm_time.Tc0_0;
// EPwm7Regs.CMPA.half.CMPA = xpwm_time.Ta1_1;
// EPwm8Regs.CMPA.half.CMPA = xpwm_time.Ta1_0;
// EPwm9Regs.CMPA.half.CMPA = xpwm_time.Tb1_1;
// EPwm10Regs.CMPA.half.CMPA = xpwm_time.Tb1_0;
// EPwm11Regs.CMPA.half.CMPA = xpwm_time.Tc1_1;
// EPwm12Regs.CMPA.half.CMPA = xpwm_time.Tc1_0;
// ðàçðåøàåì èìïóëüñû
EALLOW;
EPwm1Regs.TZCLR.all = 0x0004;
EPwm2Regs.TZCLR.all = 0x0004;
EPwm3Regs.TZCLR.all = 0x0004;
EPwm4Regs.TZCLR.all = 0x0004;
EPwm5Regs.TZCLR.all = 0x0004;
EPwm6Regs.TZCLR.all = 0x0004;
#ifdef ML
EPwm7Regs.TZCLR.all = 0x0004;
EPwm8Regs.TZCLR.all = 0x0004;
EPwm9Regs.TZCLR.all = 0x0004;
EPwm10Regs.TZCLR.all = 0x0004;
EPwm11Regs.TZCLR.all = 0x0004;
EPwm12Regs.TZCLR.all = 0x0004;
#endif //ML
EDIS;
}

View File

@ -1,50 +0,0 @@
#ifndef UPR
#define UPR
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â upr.c (begin)
//#########################################################################
volatile short onceUpr;
struct SgmPar sgmPar;
struct Rf rf;
struct Rs rs;
struct Rp rp;
float IzLim;
volatile float psi;
float idZ;
float iqZ;
float iZ;
float ws;
float sinTheta;
float cosTheta;
float id1;
float iq1;
float id2;
float iq2;
struct Cc cc;
struct Cf cf;
struct Csp csp;
struct Ivc ivc;
struct Ip ip;
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îïðåäåëåíû â upr.c (end)
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â upr.c (begin)
//#########################################################################
extern volatile float wmNf;
extern volatile float wm;
extern volatile float wmAbs;
extern volatile float ix1;
extern volatile float iy1;
extern volatile float ix2;
extern volatile float iy2;
extern volatile float kMe;
extern volatile short inuWork;
extern struct Mst mst;
extern volatile short faultNo;
//#########################################################################
// Ïåðåìåííûå, êîòîðûå îáúÿâëåíû â upr.c (end)
#endif //UPR

View File

@ -1,267 +0,0 @@
/**************************************************************************
Description: Ïðîãðàììà - óïàêîâùèê.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.09.23
**************************************************************************/
#define S_FUNCTION_NAME wrapper_inu
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include "math.h"
#include "wrapper_inu.h"
#define MDL_UPDATE
/* Function: mdlUpdate ====================================================
* Abstract:
* This function is called once for every major integration time step.
* Discrete states are typically updated here, but this function is useful
* for performing any tasks that should only take place once per
* integration step.
*/
static void mdlUpdate(SimStruct *S, int_T tid)
{
const real_T *u = (const real_T*) ssGetInputPortRealSignal(S,0);
real_T *xD = ssGetDiscStates(S);
real_T *rW = ssGetRWork(S);
int_T *iW = ssGetIWork(S);
controller(S, u, xD, rW, iW);
}//end mdlUpdate
/* Function: mdlCheckParameters ===========================================
* Abstract:
* mdlCheckParameters verifies new parameter settings whenever parameter
* change or are re-evaluated during a simulation.
*/
#define MDL_CHECK_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_CHECK_PARAMETERS) && defined(MATLAB_MEX_FILE)
static void mdlCheckParameters(SimStruct *S)
{
int i;
// Ïðîâåðÿåì è ïðèíèìàåì ïàðàìåòðû è ðàçðåøàåì èëè çàïðåùàåì èõ ìåíÿòü
// â ïðîöåññå ìîäåëèðîâàíèÿ
for (i=0; i<NPARAMS; i++)
{
// Input parameter must be scalar or vector of type double
if (!mxIsDouble(ssGetSFcnParam(S,i)) || mxIsComplex(ssGetSFcnParam(S,i)) ||
mxIsEmpty(ssGetSFcnParam(S,i)))
{
ssSetErrorStatus(S,"Input parameter must be of type double");
return;
}
// Ïàðàìåòð ì.á. òîëüêî ñêàëÿðîì, âåêòîðîì èëè ìàòðèöåé
if (mxGetNumberOfDimensions(ssGetSFcnParam(S,i)) > 2)
{
ssSetErrorStatus(S,"Ïàðàìåòð ì.á. òîëüêî ñêàëÿðîì, âåêòîðîì èëè ìàòðèöåé");
return;
}
// Parameter not tunable
// ssSetSFcnParamTunable(S, i, SS_PRM_NOT_TUNABLE);
// Parameter tunable (we must create a corresponding run-time parameter)
ssSetSFcnParamTunable(S, i, SS_PRM_TUNABLE);
// Parameter tunable only during simulation
// ssSetSFcnParamTunable(S, i, SS_PRM_SIM_ONLY_TUNABLE);
}//for (i=0; i<NPARAMS; i++)
}//end mdlCheckParameters
#endif //MDL_CHECK_PARAMETERS
#define MDL_PROCESS_PARAMETERS /* Change to #undef to remove function */
#if defined(MDL_PROCESS_PARAMETERS) && defined(MATLAB_MEX_FILE)
/* Function: mdlProcessParameters =========================================
* Abstract:
* This method will be called after mdlCheckParameters, whenever
* parameters change or get re-evaluated. The purpose of this method is
* to process the newly changed parameters. For example "caching" the
* parameter changes in the work vectors. Note this method is not
* called when it is used with the Real-Time Workshop. Therefore,
* if you use this method in an S-function which is being used with the
* Real-Time Workshop, you must write your S-function such that it doesn't
* rely on this method. This can be done by inlining your S-function
* via the Target Language Compiler.
*/
static void mdlProcessParameters(SimStruct *S)
{
int_T *iW = ssGetIWork(S);
iW[0] = 1;//processParameters
}
#endif //MDL_PROCESS_PARAMETERS
/* Function: mdlInitializeSizes ===========================================
* Abstract:
* The sizes information is used by Simulink to determine the S-function
* block's characteristics (number of inputs, outputs, states, etc.).
*/
static void mdlInitializeSizes(SimStruct *S)
{
//---------------------------------------------------------------------
// Number of expected parameters
ssSetNumSFcnParams(S, NPARAMS);
// Â íîðìàëüíîì ðåæèìå ðàáîòû, äëÿ îáðàáîòêè ïàðàìåòðîâ âûçûâàåì ô-öèþ
// mdlCheckParameters()
#ifdef MATLAB_MEX_FILE
// Êîë-âî îæèäàåìûõ è ôàêòè÷åñêèõ ïàðàìåòðîâ äîëæíî ñîâïàäàòü
if(ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S))
{
// Ïðîâåðÿåì è ïðèíèìàåì ïàðàìåòðû
mdlCheckParameters(S);
}
else
{
return;// Parameter mismatch will be reported by Simulink
}
#endif // MATLAB_MEX_FILE
//---------------------------------------------------------------------
// Register the number and type of states the S-Function uses
ssSetNumContStates(S, 0); // number of continuous states
ssSetNumDiscStates(S, OUTPUT_0_WIDTH); // number of discrete states
//---------------------------------------------------------------------
// Óñòàíàâëèâàåì êîë-âî âõ-ûõ ïîðòîâ
if (!ssSetNumInputPorts(S, 1)) return;
// Óñòàíàâëèâàåì êîë-âî ñèãíàëîâ âî âõ-îì ïîðòó
ssSetInputPortWidth(S, 0, INPUT_0_WIDTH);
// Çàÿâëÿåì, ÷òî äëÿ íàøåãî âõ-ãî ïîðòà íåò direct feedthrough
ssSetInputPortDirectFeedThrough(S, 0, 0);
// Òðåáóåì, ÷òîáû ñèãíàëû âî âõîäíîì ïîðòó øëè ïîñëåäîâàòåëüíî, à íå
// â ðàçáðîñ
ssSetInputPortRequiredContiguous(S, 0, 1); // direct input signal access
//---------------------------------------------------------------------
// Óñòàíàâëèâàåì êîë-âî âûõ-ûõ ïîðòîâ
if (!ssSetNumOutputPorts(S, 1)) return;
// Óñòàíàâëèâàåì êîë-âî ñèãíàëîâ â âûõ-îì ïîðòó
ssSetOutputPortWidth(S, 0, OUTPUT_0_WIDTH);
//---------------------------------------------------------------------
// Number of sample times
ssSetNumSampleTimes(S, 1);
//---------------------------------------------------------------------
// Set size of the work vectors
ssSetNumRWork( S, RWORK_0_WIDTH); // number of real work vector elements
ssSetNumIWork( S, IWORK_0_WIDTH); // number of integer work vector elements
ssSetNumPWork( S, 0); // number of pointer work vector elements
ssSetNumModes( S, 0); // number of mode work vector elements
ssSetNumNonsampledZCs( S, 0); // number of nonsampled zero crossings
// ssSetNumDWork(S, 1);
// ssSetDWorkWidth(S, 0, 12);//Inm
// ssSetDWorkDataType(S, 0, SS_DOUBLE);
//---------------------------------------------------------------------
/*
* All options have the form SS_OPTION_<name> and are documented in
* matlabroot/simulink/include/simstruc.h. The options should be
* bitwise or'd together as in
* ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_name2))
*/
// Ñ ïîìîùüþ îïöèè SS_OPTION_EXCEPTION_FREE_CODE îáåùàåì, ÷òî â
// íàøåé ïðîãðàììå íåò "èñêëþ÷åíèé"
ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE));
}//end mdlInitializeSizes
/* Function: mdlInitializeSampleTimes =====================================
* Abstract:
* This function is used to specify the sample time(s) for your
* S-function. You must register the same number of sample times as
* specified in ssSetNumSampleTimes.
*/
static void mdlInitializeSampleTimes(SimStruct *S)
{
double dt;
// Øàã äèñêðåòèçàöèè
dt = mxGetPr(ssGetSFcnParam(S,NPARAMS-1))[0];
// Register one pair for each sample time
ssSetSampleTime(S, 0, dt);
ssSetOffsetTime(S, 0, 0.0);
}//end mdlInitializeSampleTimes
#define MDL_START // Change to #undef to remove function
#if defined(MDL_START)
/* Function: mdlStart =====================================================
* Abstract:
* This function is called once at start of model execution. If you
* have states that should be initialized once, this is the place
* to do it.
*/
static void mdlStart(SimStruct *S)
{
int_T *iW = ssGetIWork(S);
iW[0] = 1;//processParameters
iW[1] = 1;//start
}
#endif // MDL_START
/* Function: mdlOutputs ===================================================
* Abstract:
* In this function, you compute the outputs of your S-function
* block. Generally outputs are placed in the output vector(s),
* ssGetOutputPortSignal.
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T *y = ssGetOutputPortRealSignal(S,0);
real_T *xD = ssGetDiscStates(S);
int i;
// OUTPUTS
for (i=0; i<OUTPUT_0_WIDTH; i++)
y[i] = xD[i];
}//end mdlOutputs
/* Function: mdlTerminate =================================================
* Abstract:
* In this function, you should perform any actions that are necessary
* at the termination of a simulation. For example, if memory was
* allocated in mdlStart, this is the place to free it.
*/
static void mdlTerminate(SimStruct *S)
{
}
/*=============================*
* Required S-function trailer *
*=============================*/
#ifdef MATLAB_MEX_FILE // Is this file being compiled as a MEX-file?
#include "simulink.c" // MEX-file interface mechanism
#else
#include "cg_sfun.h" // Code generation registration function
#endif

View File

@ -1,25 +0,0 @@
/**************************************************************************
Description: Çàäàíèå êîëè÷åñòâà âõîäîâ, âûõîäîâ, ïàðàìåòðîâ, à òàêæå
ðàçìåðà ðàáî÷èõ âåêòîðîâ S-function.
Àâòîð: Óëèòîâñêèé Ä.È.
Äàòà ïîñëåäíåãî îáíîâëåíèÿ: 2021.09.22
**************************************************************************/
#include "simstruc.h"
#ifndef WRAPPER
#define WRAPPER
#define INPUT_0_WIDTH 20 //êîë-âî âõîäîâ
#define OUTPUT_0_WIDTH 49 //êîë-âî âûõîäîâ
#define NPARAMS 1 //êîë-âî ïàðàìåòðîâ (ñêàëÿðîâ è âåêòîðîâ)
#define RWORK_0_WIDTH 5 //width of the real-work vector
#define IWORK_0_WIDTH 5 //width of the integer-work vector
void controller(SimStruct *S, const real_T *u, real_T *xD, real_T *rW,
int_T *iW);
extern double dt;
#endif

View File

@ -4,8 +4,9 @@ currFolder = cd;
%cd([currFolder, '\Inu']);
delete("wrapper_inu.mexw64")
delete("*.mexw64.pdb")
status=system('run_mex.bat wrapper_inu.c')
status=system('run_mex.bat debug')
if status==0
else
error('Error!')

Binary file not shown.

View File

@ -1,32 +1,30 @@
@echo off
IF [%1]==[] (set params_sfunction=.\Inu\wrapper_inu_1.c)
IF NOT [%1]==[] (set params_sfunction=.\Inu\%1)
echo %params_sfunction%
set params_d1=-D"ML" -D"__IQMATHLIB_H_INCLUDED__" -D"_MATLAB_SIMULATOR"
set params_d2=-D"_MATLAB_FAST_SIMULATOR" -D"PROJECT_SHIP=1"
set params_i=-I"..\device_support_ml\include"^
-I"."^
set defines=-D"ML" -D"__IQMATHLIB_H_INCLUDED__" -D"_MATLAB_SIMULATOR"^
-D"_MATLAB_FAST_SIMULATOR" -D"PROJECT_SHIP=1"
:: -------------------------USERS PATHS AND CODE---------------------------
set includes_USER=-I"..\device_support_ml\include"^
-I".\"^
-I".\Inu"^
-I".\Inu\tms_matlab\"^
-I".\Inu\main_matlab"^
-I".\Inu\Src\main"^
-I".\Inu\Src\N12_VectorControl"^
-I".\Inu\Src\main_matlab"^
-I".\Inu\Src\N12_Libs"^
-I".\Inu\Src\N12_Xilinx"
set params_o=-outdir "."
set params_wrapper_c=.\Inu\controller.c^
.\Inu\pwm_sim.c^
.\Inu\Src\main_matlab\init28335.c^
.\Inu\Src\main_matlab\param.c^
.\Inu\Src\main_matlab\main_matlab.c^
.\Inu\Src\main_matlab\IQmathLib_matlab.c
:: исходный код
set params_main_c=.\Inu\Src\main\adc_tools.c^
.\Inu\Src\main\v_pwm24_v2.c^
.\Inu\Src\main\limit_power.c^
.\Inu\Src\main\limit_lib.c^
.\Inu\Src\main\pll_tools.c^
.\Inu\Src\main\calc_rms_vals.c^
.\Inu\Src\main\alg_simple_scalar.c^
.\Inu\Src\main\control_station_project.c^
.\Inu\Src\main\ramp_zadanie_tools.c
set params_vectorcontorl_c=.\Inu\Src\N12_VectorControl\vector_control.c^
.\Inu\Src\N12_VectorControl\teta_calc.c^
.\Inu\Src\N12_VectorControl\regul_power.c^
@ -36,8 +34,7 @@ set params_vectorcontorl_c=.\Inu\Src\N12_VectorControl\vector_control.c^
.\Inu\Src\N12_VectorControl\alphabeta_to_dq.c^
.\Inu\Src\N12_VectorControl\abc_to_alphabeta.c^
.\Inu\Src\N12_VectorControl\alg_pll.c
set params_libs_c=.\Inu\Src\N12_Libs\mathlib.c^
.\Inu\Src\N12_Libs\pid_reg3.c^
.\Inu\Src\N12_Libs\rmp_cntl_v1.c^
@ -48,23 +45,44 @@ set params_libs_c=.\Inu\Src\N12_Libs\mathlib.c^
.\Inu\Src\N12_Libs\svgen_dq_v2.c^
.\Inu\Src\N12_Libs\control_station.c^
.\Inu\Src\N12_Libs\global_time.c^
.\Inu\Src\N12_Xilinx\xp_write_xpwm_time.c^
.\Inu\Src\main\adc_tools.c^
.\Inu\Src\main\v_pwm24_v2.c^
.\Inu\Src\main\limit_power.c^
.\Inu\Src\main\limit_lib.c^
.\Inu\Src\main\pll_tools.c^
.\Inu\Src\main\calc_rms_vals.c^
.\Inu\Src\main\alg_simple_scalar.c^
.\Inu\Src\main\control_station_project.c^
.\Inu\Src\main\ramp_zadanie_tools.c
set params_obj=..\device_support_ml\source\C28x_FPU_FastRTS.obj ..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj
.\Inu\Src\N12_Xilinx\xp_write_xpwm_time.c
set params_device_support=..\device_support_ml\source\C28x_FPU_FastRTS.obj^
..\device_support_ml\source\DSP2833x_GlobalVariableDefs.obj^
..\device_support_ml\source\IQmathLib_matlab.c
echo mex %params_d1% %params_d2% %params_i% %params_o% %params_sfunction% %params_wrapper_c% %params_vectorcontorl_c% %params_libs_c% %params_obj% -g
set code_USER=%params_main_c% %params_vectorcontorl_c% %params_libs_c% %params_device_support%
::-------------------------------------------------------------------------
mex %params_d1% %params_d2% %params_i% %params_o% %params_sfunction% %params_wrapper_c% %params_vectorcontorl_c% %params_libs_c% %params_obj% -g
:: -------------------------WRAPPER PATHS AND CODE---------------------------
:: оболочка, которая будет моделировать работу МК в симулинке
set includes_WRAPPER= -I".\Inu"
set code_WRAPPER= .\Inu\MCU.c^
.\Inu\mcu_wrapper.c^
.\Inu\main_matlab\pwm_sim.c^
.\Inu\main_matlab\init28335.c^
.\Inu\main_matlab\param.c^
.\Inu\main_matlab\main_matlab.c
::-------------------------------------------------------------------------
:: ---------------------SET PARAMS FOR MEX COMPILING-----------------------
:: --------ALL INCLUDES--------
set includes= %includes_USER% %includes_WRAPPER%
set codes= %code_WRAPPER% %code_USER%
:: -------OUTPUT FOLDER--------
set output= -outdir "." -output wrapper_inu
:: если нужен дебаг, до запускаем run_mex с припиской debug
IF [%1]==[debug] (set debug= -g)
::-------------------------------------------------------------------------
::------START COMPILING-------
echo mex %output% %defines% %includes% %codes% %debug%
echo Compiling...
mex %output% %defines% %includes% %codes% %debug%