Go Down

Topic: Alarm (Read 11923 times) previous topic - next topic

mem

#15
Apr 21, 2010, 04:33 am Last Edit: Apr 21, 2010, 04:38 am by mem Reason: 1
Quote
but it is still acting funny.

Do you mean to say that it has exactly the same symptoms as before you made the change in loop?

If not, what are the symptoms?

edit: it would help you if you added some serial print statements in the alarm code to see which alarm was being triggered. You could also print the minute and second to show the time the alarm function was called.

cne

When I turn it on, it cycles through all of the alarms correctly, but after I turn pin 2 high, it sounds the alarm about 6 times really fast.

mem

#17
Apr 21, 2010, 05:26 am Last Edit: Apr 21, 2010, 05:30 am by mem Reason: 1
The alarm logic does not expect time to run backwards and when you reset the clock back to the start of the previous day the scheduler can get confused.

If you want to adjust for drift, you could use the adjustTime function. This moves the clock forwards or backwards by a given number of seconds but does not disrupt the day and date.

Here is an untested fragment of code you could use when you get your sync pulse. To try this you should run it in real time-  the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.

Code: [Select]
 
 long  drift = elapsedSecsToday(now());
 // if the elapsed time since previous midnight is a big number,
 // then its not quite reached midnight so the clock is slow
 // as small positive number means it running fast
 if(drift > 3600)  
   drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number
 // a positive number indicates that the clock has passed midnight so its fast
 Serial.print("the drift in seconds is ");
 Serial.println(drift);
 adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast  


BTW, where are your sync pulses coming from?

cne

I used your suggestion on the serial.
The program works great, except for the fact that when the midnight pulse is recieved, the program cyles through all the alarms quickly. Is there a way to prevent this?
Also, when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

Here is the serial monitor:
Code: [Select]


Power Up:
0:00:00
0:00:01
0:00:02
0:00:03
..........


MIDNIGHT PULSE RECIEVED
MEETING ONE CALLED
MEETING TWO CALLED
MEETING THREE CALLED
MEETING FOUR CALLED
MEETING FIVE CALLED
MEETING SIX CALLED
1:00:05
1:00:06
1:00:07
.........


cne

I am building a meeting alarm that will be tied in with an existing clock system. All the clocks are syncronised at midnight via 1 second DC pulse. Using this reference point I can make sure all the meetings are correctly timed compared to the clocks.

mem

#20
Apr 21, 2010, 06:19 am Last Edit: Apr 21, 2010, 06:22 am by mem Reason: 1
Quote
when the midnight pulse is recieved, the program cyles through all the alarms quickly.


Did you try the suggestions in my previous post.
also:
Quote
To try this you should run it in real time-  the drift calculation will not be realistic if you feed it sync pulses much more frequently than every 24 hours.


Quote
when the power is turned on, the time is set to 0:00:00 automaticly. Is there a way to prevent this?

You can set the time in setup before you set the alarms

mem

If only six of the nine alarms are triggering, read through the earlier posts in this thread that explained how to increase the number of alarms.

cne

I used your suggestion. It works to set the time to 0:00:00, but the alarms do not trigger after the midnight reset. I also changed the number of alarms.

Here is the serial report...
Code: [Select]
0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
MEETING CALL
MEETING ONE CALLED
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17
0:00:18
0:00:19
MEETING CALL
MEETING TWO CALLED
0:00:21
0:00:22
0:00:23
0:00:24
0:00:25
0:00:26
0:00:27
0:00:28
0:00:29
MEETING CALL
MEETING THREE CALLED
0:00:31
0:00:32
0:00:33
0:00:34
0:00:35
0:00:36
0:00:37
0:00:38
0:00:39
MEETING CALL
MEETING FOUR CALLED
0:00:41
0:00:42
0:00:43
0:00:44
0:00:45
0:00:46
0:00:47
0:00:48
0:00:49
MEETING CALL
MEETING FIVE CALLED
0:00:51
0:00:52
0:00:53
0:00:54
0:00:55
0:00:56
0:00:57
0:00:58
MEETING CALL
MEETING SIX CALLED
0:01:00
0:01:01
0:01:02
0:01:03
0:01:04
0:01:05
0:01:06
0:01:07
0:01:08
0:01:09
MEETING CALL
MEETING SEVEN CALLED
0:01:11
0:01:12
0:01:13
0:01:14
0:01:15
0:01:16
0:01:17
0:01:18
0:01:19
MEETING CALL
MEETING EIGHT CALLED
0:01:21
0:01:22
0:01:23
0:01:24
0:01:25
0:01:26
0:01:27
0:01:28
0:01:29
MEETING CALL
MEETING NINE CALLED
0:01:31
0:01:32
0:01:33
0:01:34
0:01:35
0:01:36
0:01:37
0:01:38
0:01:39
the drift in seconds is 100
MIDNIGHT PULSE RECIEVED
0:00:00
0:00:01
0:00:02
0:00:03
0:00:04
0:00:05
0:00:06
0:00:07
0:00:08
0:00:09
0:00:10 //Meeting One is suppoused to go off here
0:00:11
0:00:12
0:00:13
0:00:14
0:00:15
0:00:16
0:00:17

mem

Lets have a look, can you post the sketch

cne

Here it is...


Code: [Select]
#include "Time.h"
#include "TimeAlarms.h"

const int midnightPin= 2;
const int timerPin= 13;
const int buzzerPin= 4;



int midnightState=0;

void setup()
{
 pinMode(midnightPin, INPUT);
 pinMode(timerPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);
 
 Alarm.alarmRepeat(0,00,10,MeetingOne);
 Alarm.alarmRepeat(0,00,20,MeetingTwo);
 Alarm.alarmRepeat(0,00,30,MeetingThree);
 Alarm.alarmRepeat(0,00,40,MeetingFour);
 Alarm.alarmRepeat(0,00,50,MeetingFive);
 Alarm.alarmRepeat(0,00,59,MeetingSix);
 Alarm.alarmRepeat(0,01,10,MeetingSeven);
 Alarm.alarmRepeat(0,01,20,MeetingEight);
 Alarm.alarmRepeat(0,01,30,MeetingNine);
 
 Serial.begin(9600);    
 
}

void MeetingOne()
{
 MeetingCall();
 Serial.println("MEETING ONE CALLED");    
}

void MeetingTwo()
{
 MeetingCall();
 Serial.println("MEETING TWO CALLED");
}

void MeetingThree()
{
 MeetingCall();
 Serial.println("MEETING THREE CALLED");
}

void MeetingFour()
{
 MeetingCall();
 Serial.println("MEETING FOUR CALLED");  
}

void MeetingFive()
{
 MeetingCall();
 Serial.println("MEETING FIVE CALLED");
}

void MeetingSix()
{
 MeetingCall();
 Serial.println("MEETING SIX CALLED");  
}

void MeetingSeven()
{
 MeetingCall();
 Serial.println("MEETING SEVEN CALLED");
}


void MeetingEight()
{
 MeetingCall();
 Serial.println("MEETING EIGHT CALLED");
}

void MeetingNine()
{
 MeetingCall();
 Serial.println("MEETING NINE CALLED");
}

void MeetingCall()
{
 digitalWrite(timerPin, HIGH);
 digitalWrite(buzzerPin, HIGH);
 Alarm.delay(90);  
 digitalWrite(timerPin, LOW);
 Alarm.delay(910);
 digitalWrite(buzzerPin, LOW);
 Serial.println("MEETING CALL");
}

void  loop()
{
midnightState = digitalRead(midnightPin);  //reads the pulse
 if (midnightState == HIGH) {  
   long  drift = elapsedSecsToday(now());
 // if the elapsed time since previous midnight is a big number,
 // then its not quite reached midnight so the clock is slow
 // as small positive number means it running fast
 if(drift > 3600)  
   drift = drift - SECS_PER_DAY ;   // clock slow - this will be a negative number
 // a positive number indicates that the clock has passed midnight so its fast
 Serial.print("the drift in seconds is ");
 Serial.println(drift);
 adjustTime(-drift); // compensate by adding  seconds if slow, subtract if fast  

   Serial.println("MIDNIGHT PULSE RECIEVED");
   
 }
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
}

void digitalClockDisplay()
{
 // digital clock display of the time
 Serial.print(hour());
 printDigits(minute());
 printDigits(second());
 Serial.println();
}

void printDigits(int digits)
{
 // utility function for digital clock display: prints preceding colon and leading 0
 Serial.print(":");
 if(digits < 10)
   Serial.print('0');
 Serial.print(digits);
}

mem

#25
Apr 23, 2010, 05:52 pm Last Edit: Apr 23, 2010, 05:53 pm by mem Reason: 1
The code looks ok.

Try it with the alarms  set to a few minutes after midnight. Your drft is almost two minutes but the alarms are supposed to go off within a minute.

I wonder why you have so much drift. For a timekeeping application a board with a crystal would be more suitable because the drift would only be couple of seconds per day. What board are you using?

cne

I am using the Duemilanove.
Isn't the drift just how many seconds have passed since midnight?
0:00:00
.......
0:01:40 //Midnight Pulse

=100 seconds

mem

#27
Apr 24, 2010, 12:16 pm Last Edit: Apr 24, 2010, 12:36 pm by mem Reason: 1
Quote
Isn't the drift just how many seconds have passed since midnight?

Yes, but standard arduino board should not drift more than 2 or 3 seconds per day.

what board are you using?

cne

I am using the Duemilanove

Go Up