![]() |
Forum Index : Microcontroller and PC projects : GPS clock
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
ajkw Senior Member ![]() Joined: 29/06/2011 Location: AustraliaPosts: 290 |
Andrew, I have a DS1302 on my Maximite and it has been very reliable. It is not SPI or I2C, you just have to bit bang it with 3 I/O lines. Refer, http://www.thebackshed.com/forum/forum_posts.asp?TID=3775&KW =RTC I now have much more refined software to read and write to it than what is linked in the thread/topic but what is there would get you going. Anthony. |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
Thanks Anthony I will tackle that tomorrow - Andrew - Andrew Rich VK4TEC www.tech-software.net |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Andrew, I have a few of these lying around, but not connected yet. MCP79400-I/SN (You get a list of Microchip datasheets, click on the one about this chip. I am still organizing my website, so i can not link straight to the document yet.) It has a little RAM a unique ID and an automatic battery failover. The commands look easy enough and is accessible with I2C. They should be around 2-3US$. Microblocks. Build with logic. |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
Would I be right in saying most protocols can be bit banged ? I have seen it done in assembly Have to look how to do it in MMbasic Andrew Andrew Rich VK4TEC www.tech-software.net |
||||
cwilt Senior Member ![]() Joined: 20/03/2012 Location: United StatesPosts: 147 |
I will try to post some code by the end of the weekend. |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
There are a lot of GPS modules out there and they are not all the same. I am looking for a unit and, so far, I have looked at the EM-406A, EM-408 and the EM-411, all made by GlobalSat. Of these, only one has a 1PPS output. Two are 5 volts and one is 3.3 volts. One has an external antenna socket in addition to the on-board antenna. All three support the NMEA 0183 data protocol. Andrew, what unit are you using? Does it have a 1PPS output? |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
It's Alive ![]() My GPS module is a SIRF It does not have PPS It has RS232 / TTL I have Garmin GPS18 that does have PPS + SIRF GPS TTL + MaxiMite Mini + 5 volts PSU + 3 volts PSU + SDP8 LED 7 seg x 8 ( SPI ) - needs power on 10 header 9,5 and GND on 7 and 10 + Pins 20 / 19 GPS TX / RX TTL + Pins 18, 17, 15 SPI (L) low speed - Andrew - Andrew Rich VK4TEC www.tech-software.net |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Why would a RTC chip with a 32.768 Khz crystal not be accurate? Without a GPS signal the PPS is generated just like in a RTC chip. In my experience a RTC deviates a few seconds in about a month. Meaning you would only need to synchronize a RTC just once every week to stay within a second accuracy. Microblocks. Build with logic. |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
It's all good Needed an excuse to do some more building One second a month is fine Now to tidy it up and put it into a box Andrew Andrew Rich VK4TEC www.tech-software.net |
||||
Dylan Regular Member ![]() Joined: 17/06/2013 Location: NetherlandsPosts: 81 |
Perhaps because (apparently/allegedly) the resonant frequency is actually 32.765, and the capacitors over the RTC crystal need to be expertly balanced to up it by 3Hz. |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
The Maxim DS3231 has its crystal on-board in the chip. This allows the chip to read the temperature of the crystal and dynamically adjust the frequency to achieve better accuracy. The chip also has a user adjustable "aging register" and the user can read the temperature of the chip. Not sure if all this gets better accuracy than other RTCs but at least you don't need to buy a crystal and capacitors. edit It also comes as a product called Chronodot, a pluggable module with a battery and it's I2C although I think others in the family use SPI. |
||||
cwilt Senior Member ![]() Joined: 20/03/2012 Location: United StatesPosts: 147 |
I use chronodots which are temperature compensated DS3231 and even it is off by 5 seconds a month. |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
Rem FUTURELEC GPS 7 segment x 8 LED max = 20 ' maximum nbr of params Dim arg$(max) ' used to hold the data fields SetPin 16,2 ' RX SetPin 17,8 ' TX SetPin 18,8 ' CLK SetPin 15,8 ' Enable Pin(15) =0 Pause 10 a = SPI(16,17,18,&H0A,L) a = SPI(16,17,18,&H02,L) Pin(15)=1 Pause 10 Pin(15) =0 Pause 10 a = SPI(16,17,18,&H0B,L) a = SPI(16,17,18,&H07,L) Pin(15)=1 Pause 10 Pin(15) =0 Pause 10 a = SPI(16,17,18,&H09,L) a = SPI(16,17,18,&Hff,L) Pin(15)=1 Pause 10 Pin(15) =0 Pause 10 a = SPI(16,17,18,&H0C,L) a = SPI(16,17,18,&H01,L) Pin(15)=1 Pause 10 Open "COM2:19200" As #1 Do nmea_sentence If arg$(0) = "GPRMC" Then Print arg$(1) tme$ = arg$(1) utchr$ = Mid$(arg$(1),1,2) utchr = Val(utchr$) If utchr > 13 Then lclhr = utchr - 14 EndIf If utchr < 14 Then lclhr = utchr + 10 EndIf utcmn$ = Mid$(arg$(1),3,2) utcmn = Val(utcmn$) lclhr$ = Format$(lclhr,"%02g") lclmn$ = Format$(utcmn,"%02g") digit1$ = Mid$(arg$(1),6,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H01,L) a = SPI(16,17,18,Val(digit1$),L) Pin(15)=1 Pause 10 digit2$ = Mid$(arg$(1),5,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H02,L) a = SPI(16,17,18,Val(digit2$),L) Pin(15)=1 Pause 10 Pin(15) =0 Pause 10 a = SPI(16,17,18,&H03,L) a = SPI(16,17,18,10,L) Pin(15)=1 Pause 10 digit3$ = Mid$(arg$(1),4,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H04,L) a = SPI(16,17,18,Val(digit3$),L) Pin(15)=1 Pause 10 digit4$ = Mid$(arg$(1),3,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H05,L) a = SPI(16,17,18,Val(digit4$),L) Pin(15)=1 Pause 10 Pin(15) =0 Pause 10 a = SPI(16,17,18,&H06,L) a = SPI(16,17,18,10,L) Pin(15)=1 Pause 10 digit5$ = Mid$(lclhr$,2,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H07,L) a = SPI(16,17,18,Val(digit5$),L) Pin(15)=1 Pause 10 digit6$ = Mid$(lclhr$,1,1) Pin(15) =0 Pause 10 a = SPI(16,17,18,&H08,L) a = SPI(16,17,18,Val(digit6$),L) Pin(15)=1 Pause 10 EndIf Loop Rem -- SUBS -- Sub nmea_sentence Do msg$ ="$" ' subroutine start 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) msg$ = msg$ + x$ ' get the character If x$ = "," Then Exit ' new data field, increment i If x$ = "*" Then Return ' we have all the data so return arg$(i) = arg$(i) + x$ 'Print arg$(i) ' add to the data Loop 'Print arg$(i) ' loop back for the next char Next i ' move to the next data field ' Print "Corrupt data..." ' exceeded max data items 'Print msg$ Loop End Sub Andrew Rich VK4TEC www.tech-software.net |
||||
cwilt Senior Member ![]() Joined: 20/03/2012 Location: United StatesPosts: 147 |
GPS serial connected to COM2. 1PPS to pin 3. This is a simple one shot event to set CMM time. I have a chronodot attached to my CMM so it updates it too. I wish there was a command to force CMM time update from RTC not just during boot. Open "COM2:9600" As #1 tz=-6 'timezone cls pause 200 Do:Loop Until Loc(1)>0 Do Line Input #1, temp$ loop until left$(temp$,6)="$GPRMC" Close #1 gpshour=Val(Mid$(temp$,8,2))+tz If gpshour<0 Then gpshour=24+gpshour gpsminute=Val(Mid$(temp$,10,2)) gpssecond=Val(Mid$(temp$,12,2))+1 gpstime$=Str$(gpshour)+":"+Str$(gpsminute)+":"+Str$(gpssecon d) setpin 3,6,settime Do:Loop Sub settime Time$=gpstime$ SetPin 3,0 Print "Done" Exit End Sub |
||||
Talbit Senior Member ![]() Joined: 07/06/2011 Location: AustraliaPosts: 210 |
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 Talbit |
||||
Talbit Senior Member ![]() Joined: 07/06/2011 Location: AustraliaPosts: 210 |
If anyone is interested, I'll send some happy snaps of my latest clock using the Futurlec LED display. It's mounted in a Jaycar 1U 19" box. I think the software is unchanged from my latest post in my "MM - GPS clock update" posts but I'll add it to this post if someone asks. Talbit Talbit |
||||
vk4tec![]() Senior Member ![]() Joined: 24/03/2012 Location: AustraliaPosts: 239 |
Photos yes please I was going to go for a 1 ru as well But I thought it might be overkill Andrew Andrew Rich VK4TEC www.tech-software.net |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Photos and software please. |
||||
Talbit Senior Member ![]() Joined: 07/06/2011 Location: AustraliaPosts: 210 |
Okay, give me a couple of days. I updated the interface PCB the other week so it's a bit neater. I'm using a mono MM but there is no reason you can't use a mini MM. One thing I did do was remove the 5 volt regulator from the MM board and feed the MM from a small 12 to 5V switcher I made. Again, anything similar will do the job. Talbit Talbit |
||||
Talbit Senior Member ![]() Joined: 07/06/2011 Location: AustraliaPosts: 210 |
Here you go... ' Garmin GPS/FUTURLEC 7 segment x 8 LED
' Trevor Dalziell 15 June 2013 'SPI setup 'Pin 12 = Rx 'Pin 13 = Enable (Active low) 'Pin 14 = Tx 'Pin 15 = Clk (active Low) max = 20 ' maximum nbr of params Dim arg$(max) ' used to hold the data fields Pin_set ' Set the I/O pins Start: PB=1 Set_Board ' Set up the LED Display board Do while pin(17)=0 : Loop ' Wait for PPS to go high, Pause 2000 ' Then wait for 2 seconds until things settle. '''''''''''''''''''' Main '''''''''''''''''''''''''''''''''''''' Do Open "COM2:19200" As #1 ' Read the data from the GPS nmea_sentence ' Get the NMEA string Close #1 ' Close and clear the port ' This is necessary to fix the system if the ' PPS or GPS in general is disconnected If arg$(0) = "GPRMC" then ' We have the correct NMEA string If arg$(2) = "A" then Extract_info ' A means locked, data is good Endif Endif Print GPST$; Add_Second tme$ = hh$+mm$+ss$ dte$ = dd$+mo$+yy$ Do while pin(17)=0 : Loop ' Wait for PPS to go high, set the Time Break high print " "+hh$+":"+mm$+":"+ss$ If DAY=1 THEN PULSE 2,6000: Goto Getout If HOUR=1 THEN PULSE 2,4000: Goto Getout If MINUTE=1 THEN PULSE 2,2000 Getout: Endif ' Now send the information to the LED display If PB=1 then Display_tme If PB=0 then Display_dte EndIf Loop Start ' -- SUBS -- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' 'Set the I/O pins Sub Pin_Set SETPIN 17,2 'Make Pin 17 digital Input (PPS) SETPIN 2,8 'Make Pin 2 a digital output (Time Break) SETPIN 1,7,Button 'Interrupt routine to toggle PB after button is pressed End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' ' Get the NMEA String from the GPS 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 RETURN ' we have all the data so return arg$(i) = arg$(i) + x$ ' add to the data LOOP ' keep going NEXT i ' increment i LOOP ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' 'Extracting Time & Date Sub Extract_info GPST$=LEFT$(arg$(1),6) ' Get the Time GPSD$=LEFT$(arg$(9),6) ' Get the Date End Sub ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' 'Update time by 1 second Sub Add_Second hh$ = MID$(GPST$, 1, 2) 'Get the hours mm$ = MID$(GPST$, 3, 2) 'Get the minutes ss$ = MID$(GPST$, 5, 2) 'Get the seconds dd$ = MID$(GPSD$, 1, 2) 'Get the days mo$ = MID$(GPSD$, 3, 2) 'Get the months yy$ = MID$(GPSD$, 5, 2) 'Get the years ss = VAL(ss$) 'Change Time to an integer mm = VAL(mm$) hh = VAL(hh$) dd = VAL(dd$) 'Change Date to an integer mo = VAL(mo$) yy = VAL(yy$) ' Minute=0:Hour=0:Day=0 ss=ss+1 'Add 1 second IF ss<60 THEN GOTO Change_Back else ss=00 mm=mm+1 'Increment the minute Minute=1 IF mm<60 THEN GOTO Change_Back else mm=00 hh=hh+1 'Increment the hour Hour=1 IF hh<24 THEN GOTO Change_Back else hh=00 Day=1 Change_Back: ss$=STR$(ss) 'Change them all back to Strings... mm$=STR$(mm) hh$=STR$(hh) IF LEN(ss$) = 1 THEN ss$ = "0" +ss$ 'Add leading zeros IF LEN(mm$) = 1 THEN mm$ = "0" +mm$ IF LEN(hh$) = 1 THEN hh$ = "0" +hh$ IF LEN(dd$) = 1 THEN dd$ = "0" +dd$ IF LEN(mo$) = 1 THEN mo$ = "0" +mo$ IF LEN(yy$) = 1 THEN yy$ = "0" +yy$ End SUB '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' 'Interrupt routine to toggle PB after button is pressed Button: PAUSE 2 'Wait for switch to debounce PB=NOT(PB) IRETURN '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Sub Set_Board Pin(13) =1 Pin(15) =1 SetPin 12,2 'Input - Ingored SetPin 13,8 'Digital output - Enable SetPin 14,8 'Digital output - Data SetPin 15,8 'Digital output - Clk Pin(13) =0 a = SPI(12,14,15,&H0A,H) a = SPI(12,14,15,&H05,H) 'Intensity = 5 Pin(13)=1 Pin(13) =0 a = SPI(12,14,15,&H0B,H) a = SPI(12,14,15,&H07,H) 'Scan limit - All digits Pin(13)=1 Pin(13) =0 a = SPI(12,14,15,&H09,H) a = SPI(12,14,15,&HFF,H) 'Code B decode for all digits Pin(13)=1 Pin(13) =0 a = SPI(12,14,15,&H0C,H) a = SPI(12,14,15,&H01,H) 'Shutdown, Normal Pin(13)=1 Pin(13) =0 a = SPI(12,14,15,&H0F,H) a = SPI(12,14,15,&H01,H) 'Display test, All segments on Pin(13)=1 Pause 1000 'for 1 second Pin(13) =0 a = SPI(12,14,15,&H0F,H) a = SPI(12,14,15,&H00,H) 'Normal operation Pin(13)=1 'Write Dashes to the display Pin(13) =0 a = SPI(12,14,15,&H01,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H02,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H03,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H04,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H05,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H06,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H07,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 Pin(13) =0 a = SPI(12,14,15,&H08,H) a = SPI(12,14,15,&H0A,H) 'Dash Pin(13) =1 End Sub '''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub Display_TME digit1$ = Mid$(tme$,6,1) Pin(13) =0 a = SPI(12,14,15,&H01,H) a = SPI(12,14,15,Val(digit1$),H) 'Seconds Pin(13) =1 digit2$ = Mid$(tme$,5,1) Pin(13) =0 a = SPI(12,14,15,&H02,H) a = SPI(12,14,15,Val(digit2$),H) '10s Seconds Pin(13) =1 ' Digit 3 Pin(13) =0 a = SPI(12,14,15,&H03,H) a = SPI(12,14,15,&H0F,H) 'Blank Pin(13) =1 digit4$ = Mid$(tme$,4,1) Pin(13) =0 a = SPI(12,14,15,&H04,H) a = SPI(12,14,15,Val(digit4$),H) 'Mins Pin(13) =1 digit5$ = Mid$(tme$,3,1) Pin(13) =0 a = SPI(12,14,15,&H05,H) a = SPI(12,14,15,Val(digit5$),H) '10s Mins Pin(13) =1 ' Digit 6 Pin(13) =0 a = SPI(12,14,15,&H06,H) a = SPI(12,14,15,&H0F,H) 'Blank Pin(13) =1 digit7$ = Mid$(tme$,2,1) Pin(13) =0 a = SPI(12,14,15,&H07,H) a = SPI(12,14,15,Val(digit7$),H) 'Hours Pin(13) =1 digit8$ = Mid$(tme$,1,1) Pin(13) =0 a = SPI(12,14,15,&H08,H) a = SPI(12,14,15,Val(digit8$),H) '10s Hours Pin(13) =1 End Sub '''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' '''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' Sub Display_DTE digit1$ = Mid$(dte$,6,1) Pin(13) =0 a = SPI(12,14,15,&H01,H) a = SPI(12,14,15,Val(digit1$),H) 'Year Pin(13) =1 digit2$ = Mid$(dte$,5,1) Pin(13) =0 a = SPI(12,14,15,&H02,H) a = SPI(12,14,15,Val(digit2$),H) '10s Year Pin(13) =1 ' Digit 3 Pin(13) =0 a = SPI(12,14,15,&H03,H) a = SPI(12,14,15,&H0F,H) 'Blank Pin(13) =1 digit4$ = Mid$(dte$,4,1) Pin(13) =0 a = SPI(12,14,15,&H04,H) a = SPI(12,14,15,Val(digit4$),H) 'Month Pin(13) =1 digit5$ = Mid$(dte$,3,1) Pin(13) =0 a = SPI(12,14,15,&H05,H) a = SPI(12,14,15,Val(digit5$),H) '10s Month Pin(13) =1 ' Digit 6 Pin(13) =0 a = SPI(12,14,15,&H06,H) a = SPI(12,14,15,&H0F,H) 'Blank Pin(13) =1 digit7$ = Mid$(dte$,2,1) Pin(13) =0 a = SPI(12,14,15,&H07,H) a = SPI(12,14,15,Val(digit7$),H) 'Day Pin(13) =1 digit8$ = Mid$(dte$,1,1) Pin(13) =0 a = SPI(12,14,15,&H08,H) a = SPI(12,14,15,Val(digit8$),H) '10s Day Pin(13) =1 End Sub '''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' '''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' and the circuit... 2013-06-30_113541_SPI_LED_2_June_2013.pdf Please be aware that this is a slightly different version to my earlier version posted under MM GPS clock update. Happy snaps to follow Talbit Talbit |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |