Pages: [1]   Go Down
Author Topic: How to tell when 5 mins have gone by with Real Time Clock Module  (Read 727 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So my after school group at my high school is competing in an autonomous sail boat competition and one of the challenges is to have your boat stay in this given area for 5 mins then drive out of the box. Our sail boat will have an arduino uno accompanied with a gps/compass and wind sensor. I know the arduino can't tell time alone so I found the Real Time Clock Module from sparkfun. https://www.sparkfun.com/products/99 I want to know if its possible to create a program that can tell when 5 minutes has gone by?

Any help much appreciated I have experimented with arduino's a good amount just never with a timing circuit.
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, for this purpose it is capable...

Just use millis(). This will count the number of milliseconds since the last reset. Capture the current count at the point your boat enters the box and then keep checking it until it reaches 300000 + captured millis() or, you could count millis() and increment another counter every 1000 for 1 second, then another counter for 60 seconds for 1 minute. etc... some interrupts and while() loops may interfere with millis() so if your boat is expected to simply sit there and do nothing, turn off interrupts when you begin counting.

Code:

void loop(){

...

   If(inside box){
     count();
   }

}

void count(){
startmillis = millis();
stopmillis = startmillis + 300000;

while(millis() < stopmillis){
}

return;

« Last Edit: April 03, 2013, 07:53:31 pm by Retroplayer » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 108
Posts: 5145
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
some interrupts and while() loops may interfere with millis() so if your boat is expected to simply sit there and do nothing, turn off interrupts when you begin counting.

That's a bad idea because the millis() functionality is driven by a timer interrupt. If you turn off interrupts millis() will never increase.
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You probably don't need the RTC at all; you can use millis to time five minutes for you as already mentioned or you can get the time from the GPS. I imagine you'll be parsing the  NMEA $GPGGA sentence to get position information - it has the time in it too.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How would I be able to tell when 5 mins have gone by with the gps? I have been able to get readings from it
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Same method... you record the time at the beginning of the event, add 5 minutes to it, and then test for the current time to match the projected time within a loop.
Logged

BHZ, MG, Brazil
Offline Offline
Sr. Member
****
Karma: 10
Posts: 346
Android developer; Arduino enthusiast
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the GPS have to do with the time keeping? The Arduino will keep time and when 5 mins have elapsed it will do something with the GPS.

If you insist on using the RTC (since you already bought it), some of them have programmable interrupts. For example, the DS1337+ can be programmed to generate a HIGH signal in a digital pin (your interrupt int) in 300 seconds. Therefore you don't have to worry about timekeeping in your code. You choose a pin that will receive the interrupt signal from the RTC, define how the interrupt should work (enable HIGH or LOW) and what function is to be called when the event happens.

If you got the DS1307 breakout board from Sparkfun, I don't think it has an Interrupt signal (that is why I prefer the DS1337+ over the DS1307 anytime).
Logged

Learn to live: Live to learn.
Showing off my work: http://arduino.cc/forum/index.php/topic,126197.0.html

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't bought the RTC because I wanted to make sure that is what I needed, now I am not going to get it and just use millis Thanks for the help everyone much appreciated
Logged

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

BTW, there is an example in the playground on this site for getting the time from your GPS module. Unfortunately, I can't link to it because I can't get the playground section to open. It is located in the time section of the playground.
Logged

Pages: [1]   Go Up
Jump to: