229 lines
6.7 KiB
C
229 lines
6.7 KiB
C
|
/*
|
|||
|
* xp_write_xpwm_time.h
|
|||
|
*
|
|||
|
* Created on: 03 <EFBFBD><EFBFBD><EFBFBD>. 2018 <EFBFBD>.
|
|||
|
* Author: stud
|
|||
|
*/
|
|||
|
|
|||
|
#ifndef XP_WRITE_TIME_H_
|
|||
|
#define XP_WRITE_TIME_H_
|
|||
|
|
|||
|
|
|||
|
#include "word_structurs.h"
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#define PWM_ERROR_LEVEL_INTERRUPT 0 // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!!!
|
|||
|
#define PWM_LOW_LEVEL_INTERRUPT 1 // <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
#define PWM_HIGH_LEVEL_INTERRUPT 2 // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
#define PWM_MODE_RELOAD_FORCE 0 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
#define PWM_MODE_RELOAD_LEVEL_LOW 1 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD> saw_direct=1
|
|||
|
#define PWM_MODE_RELOAD_LEVEL_HIGH 2 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><><EFBFBD> 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. <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0)-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> = 0, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)., <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>- <EFBFBD><EFBFBD><EFBFBD> soft mode <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* (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_high;
|
|||
|
// unsigned int Tclosed_1;
|
|||
|
unsigned int pwm_tics;
|
|||
|
unsigned int half_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;
|
|||
|
unsigned int what_next_interrupt;
|
|||
|
unsigned int do_sync_out;
|
|||
|
unsigned int disable_sync_out;
|
|||
|
WORD_UINT2BITS_STRUCT saw_direct;
|
|||
|
void (*write_1_2_winding_break_times)();
|
|||
|
void (*write_zero_winding_break_times)();
|
|||
|
void (*init)();
|
|||
|
} 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,0, {0}, \
|
|||
|
xpwm_write_1_2_winding_break_times_16_lines, \
|
|||
|
xpwm_write_zero_winding_break_times_16_lines, \
|
|||
|
initXpwmTimeStructure \
|
|||
|
}
|
|||
|
|
|||
|
void xpwm_write_1_2_winding_break_times_16_lines(XPWM_TIME *p);
|
|||
|
void xpwm_write_zero_winding_break_times_16_lines(XPWM_TIME *p);
|
|||
|
|
|||
|
void initXpwmTimeStructure(XPWM_TIME *p);
|
|||
|
|
|||
|
extern XPWM_TIME xpwm_time;
|
|||
|
|
|||
|
#define write_winding1_fase_a(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 0); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 1); i_WriteMemory(ADR_PWM_TIMING, T1);}
|
|||
|
|
|||
|
#define write_winding1_fase_b(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 2); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 3); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
#define write_winding1_fase_c(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 4); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 5); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
#define write_winding2_fase_a(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 6); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 7); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
#define write_winding2_fase_b(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 8); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 9); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
#define write_winding2_fase_c(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 10); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 11); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
#define write_break_winding1(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 12); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 13); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
#define write_break_winding2(T0, T1) \
|
|||
|
{ i_WriteMemory(ADR_PWM_KEY_NUMBER, 14); i_WriteMemory(ADR_PWM_TIMING, T0); \
|
|||
|
i_WriteMemory(ADR_PWM_KEY_NUMBER, 15); i_WriteMemory(ADR_PWM_TIMING, T1); }
|
|||
|
|
|||
|
|
|||
|
////
|
|||
|
// stop
|
|||
|
void hard_stop_x24_pwm_all(void);
|
|||
|
void soft_stop_x24_pwm_all(void);
|
|||
|
|
|||
|
void soft_stop_x24_pwm_1_2(void);
|
|||
|
|
|||
|
void soft_stop_x24_pwm_1(void);
|
|||
|
void soft_stop_x24_pwm_2(void);
|
|||
|
|
|||
|
void soft_stop_x24_break_1(void);
|
|||
|
void soft_stop_x24_break_2(void);
|
|||
|
|
|||
|
void soft_stop_x24_break_all(void);
|
|||
|
|
|||
|
////
|
|||
|
// start
|
|||
|
void soft_start_x24_pwm_all(void);
|
|||
|
|
|||
|
void soft_start_x24_pwm_1(void);
|
|||
|
void soft_start_x24_pwm_2(void);
|
|||
|
void soft_start_x24_pwm_1_2(void);
|
|||
|
|
|||
|
void soft_start_x24_break_1(void);
|
|||
|
void soft_start_x24_break_2(void);
|
|||
|
void soft_start_x24_break_all(void);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
///////////////
|
|||
|
void set_mode_soft_x24(void);
|
|||
|
void set_mode_hard_x24(void);
|
|||
|
|
|||
|
void set_start_pwm_x24(void);
|
|||
|
void set_stop_pwm_x24(void);
|
|||
|
////////////////
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#endif /* XP_WRITE_TIME_H_ */
|