Go Down

Topic: Interrupts getting ignored (Read 1 time) previous topic - next topic

Robin2

#15
Apr 08, 2018, 11:42 am Last Edit: Apr 08, 2018, 11:43 am by Robin2
How do I do that can you guide me please
Just change
Code: [Select]
long debouncing_time = 400;
to
Code: [Select]
long debouncing_time = 400000;

To be honest, if you can't figure that out without my help you are probably too inexperienced to be using interrupts. Spend some more time learning the basics.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Count

Just change
Code: [Select]
long debouncing_time = 400;
to
Code: [Select]
long debouncing_time = 400000;

To be honest, if you can't figure that out without my help you are probably too inexperienced to be using interrupts. Spend some more time learning the basics.

...R
Thanks robin2 for your reply I know I need to learn alot more. But I was asking about how to make those calculations in setup.

Count

OK. For the third time:

Then this question:
Also: how are you determining that an interrupt has not been detected ?

Ignore the last test code change I gave you and temporarily replace your loop with this which will determine if interrupts are working or not or maybe point to a logic error in your code.

Code: [Select]

void loop ()
{

  if (ang == false )
  {
    Serial.println("Interrupt detected");
    ang = true ;
  }

}


Two reset switches are connected to pin 2 and 3 when pressed it gives HIGH to these pins. I press them manually.


After I use the code that you gave to me, in serial monitor I can see " Interrupt is detected" every time I press any of the two switches. Is it what is expected to happen?

6v6gt

Two reset switches are connected to pin 2 and 3 when pressed it gives HIGH to these pins. I press them manually.


After I use the code that you gave to me, in serial monitor I can see " Interrupt is detected" every time I press any of the two switches. Is it what is expected to happen?
OK. That would all imply that interrupts are indeed being detected and the interrupt service routines correctly  triggered.

Your post is entitled "Interrupts getting ignored". What is not happening in your sketch which you believe should happen ? In other words, how have you concluded that interrupts are being ignored ?

Robin2

Thanks robin2 for your reply I know I need to learn alot more. But I was asking about how to make those calculations in setup.
That is straightforward also - something like
Code: [Select]
debouncing_time_millis = debouncing_time * 1000;

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Count

Quote
OK. That would all imply that interrupts are indeed being detected and the interrupt service routines correctly  triggered.

Your post is entitled "Interrupts getting ignored". What is not happening in your sketch which you believe should happen ? In other words, how have you concluded that interrupts are being ignored ?
I say that bcoz I can see the values getting updated in this loop
Code: [Select]

       if (ang == false)
    {
      Serial.println("Motor ON time Updtae EnABLED");
      Serial.println("Updating ANCHI");
      yog = now.hour();
      anchi = now.minute();
      anchi = anchi + EEPROM.read(address);
      Serial.print("EEPROM:");
      Serial.println(EEPROM.read(address));
      Serial.print("MOTOr will be OFF at:");
      Serial.println(anchi);
      ang = true;
    }


only when the pin 9 is LOW. Once the pin 9 goes HIGH the values are not updated in it

6v6gt

OK. This is a potential source of error:

Code: [Select]

void dec()
{
  chiran --;
  EEPROM.write(address, chiran);
  ang = false;
}



1. chiran is declared as a (signed) int and your EEPROM.write can write only a single (unsigned) byte. It will cause a mess also if chiran goes negative. You should use EEPROM.put and EEPROM.get instead.

2. The EEPROM  has a limited lifetime (number of write operations).  Writing to it in the loop() is not generally a good idea. Do you have to maintain the status of the system after it is switched off ?

Count

OK. This is a potential source of error:

Code: [Select]

void dec()
{
  chiran --;
  EEPROM.write(address, chiran);
  ang = false;
}



1. chiran is declared as a (signed) int and your EEPROM.write can write only a single (unsigned) byte. It will cause a mess also if chiran goes negative. You should use EEPROM.put and EEPROM.get instead.

2. The EEPROM  has a limited lifetime (number of write operations).  Writing to it in the loop() is not generally a good idea. Do you have to maintain the status of the system after it is switched off ?
1. Considering your first point, it works well when I fetch and compare minutes instead of hours. But when hours are fetched from RTC and compared the problem arrises. Even if I assugn fixed values to variables nil and yogesh everything works fine. Problem only arrises whrn I fetch the hours and save it in nil and minutes in yogesh and compare them in the next loop. If EEPROM.write and EEPROM.read was the problem then it shouldn't have worked in these cases I guess.

2. Yes I need to save those values each time on eeprom so as to get them back when the power resumes after failure

Count

So, is there any way out.....? Why the interrupts aren't serviced or if they are serviced then why the variables aren't updated.

Count

So, is there any way out.....? Why the interrupts aren't serviced or if they are serviced then why the variables aren't updated when pin 9 goes HIGH.

6v6gt

You'll have to deal with that problem an example of which is in #21.

In the meantime:

1) add a print statement after the Serial.begin(9600) so you can see if the system is  restarting.

2) post the code that you are now using. You have surely made changes since your first post.

3) explain exactly what you are doing. It looks like you are setting a timers  so a motor start at a particular hour (or minute) and switches off at a particular time, but you appear to be setting only one counter chiran.

Count

You'll have to deal with that problem an example of which is in #21.

In the meantime:

1) add a print statement after the Serial.begin(9600) so you can see if the system is  restarting.

2) post the code that you are now using. You have surely made changes since your first post.

3) explain exactly what you are doing. It looks like you are setting a timers  so a motor start at a particular hour (or minute) and switches off at a particular time, but you appear to be setting only one counter chiran.
1)Well I have to try this, but I guess problem is not there in restarting of program

2) I am using exactly the same code which I have posted and I haven't made any changes in it yet.

3) This is what I expect to get done:

A) Motor turns ON (there is no any specific requirement for when to turn ON the motor for the very first time when the system is initiated)

B) Once the motor is ON its ON time should be able to varied from 2 mins to 16 mins max. (the user will decide it for how much time the motor remains ON min is 2 mins and max is 16 mins. The user should be able to vary the time for which the motor remains ON, only when the motor is turned ON)

C) After getting the time from user, turn the motor of after the set minutes.

D) After the motor is turned OFF, It should be turned ON again after 2 hours.

Note: all of this working should have no effect of the power failures. What I am trying to say is consider a situation where motor is turned OFF and there is a power failure. The power resumes after one hour, now the system should compensate this one hour and start the motor again ON after one hour for now, since there was a power failure for one hour

Go Up