定时中断中时间过长
时间:10-02
整理:3721RD
点击:
中断程序:
__interrupt void isrVrti(void)
{
unsigned char i,j;
CRGFLG_RTIF = 1; /* Clear Interrupt Flag */
ulCLOCK_SYSTEM_TICK++;
if(ADcount<ADNR)
{
for(i=0;i<3;i++)
AN[ADcount]=AD_Average(i); //ADcount 采样个数=30
ADcount++;
ArryFull=0;
} else
{
ArryFull=1;
for(i=0;i<3;i++)
{
for(j=ADNR-1;j>0;j--)
AN[j]=AN[j-1] ;
AN[0]= AD_Average(i);
}
}
}
时钟程序:
void Clock_Init(void) { //OSCCLK=20M
CRGFLG_LOCKIF = 1; //0:RTI timeout iterrupt disable 1:interupt enbale
CRGINT_LOCKIE = 0; //PLL Lock interruput request disabled
CLKSEL_PLLSEL = 0; //时钟信号来自晶振 BusCLK=OSCCLK/2
PLLCTL_PLLON = 0; //PLL Turned off
SYNR = 0x01;
REFDV = 0x00; //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)=2*16*2/1= 64MHz
PLLCTL_PLLON = 1; //0:PLLCLK OFF 1:PLLCLK ON
while(CRGFLG_LOCK == 0) {
;
}
CLKSEL_PLLSEL = 1; //1:busclk=PLLCLK/2;0:busclk=oscclk/2
RTICTL = 0xA7; //time out interrupt period=busclk/40*10^3
CRGINT_RTIE = 1; //0:interrupt disable 1:interrupt enable
}
主程序:
Clock_Init();
IO_Init();
PWM_Init();
AD_Init();
EnableInterrupts;
Clock_SysDelay(10);
Digital.cycle_1st=1;
for(;;)
{
Digital.A11_A12=PORTA_PA0;//********************* 读A3_A4开关状态*********************************
Digital.A3_A4=PORTA_PA1;//********************* 读A3_A4开关状态*********************************
if(ArryFull==0) continue;
Digital.ON= (Digital.A11_A12| Digital.A3_A4);
}
单片机晶振为20M,发现程序运行至 Digital.ON= (Digital.A11_A12| Digital.A3_A4);需要2~3S
中断采集数据需要那么长时间吗,中断定时0.5ms,理论上运行完15ms
是否这款单片机是中断有问题?单片机型号:MC9S12XET256
__interrupt void isrVrti(void)
{
unsigned char i,j;
CRGFLG_RTIF = 1; /* Clear Interrupt Flag */
ulCLOCK_SYSTEM_TICK++;
if(ADcount<ADNR)
{
for(i=0;i<3;i++)
AN[ADcount]=AD_Average(i); //ADcount 采样个数=30
ADcount++;
ArryFull=0;
} else
{
ArryFull=1;
for(i=0;i<3;i++)
{
for(j=ADNR-1;j>0;j--)
AN[j]=AN[j-1] ;
AN[0]= AD_Average(i);
}
}
}
时钟程序:
void Clock_Init(void) { //OSCCLK=20M
CRGFLG_LOCKIF = 1; //0:RTI timeout iterrupt disable 1:interupt enbale
CRGINT_LOCKIE = 0; //PLL Lock interruput request disabled
CLKSEL_PLLSEL = 0; //时钟信号来自晶振 BusCLK=OSCCLK/2
PLLCTL_PLLON = 0; //PLL Turned off
SYNR = 0x01;
REFDV = 0x00; //PLLCLK=2*OSCCLK*(SYNR+1)/(REFDV+1)=2*16*2/1= 64MHz
PLLCTL_PLLON = 1; //0:PLLCLK OFF 1:PLLCLK ON
while(CRGFLG_LOCK == 0) {
;
}
CLKSEL_PLLSEL = 1; //1:busclk=PLLCLK/2;0:busclk=oscclk/2
RTICTL = 0xA7; //time out interrupt period=busclk/40*10^3
CRGINT_RTIE = 1; //0:interrupt disable 1:interrupt enable
}
主程序:
Clock_Init();
IO_Init();
PWM_Init();
AD_Init();
EnableInterrupts;
Clock_SysDelay(10);
Digital.cycle_1st=1;
for(;;)
{
Digital.A11_A12=PORTA_PA0;//********************* 读A3_A4开关状态*********************************
Digital.A3_A4=PORTA_PA1;//********************* 读A3_A4开关状态*********************************
if(ArryFull==0) continue;
Digital.ON= (Digital.A11_A12| Digital.A3_A4);
}
单片机晶振为20M,发现程序运行至 Digital.ON= (Digital.A11_A12| Digital.A3_A4);需要2~3S
中断采集数据需要那么长时间吗,中断定时0.5ms,理论上运行完15ms
是否这款单片机是中断有问题?单片机型号:MC9S12XET256