Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Two functions in the high priority interrupt.

Status
Not open for further replies.

maniac84

Full Member level 6
Joined
Mar 4, 2012
Messages
337
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
3,661
Hi guys, I'm using the PIC18F46k22 mcu and I'm using two function in my high priority interrupt routine:

Code:
#pragma code
#pragma code My_HiPrio_Int=0x0008	
#pragma code
#pragma interrupt chk_isr

#pragma code
void My_HiPrio_Int(void)
{
	_asm
		GOTO chk_isr
	_endasm
}

void chk_isr(void)		/*Serial Interrupt*/
{	
	INTCONbits.GIE = 0;

	if(INTCONbits.TMR0IF==1)   //Timer routine
		Timer0_ISR();

	if(PIR1bits.RC1IF)     //RS485 receiver 
		RC_ISR();

	INTCONbits.GIE = 1;


}


void Timer0_ISR(void)
{
	nTick0++;

	if(pSet == 0) nTickSetPress++;
	else nTickSetPress = 0;

	if(pPlus == 0) nTickPlusPress++;
	else nTickPlusPress = 0;

	if(pMinus == 0) nTickMinusPress++;
	else nTickMinusPress = 0;

	if(pShift == 0) nTickShfPress++;
	else nTickShfPress = 0;

	if(pCountPlus == 0) nTickCount++;
	else nTickCount = 0;

	if(pReset == 0) nTickResetPress++;
	else nTickResetPress = 0;

	if(bCdlyStart == 1) nCdlyCount++;
	if(nCdlyCount >= nTickCdly) bCdlyStart = 0;

	if(bDisplayTime == 1) nDisplayTimeCount++;
	
	if(bBlinkDigitFast == 1) nTickBlinkFast++;

	TMR0H = TMR0HValue;
	TMR0L = TMR0LValue;
	INTCONbits.TMR0IF = 0;
}


void RC_ISR(void)		
{
	rxbuf485 = RCREG1;
	
	if (rxbuf485 == 0)
	{
		return;
	}

	if (rxbuf485 == TOKEN)
	{
		b485RxToken = 1;
		return;
	}

	if (b485RxComplete) return;
	
	if (!b485SOH)
	{
		if (rxbuf485 != SOH) return;
		b485SOH = 1;
		n485RxDataPos = 0;
		b485RxComplete = 0;
		memset (RS485RXDATA, 0, sizeof(RS485RXDATA));
		return;
	}	
	else if (rxbuf485 == EOT)
	{
		b485SOH = 0;
		b485RxComplete = 1;
		return;
	}
	if (n485RxDataPos == 50) 
		n485RxDataPos = 50;

	if (n485RxDataPos>=RS485RXSIZE)	
		n485RxDataPos--;
	
	RS485RXDATA[n485RxDataPos++] = rxbuf485;
	return;
	
}

void Timer0Init(void)
{
	T0CON = 0x07;
	TMR0H = TMR0HValue;
	TMR0L = TMR0LValue;
	T0CONbits.TMR0ON = 1;
	INTCONbits.TMR0IE = 1;
	nTick0 = 0; 
	nTickSetPress = 0;
	nTickResetPress = 0;
	nTickCdly = 0; 
	nTickBlinkFast = 0;
}

void RS485Init(void)
{
	TRISCbits.TRISC7=1; 	// RX
    TRISCbits.TRISC6=0; 	// TX

	TXSTA1 = 0x00;			
	RCSTA1 = 0x90;		
	SPBRG1 = 30;			
	BAUDCON1 = 0x00;	
	PIE1bits.RC1IE = 1;		 
	TRISCbits.TRISC3 = 0;
	p485 = 0;				
	
	memset (RS485RXDATA, 0, sizeof(RS485RXDATA));	
}

Can two routine be done in a high priority interrupt? Will there be any problem in long term?
This is because I'm trying to find out why my device always hang after running a few days...
 

Normally its not advised to call functions inside an ISR, rather you can rise a flag and based on the flag you can manipulate as required in while loop of the main function.

while calling functions in ISR you should be aware of Instruction execution time every time you add up code otherwise the code structs up in ISR
 

Normally its not advised to call functions inside an ISR, rather you can rise a flag and based on the flag you can manipulate as required in while loop of the main function.

while calling functions in ISR you should be aware of Instruction execution time every time you add up code otherwise the code structs up in ISR

Don't understand what you mean. Any examples?
I already raise the INTCONbits.TMR0IF flag and PIR1bits.RC1IF flag in the chk_isr routine...
 

There is a problem in your program you cant just use assembly GOTO to call a function in C. That is consists of lot of stack operations. otherwise it is ok to call a small functions inside a ISR (without delay).

Better you move the code of check_ISR in to your high prio ISR.
 

if it is an ordinary function then why

Code C - [expand]
1
#pragma interrupt chk_isr


which compiler you are using ?

Try compiling and executing

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
void My_HiPrio_Int(void)
{
    INTCONbits.GIE = 0;
 
    if(INTCONbits.TMR0IF==1)   //Timer routine
        Timer0_ISR();
 
    if(PIR1bits.RC1IF)     //RS485 receiver 
        RC_ISR();
 
    INTCONbits.GIE = 1;
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top