Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

GetDateTime

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Mon Aug 06, 2018 8:45 pm    Post subject: GetDateTime Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Aug 07, 2018 2:43 am    Post subject: Reply with quote

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
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Aug 07, 2018 4:53 am    Post subject: Reply with quote

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"
Check if its work LINK
When clock is configured for USER then you must read it when you need to know what time is Razz


Code:

'use some timer to fire this job
     Gosub Getdatetime                                      ' co 100ms
If Old_sec <> _sec Then
 Old_sec = _sec
  'place for your code
End If
 


If you need help to configure the timer then dont forget to tell us what system clock is.


Last edited by EDC on Wed Aug 22, 2018 7:57 pm; edited 1 time in total
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Aug 07, 2018 5:22 am    Post subject: Re: GetDateTime Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Aug 07, 2018 8:29 am    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Aug 07, 2018 9:48 am    Post subject: Reply with quote

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
Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Aug 07, 2018 2:17 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Aug 07, 2018 4:31 pm    Post subject: Reply with quote

thanks for this clear answers
JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Wed Aug 08, 2018 6:15 pm    Post subject: Reply with quote

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
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Aug 08, 2018 7:19 pm    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum