Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:22 14 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : GPS clock

     Page 3 of 5    
Author Message
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 01:52am 30 Jun 2013
Copy link to clipboard 
Print this post

Here's some photos...





Let me know if you want more.
Talbit

Talbit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 03:21am 30 Jun 2013
Copy link to clipboard 
Print this post

Your program has a couple of errors which fortunately MMBasic seems to ignore.

In the subroutine nmea_sentence you should use EXIT SUB to leave the subroutine and it should be terminated with an END SUB.

This is what it should look like:
SUB nmea_sentence
DO
DO WHILE INPUT$(1, #1) <> "$" : LOOP ' wait for the start
FOR i = 0 TO max
arg$(i) = "" ' clear ready for data
DO ' loops until a specific exit
x$ = INPUT$(1, #1) ' get the character
IF x$ = "," THEN EXIT ' new data item, increment i
IF x$ = "*" THEN EXIT SUB ' we have all the data so exit
arg$(i) = arg$(i) + x$ ' add to the data
LOOP ' keep going
NEXT i ' increment i
LOOP
END SUB


I only mention this because a future update may throw an error on your program.

Great project by the way, I love it when the MM is put to real work.

GeoffEdited by Geoffg 2013-07-01
Geoff Graham - http://geoffg.net
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:32am 30 Jun 2013
Copy link to clipboard 
Print this post

  Talbit said   cwilt,
I'm not sure but my guess is that you are extracting the time from the GPS and loading it into the RTC on the PPS, right? Well I recon your RTC will be a whole second behind UTC. Have a look at my GPS clocks and you'll see that I add one second to the time then load it into the display on the PPS. This doesn't depend on crystal accuracy but on the precision of the PPS which is meant to be within 1uSec. I'm fussy about accuracy and no matter how good your RTC crystal is, it will still drift. The only delays are in the actual MM execution times. If you reset you RTC say once a day AND sync it to the PPS then that would probably be okay but you can't have too much of a jump in your time accuracy. I've got a lot on my plate at the moment but am keen to get back to adding a RTC to my clock that is set by the GPS and synced to the PPS.
Talbit


You are wrong. Note the +1 on the gpssecond. You will need to sync RTC to GPS once every 3 hours to maintain millisecond accuracy.

It would be best to have a GPS that outputs a NEMA PPS but not many do that.
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 05:07pm 30 Jun 2013
Copy link to clipboard 
Print this post

Geoff,
Thanks for spotting the error. I put it in deliberately to see if anyone was reading my code.
Just kidding. Well spotted.
I'll fix it tonight and test it.
Trevor
Talbit
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 05:20pm 30 Jun 2013
Copy link to clipboard 
Print this post

cwilt,
I'm not the worlds best programmer but...
If you have a gps time of say 23:59:59 and add 1 second, how does it update the time to 00:00:00 before it sets the CMM clock or do you make sure you only update when there is no minute changeover?
Trevor
Talbit
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 08:15pm 30 Jun 2013
Copy link to clipboard 
Print this post

  Talbit said   cwilt,
I'm not the worlds best programmer but...
If you have a gps time of say 23:59:59 and add 1 second, how does it update the time to 00:00:00 before it sets the CMM clock or do you make sure you only update when there is no minute changeover?
Trevor


23:59:60 is a valid time to the CMM
 
vk4tec

Senior Member

Joined: 24/03/2012
Location: Australia
Posts: 239
Posted: 09:17pm 30 Jun 2013
Copy link to clipboard 
Print this post

I guess with the whole clock thing you have to consider.

1. LED update rate
2. Synch to 1 PPS
3. Time it takes to get NMEA time
4. Time it takes to read RTC
5. Time it takes to set RTC

I think what I was getting at was if the GPS is not able to contribute, fall back to RTC.

And always have the RTC in synch with the GPS.

I think that would need some extra thinking on the 1 PPS part.

Is 1 PPS still valid if a GPS cant see sats ? I guess not ?

- Andrew -
Andrew Rich VK4TEC
www.tech-software.net
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 10:01pm 30 Jun 2013
Copy link to clipboard 
Print this post

Geoff,
Your fix works okay. By why didn't my version with the error crash?

cwilt,
I haven't played with a CMM so I'll have to believe you! But it's odd to have a time like that. Is your routine bullet proof?
Checking the clock with the PPS every few hours is okay.

I must try the RTC with my Mono MM. I have some Futurlec I2C/RTC boards and too many mono MM. Can someone point me to where the summary of how to hook it up to the MM and the code is on this forum?

Regards
Trevor
Talbit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3272
Posted: 10:24pm 30 Jun 2013
Copy link to clipboard 
Print this post

  Talbit said   Geoff,
Your fix works okay. By why didn't my version with the error crash?

Essentially it worked because EXIT SUB does the same thing as RETURN (that may change in the future) and your subroutine never finished executing the FOR ... NEXT loop so it never found that the END SUB was missing.

Detecting all the weird errors that a user can make is amazingly hard. Basically there is only one correct syntax but thousands of incorrect ones - detecting them all and issuing an appropriate error message is a big job. Already a large part of MMBasic is involved in error checking but obviously it could be better.

Geoff
Geoff Graham - http://geoffg.net
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 12:49am 01 Jul 2013
Copy link to clipboard 
Print this post

Geoff,
That all makes sense. I'm the sort of "programmer" who says if it works then it must be okay. Then I wonder why in a years time it crashes!
Thanks for pointing out my error. I'm wondering now if it was the reason my program did an odd thing during development. But that's another story!

Trevor
Talbit
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 04:58am 01 Jul 2013
Copy link to clipboard 
Print this post

  vk4tec said   I guess with the whole clock thing you have to consider.

1. LED update rate
2. Synch to 1 PPS
3. Time it takes to get NMEA time
4. Time it takes to read RTC
5. Time it takes to set RTC

I think what I was getting at was if the GPS is not able to contribute, fall back to RTC.

And always have the RTC in synch with the GPS.

I think that would need some extra thinking on the 1 PPS part.

Is 1 PPS still valid if a GPS cant see sats ? I guess not ?

- Andrew -


Most GPS units have accurate time and 1PPS output once they have locked onto 3 sats. Less than 3 and you start to loose accuracy. Each GPS unit will have its own rate of decay once those sats are lost.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:07am 01 Jul 2013
Copy link to clipboard 
Print this post

  Talbit said  
cwilt,
I haven't played with a CMM so I'll have to believe you! But it's odd to have a time like that. Is your routine bullet proof?
Checking the clock with the PPS every few hours is okay.


Of course its not bullet proof. Not nearly enough code for that. It was meant as a working proof of concept.

 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:33am 01 Jul 2013
Copy link to clipboard 
Print this post

I think going beyond 1 second accuracy is incredible difficult for household stuff.
Maybe setting the clock is of by 0.1 second? Does it matter? Even when it is off a whole second. Who is going to tell you your clock is running slow.
You just say with 100% confidence that theirs is running fast.

For my daily use i prefer a clock without a second indicator.
For measurements of a few seconds length and nanosecond accuracy i use my scope.
The only time the smaller then one second accuracy is nice to have is when you have a countdown for new year.

Maybe a nice gadget, a down counter until the next new year. I think i will have a go at that.

I think GPS is a good way to set an RTC accurate, internet time server can also be used forthe same purpose and have tens of millisecond accuracy. Windows was never very accurate (5 seconds off is normal) because frankly it was not needed. I think it was influenced by the Kerberos authentication neading a timestamp within a 5 minute accuracy.
The NTP is a very known and solid protocol and when used correctly it allows for high accuracy.

Also a microcontroller has a very solid time base itself. For bridging time between update intervals it can hold time as good as an RTC. The main selling point of a RTC is that it is battery backed up. In case of using GPS or NTP the whole RTC chip is not really necessary.
The microcontroller has a system clock, it runs on 20Mhz or more. You have 20.000.000 pulses per second, setting a timer for a tick per second will be very accurate.
The PPS from a GPS module does the same thing, it uses its internal clock to generate the PPS and synchronizes it with a GPS signal. Want an accurate PPS use SETTICK 1000.

I have a few thousand GPS modules (of all different kinds) driving in cars sending information to one of my websites every minute and can tell by experience that the GPS time is sometimes of by a year, or ten year, or a day. When it can not get a good lock on the satellites it can go haywire and stay wrong for a long period until it is reset. If you run a clock check the number of satellites and the strength of that signal. Check also for out of range data. When the GPS is stationary it is much less of a problem.

You can use the $GPZDA message for time data. It is a simpler container without all the other unnecessary data.
In principle only one satellite is enough for that, but it depends on the firmware of the module.

All the examples shown, very nice results , makes me want to make one too. Not really to use as i already have a few clocks, it is the making that is the fun part.

Microblocks. Build with logic.
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 07:36am 01 Jul 2013
Copy link to clipboard 
Print this post

  vk4tec said  
Is 1 PPS still valid if a GPS cant see sats ? I guess not ?

- Andrew -

I couldn't find an answer to that. Not to say an answer doesn't exist though and I would assume that 1PPS would not be output if the time was not valid.

What I did find was that some of the NMEA sentences have data valid indicators. There may be some wisdom in using those indicators if using one of those sentences. However, I would think that if the data (time, position fix etc.) was not valid then there would not be any output. Does anyone here know the answer? Those sentences with validity indicators are ($GP prefixed) GGA, GLL, GSA, and RMC.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:50am 01 Jul 2013
Copy link to clipboard 
Print this post

You can look at a $GPGSV message and use the field SNR (Signal-To-Noise) ratio. 30Db is the minimum for a good signal.
The message $GPGSA has a field Fix that tells you if you have a fix at all, a 2d or 3d fix. 2d is enough for a time.
It also has the number of satellites used and the dilution of precision.
Satellites preferably higher then 4, xDOP as low as possible, smaller is better where 1.0 is excellent and 2.0 to 3 is ok.
$GPGGA has also a fix quality field. It is 0 when the data in the message is invalid.



Microblocks. Build with logic.
 
Dylan
Regular Member

Joined: 17/06/2013
Location: Netherlands
Posts: 81
Posted: 07:52am 01 Jul 2013
Copy link to clipboard 
Print this post

  TZAdvantage said   I think going beyond 1 second accuracy is incredible difficult for household stuff.


I'm still learning, and you seem to know your stuff.

In a household, where AC (110-120V or 220-240V) is available, it should be possible to make a power supply which provides ground, a regulated 5V DC, and a low analogue AC cut off by a diode at roughly 50/60Hz. Or even double the frequency to 100/120Hz.

Add a cheap, simple microcontroller (TX/RX lines only) which allows devices to communicate (similar to https://en.wikipedia.org/wiki/Power_line_communication#Low-s peed_narrow-band).

In situations where you want the devices to be CHEAP but able to keep in synch to within 0.01 second of each other, but potentially more complex than just switching lights on and off or other such automation.

Perhaps provide USB charging also.

But back to GPS. Of course if the time being reported is ridiculous, ignore it. For a stationary clock using a GPS module, but not on the mains for whatever reason, turning GPS on only every so often (hour? day?) might make sense. But by the very nature of GPS, the time it reports should be extremely accurate, what with using (half a) dozen atomic clocks in orbit and adjusting for relativistic effects to get an accuracy of (less than?) 5 metres. Specifically, https://www.google.com/search?q=(5+meters)+%2F+the+speed+of+ light. Sending the info over asynch is going to take an order or two of magnitude longer, but removes the wire problem.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:47am 01 Jul 2013
Copy link to clipboard 
Print this post

Dylan,

Good that you mention the AC power and frequency.
In The Netherlands in the old days a lot of cities used the 50Hz to synchronize the public clocks.
By varying the frequency slightly the clocks could be adjusted to stay within a second accuracy.

With GPS is a date 2014, februari 28, 23:00:00 a valid time?
It is on that day, it is not now. It is not that easy to determine if the GPS date you get is actually good. You probably just trust it. What you need to do is store a sequence somewhere to be able to detect errors like that. Otherwise your clock will happily show a completely wrong time. Not happens frequently and maybe with your own clock never.

With my gps's in the field i get these wrong messages many times per day. The server that receives those messages has its own time base and compares against that. If the GPS is to far off (delays sending over GPRS can happen and need to be compensated for) it sends a GPS reset code to the microcontroller that controls the GPS.
This also happens with positions. Server also maintains a few positions to detect 'jumps'.
Jumps can happen when vehicles are driving in 'urban canyons', under power lines, very bad weather or just simply parked close to a wall where reflections can screw up the measurements. The GPS will tell it is a good fix, while it is not.

If you want a really really good clock, make sure you have an RTC with approximately the right time, or use an alternative source like NTP to check the GPS time.

Microblocks. Build with logic.
 
Talbit
Senior Member

Joined: 07/06/2011
Location: Australia
Posts: 210
Posted: 04:17pm 01 Jul 2013
Copy link to clipboard 
Print this post

In the scientific world you need REAL accuracy in you clocks.
Positioning, Navigation, Astronomy, measurement of scientific phenomenon.
Trevor
Talbit
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:19pm 01 Jul 2013
Copy link to clipboard 
Print this post

Talbit,

Here in the US, actually not far from my home we have a ULF broadcast system for NIST synced with atomic clocks on site and other local atomic clocks. Do they have anything like that in Australia?

I ask because we have a clock purchased from a retail store that syncs to that broadcast time signal.
 
cwilt
Senior Member

Joined: 20/03/2012
Location: United States
Posts: 147
Posted: 05:30pm 01 Jul 2013
Copy link to clipboard 
Print this post

TZ,

I am surprised that you would say micro controllers have a solid time base.
 
     Page 3 of 5    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025