Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:12 02 Aug 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 : CMM2 RTC & TIME$

     Page 2 of 2    
Author Message
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 11:49pm 16 Jun 2020
Copy link to clipboard 
Print this post

  TassyJim said  I think the manual is wrong but I will like to see what Brian ends up with before annoying Geoff.
Jim


Hi

Do we want to get the manual changed for this?

Brian
ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 04:44am 17 Jun 2020
Copy link to clipboard 
Print this post

  Chopperp said  
Do we want to get the manual changed for this?

Brian

It's been done.

Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:00am 17 Jun 2020
Copy link to clipboard 
Print this post

If you have a GPS module with a 1 second Pulse, this program will set the CALIBRATE value for you.
It reads the time every minute and every 15 minutes adjusts the RTC CALIBRATE value.

 ' clock drift test and RTC CALIBRATE setting
 ' TassyJim June 2020
 '
 DIM INTEGER calValue = 0        ' initial calibrate vale
 DIM GPSint = 38                 ' connect to GPS 1pps pulse
 DIM interval = 60               ' time between calculations in seconds
 DIM adjustTime = 15             ' number of intervals to use for setting RTC CALIBRATE
 DIM perDay = 60*60*24/interval  ' calculations per day
 DIM FLOAT cal = 0.0824          ' secs per day for each unit of RTC CALIBRATE
 DIM INTEGER tick, tock, longCount
 DIM GPStime$
 DIM FLOAT caseTemp
 DIM FLOAT RTCtime, lastRTCTime, OSCtime, lastOSCtime, RTCinterval, OSCinterval, OSCerror
 DIM FLOAT firstRTC, firstOSC, longRTC, longOSC
 DIM FLOAT RTCperDay
 DIM INTEGER longTime = LEN(TIME$) ' check to see if MILLISECONDS ON is set"
 OPTION milliseconds ON
 CLS
 INPUT "Starting RTC CALIBRATE value"; calValue
 OPTION RTC CALIBRATE calValue
 PRINT ""
 
 PRINT "OPTION RTC CALIBRATE is set to ";calValue
 PRINT "                _______RTC_______    ___8MHz Osc___    Room "
 PRINT "    Time        drift   S/Day   n    Main OSC   ppm    Temp "
 
 SETPIN GPSint, INTH, GPStick, PULLDOWN
 tick = -1
 DO
   IF tock THEN
     doTock
     tock = 0
   ENDIF
 LOOP UNTIL INKEY$ <> ""     ' any key to exit
   PAUSE 10
 IF longTime = 8 THEN        ' restore normal TIME$ setting
 OPTION milliseconds OFF
 PRINT "Time reset to short mode"
 ENDIF
 PRINT TIME$
 PRINT "OPTION RTC CALIBRATE is set to ";calValue

 END
 
SUB GPStick
 tick = tick + 1
 IF (tick MOD interval) = 0 THEN
   tock = 1
   GPStime$ = TIME$
   OSCtime = TIMER
 ENDIF
END SUB
 
SUB doTock
 caseTemp = TEMPR(42)
 IF caseTemp > 100 THEN caseTemp = 0
 RTCTime = VAL(FIELD$(GPStime$,3,":")) ' only interested in the seconds field
 IF tick = 0 THEN
   firstRTC = RTCtime
   firstOSC = OSCtime
   longCount = 0
   longRTC = 0
   longOSC = 0
   RTCinterval = 0
   OSCinterval = 0
   OSCerror = 0
 ELSE
   RTCinterval = RTCtime - lastRTCtime
   OSCinterval = OSCtime - lastOSCtime
   OSCerror = OSCinterval - interval*1000
   longCount = longCount + 1
   longRTC = (RTCtime - firstRTC)/longCount ' average since program start
   longOSC = ((OSCtime - firstOSC)/longCount - interval*1000)*1000/interval ' ppm
 ENDIF
 RTCperDay = longRTC*perDay
 lastRTCtime = RTCtime
 lastOSCtime = OSCtime
 
 PRINT GPStime$;"  ";STR$(RTCinterval,3,3);"  ";STR$(RTCperDay,3,2);" ";
 PRINT STR$(-RTCperDay/cal,4,0);"  ";STR$(OSCerror,3,3);"  ";
 PRINT STR$(longOSC,3,3);"  ";caseTemp
 
 IF (tick MOD (interval*adjustTime)) = 0 AND tick > 0 THEN ' reset the counter for adjusting
   calValue = calValue -RTCperDay/cal
   OPTION RTC CALIBRATE calValue
   PRINT "New RTC CALIBRATE : ";calValue
   tick = -1 ' force reset next tick
 ENDIF
 
END SUB
 


Starting RTC CALIBRATE value?

OPTION RTC CALIBRATE is set to  0
               _______RTC_______    ___8MHz Osc___    Case
   Time        drift   S/Day   n    Main OSC   ppm    Temp
17:28:38.374    0.000    0.00    0    0.000    0.000   23.75
17:29:38.367   -0.007  -10.08  122    1.310   21.833   23.5
17:30:38.359   -0.008  -10.80  131    1.322   21.933   23.5
17:31:38.352   -0.007  -10.56  128    1.317   21.939   23.5
17:32:38.345   -0.007  -10.44  127    1.316   21.937   23.5
17:33:38.338   -0.007  -10.37  126    1.318   21.943   23.5
17:34:38.331   -0.007  -10.32  125    1.318   21.947   23.5
17:35:38.324   -0.007  -10.29  125    1.321   21.957   23.5
17:36:38.316   -0.008  -10.44  127    1.318   21.958   23.5
17:37:38.309   -0.007  -10.40  126    1.313   21.950   23.5
17:38:38.302   -0.007  -10.37  126    1.319   21.953   23.5
17:39:38.295   -0.007  -10.34  126    1.323   21.962   23.5
17:40:38.288   -0.007  -10.32  125    1.315   21.958   23.5
17:41:38.281   -0.007  -10.30  125    1.320   21.962   23.5
17:42:38.274   -0.007  -10.29  125    1.318   21.962   23.5
17:43:38.266   -0.008  -10.37  126    1.323   21.968   23.5
New RTC CALIBRATE :  126
17:43:39.266    0.000    0.00    0    0.000    0.000   23.5
17:44:39.266    0.000    0.00    0    1.324   22.067   23.5
17:45:39.266    0.000    0.00    0    1.321   22.042   23.25
17:46:39.266    0.000    0.00    0    1.320   22.028   23.25
17:47:39.266    0.000    0.00    0    1.325   22.042   23.25
17:48:39.266    0.000    0.00    0    1.319   22.030   23.25
17:49:39.266    0.000    0.00    0    1.322   22.031   23.25


columns are
Time
drift in seconds per timing period (60 seconds)
Average drift in seconds per day
Recommended setting for RTC CALIBRATE based on average drift

Main Oscillator error per timing period
Average main osc error in ppm
Case or room temperature (if fitted)

Only need the pps pulse line from the GPS connected.

Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 11:58am 17 Jun 2020
Copy link to clipboard 
Print this post

Gee thanks Jim.

I will need to modify my GPS module to get a 1 sec pulse out.

It has a 1 sec flashing LED on board so it shouldn't be too hard to do.

For interest, I just had a play with modifying
  "open "com4:9600" as GPS,10"
   on an F4 hoping to have an INT routine triggered I.E
  "open "com4:9600, 2, Test_GPS, 2" as gps,10 "
but the INT routine was ignored.

BTW, is there, or do you have an MMEdit version/update for the CMM2?

Brian
ChopperP
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 03:50pm 17 Jun 2020
Copy link to clipboard 
Print this post

  Quote  In my days, even with precision xtal clocked Micros, you still had to code critical u-sec timing tasks in assembler,


The CMM2 firmware sets up a 32-bit timer to increment 240,000,000 times per second. This happens in the background irrespective of any CPU activity.  The main timing uSec routine is then

#define SetupTime 22
#define ticks_per_microsecond 240
void uSec(unsigned int us) {
 us=us*ticks_per_microsecond-SetupTime;
 WriteCoreTimer(0);
 while (ReadCoreTimer()<us);
}


SetupTime is a fudge factor which I tuned as part of the development that counteracts the number of cycles needed to enter, setup the timer and leave the subroutine.

I also use another timer which is setup to clock at 20MHz for things like WS2812 timings. The STM32H743 has lots of timers
Edited 2020-06-18 01:51 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:54pm 17 Jun 2020
Copy link to clipboard 
Print this post

  Chopperp said  
BTW, is there, or do you have an MMEdit version/update for the CMM2?

Brian

You need to go to version 4x for the CMM2.
I am still finding keywords that I missed but most of them are there.
I have changed the way keywords are stored to make it easier to keep up with the multitude of systems out there.

Jim
VK7JH
MMedit
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 10:25pm 17 Jun 2020
Copy link to clipboard 
Print this post

Thanks Jim

Just downloaded it. I see CMM2. Will try ii out later today.

Must remember to give you some beer money as well.....

Brian
ChopperP
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025