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.

PIC18F26K22 interrupt problem

Status
Not open for further replies.

UroBoros

Advanced Member level 2
Joined
May 5, 2004
Messages
642
Helped
19
Reputation
38
Reaction score
8
Trophy points
1,298
Location
Cochin - India
Activity points
6,463
I am trying to make a interrupt driven code on this chip. I am using timer 0 and timer 6 here. This is my initialization code for timer 6 and interrupt. The overflow flag is getting set as expected. I can it polled positive in mainline also. The timing is also happening as expected. But simply interrupt is not throwing. what is I am missing here?
Timer0 code is giving interrupts as expected, but timer 6 is not vectoring to ISR on overflow.

Code:
//*******************************************************************************
//for 1ms - 1 clock cycle 15.625nSec @ 64Mhz. 1 instruction cycle 62.5nS. 
//Prescalar 16, postscalar 4 and reload value 250 will give 1ms interrupt
void Timer6_ini(void)
{
T6CON = 0b00011011;        
TMR6=0;                         //Clear Timer    
PR6=250;                         //Reload value for 1ms
PIR5bits.TMR6IF=0;            //Timer6 flag cleared(2nd bit 0 clear)
IPR5bits.TMR6IP=0;            //Timer6 interrupt on low priority(2nd Bit - 0) 
PIE5bits.TMR6IE=1;            //Timer6 interrupt enabled(2nd bit enabled)
PMD0bits.TMR6MD=0;        //Timer6 module not disabled
T6CONbits.TMR6ON = 1;    //Enable the timer.
}
//*******************************************************************************
void EnableInterrupts(void)
{
RCONbits.IPEN=1;            // interrupt priority enabled (7tH bit)
INTCONbits.GIE=1;        //global interrupt  enabled
INTCONbits.PEIE=1;            // all interrupts enabled
Nop();
}
//**********************************************************************************/
Thanks
 

Those 2 functions are seems to be ok. may be something wrong in your main code.
How did you called them ?
did you clear interrupt flag after working on it ?
How did you check the code ? simulator or debugger ?
 
This is the mainline code

Code:
#pragma code HIGH_INTERRUPT_VECTOR = 0x08
	void High_ISR (void)
	{						// If you are using this programe hex file with a conventional
	  	_asm goto YourHighPriorityISRCode _endasm	//device programmer this directives will help
	}
	#pragma code LOW_INTERRUPT_VECTOR = 0x18
	void Low_ISR (void)
	{
	  	_asm goto YourLowPriorityISRCode _endasm
	}
//---------------------------------------------------------------End of re-direction-----------------


void main(void)
{
	Delay10KTCYx(2);	
	ports_ini();

	Timer0_ini();
	Timer4_ini();	
	Timer5_ini()	;
	Timer6_ini();

	EnableInterrupts();// two times

	lcd_ini();

	PORTCbits.RC2=1;
	Delay_Ms(100);
	PORTCbits.RC2=0;
	Delay_Ms(150);
	PORTCbits.RC2=1;
	Delay_Ms(100);
	PORTCbits.RC2=0;
			
	lcdstringptr(EmbCkit,1);
	lcdstringptr(USBMicro,2);
	lcdstringptr(CurCount,3);
	lcdstringptr(Digitis,4);

	while(1)
		{
		
				PORTC |=0b00000011;
				PORTB |=0b00011111;
				Delay1KTCYx(250);
				PORTC &= 0b11111100;
				PORTB &= 0b11100000;
				Delay1KTCYx(250);

				if(INTCONbits.TMR0IF)
					{
						INTCONbits.TMR0IF=0;
						_asm nop _endasm
					}
				if(PIR5bits.TMR4IF)
					{
						PIR5bits.TMR4IF=0;
						_asm nop _endasm	
					}
				if(PIR5bits.TMR6IF)
					{
						PIR5bits.TMR6IF=0;	//I am getting flag set here on all timers
						_asm nop _endasm
					}
				if(PIR5bits.TMR5IF)
					{
						PIR5bits.TMR5IF=0;
						_asm nop _endasm;	
					}
		}

Here is the interrupt code. I placed the traps in both high and low priority vectors

Code:
//Here we starts the real interrupt code!
#pragma code InterruptFunctions
//------------------This is the actual interrupt functions---------------------------------------------------------------------------------
#pragma interrupt YourHighPriorityISRCode//08h
void YourHighPriorityISRCode()
	{
		//Here we can insert any high priority interrupt code if required
			if(PIR5bits.TMR6IF)
			{
				PIR5bits.TMR6IF=0;	
				_asm nop _endasm
			}
		if(INTCONbits.TMR0IF)
			{
				INTCONbits.TMR0IF=0;
				_asm nop _endasm
			}
		if(PIR5bits.TMR4IF)
			{
				PIR5bits.TMR4IF=0;
				_asm nop _endasm	
			}
		if(PIR5bits.TMR5IF)
			{
				PIR5bits.TMR5IF=0;
				_asm nop _endasm;	
			}
		_asm nop _endasm
	}	//This return will be a "retfie fast", since this is in a #pragma interrupt section 
//---------------------------------------------------------------------------------------------------------------------------------------------

#pragma interruptlow YourLowPriorityISRCode//18h
void YourLowPriorityISRCode()
	{
		if(PIR5bits.TMR6IF)
			{
				PIR5bits.TMR6IF=0;	
				_asm nop _endasm
			}
		if(INTCONbits.TMR0IF)
			{
				INTCONbits.TMR0IF=0;
				_asm nop _endasm
			}
		if(PIR5bits.TMR4IF)
			{
				PIR5bits.TMR4IF=0;
				_asm nop _endasm	
			}
		if(PIR5bits.TMR5IF)
			{
				PIR5bits.TMR5IF=0;
				_asm nop _endasm;	
			}
	}

I am testing on MPLAB SIM and on MPLB ICD2. in both cases result same.
Thanks for the time
 

For any interrupt of timers that you have used; will it correctly jump to interrupt vector ?
Will it jump to YourHighPriorityISRCode() or YourLowPriorityISRCode() ?
(Although you have same code on both locations)

Check you declaration; is it according to syntax ?

#pragma code HIGH_INTERRUPT_VECTOR = 0x08
void High_ISR (void)
{ // If you are using this programe hex file with a conventional
_asm goto YourHighPriorityISRCode _endasm //device programmer this directives will help
}
#pragma code LOW_INTERRUPT_VECTOR = 0x18
void Low_ISR (void)
{
_asm goto YourLowPriorityISRCode _endasm
}
 
Yes. Timer0 behaves as expected- in timing and reaching proposed locations , clearing the flag and reappears at the expected time again in ISR.
 

T6CON = 0b00011011
means you have selected 1:4 postscaler, can you change it to 1:1 as below,
T6CON = 0b00000011
and check when first matching of TMR6 and PR6 occur, program branch to interrupt.
 
Still only Timer 0 vectors to interrupt.
I have attached this test project which can be opened in MPLAB installed with MPLABC18 and compile. If somebody can throw some light into this problem, it will be helpful.

Thanks
 

Attachments

  • TestLedBlink.rar
    46.8 KB · Views: 63

I can't check the code in MPLABC at the moment.
When you debug the program, will you see TMR6 register increase and when it match to PR6, TMR6IF goes high ?

If yes, at the moment TMR6=PR6; watch interrupt enable bits
Global interrupts / Low priority interrupts / Interrupt for timer6;
May be some other interrupt masking the timer6 interrupt.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top