matlab_23550/Inu/Src2/main/xp_write_xpwm_time.h
2024-12-27 10:50:32 +03:00

184 lines
5.8 KiB
C

/*
* 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_ */