📄 pwm_120slc20.c
字号:
}
else
{
;
}
//}
#ifdef DEBUG_SIM
TIMEBASETEST;
#endif
}
/*********************
CALLED BY TB1 INT
**********************/
//#define CHGDELAY (1000)
#define DEG30MIN (8)//(15)
void pwm_tujo_cal(void)
{
static UINT_8 edge_flag = 0;
SINT_16 set_tim;
SINT_16 stg_p;
SINT_16 w_si16;
// SINT_16 DEG30MIN;
stg_p = stage;
// if ( wr_soft.wrd.hi <= 2204 )
// {
// DEG30MIN = 9;
// }
// else
// {
// DEG30MIN = 6;
// }
if(dlt_cnt < RPM500_60DGREE_20K)
{
// #ifdef DEBUG_SIM
// TIMEBASETEST1;
// #endif
dlt_cnt ++;
// #ifdef DEBUG_SIM
// TIMEBASETEST1;
// #endif
g_TxdDat[3] = 0x0;
}
else
{
tb2s = 0;
tb2 = 10;
tb1s = 0;
wr_act = 0;
ActSpdCnt = 0;
kido_cnt = 0;
mot_theta = 0;//stage * THETA_60DEG;
out_theta = 0;//stage * THETA_60DEG;
if ( 0 == ReStaTim )
{
out_mode = STOP_MODE;//
g_TxdDat[3] = M_ErrMotSyn; /* synchronization error*/
}
else
{
ReStaTim = 0;
out_mode = KIDO_MODE;//
}
pre_dlt_cnt = 418;
idb0 = 0x3f;
idb1 = 0x3f;
int4ic &= 0x00;
int3ic &= 0x00;
int5ic &= 0x00;
tb2s = 1;
tb2 = CARR_CNT_4K;
return;
}
if(stage == reload_stg)
{
// if ( 0 == commutation_FLAG )
// {
// commutation_FLAG = 1;
// dlt_30deg_cnt = 0;
// }
// else
// {
// dlt_30deg_cnt ++;
// }
if(chk_on_cnt > 0)
{
chk_on_cnt --; // output delay
int4ic &= 0x00;
int3ic &= 0x00;
int5ic &= 0x00;
}
else
{
chk_on_cnt = 0;
}
switch(stage)
{
case 0: /* pattern 1 output */
if(((int3ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a v phase? */
{
int3ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
}
int4ic &= 0x00;
int5ic &= 0x00;
break;
case 1: /* pattern 2 output */
if(((int5ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a u phase? */
{
int5ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
}
int4ic &= 0x00;
int3ic &= 0x00;
break;
case 2: /* pattern 3 output */
if(((int4ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a w phase? */
{
int4ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
}
int5ic &= 0x00;
int3ic &= 0x00;
break;
case 3: /* pattern 4 output */
if(((int3ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a v phase? */
{
int3ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
}
int5ic &= 0x00;
int4ic &= 0x00;
break;
case 4: /* pattern 5 output */
if(((int5ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a u phase? */
{
int5ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
}
int4ic &= 0x00;
int3ic &= 0x00;
break;
case 5: /* pattern 0 output */
if(((int4ic & 0x08) != 0) && (chk_on_cnt == 0)) /* rising edge detection of a w phase? */
{
// #ifdef DEBUG_SIM
// TIMEBASETEST1;
// #endif
int4ic &= 0x00;
if ( 0 == edge_flag )
{
// if( dlt_30deg_cnt < DEG30MIN )
// {
edge_flag = 1;
// }
// else
// {
// cal_sub_wr_duty();
// edge_flag = 0;
// }
}
else
{
cal_sub_wr_duty();
edge_flag = 0;
// reload_stg = 1;
}
// #ifdef DEBUG_SIM
// TIMEBASETEST1;
// #endif
}
int5ic &= 0x00;
int3ic &= 0x00;
break;
}
}
else
{
if ( wr_act < 1024 )//wr_soft.wrd.hi
{
w_si16 = wr_soft.wrd.hi;
if ((w_si16>>6) >=49) w_si16 = 49 << 6;
chk_on_cnt = remin_tbl[(w_si16 >> 6)]; //phaseperiod/6 - 2;//remin_tbl[(w_si16 >> 6)]; //reload_cnt - 2;// /* output delay counter */
edge_flag = 1;
}
else
{
chk_on_cnt = 3;//5;
}
chkoncnt_map = chk_on_cnt;
int4ic &= 0x00;
int3ic &= 0x00;
int5ic &= 0x00;
}
/* It is made to be delayed at 30degree. */
if(reload_cnt > 0)
{
reload_cnt --; /* pattern switching delay count */
tb2chg1 = 0;
}
else
{
;
}
if(reload_cnt == 0)
{
stage = reload_stg;
dlt_30deg_cnt ++; /*this point is error */
if ( 0 == tb2chg1 )
{
tb2s = 0;
tb2 = 10;
// tb2chg = 1;
tb2chg1 = 1;
stg_p = stage;
idb0 = pwm_out_tbl0[stg_p];
idb1 = pwm_out_tbl1[stg_p]; /* commutation */
tb2s = 1;
tb2 = CARR_CNT_4K - 1;
}
}
// int4ic &= 0x00;
// int3ic &= 0x00;
// int5ic &= 0x00;
}
void extint3_int(void)
{
;
}
void extint4_int(void)
{
;
}
void extint5_int(void)
{
;
}
void extintsvc (void)
{
;
}
void ta0_int(void)
{
;
}
UINT_16 SecTimCnt = 100; /* 1 sec timer*/
void ActSpdCal(void)
{
if ( SecTimCnt > 0 )
{
SecTimCnt --;
}
else
{
SecTimCnt = 100;
if ( ActSpdCnt < 600 ) /* < 50rps */
{
g_TxdDat[1] = (ActSpdCnt/POLESNUM) * 10/36;
}
else
{
g_TxdDat[1] = ((ActSpdCnt - 6)/POLESNUM) * 10/36;
}
ActSpdCnt = 0;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -