- 积分
- 28
- 回帖
- 0
- 西莫币
-
- 贡献
-
- 威望
-
- 存款
-
- 阅读权限
- 5
- 最后登录
- 1970-1-1
该用户从未签到
|
楼主 |
发表于 2010-4-2 23:26
|
显示全部楼层
interrupt void z_int(void)
{ counter++; /* Add variable 'counter' */
watch_data();
}
interrupt void carrier_int(void) /* 僉儍儕傾摨婜妱傝崬傒張棟儖乕僠儞 */
{
pev_ad_start(0, 0);
while (pev_ad_in_st(0, 0)) ; /* AD撉傒崬傒 */
pev_ad_in_grp(0, 0, &vu, &vw, &iu, &iw);
pev_ad_start(0, 1); /* AD撉傒崬傒 */
while (pev_ad_in_st(0, 1)) ;
pev_ad_in_grp(0, 1, &E, &Idc, &CH6, &CH7); /* AD曄姺奐巒 */
iu = iu + 0.24; /* 揹棳岆嵎偺挷惍 */
iw = iw + 0.08; /* 揹棳岆嵎偺挷惍 */
iv = -iu - iw;
mwPIDcal(ppid_iu, iu); /* PID惂屼(iu) */
mwPIDcal(ppid_iu, iw); /* PID惂屼(iw) */
uw2ab (iu, iw, pia, pib); /* 憡弴偼u,v,w偲偡傞偙偲(dq曄姺偑惓偟偔側偝傟側偄) */
ab2dq (ia, ib, theta, pid, piq);
omega_ref = rpm_ref / ( PI(2) * 60); /* 懍搙巜椷偺曄姺(rpm 仺 rad/s) */
if (omega_ref > omega_limit) {omega_ref = omega_limit;} /* 懍搙巜椷偺忋尷丆壓尷 */
if (omega_ref < omega_min)
{ omega_ref = omega_ref - omega_min;
if( omega_e < omega_min )
{ Status = 0.0;
pev_inverter_stop_pwm( BDN, CH ); /* Stop of 3-phase PWM output */
}
}
else { Status = 1.0;}
torque = K_torque * ( omega_ref - omega_r ); /* 僩儖僋巜椷寁嶼 */
if ( torque > 0.5) { torque = 0.5;} /* 僩儖僋忋尷 */
id_ref = flux / M; /* d幉揹棳巜椷抣丂id = 冇2 / M */
iq_ref = (torque * L2) / (2 * M * flux); /* q幉揹棳巜椷抣丂iq = ( 冄 * L2 ) / ( 嬌懳悢(2) * M * 冇2丂) */
d = K * ( K_d * (id_ref - id ) + r1 * id - omega_e * l1 *iq ); /* d幉揹埑巜椷 */
q = K * ( K_q * (iq_ref - iq ) + omega_e * l1 * id + r1 * iq + (( omega_e * M * M )/ L2 ) * id ); /* q幉揹埑巜椷 */
dq2ab (d, q, theta, pa, pb);
ab2uvw (a, b, pu, pv, pw);
if (u > umax) {u = umax;}
if (u < umin) {u = umin;}
if (v > vmax) {v = vmax;}
if (v < vmin) {v = vmin;}
if (w > wmax) {w = wmax;}
if (w < wmin) {w = wmin;}
pev_inverter_set_uvw( BDN, CH, u, v, w ); /* PWM signal setting */
if (Status == 1.0) { pev_inverter_start_pwm( BDN, CH ); }
/* Start of 3-phase PWM output */
watch_data(); /* Send data to Wave display board */
}
interrupt void rpm_timer0(void) /* Interrupt routine of timer0 */
{ cnt0 = cntn;
cntn = pev_abz_read(BDN); /* Read value of ABZ encoder's count */
dcnt = cntn - cnt0;
if (dcnt > dcntmax) { dcnt = dcnt - RESOLUTION; }
else if (dcnt < -dcntmax) { dcnt = dcnt + RESOLUTION; }
if (dcnt <= 0.0 ) { dcnt = (-1.0) * dcnt;} /* 愨懳抣 */
rpm = Krpm * dcnt;
omega_r = Komega_r * dcnt;
omega_e = omega_r + (1.0 / tr) * (iq_ref / id_ref);
theta += TM * 0.000001 * omega_e; /* 愊暘婍 ( 兤 = 兤 + 儮t * wr ) 儮t偼僒儞僾儕儞僌娫妘 */
if ( theta > PI(2.0) ) { theta -= PI(2.0); }
else if ( theta < - PI(2.0) ) { theta += PI(2.0); }
if (Status == 0.0) { theta = 0.0; }
watch_data();
}
void main(void) /* 曄悢弶婜壔 */
{
Fc = 5000.0; /* Carrier frequency [Hz] */
DeadT = 3.5; /* Deadtime [兪s] */
flux = 0.7735;
torque = 0.0; /* 僩儖僋弶婜抣 */
kp_i = 1.0; /* PID 斾椺學悢 */
ki_i = 1.0; /* PID 愊暘學悢 */
kd_i = 0.0; /* PID 旝暘學悢 */
t_i = 1/(2*Fc); /* PID 儘乕僷僗僼傿儖僞帪掕悢 */
K_d = 0.2;
K_q = 0.2;
K_torque = 1.0;
K=0.04;
umax = vmax = wmax = 0.99 ;
umin = vmin = wmin = -0.99 ;
omega_limit = 52.36; /* 懍搙忋尷 */
omega_min = 0.0628; /* 懍搙壓尷 */
dcnt = 0.0;
dcntmax = RESOLUTION * 0.5;
Krpm = 60.0 * FM / RESOLUTION;
Komega_r = PI(2) * FM / RESOLUTION;
pu = &u;
pv = &v;
pw = &w;
pa = &a;
pb = &b;
pia = &ia;
pib = &ib;
pid = &id;
piq = &iq;
/********** 弶婜忦審 **********/
d = 0.0;
q = 0.0;
id_ref = 0.0;
iq_ref = 0.0;
omega_ref = 0.0;
rpm_ref = 0.0;
counter = 0.0;
cnt0 = cntn = 0.0;
pin = 0.0;
u = v = w = 0.0;
vu = vw = 0.0;
iu = 0.0;
iw = 0.0;
iv = 0.0;
CH6 = CH7 = 0.0;
omega_s = omega_e = omega_r = 0.0;
theta =0.0;
rpm = 0.0;
mwPIDinit(ppid_iu, kp_i, ki_i, kd_i, t_i, (1/Fc), 0.0, 0.0); /* PID惂屼偺愝掕 iu */
mwPIDinit(ppid_iw, kp_i, ki_i, kd_i, t_i, (1/Fc), 0.0, 0.0); /* PID惂屼偺愝掕 iw */
/* 1:ON SW, 0:OFF SW */
while ( rpm_ref == 0.0) {Status = 0.0; watch_data();}
int_disable(); /* Prohibition of all interrupt */
pev_init( BDN );
pev_inverter_init( BDN, CH, Fc, 1000.0*DeadT ); /* Setting of 3-phase PWM function */
/* Carrier frequency = Fc(Hz) Deadtime [ns] */
pev_inverter_set_syncint( BDN, (1/(Fc*4.0)) ); /* Setting of carrier synchronization interrupt */
pev_inverter_set_uvw( BDN, CH, 0, 0, 0 ); /* Initialization of 3-phase reference */
int5_init_vector( carrier_int ); /* Setting of interrupt routine */
pev_inverter_enable_up_int5( BDN ); /* Output start of signal of carrier synchronization interrupt */
int5_enable_int(); /* Permission of interrupt by int5 */
int_enable(); /* Permission of interrupt action */
int6_init_vector( z_int ); /* Selection of routine executed */
pev_abz_set_mode(BDN,0); /* Select 'Open collecter mode' */
/* pev_abz_set_mode(BDN,2); */ /* Select 'Defferential input mode' */
pev_abz_enable_int6(BDN); /* Permission of Z interrupt */
int6_enable_int(); /* Permission of interrupt by DSP */
wait(1000000.0/(Fc)); /* Setting of 3-phase reference, */
/* then wait more than half of carrier period */
Status = 1.0;
pev_inverter_start_pwm( BDN, CH ); /* Start of 3-phase PWM output */
/**************丂AD偺弶婜壔丂**************/
pev_ad_set_range(0, 0, CH0_RANGE,CH1_RANGE,CH2_RANGE,CH3_RANGE);
pev_ad_set_range(0, 1, CH4_RANGE,CH5_RANGE,CH6_RANGE,CH7_RANGE);
timer0_init(TM); /* RPM */
timer0_init_vector(rpm_timer0); /* Timer routine */
timer0_start(); /* Start timer0 */
timer0_enable_int(); /* Permission of timer0 interrupt */
int_enable(); /* Permission of interrupt */
while (1) /* Repeat endlessly */
{
pin = pev_abz_in_pin(BDN); /* Check status of ABZ encoder's signal */
watch_data(); /* Send data to Wave display board */
}
} |
|