#7 бля, надо чет делать с этим, слишком запарно постоянно синхронизировать две ветки...
134 lines
3.4 KiB
C
134 lines
3.4 KiB
C
#include "mcu_wrapper_conf.h"
|
||
|
||
#ifndef PWM_SIM
|
||
#define PWM_SIM
|
||
|
||
|
||
|
||
#define ENABLE_UNITED_COUNTER_FOR_ALL_PWM
|
||
|
||
|
||
#define PWM_SIMULATION_MODE_TK_LINES
|
||
//#define PWM_SIMULATION_MODE_REGULAR_PWM
|
||
|
||
#define PWM_PERIOD (FREQ_INTERNAL_GENERATOR_XILINX_TMS / FREQ_PWM)
|
||
#define PWM_TICK_STEP (FREQ_INTERNAL_GENERATOR_XILINX_TMS * hmcu.sSimSampleTime)
|
||
|
||
|
||
/* ОТ УЛИТКОВСКОГО (не используется) */
|
||
// период ШИМ, c
|
||
#define T_PWM 2220e-6 //F_PWM = 450 Гц
|
||
//#define T_PWM 6000e-6 //F_PWM = 166.7 Гц
|
||
// период вызова основной программы, с
|
||
#define TY (T_PWM*0.5)
|
||
// "мертвое время", с
|
||
#define DT 30e-6
|
||
//#define DT 60e-6
|
||
// Time-Base Period Register, ед. счётчика таймера
|
||
#define T1_PRD (FTBCLK*T_PWM*0.5)
|
||
// максимальное значение амплитуды напряжения управления устанавливаем так,
|
||
// чтобы минимальная ширина импульса была 10 мкс, ед. счётчика таймера
|
||
#define Y_LIM (T1_PRD - (DT + 10e-6)*FTBCLK)
|
||
|
||
|
||
// Для моделирования ШИМ
|
||
/**
|
||
* @brief 3lvl PWM One Phase Simulation handle
|
||
*/
|
||
typedef struct
|
||
{
|
||
int ci1A;
|
||
int ci1B;
|
||
int ci2A;
|
||
int ci2B;
|
||
|
||
}PWMPhaseOutput;
|
||
/**
|
||
* @brief DeadTime Simulation Handle
|
||
*/
|
||
typedef struct
|
||
{
|
||
int DtPeriod;
|
||
int stateDt;
|
||
int dtcnt;
|
||
int pre_ciA;
|
||
int pre_ciB;
|
||
}DeadTimeSimHandle;
|
||
enum StateDeadTime {
|
||
stateDtWait = 0,
|
||
stateDtReady
|
||
};
|
||
/**
|
||
* @brief Tim Simulation Handle
|
||
*/
|
||
typedef struct
|
||
{
|
||
double TxCntPlus;
|
||
double TxPeriod;
|
||
double tcntAux;
|
||
double tcntAuxPrev;
|
||
double tcnt;
|
||
double cmpA;
|
||
double cmpB;
|
||
DeadTimeSimHandle deadtime;
|
||
|
||
void (*simulatePwm)();
|
||
}TimerSimHandle;
|
||
|
||
/**
|
||
* @brief PWM Phase Simulation Handle
|
||
*/
|
||
typedef struct
|
||
{
|
||
PWMPhaseOutput pwmOut;
|
||
TimerSimHandle* tsim1;
|
||
TimerSimHandle* tsim2;
|
||
int tkLineA;
|
||
int tkLineB;
|
||
DeadTimeSimHandle deadtime;
|
||
}PWMPhaseSimHandle;
|
||
|
||
extern TimerSimHandle t1sim;
|
||
extern TimerSimHandle t2sim;
|
||
extern TimerSimHandle t3sim;
|
||
extern TimerSimHandle t4sim;
|
||
extern TimerSimHandle t5sim;
|
||
extern TimerSimHandle t6sim;
|
||
extern TimerSimHandle t7sim;
|
||
extern TimerSimHandle t8sim;
|
||
extern TimerSimHandle t9sim;
|
||
extern TimerSimHandle t10sim;
|
||
extern TimerSimHandle t11sim;
|
||
extern TimerSimHandle t12sim;
|
||
|
||
extern PWMPhaseSimHandle PWMPhaseA1;
|
||
extern PWMPhaseSimHandle PWMPhaseB1;
|
||
extern PWMPhaseSimHandle PWMPhaseC1;
|
||
extern PWMPhaseSimHandle PWMPhaseA2;
|
||
extern PWMPhaseSimHandle PWMPhaseB2;
|
||
extern PWMPhaseSimHandle PWMPhaseC2;
|
||
|
||
void Simulate_PWM(void);
|
||
void Init_PWM_Simulation(void);
|
||
|
||
void Simulate_PWMPhase(PWMPhaseSimHandle* tksim, int T1, int T0);
|
||
|
||
void Simulate_MainTIM(TimerSimHandle* tsim, int compare);
|
||
void Simulate_SimpleTIM(TimerSimHandle* tsim, int compare);
|
||
|
||
int simulateTimAndGetCompare(TimerSimHandle* tsim, int compare);
|
||
void simulateActionActionQualifierSubmodule(TimerSimHandle* tsim);
|
||
void simulateDeadBendSubmodule(TimerSimHandle* tsim, int* ciA, int* ciB);
|
||
void simulateTripZoneSubmodule(TimerSimHandle* tsim);
|
||
|
||
|
||
void Init_TIM_Simulation(TimerSimHandle* tsim, int period, double step);
|
||
void Init_PWMPhase_Simulation(PWMPhaseSimHandle* tksim, TimerSimHandle* tsim1, TimerSimHandle* tsim2, int period, double step);
|
||
void convertSVGenTimesToTkLines(PWMPhaseSimHandle* tksim);
|
||
void xilinxPwm3LevelSimulation(PWMPhaseSimHandle* tksim);
|
||
|
||
#if defined(PWM_SIMULATION_MODE_REGULAR_PWM) && defined(PWM_SIMULATION_MODE_TK_LINES)
|
||
#error Choose only one PWM simulation mode!
|
||
#endif
|
||
#endif //PWM_SIM
|