Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Not coming back to main from the ISR

Status
Not open for further replies.

srikanthind

New Member
could you someone suggest me, why the program not coming back to main from ISR..

the code is
Code:
/*  pin1 -- pedestrain green  (RED is NOT of GREEN)

    2--- ped LED
   
    3-- Button


    4 --- cars Green   (RED is NOT of GREEN)

    5 ---- car amber

*/


#define _LEGACY_HEADERS
#include <pic.h>
#define _XTAL_FREQ 4000000
__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTDIS & INTIO);

#define TRISIO_DEFAULT 0b11101101
#define TRISIO_LED 0b11111011
#define TRISIO_LEDAMB 0B11011011
#define TRISIO_AMBER 0B111011111


#define GPIO_DEFAULT 0b00011001
#define GPIO_LED 0b00000101
#define GPIO_LEDAMB 0b00100101
#define GPIO_PED 0B000000011
#define GPIO_AMBER 0B00101001    // AMBER ON


unsigned char cnt=0, i,j, cnt_delay=1;

// Interrupt service routine
void interrupt Isr(void)
{
    if(GPIF)
    {
     	if(GPIO3==0)
         {
          for (cnt=0; cnt<=5; cnt++)  // prevent debouncing
           { 
            __delay_ms(1);
            if((GPIO3)==0)
            cnt=0;
           } 
         }
	        	 	
          for (cnt=0;cnt<15;cnt++)                    // LED ON
         {
         TRISIO = TRISIO_DEFAULT;
         GPIO= GPIO_DEFAULT ;
         __delay_ms(150);
         TRISIO= TRISIO_LED;
         GPIO=GPIO_LED;
          }

 
      for(j=0;j<95;j++)                  // AMBER LIGHT IS ON WITH DELAY
        {
        for (cnt =0; cnt<250; cnt++); // 2 seconds delay
         {
          TRISIO = TRISIO_LEDAMB;
          GPIO = GPIO_LEDAMB;
          __delay_ms(20);
          TRISIO = TRISIO_DEFAULT;
         GPIO = GPIO_DEFAULT;
         }
        }


// task d:


      
       __delay_ms(55);

       GPIO &= ~(1<<2);              // PED Led  indicator OFF, 
       TRISIO = TRISIO_DEFAULT;      // PED GREEN ON.
       GPIO= GPIO_PED;

       while((GPIO0 == 0) && (cnt_delay!=6))    // VARIABLE DELAY
               {
                 cnt_delay++;
                 GPIO |= (1<<0);
                for(cnt=0; cnt<10;cnt++) // 1 second delay
                 __delay_ms(100);
                
               } 

        for(cnt_delay;cnt_delay!=0; cnt_delay--)
         {
           for(cnt=0; cnt<50;cnt++) // 5 seconds delay
            __delay_ms(100);
         }

      
        __delay_ms(155);
             
           for(j=0;j<30;j++)        // AMBER IS ON, PEDSTRAIN GREEN ON WITH 3 SECONDS DELAY
              {
                for (cnt =0; cnt<250; cnt++); // 3 seconds delay
  
                   {
                      TRISIO = TRISIO_DEFAULT;
                      GPIO = GPIO_PED;
                      __delay_ms(100);
                      TRISIO= TRISIO_AMBER;
                      GPIO=GPIO_AMBER;
                   }
              }
         __delay_ms(155);
 
      TRISIO=TRISIO_DEFAULT;        // GOES BACK TO DEFAULT
      GPIO=GPIO_DEFAULT;
}
      GPIF=0;

 }


void main(void)
{
	ANSEL = 0b00000000;
	OPTION = 0b10000001; // Configure the time (bit5=0, bit3=0, bits 2-0=100 - prescaler=32); Thus, overflow occurs each 8.192ms
	CMCON = 0b00000000;

    GPIO=0;

	GIE = 1;
	T0IE = 1;
	GPIE = 1;
	IOCB3 = 1;
	T0IF = 0;
	GPIF = 0;
    GPIO |= (1<<3);


	TRISIO = TRISIO_DEFAULT; // 
	GPIO = GPIO_DEFAULT;

	while(1){}
}


thank you
 
unable to get desired output

can someone have a look the below program please.. I wanted to check how many times GPIO0( 0th pin of GPIO) button is pressed.. depends on that delay would vary..

but, cnt_delay variable taking 5 or 6 all the time.. ( when button is pressed gpio0 is 0)

Code:
while((GPIO0 == 0) && (cnt_delay!=6))    // VARIABLE DELAY
               {
                 cnt_delay++;
                 GPIO |= (1<<0);
                for(cnt=0; cnt<10;cnt++) // 1 second delay
                 __delay_ms(100);
                
               } 

        for(cnt_delay;cnt_delay!=0; cnt_delay--)
         {
           for(cnt=0; cnt<50;cnt++) // 5 seconds delay
            __delay_ms(100);
         }
 
How do you know it never comes back? Have you waited long enough. The ISR is a mess. I suggest you re-write the whole thing. Write first a very simple (empty) ISR and see if it comes back to main then.. You can eliminate one problem at a time. Always debug step by step. It is impossible to debug the whole system at once.
 
Could you comment the code more to explain exactly what is going on? Is your hardware correct?
 
Last edited:
I am trying to write code for variable delay from 5 seconds to 30 seconds.. depends on , how many times user presses the button the delay varies.. if the button pressed twice (3*5) 15 seconds delay
(initlilised the cnt_delay=1)

if the button is not pressed, delay should be get 5 seconds..

Could you comment the code more to explain exactly what is going on? Is your hardware correct?
 
it was working before when there were not many instructions, but not now.... it was staying the ISR loop (keep checking the GPIF and going to last instruction),
i thought i waiated for long enough..

How do you know it never comes back? Have you waited long enough. The ISR is a mess. I suggest you re-write the whole thing. Write first a very simple (empty) ISR and see if it comes back to main then.. You can eliminate one problem at a time. Always debug step by step. It is impossible to debug the whole system at once.
 
THE BASIC PROGRAM, EVEN ITS NOT COMING BACK.... (STAYING IN THE ISR LOOP).. COULD YOU HAVE A LOOK PLEASE..

THANK YOU

Code:
unsigned char cnt=0, i,j, cnt_delay=1;

// Interrupt service routine
void interrupt Isr(void)
{
    //if(GPIF)
GPIF=0;
}


void main(void)
{
	ANSEL = 0b00000000;
	OPTION = 0b10000001; // Configure the time (bit5=0, bit3=0, bits 2-0=100 - prescaler=32); Thus, overflow occurs each 8.192ms
	CMCON = 0b00000000;

    GPIO=0;

	GIE = 1;
	T0IE = 1;
	GPIE = 1;
	IOCB3 = 1;
	T0IF = 0;
	GPIF = 0;
    GPIO3=1;
    GPIO |= (1<<3);


	TRISIO = TRISIO_DEFAULT; // 
	GPIO = GPIO_DEFAULT;

	while(1){}
}



How do you know it never comes back? Have you waited long enough. The ISR is a mess. I suggest you re-write the whole thing. Write first a very simple (empty) ISR and see if it comes back to main then.. You can eliminate one problem at a time. Always debug step by step. It is impossible to debug the whole system at once.
 
I am trying to write code for variable delay from 5 seconds to 30 seconds.. depends on , how many times user presses the button the delay varies.. if the button pressed twice (3*5) 15 seconds delay
(initlilised the cnt_delay=1)

if the button is not pressed, delay should be get 5 seconds..

Could you comment the code more to explain exactly what is going on? Is your hardware correct?
 
In line with what Mister T suggests, do this:

Testing includes simulation. It is what pays the most for your efforts. Many times you will not need to ask for help because simulation will tell you what was wrong.

Always develop and test any (ANY) software in progressive steps. When the last addition does not work you know you have reached a point where something was not correct.

The empty ISR he suggets, is one of the best things you could do.

When you are asked to comment code it means to wirte "comments" explaining what is the intention, prior starting a routine or piece of code and (AND) comments following each line of it.
 
srikanthind, the last code you posted doesn´t do anything, so how can you tell whether it returns from the isr or not?
 
Status
Not open for further replies.

Latest threads

Back
Top