📄 interrupt_sevice.c
字号:
#include <p30f4011.h>
#include "adr_port_define.h"
#include "extern_define.h"
void _ISR _T1Interrupt(void)
{
IFS0bits.T1IF=0;
Time_base=Time_base+1600; //400us
}
void _ISR _T2Interrupt(void)
{
IFS0bits.T2IF=0;
//**********************test motor output
//通过timer2 interupt test motor out:0,1,0,1,0,1,0
// PORTEbits.RE0=!PORTEbits.RE0;
//********************************
if(FPWM==300)
{
FPWM=FPWM+3;//80; //200段 ptper=5us-10us
PTPER=FCY/FPWM - 1; //上升过程中改变PTPER
//250段*20us(每段时间)
PDC1=PTPER; //动态改变占空比
pwm_flag=1;
/* if(total_pluse<5)
{
PWM_ON=0;
T2_ON=0;
}*/
}
else if(pwm_flag==1)
{
FPWM=FPWM+3;//80; //250段 ptper=5us-10us
PTPER=FCY/FPWM - 1; //上升过程中改变PTPER
//250段*20us(每段时间)
PDC1=PTPER; //动态改变占空比
if(FPWM==2400)
{
pwm_flag=2;
pluse_con=pluse_counter; //fpwm=f1:100k--f2:200k
mid_pluse=total_pluse-pluse_con;
}
else pwm_flag=1;
// if(z_waitpostion_flag==0) //连续运动 reset key
// {
// if(motor_jingei==7) //主轴微进给也可以view postion
// {
// if(KEYUPDOWN==0)
// {
// PWM_ON=0;
// T2_ON=0;
// }
// }
// }
/* if(total_pluse<80)
{
PWM_ON=0;
T2_ON=0;
} */
}
else if (pwm_flag==2)
{
if(pluse_counter>mid_pluse)pwm_flag=3;
else pwm_flag=2;
// if(z_waitpostion_flag==0) //连续运动 reset key
// {
// if(motor_jingei==7)
// {
// if(KEYUPDOWN==0)
// {
// PWM_ON=0;
// T2_ON=0;
// }
// }
// }
}
else if(pwm_flag==3)
{
FPWM=FPWM-140;
if(FPWM<200)FPWM=200;
PTPER=FCY/FPWM-1;
PDC1=PTPER;
if(FPWM==200)
{
/* PWM_ON=0;
timer=pluse_counter;
T2_ON=0;
Nop();*/
pwm_flag=4;
}
else pwm_flag=3;
// if(z_waitpostion_flag==0) //连续运动 reset key
// {
// if(motor_jingei==7)
// {
// if(KEYUPDOWN==0)
// {
// PWM_ON=0;
// T2_ON=0;
// }
// }
// }
}
Nop();
}
void _ISR _PWMInterrupt(void)
{
IFS2bits.PWMIF=0;
pluse_counter=pluse_counter+1;
if(pwm_flag==4)
{
PWM_ON=0;
T2_ON=0;
pwm_flag=0;
// z_waitpostion_flag=0; //z_waitpostion view motor run encoder
}
}
void _ISR _DefaultInterrupt(void)// error
{
while(1)
{
}
asm("RESET");
}
void _ISR _AddressError(void)
{
// DISABLE_FIRING;
// Clear WDT and drive LED4 at 100% Duty
while(1)
{
// ClrWdt();
}
asm("RESET");
return;
}
void _ISR _StackError(void)
{
// unsigned char i;
// DISABLE_FIRING;
// Clear WDT and drive LED4 at 50% Duty
while(1)
{
// ClrWdt();
}
asm("RESET");
return;
}
void _ISR _MathError(void)
{
// unsigned char i;
// DISABLE_FIRING;
// Clear WDT and drive LED4 at 33% Duty
while(1)
{
// ClrWdt();
}
asm("RESET");
return;
}
void _ISR _OscillatorFail(void)
{
while(1)
{
}
asm("RESET");
}
void _ISR _ReservedTrap0(void)
{
while(1)
{
}
asm("RESET");
}
void _ISR _ReservedTrap5(void)
{
while(1)
{
}
asm("RESET");
}
void _ISR _ReservedTrap6(void)
{
while(1)
{
}
asm("RESET");
}
void _ISR _ReservedTrap7(void)
{
while(1)
{
}
asm("RESET");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -