Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 03, 2016, 06:38:43 18:38


Login with username, password and session length


Pages: [1]
Print
Author Topic: Need help: Timer2 Low-Priority Interrupt on PIC18F452 not work  (Read 7479 times)
0 Members and 1 Guest are viewing this topic.
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« on: December 28, 2008, 10:24:20 22:24 »

Hi all,

I am trying to setup TMR2 interrupt to Low-Priority but not working. It always trigger interrupt at Hi-Priority. Here is what I setup in MCC18:

// Locate ISR handler code at interrupt vector
#pragma code isrcode = 0x0008
         
void Hi_isrhandler(void)      // This will jump to actual ISR
{                                             
_asm
   goto RB01_int       // RB0 Hi-Pri Int
_endasm
}


#pragma code low_vector_section = 0x18
void low_vector (void)
{
   _asm
      goto Low_isr      //goto TMR2_int
   _endasm
}



         
#pragma code    //

///* Setup timer 2 int */

PR2 = 250;
IPR1bits.TMR2IP = 0;                     // Clr for TMR2 Low priority
OpenTimer2(T2_PS_1_4 & T2_POST_1_4);  // setup Pre-scale and Postscale
PIE1bits.TMR2IE = 1;                     // Enable TMR2 int

//--- some other code ---
//   ...
//   ...

PIR1bits.TMR2IF = 0;      // Enable Timer2 Interrupt.
INTCONbits.PEIE = 1;      // Enable peripheral interrupts
INTCONbits.GIEL = 1;      // Enable all Low-Pri interrupts
INTCONbits.GIEH = 1;      // Enable all Hi-Pri interrupts

//--- Hi Priority interrupt here ---
void RB01_int(void)       // RB0 Hi-Pri Int
{
...
...
}

//--- Low Priority interrupt here ---
void Low_isr(void)              // TMR2_int
{
...
...
PIR1bits.TMR2IF = 0;      // clear flag for next Timer2 Interrupt.
}

//--- main() here ---
//--- other routins here ---
//

I don't know what is the problem, I read the PIC18F452 for errecta but could not trigger Low-Pri for TMR2. I also try on PIC18F4550, same problem; All interrups goto Hi-Pri vector.

Any body know the solution please help.

Tom
« Last Edit: December 28, 2008, 10:30:10 22:30 by TomJackson69 » Logged

Con Rong Chau Tien
sohel
Senior Member
****
Offline Offline

Posts: 437

Thank You
-Given: 140
-Receive: 124



WWW
« Reply #1 on: December 28, 2008, 11:47:58 23:47 »

enable priorities IPEN = RCON(7)  .sorry if i am wrong.
Logged

A Thousand Miles Journey Start With a Single Step<br />http://www.youtube.com/user/masud58
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #2 on: December 29, 2008, 12:33:13 00:33 »

sohel ,

Yes, I did enable IPEN, I forget to include in the post above.

RCONbits.IPEN = 1;      // Enable interrupt priority (both Hi and Low)

I put this before I setup TMR2.

Any suggestion that can make the Low-Pri interrupt works? I did try to work on this for two days but, still not be able to get it go to low intrrupt vector.

I need to have TMR2 interrupt at regular interval (about 310uS) and then INT0 (RB0) can be intrrupt any time. I have not use two interupts before.

Thank you,

Tom
Logged

Con Rong Chau Tien
sohel
Senior Member
****
Offline Offline

Posts: 437

Thank You
-Given: 140
-Receive: 124



WWW
« Reply #3 on: December 29, 2008, 12:42:35 00:42 »

i will help with HI-TECH. PLEASE GIVE ME TIME. now the time is  5:30 am here. i am typing from my cell.
Logged

A Thousand Miles Journey Start With a Single Step<br />http://www.youtube.com/user/masud58
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #4 on: December 29, 2008, 01:49:09 01:49 »

sohel ,

Now is 05:35PM Sunday here. Yes take your time.

I just switch to 18F4550 and read the ERRATA for the 4550; it suggest:

This is from 4550 errata:
PIC18F2455/2550/4455/4550
The code segment shown in Example 2
demonstrates the work around using the C18
compiler:
#pragma interruptlow MyLowISR
void MyLowISR(void)
// Handle low priority interrupts.
// Although MyHighISR is a high priority interrupt, use interruptlow pragma so that
// the compiler will not use retfie FAST.
#pragma interruptlow MyHighISR
void MyHighISR(void)
// Handle high priority interrupts.
#pragma code highVector=0x08
void HighVector (void)
_asm goto MyHighISR _endasm
#pragma code /* return to default code section */
#pragma code lowVector=0x18
void LowVector (void)
_asm goto MyLowISR _endasm
#pragma code /* return to default code section */

See how Microchip suggest using both #pragma interruptlow for HI and LOW.
I used this and the Low-Pri interrupt work but the Hi-Pri int is not working. There is only one interrupt vector work at one time. I think, it has something to do with the STACK when interrupt returns. I thing there are working code somewhere and I know people working on this before me.

It needs sometimes to get the code working. I am passion person. Wink

Tom
« Last Edit: December 29, 2008, 01:53:27 01:53 by TomJackson69 » Logged

Con Rong Chau Tien
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #5 on: December 29, 2008, 06:29:02 06:29 »

Hello Sohel ,

I have the interrupts working (kinda) but after several interupt on port B0, the system hang. I think I have to do some saving of several variables that I am using in the delay routin.

Anyway, I have to use both int-hi and int-low in definning:

#pragma interruptlow MyLowISR
#pragma interrupt MyHighISR

Thank you for your help, I think I can handle from here.

Tom
Logged

Con Rong Chau Tien
sohel
Senior Member
****
Offline Offline

Posts: 437

Thank You
-Given: 140
-Receive: 124



WWW
« Reply #6 on: December 29, 2008, 11:25:35 11:25 »

Here is ur requerment. its may be handy for u. I Am also  new in "C". there are many "C" codder in sonsivri. I cant get attention of them to teach me. its hurt me a lot.

http://rapidshare.com/files/177789734/PIC18Fxxxfrom_microchip.rar

main terget is learn "C" anyhow.

thanks
Logged

A Thousand Miles Journey Start With a Single Step<br />http://www.youtube.com/user/masud58
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #7 on: January 01, 2009, 09:15:02 21:15 »

Here is ur requerment. its may be handy for u. I Am also  new in "C". there are many "C" codder in sonsivri. I cant get attention of them to teach me. its hurt me a lot.

http://rapidshare.com/files/177789734/PIC18Fxxxfrom_microchip.rar

main terget is learn "C" anyhow.

thanks


Hello Sohel ,

I solved the problem. I have to save the context manually.

Tom
Logged

Con Rong Chau Tien
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC