Project

General

Profile

Scheduler and interrupts under Arduino 1.6.0

Added by vladS about 5 years ago

I have been using scheduler since it was introduced in “roomNode”. In my weather station scheduler determines measurement and reporting intervals. Interrupt INT1 on Arduino pin3 is used to count tipping of rain gauge.
Set up of the scheduler is to measure every minute and report every 5 minutes

MEASURE_PERIOD 600
REPORT_EVERY 5

This always worked independent of any interrupt.

I recently switched to Arduino 1.6.0 and when I compile program I can see subtle change.
This time when interrupt occurs it resets measurement period and measurement will be done one minute from when interrupt occurred. So when interrupt happens soon after measurement period started, it will add only few seconds. But when interrupt happens near the end of measurement period, it will add nearly a minute. So reporting can be anywhere between 5 and 6 minutes.
I am attaching data comparing results from both IDEs. Interrupt is indicated by red marker. You can see that under 0022 reporting interval is quite consistent at 5:04 irrespective of any interrupts. With IDE1.6.0 reporting period is anywhere between 5:09 and 6:06 depending when interrupt happened.
It is also interesting that total time interval is different between the two IDEs.
I must add that interrupts were generated by me, tipping the bucket manually. That gave me control when tipping occurred.

Any ideas what is happening and how to fix it? Any help would be appreciated.


Replies (5)

RE: Scheduler and interrupts under Arduino 1.6.0 - Added by vladS about 5 years ago

I decided to look into my problem further, this time using much simpler program, Schedule from examples in Port library. I made two small additions to Schedule program. I inserted Print statement where LED in TASK1 gets turned on, and where it gets turned off. It prints millis() to keep track of time. I also inserted INT1 on PIN3in setup(). Interrupt increments counter. Counter gets printed at the bottom of loop() together with millis(). I compiled Schedule in Arduino 0022 and in Arduino 1.6.0.
Resulting printout is attached. In the printout I marked LED on time with ‘*’ and LED off time with ‘^’. It just makes it easier to follow what is happening.
Results are similar to results from previous posting. Sketch compiled under Arduino0022 maintains timing independent of interrupts with exception of small delay of about 67 msec. When compiled under Arduino 1.6.0 timing starts again from interrupt. In example at about 75 sec you can see that interrupt occurred at about 9.5 sec into 10 sec interval and total interval then was about 19.5 sec instead of 10 sec.
This experiment also confirm previous observation that Sketch under Arduino 0022 runs bit faster. To achieve similar timing, I had to increase “tenth” variable from 100 to 104.
It just intrigues me, how change in IDE and compiler changes behaviour of program.

RE: Scheduler and interrupts under Arduino 1.6.0 - Added by JohnO about 5 years ago

Interesting work vladS, so I guess that the remaining time in the watchdog value (Sleepy) is being preserved by 0022 but reset by 1.6.0. Could you post your exact .ino file and I may take a look at it.

RE: Scheduler and interrupts under Arduino 1.6.0 - Added by JohnO about 5 years ago

What is driving the INT1 pin?

RE: Scheduler and interrupts under Arduino 1.6.0 - Added by JohnO about 5 years ago

I wonder if the running of the millis timer is different between 0022 and 1.6.0, perhaps the later code disables interrupts less.

RE: Scheduler and interrupts under Arduino 1.6.0 - Added by vladS about 5 years ago

JohnO,

thanks, I will try to reply as best as I can.
I attached file in question. Additions to standard “Schedule” file are:
1. additional variable to count interrupts
2. comment off anything about radio
3. attach interrupt INT1
4. print when LED1 goes on and off
5. TASK2 does nothing
6. print count variable and corresponding millis
7. added counter for interrupt

File for Arduino0022 is the same, again with few changes required by this IDE
1. JeeLib replaced by Ports and RF12
2. Serial.flush() replaced by delay(2)

This is all.

Interrupt pin is driven by simple switch with classical 2Rs and C debouncing circuit. (www.ganssle.com/debouncing.htm).
Time constant is quite long since interrupts are coming only infrequently. It is quite reliable for infrequent interrupts. This circuit also provides pull-up, actually you can not use internal pull-up because voltage will never go bellow Supply/2 due to voltage divider effect of debouncing circuit.

    (1-5/5)