This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem in Interrupt

I have a strange problem in interrupt, I am incrementing a variable in interrupt and displayng in main program, the code is working fine for some time , latter the system gets hanged , i dont know why??

if there is any solution to this problem plz let me know, I am using Silabs C8051F120

int var=0;
        void PCA_Timer_Interrupt(void) interrupt 9 using 2
         {
                 var++;
          }


       void main()

{
          sprintf(buffer,"%d",(int)var);
          display(buffer,LINE1);

}



Parents
  • Hello All,

    A newbie to this forum, I was going through a lot of threads and found that this thread is already talking about the interrupt problem in Nordic nrf24e1. I am working with the same chip and having trouble programming the interrupt. Here is the brief.
    I am using the RTC to wake up from sleep. The program should vector to the programmed interrupt and after exiting the interrupt should go to the next instruction after the sleep (thats what it says in the manual...) and output the value that I am changing in the interrupt. It should keep doing this just to show that the interrupt works.

    Here is the code:

    #pragma iv(0x0000) // Interrupt vector begins at 0
    #pragma interval(8) // Interval for vector is 8

    #include <Nordic\reg24e1.h>
    #include <stdio.h>

    #define TICK 10e-3 // 10ms (100Hz) tick

    unsigned char xdata a=0;

    void WriteRTC(unsigned int w){

    while(REGX_CTRL & 0x10) // Wait to be ready

    ;

    REGX_MSB = w >> 8;

    REGX_LSB = w & 0xff;

    REGX_CTRL = 0x0a;

    while(REGX_CTRL & 0x10) // Wait to be ready

    ;
    }

    void RTCINT (void) interrupt 12 using 0{

    WDTI = 0; // reset RTC interrupt flag

    a++;

    }

    void main(void){

    EA = 1; // Enable Global Interrupt

    EWDI = 1; // Enable RTC interrupt

    PWDI = 1; // RTC Interrupt High priority

    WriteRTC(1/TICK); // RTC Real time clock - 1 sec

    while(1){

    CK_CTRL = 0x01; // sleep

    printf("%d\n",&a);

    }

    }

    I have enabled global interrupts and only one other interrupt, that is RTC. I am sure they are no other interrupt sources. I have put in the using operator as '0' since the default register bank is '0'. So my interrupt function will also be in bank '0'. The interrupt number is also correct according to the manuals.
    I tried with the breakpoints but the program just does not vector to the interrupt and increment 'a'! I don't know whether it is to do with the using or declaration or something else. Has anyone done it before and any differently than I have?

    Thanks in advance,

    - Nikhil

Reply
  • Hello All,

    A newbie to this forum, I was going through a lot of threads and found that this thread is already talking about the interrupt problem in Nordic nrf24e1. I am working with the same chip and having trouble programming the interrupt. Here is the brief.
    I am using the RTC to wake up from sleep. The program should vector to the programmed interrupt and after exiting the interrupt should go to the next instruction after the sleep (thats what it says in the manual...) and output the value that I am changing in the interrupt. It should keep doing this just to show that the interrupt works.

    Here is the code:

    #pragma iv(0x0000) // Interrupt vector begins at 0
    #pragma interval(8) // Interval for vector is 8

    #include <Nordic\reg24e1.h>
    #include <stdio.h>

    #define TICK 10e-3 // 10ms (100Hz) tick

    unsigned char xdata a=0;

    void WriteRTC(unsigned int w){

    while(REGX_CTRL & 0x10) // Wait to be ready

    ;

    REGX_MSB = w >> 8;

    REGX_LSB = w & 0xff;

    REGX_CTRL = 0x0a;

    while(REGX_CTRL & 0x10) // Wait to be ready

    ;
    }

    void RTCINT (void) interrupt 12 using 0{

    WDTI = 0; // reset RTC interrupt flag

    a++;

    }

    void main(void){

    EA = 1; // Enable Global Interrupt

    EWDI = 1; // Enable RTC interrupt

    PWDI = 1; // RTC Interrupt High priority

    WriteRTC(1/TICK); // RTC Real time clock - 1 sec

    while(1){

    CK_CTRL = 0x01; // sleep

    printf("%d\n",&a);

    }

    }

    I have enabled global interrupts and only one other interrupt, that is RTC. I am sure they are no other interrupt sources. I have put in the using operator as '0' since the default register bank is '0'. So my interrupt function will also be in bank '0'. The interrupt number is also correct according to the manuals.
    I tried with the breakpoints but the program just does not vector to the interrupt and increment 'a'! I don't know whether it is to do with the using or declaration or something else. Has anyone done it before and any differently than I have?

    Thanks in advance,

    - Nikhil

Children
  • "found that this thread is already talking about the interrupt problem in Nordic nrf24e1"

    The Nordic chip is never mentioned in this thread. You should really open a new thread to discuss your problem. If not for netiquette, to show others that your problem is not the old problem already discussed in the thread.

    One note regarding using 0: when you declare a interrupt function specifying using N, the interrupt entry code assumes that the declared bank is 'set aside' for the interrupt, and does not preserve any used registers. So, if you declare using 0 and your program uses bank 0 for anything else, your interrupt will overwrite main program registers, and if you're lucky your program will crash. If you're out of luck, the program may actually run with some weird side effect.

    The using directive should only be used for ISRs that are at the same priority level, and that don't call any functions that are declared with other banked domains.