extrnal interrupt handling issue

I am facing problem in External interrupt code. The flow enters the ISR but wont come out. I am using arduino Due, IDE 1.6.7. Please help me. Attached is the code. i have commented the problem.

E312_CODE_1.ino (4.76 KB)

fun.h (5.9 KB)

void Dev_length()
{

  Value++; //increments the counter and need to enter while loop named "xyz". it enters .but doesnt compare itself with variable Tmp
  

  return;
}

It has no return type so you don't return a thing. Remove the return. Don't know if it's the problem but that's where you pointed me.

Ow, and a second look

Why is your loop empty?

Why do you have a whole list of while(1) but the last line of it always is a unconditional break... That makes them useless.

Thanks for the reply Sir,

actually I tried it without return statement also. Still not working

and in loop i need to include some inputs and also some functions like auto mode, manual mode and semi auto mode. I need to do it yet.. i am programming for a special purpose machine

"Why do you have a whole list of while(1) but the last line of it always is a unconditional break... That makes them useless."

once the condition satisfies, flow should come out of while. but it doesn't come out. so I am breaking it

void semi_auto()
{
  while (1)
  {
    lcd_set();
    lcd.print("Press start button ");
    digitalRead(PB1);
    delay(250);
    digitalRead(PB1);
    while (digitalRead(PB1) != LOW);
    {
      lcd_set();
      lcd.print("Cycle start");
      delay(2000);
      break;
    }
  }

// you will never get here !!

You will break from the inner loop but will be stuck in the outer one.

Then whats the Solution Sir?

mayuri_creintors: Then whats the Solution Sir?

Adopt conventional programming practices. An endless loop that you can only break out of to resume your program, is not one of those.

Thanks for the suggestion Sir, i have attached a bit modified code. But still ISR is not returning for comparison i.e if (Value==Tmp). Kindly comment for this
const unsigned char PC1 = 2;
const unsigned char PC2 = 3;
const unsigned char PC3 = 4;
const unsigned char PC4 = 5;
const unsigned char PC5 = 6;
const unsigned char MOT = 7;
const unsigned char IL_G = 14;
const unsigned char IL_R = 15;
const unsigned char Pf1 = 16;
const unsigned char Pr1 = 17;
const unsigned char Pf2 = 18;
const unsigned char Pr2 = 19;
const unsigned char Pf3 = 20;
const unsigned char Pr3 = 21;
const unsigned char Pf4 = 22;
const unsigned char Pr4 = 23;
const unsigned char Pf5 = 24;
const unsigned char Pr5 = 25;
const unsigned char Enc = 26;
const unsigned char PB1 = 27;
const unsigned char PB2 = 28;
const unsigned char Px1 = 29;
const unsigned char Px2 = 30;
const unsigned char S1_A = 31;
const unsigned char S1_S = 32;
unsigned char start_button, temp, temp1, warm_up, auto_start = ‘N’;
volatile unsigned int Value = 0, Value1 = 0, Tmp = 30, Tmp1 = 2, count = 0, count1,flag=0;

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

//--------------------------------------------------------------------------------------------------
void lcd_set()
{
lcd.clear();
lcd.setCursor(0, 0);
}

//--------------------------------------------------------------------------------------------------
void config_ports()
{

pinMode(PC1, OUTPUT);
pinMode(PC2, OUTPUT);
pinMode(PC3, OUTPUT);
pinMode(PC4, OUTPUT);
pinMode(PC5, OUTPUT);
pinMode(MOT, OUTPUT);
pinMode(IL_G, OUTPUT);
pinMode(IL_R, OUTPUT);
}

//--------------------------------------------------------------------------------------------------

void Dev_length()
{

Value++; //increments the counter and need to enter while loop named “xyz”. it enters .but doesnt compare itself with variable Tmp
flag=1;

return;
}

//----------------------------------------------------------------------------------------------------

void stop_process()
{
lcd_set();
lcd.print("Process stopped ");
while (1)
{

}
}

//-----------------------------------------------------------------------------------------------------

void semi_auto()
{

lcd_set();
lcd.print("Press start button ");
digitalRead(PB1);
delay(250);
digitalRead(PB1);
while (digitalRead(PB1) != LOW);
{
lcd_set();
lcd.print(“Cycle start”);
delay(2000);
//break;
}

lcd_set();
lcd.print(“press for PC1 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr1);
delay(250);
digitalRead(Pr1);
digitalRead(Px2);
delay(250);
digitalRead(Px2);
while (digitalRead(PB1) != LOW || digitalRead(Pr1) != LOW || digitalRead(Px2) != HIGH );
{
digitalWrite(PC1, LOW);
lcd_set();
lcd.print(“PC1 forward stroke”);
}

lcd_set();
lcd.print(“press for PC2 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr2);
delay(250);
digitalRead(Pr2);
digitalRead(Pr1);
delay(250);
digitalRead(Pr1);
while (digitalRead(PB1) != LOW || digitalRead(Pr2) != LOW || digitalRead(Pr1) != HIGH );
{
digitalWrite(PC2, LOW);
lcd_set();
lcd.print(“PC2 forward stroke”);
}

lcd_set();
lcd.print(“press for PC1, PC2 rev stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pf1);
delay(250);
digitalRead(Pf1);
digitalRead(Pf2);
delay(250);
digitalRead(Pf2);
digitalRead(Pr2);
delay(250);
digitalRead(Pr2);
while (digitalRead(PB1) != LOW || digitalRead(Pf1) != LOW || digitalRead(Pf2) != LOW || digitalRead(Pr2) != HIGH);
{
digitalWrite(PC1, HIGH);
digitalWrite(PC2, HIGH);
lcd_set();
lcd.print(“PC1, PC2 rev stroke”);
}

lcd_set();
lcd.print(“press for PC3 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr3);
delay(250);
digitalRead(Pr3);
digitalRead(Pf1);
delay(250);
digitalRead(Pf1);
digitalRead(Pf2);
delay(250);
digitalRead(Pf2);
while (digitalRead(PB1) != LOW || digitalRead(Pr3) != LOW || digitalRead(Pf1) != HIGH || digitalRead(Pf2) != HIGH);
{
digitalWrite(PC3, LOW);
lcd_set();
lcd.print(“PC3 forward stroke”);
}

lcd_set();
lcd.print("Press for devp length ");
//interrupts();
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr3);
delay(250);
digitalRead(Pr3);
while (digitalRead(PB1) != LOW || digitalRead(Pr3) != HIGH);
{
lcd_set();
lcd.print(“Motor on”);
digitalWrite(MOT, LOW);

while(1) //“xyz”
{

lcd_set();
lcd.print(Value, DEC);
digitalRead(Px1);
delay(250);
digitalRead(Px1);
//while (digitalRead(Px1) != LOW && Value != Tmp);
// if(Value ==Tmp && digitalRead(Px1)==LOW )
if (Value == Tmp) //this statement not feeting executed
{

noInterrupts();
digitalWrite(MOT, HIGH);
Value = 0;
lcd_set();
lcd.print("Motor off ");

}

else if (digitalRead(Px1) == LOW) //this getting executed. but the next loop is not geeting execuated because of the [roblem in ISR
{
noInterrupts();
digitalWrite(MOT, HIGH);
Value = 0;
lcd_set();
lcd.print("Motor off ");

}

}

}

lcd_set();
lcd.print(“press for PC5 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr5);
delay(250);
digitalRead(Pr5);
digitalRead(Px1);
delay(250);
digitalRead(Px1);
while (digitalRead(PB1) != LOW || digitalRead(Pr5) != LOW || digitalRead(Px1) != LOW );
{
digitalWrite(PC5, LOW);
lcd_set();
lcd.print(“PC5 forward stroke”);
}

}

Code tags, please code tags!

Please expunge every while(1) from your code. Otherwise, you won't get any help from me.

You will break from the inner loop but will be stuck in the outer one.

Actually, that's not true. The ; on the end of the inner while statement is the body. The curly braces surrounding the next 4 statements are useless.

const unsigned char PC1 = 2;
const unsigned char PC2 = 3;
const unsigned char PC3 = 4;
const unsigned char PC4 = 5;
const unsigned char PC5 = 6;
const unsigned char MOT = 7;
const unsigned char IL_G = 14;
const unsigned char IL_R = 15;
const unsigned char Pf1 = 16;
const unsigned char Pr1 = 17;
const unsigned char Pf2 = 18;
const unsigned char Pr2 = 19;
const unsigned char Pf3 = 20;
const unsigned char Pr3 = 21;
const unsigned char Pf4 = 22;
const unsigned char Pr4 = 23;
const unsigned char Pf5 = 24;
const unsigned char Pr5 = 25;
const unsigned char Enc = 26;
const unsigned char PB1 = 27;
const unsigned char PB2 = 28;
const unsigned char Px1 = 29;
const unsigned char Px2 = 30;
const unsigned char S1_A = 31;
const unsigned char S1_S = 32;
unsigned char start_button, temp, temp1, warm_up, auto_start = ‘N’;
volatile unsigned int Value = 0, Value1 = 0, Tmp = 30, Tmp1 = 2, count = 0, count1,flag=0;

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

//--------------------------------------------------------------------------------------------------
void lcd_set()
{
lcd.clear();
lcd.setCursor(0, 0);
}

//--------------------------------------------------------------------------------------------------
void config_ports()
{

pinMode(PC1, OUTPUT);
pinMode(PC2, OUTPUT);
pinMode(PC3, OUTPUT);
pinMode(PC4, OUTPUT);
pinMode(PC5, OUTPUT);
pinMode(MOT, OUTPUT);
pinMode(IL_G, OUTPUT);
pinMode(IL_R, OUTPUT);
}

//--------------------------------------------------------------------------------------------------

void Dev_length()
{

Value++; //increments the counter and need to enter while loop named “xyz”. it enters .but doesnt compare itself with variable Tmp
flag=1;

return;
}

//----------------------------------------------------------------------------------------------------

void stop_process()
{
lcd_set();
lcd.print("Process stopped ");
while (1)
{

}
}

//-----------------------------------------------------------------------------------------------------

void semi_auto()
{

lcd_set();
lcd.print("Press start button ");
digitalRead(PB1);
delay(250);
digitalRead(PB1);
while (digitalRead(PB1) != LOW);
{
lcd_set();
lcd.print(“Cycle start”);
delay(2000);
//break;
}

lcd_set();
lcd.print(“press for PC1 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr1);
delay(250);
digitalRead(Pr1);
digitalRead(Px2);
delay(250);
digitalRead(Px2);
while (digitalRead(PB1) != LOW || digitalRead(Pr1) != LOW || digitalRead(Px2) != HIGH );
{
digitalWrite(PC1, LOW);
lcd_set();
lcd.print(“PC1 forward stroke”);
}

lcd_set();
lcd.print(“press for PC2 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr2);
delay(250);
digitalRead(Pr2);
digitalRead(Pr1);
delay(250);
digitalRead(Pr1);
while (digitalRead(PB1) != LOW || digitalRead(Pr2) != LOW || digitalRead(Pr1) != HIGH );
{
digitalWrite(PC2, LOW);
lcd_set();
lcd.print(“PC2 forward stroke”);
}

lcd_set();
lcd.print(“press for PC1, PC2 rev stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pf1);
delay(250);
digitalRead(Pf1);
digitalRead(Pf2);
delay(250);
digitalRead(Pf2);
digitalRead(Pr2);
delay(250);
digitalRead(Pr2);
while (digitalRead(PB1) != LOW || digitalRead(Pf1) != LOW || digitalRead(Pf2) != LOW || digitalRead(Pr2) != HIGH);
{
digitalWrite(PC1, HIGH);
digitalWrite(PC2, HIGH);
lcd_set();
lcd.print(“PC1, PC2 rev stroke”);
}

lcd_set();
lcd.print(“press for PC3 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr3);
delay(250);
digitalRead(Pr3);
digitalRead(Pf1);
delay(250);
digitalRead(Pf1);
digitalRead(Pf2);
delay(250);
digitalRead(Pf2);
while (digitalRead(PB1) != LOW || digitalRead(Pr3) != LOW || digitalRead(Pf1) != HIGH || digitalRead(Pf2) != HIGH);
{
digitalWrite(PC3, LOW);
lcd_set();
lcd.print(“PC3 forward stroke”);
}

lcd_set();
lcd.print("Press for devp length ");
//interrupts();
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr3);
delay(250);
digitalRead(Pr3);
while (digitalRead(PB1) != LOW || digitalRead(Pr3) != HIGH);
{
lcd_set();
lcd.print(“Motor on”);
digitalWrite(MOT, LOW);
}

lcd_set();
lcd.print(Value, DEC);
digitalRead(Px1);
delay(250);
digitalRead(Px1);
//while (digitalRead(Px1) != LOW && Value != Tmp);
// if(Value ==Tmp && digitalRead(Px1)==LOW )

  if (Value == Tmp)      //this statement not feeting executed
      {
       
        noInterrupts();
        digitalWrite(MOT, HIGH);
        Value = 0;
        lcd_set();
        lcd.print("Motor off ");
    
      }
      

      else if (digitalRead(Px1) == LOW) //this getting executed. but the next loop is not geeting execuated because of the [roblem in ISR
      {
        noInterrupts();
        digitalWrite(MOT, HIGH);
        Value = 0;
        lcd_set();
        lcd.print("Motor off ");
       
      }

lcd_set();
lcd.print(“press for PC5 fwd stroke”);
digitalRead(PB1);
delay(250);
digitalRead(PB1);
digitalRead(Pr5);
delay(250);
digitalRead(Pr5);
digitalRead(Px1);
delay(250);
digitalRead(Px1);
while (digitalRead(PB1) != LOW || digitalRead(Pr5) != LOW || digitalRead(Px1) != LOW );
{
digitalWrite(PC5, LOW);
lcd_set();
lcd.print(“PC5 forward stroke”);
}

}

Kindly comment for this

You are still a dumbass for not using code tags. Read the stickies at the top of the forum - the ones you were supposed to read BEFORE you blundered in here.

PaulS: Actually, that's not true. The ; on the end of the inner while statement is the body. The curly braces surrounding the next 4 statements are useless.

You're right (again) ;)

sterretje:
You’re right (again) :wink:

Second time this year! 8)

Mister Paul, you are wrong. i have used code tags as well as posted my whole code for reference.. i have tagged only the part which i feel problematic. this is not the way to treat new comers. i honestly wanna learn.

mayuri_creintors: i have used code tags

Once out of three. While the last time is without again.

mayuri_creintors: this is not the way to treat new comers. i honestly wanna learn.

Not reading how to use the forum isn't a nice way to threat the old dogs as well ;)

And I agree, all those while loops are ridiculous, you all break them unconditionally.

hi...sterretje

Can you send me an example code for how to use hardware interrputs???

mayuri_creintors: hi...sterretje

Can you send me an example code for how to use hardware interrputs???

No because I have never used them.