The Godfather talking
You may crack software. How about me?
Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 23, 2024, 11:02:37 23:02


Login with username, password and session length


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

Posts: 218

Thank You
-Given: 26
-Receive: 63


« on: December 28, 2008, 09:24:20 21: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, 09:30:10 21:30 by TomJackson69 » Logged

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

Posts: 442

Thank You
-Given: 167
-Receive: 149



« Reply #1 on: December 28, 2008, 10:47:58 22:47 »

enable priorities IPEN = RCON(7)  .sorry if i am wrong.
Logged
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #2 on: December 28, 2008, 11:33:13 23: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: 442

Thank You
-Given: 167
-Receive: 149



« Reply #3 on: December 28, 2008, 11:42:35 23: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
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #4 on: December 29, 2008, 12:49:09 00: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, 12:53:27 00:53 by TomJackson69 » Logged

Con Rong Chau Tien
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #5 on: December 29, 2008, 05:29:02 05: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: 442

Thank You
-Given: 167
-Receive: 149



« Reply #6 on: December 29, 2008, 10:25:35 10: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
TomJackson69
Active Member
***
Offline Offline

Posts: 218

Thank You
-Given: 26
-Receive: 63


« Reply #7 on: January 01, 2009, 08:15:02 20: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