The purpose of alarms in this case is to wake up a microcontroller every 20 minutes at 00, 20 and 40 minutes past the hour.
In the setup the following is used:
RTC.setAlarm(ALM1_MATCH_MINUTES, 0, 0, 0, 0);
..and in the routine right after every wake-up:
RTC.setAlarm(ALM1_MATCH_MINUTES, 0, ((now.minute()+20)%60), 0, 0);
So far all works well: every wake up is at 0 seconds and 0, or 20 or 40 minutes.
But to avoid having to wait a full hour in the case when the system is started at a few minutes past the hour a condition is inserted in the code for the alarm in the setup:
RTC.setAlarm(ALM1_MATCH_MINUTES, 0, (0 || 20 || 40), 0, 0);
However the issue here is that even with this code the system does not wake up until the 0 minute at the hour is reached. And instead of starting at 0, 20 and 40 minutes, it starts at 1, 21 and 41 minutes.
To test further the following was tried in the setup:
RTC.setAlarm(ALM1_MATCH_SECONDS, (0 || 20 || 40), 0, 0, 0);
Here the alarm starts at whatever the next seconds it is closest at, so works perfectly as expected! And this every time at either 0, 20 and 40 minutes past the hour.
Then the following was tried in the setup:
RTC.setAlarm(ALM1_MATCH_MINUTES, 30, 0, 0, 0);
Again this works fine and the system wakes up at 30 seconds past 0 minutes on the hour.
So it seems as if the ALM1_MATCH_SECONDS does work well with conditions in the setup phase. And the ALM1_MATCH_MINUTES only works properly whan actual integers are used; as soon as OR functions are used for the setting of the minutes, odd behaviour results (when applied in the setup phase).
What is the reason?
And how can this be corrected?