View previous topic :: View next topic |
Author |
Message |
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Mon Aug 06, 2018 8:45 pm Post subject: GetDateTime |
|
|
Last week after some problems with an I2C RTC (DS3231) I saw that when CONFIG CLOCK = USER is used, the routine GetDateTime is called with intervals of 20 and 40 mSec.
This is approximately 3 times per second.
This is of course no problem, how shorter the interval how smoother the clock shows on the display.
The RTC triggers in my case also an interrupt with his 1 Hz clock output.
I like to call GetDateTime myself in the interrupt routine triggerd by the 1 Hz clock from the RTC and disable the automatic calling of GetDateTime.
Is this possible?
What (timer) is used to generate the interval of 20 and 40 mSec. between two calls to the routine GetDateTime?
(BASCOM-AVR version : 2.0.8.1 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Aug 07, 2018 2:43 am Post subject: |
|
|
Since when does a period of 20 to 40 ms equal to 3 times per second? Rather 30 times.
The timer (if any) responsible for this, should become obvious from your code, which we don't know.
Thus it's your job to compare your code against the samples which the help shows you for Configuration Clock = User.
There's also a link to the samples folder, together this should sufficiently explain use of GetDateTime in combination with an I2C-RTC. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Tue Aug 07, 2018 5:22 am Post subject: Re: GetDateTime |
|
|
Frankeman wrote: |
I like to call GetDateTime myself in the interrupt routine triggerd by the 1 Hz clock from the RTC and disable the automatic calling of GetDateTime.
Is this possible?
(BASCOM-AVR version : 2.0.8.1 ) |
Certainly is I do it in my clock project it moves the dots up/down see #AN196
Regards Paul |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Aug 07, 2018 8:29 am Post subject: |
|
|
EDC wrote: | If I need to reaction to second change then I read clock every 100ms an check internal variable "_sec" if they differ with previous "old_sec" |
Besides having some fun with my name, you missed the point.
Same as the TO:
Quote: | I like to call GetDateTime myself |
because he does not have to call this routine.
Some Basics: GetDateTime is internally called whenever a Bascom command likes to read the date or time.
With an external I2C-timesource in combination with parameter USER this routine has to be filled with useful code that reads the RTC via I2C.
Accordingly the values fetched from the RTC are written then into Bascom's internal variables.
The reason why, regarding the TOs opinion of 3 reads each second or 30-40ms per read (whatever is more true), the GetDateTime is called, is likely because the TOs code contains somewhere these date/time-reads. It means also if the TOs goal is - which we need to guess - to lower the amount of calls to the RTC, then it would be wise to lower the date/time-reads at first.
In case this does not work out of good reasons or because the code is a mess, then the way is to leave the GetDateTime routine empty and fill the internal variables within the external interrupt routine triggered by the 1Hz output of the RTC. The code to read the RTC and set the internal variables is the same as in GetDateTime, let's say only labels have changed.
But care must be taken, as with the nature of interrupts, reads from regular code to the RTC may collide with interrupt-reads, which lock up the I2C-bus.
Imho the TO needs rather to describe his goal and not to offer questions based of improper/nonworking solutions.
In such cases I do likely not respond, or if I do, with hints as I did in my first post.
As it is common with guesswork, the TO's intention may be something completely different.
Which we may see as soon the TO will enlighten us. |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Aug 07, 2018 9:48 am Post subject: |
|
|
hi
MWS wrote Quote: | Some Basics: GetDateTime is internally called whenever a Bascom command likes to read the date or time.
With an external I2C-timesource in combination with parameter USER this routine has to be filled with useful code that reads the RTC via I2C.
Accordingly the values fetched from the RTC are written then into Bascom's internal variables. |
that's what I thought, I use "config-clock = user" and a DS3231. since years...
I also run a sub that I call getdatetime ()
Code: | Sub Getdatetime()
I2cstart ' Generate start code
I2cwbyte DS3231w ' send address
I2cwbyte 0 ' start address in 1307 /3231
I2cstart ' Generate start code
I2cwbyte DS3231r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Dow , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
If Err <> 0 Then call Error(15)
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
end sub |
and so I call getdatetime () when I finish all I have to do, and then I check if I'm still in the same second.
My question: Is there a getdatetime function hidden in a lib?
Actually all my clocks are running perfectly it is just a question
JP
_________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Aug 07, 2018 2:17 pm Post subject: |
|
|
Duval JP wrote: | I also run a sub that I call getdatetime () |
Which is required if you use the parameter USER and datetime.lib is included by default.
Quote: | My question: Is there a getdatetime function hidden in a lib? |
GetDateTime is a user-routine, call it a hook, which allows your code to alter the internal date/time values, before DATE$/TIME$ is updated.
In contrary if you use Config Clock = Soft, then code for the softclock is included and this code alters _sec, _min, a.s.o., the softclock routines are to find in mcs.lib.
For clock = USER, which excludes the mode SOFT, looking up datetime.lib returns a routine called _MAKE_DT, which is basically only a conversion routine and updates the two internal values TIME$ and DATE$ from internal variables _sec, _min, ..., _year.
The USER parameter ensures in combination with datetime.lib, that in front of said conversion the user-routine GetDateTime is called, which allows your code to update the internals like _sec before TIME$/DATE$ is updated.
_MAKE_DT is called by compiler included routines. If for example you assign my_time = TIME$, _MAKE_DT is called and TIME$ is updated before it is assigned to my_time. You can call _MAKE_DT yourself, but I do not see how this would be of any benefit.
Because of that any read of TIME$ will call _MAKE_DT, which in turn calls GetDateTime and accesses such the I2C-RTC, have mentioned that in my earlier post.
_MAKE_DT however may look different in different libs, for example the ds1307clock.lib and ds1307clock_GER.lib.
The difference there is the format of DATE$/TIME$.
Any later defined routine with same name replaces the routine defined before, which means if you include a lib with a _MAKE_DT routine in your code, it will replace any previously defined _MAKE_DT in a previous included lib.
Hope this did cover up any clarities |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Aug 07, 2018 4:31 pm Post subject: |
|
|
thanks for this clear answers
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
Frankeman
Joined: 11 Aug 2004 Posts: 948 Location: the Netherlands
|
Posted: Wed Aug 08, 2018 6:15 pm Post subject: |
|
|
Hi,
After reading the posts I realized that I use Time$ and Date$ in the main loop of the program.
That makes my question a little bit stupid I quess.
I changed it and now I do the Time$ en Date$ once per second on the 1 Hz interrupt from the RTC.
But thanks fot your answers, Frank. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Aug 08, 2018 7:19 pm Post subject: |
|
|
Frankeman wrote: | That makes my question a little bit stupid I quess. |
Don't think so.
Not to know the internal strings the compiler draws, doesn't make the question stupid. |
|
Back to top |
|
|
|