![]() |
Forum Index : Microcontroller and PC projects : Setting RTC Module.
Author | Message | ||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Just wondering if there are better ideas out there for setting the RTC modules. Have done the RTC SETTIME thing, but wondering how to easily send the Computers time, which should resynchronise regularly to the RTC. Tried setting the MicroMites time from in MmChat & then sending the MM's time to the RTC, but I know the variable types are incompatible and I'm using strings where intergers are required. Just wondering what everyone else does? Does it just all come back to RTC.... and waiting for the minute to turn before hitting Enter? RTC Settime mid$(Date$,9,2),",",Mid$(Date$,4,2),",",Mid$(Date$,1,2),",",Mid$(Time$,1,2),",",Mid$(Time$,4,2),",",Mid$(Time$,7,2)
Thanks Phil |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Not quite sure what you mean here Phil. Page 25 of the MMBasic Manual V5.1 discusses how to set up an RTC. If you've connected a RTC with a back-up battery to your Micromite then you should normally only have to set it up once using the RTC SETTIME command from your PC/notepad console e.g. RTC SETTIME 16,04,08,12,00,00 (for midday today). After that update the Micromite's internal clock with the RTC GETTIME command, either within your program at whatever frequency you want (hourly is probably good - depends on your RTC chip) or manually via the console - there are no parameters required for the RTC GETTIME command. If you mean how to set it regularly from the console when developing programs with MMEdit, then the easiest way is to tick the box "Set clock on load" in MMEdit's File/Preferences tab. Greg |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
I completely understand the concept of both clocks, have a DS3231 connected, (Must have slipped up, intended on getting a 3232). What I'm meaning is a regular not input required way of resetting the RTC from an external source, to correct for it's drift. IE PC Time -> MM Time -> RTC time. It would be nice to have a 1 click way of resetting the RTC. MM Edits Clock button could probably be optioned to set BOTH MM Clock & RTC. Could that be done with one of the Macro buttons in MM Chat? Get the PC's time & pass it to the RTC SETTIME command. No more typing RTC settime 16,04,09,07,00,00, or whatever, THEN waiting for the minute to tick over only to have:- a) the phone ring.... b) a coffee handed to you... c) someone demand immediate attention... And missing the synchronisation point.... (I Know LOL, Possible OCD showing here, but I do like all clocks sync'd). Cheers |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6266 |
Why do you have to wait for the minute to tick over? "RTC SETTIME year, month,day, hour, minute, second" I suggest that you write a function to do the RTC setting and include it in a library function. You can then call it from the command-line whenever you wish. You could also put it as a macro in MMEdit. I hope you are not relying on Windows to keep your time correct. The standard Window Internet time setup is not much use if you are trying to get this level of time control. Jim VK7JH MMedit |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Not sure which time servers my Domain controller is using these days, but I did spend time getting everything reliable & sync'd properly some time back. The coding rust in SLOWLY dissolving away & this line works:- RTC SETTIME VAL(MID$(Date$,9,2)),VAL(MID$(Date$,4,2)),VAL(MID$(Date$,1,2)),VAL(MID$(Time$,1,2)),VAL(MID$(Time$,4,2)),VAL(MID$(Time$, 7,2))
But when I paste in a Macro Button, it seems to run, then also passes a "1" to the basic, which obviously returns an error. Cheers. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6266 |
Not sure why the macro button doesn't work. I don't have an RTC connected so unable to test. Don't forget to add the \r\n to the end - saves hitting 'enter' One problem with your command line. If the time/date changes anything except the seconds while the line is being processed, it is possible that the first calls to 'Time' will be different to subsequent calls to 'Time' If it is right on the hour, you will end up with the old hour and the new minutes etc. The safest way is to read the time into a variable once and process all hh mm ss using that variable. It will be a few weeks before I can do any work on MMEdit. I will consider adding a menu option to set the RTC. I don't think it warrants a button due to it's limited value. Jim VK7JH MMedit |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9585 |
DS3231 or DS3232 RTC chips are extremely accurate. Set and forget, really. Once set, you should not really need to adjust them via the console. They have an expected drift of plus or minus two minutes PER YEAR. 60 x 60 x 24 = 86,400 seconds per day. 86,400 x 365 = 31,536,000 seconds per year. 3231 or 3232 accuracy is within 120 seconds out of 31.5 million, or an error of around 0.000380 % So accurate as to not really need your attention again once set in any one calendar year. Worst-case scenario is you need to reset the clock ONCE per entire year - but you will do it twice anyway for daylight saving. With these kinds of RTC, I don't see the need to have an ability to frequently reset the clock. The 1307 RTC is another matter, as it is quite drifty, and it does need attention semi-regularly, but the 3231 or 3232 are a different matter. There is nothing inherently wrong with that idea, but you are making much more work for yourself then you need to especially if you intend to keep using the 3231 or 3232..... ![]() Smoke makes things work. When the smoke gets out, it stops! |
||||
paceman Guru ![]() Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
I'm still a bit unsure what you're trying to do here Phil. Where are you getting the TIME$ and DATE$ string from for your programming line: RTC SETTIME VAL(MID$(Date$,9,2)),VAL(MID$(Date$,4,2)),VAL(MID$(Date$,1,2)),VAL(MID$(Time$,1,2)),VAL(MID$(Time$,4,2)),VAL(MID$(Time$, 7,2))
I presume you're reading it from the Micromite but if that's the case you're just re-setting the DS3231 RTC with a time already slightly drifted by the Micromite. The 3231 will be maintaining a much more accurate time than the Micromite (or often for that matter your PC) - see Grogs' figures in his above post for the 3231 versus the Micromite's MMBasic time drift which can be around a few tens of seconds per hour as I recall. I also presume you have got the 3231 backed up with a lithium button battery - you must have this. If your 3231 is battery backed then as Grogs' says you only need to use SETTIME when daylight savings changes, although you can get rid of needing that too with your program. There was a thread a year or so ago showing how to do this - Jim's (Tassy Jim) is right up there with this and can probably give you the correct link. I just did a quick forum search using "daylight saving" and heaps comes up. You mention syncing multiple clocks around the house - have these got their own battery backed 3231's or have you got them talking to each other with one being the master "time server", or do you set each manually? If being synchronised and accurate is your aim then there are several ways of doing it but obviously lots more involved. We can help if we know specifically what you want. Greg |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2428 |
there are I2C commands for sending configuration data directly to RTC, using these you may set the RTC quite precisely, and read it back directly. others can comment upon what the exact details are. and you can issue an RTC GETTIME command just before each time you use the normal MMBASIC time routines to ensure the time is correct. alternatively, you could write your own routines for reading from and writing to the RTC with I2C commands, and use these exclusively, effectively bypassing the inbuilt TIME$ and DATE$ functions. cheers, rob :-) |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
Hi Greg, I did check our specs before I got one & was impressed by what I saw & made a point of avoiding the likes of 1307 chips. Is there room for extreme QC errors with these? Duds? Will check It's not the idiot at this end, I know the micromite's clock is gaining like crazy, but also convinced myself the RTC had a smallish drift after a few days. |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
My thought too. Would only warrant an option in settings to enable the existing button to update both clocks. Been trying a different editor for a bit. MM Edit2 & really liking what I see. Cheers |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |