View previous topic :: View next topic |
Author |
Message |
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Fri May 29, 2015 10:38 am Post subject: Config CLOCK=USER |
|
|
Hello!
On the help of BASCOM there is a nice example of the use of CLOCK = USER.
In the code three labels are made; for empty routines:
Code: |
Settime:
Return
Getdatetime:
Return
Setdate:
Return
|
I have found these labels (or at least the 'settime' label) are actually called by the clock routine, but it is not made clear what could/should be handled by the routines.
Is there an example showing the use of these labels?
Kind thanks,
Bas
(BASCOM-AVR version : 2.0.7.8 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri May 29, 2015 12:33 pm Post subject: From the online help |
|
|
Config clock
When you use the CONFIG CLOCK (in soft or user mode) directive the compiler will DIM the following BYTE variables automatic :
_sec
_min
_hour
_day
_month
_year
The variables Time$ and Date$ will also be dimensioned. These are special variables since they are treated different. See TIME$ and DATE$.
Following a way to set Time$ and Date$ :
Date$ = "11/11/00"
Time$ = "02:20:00"
You can change the date format by using: Config Date = Mdy , Separator = "/" ' ANSI-Format
See CONFIG DATE
The _sec, _min and other internal variables can be changed by the user too.
But of course changing their values will change the Time$ and Date$ variables.
The compiler also creates an ISR that gets updates once a second. This works for AVR chips which can be asynchronously clocked from the TOSC1/2 pins.
TOSC1 = Timer Oscillator Pin 1
TOSC2 = Timer Oscillator Pin 2
For example the Timer/Counter 2 of an ATMEGA16 can be used as a Real Time Counter (RTC). The Timer/Counter 2 will then be asynchronously clocked from the TOSC Pin's. The Timer/Counter 2 can NOT be used for other tasks when configured in asynchronous mode.
noticeNotice that you need to connect a 32768 Hz crystal in order to use the timer in async mode, the mode that is used for the clock timer. You also need to enable interrupts because of the interrupt service routine.
When you choose the USER option, only the internal variables are created (like _sec , _min , _hour....).
With the USER option you need to write the clock code yourself (so the USER need to update for example the System Second or Secofday).
This means the one second clock must be generated by a "USER" source like a Timer which use the internal clock or an XTAL depending on the Xtal configuration.
There are so called "AVR Timer Calculator" online available where you input the clock frequency from xtal, which Timer you use (8 or 16 Bit) and the period you want to achieve (like 1 second or 1000ms) than it will give you number which you need to configure the timer.
You also configure the interrupt of the timer and then the program will jump to the timer interrupt routine where you can set the new system second.
Config Clock = User 'Use USER to write/use your own code
You also need to include the following labels with config clock = user:
Getdatetime:
'called when date or time is read
Return
Setdate:
'called when date$ is set
Return
Settime:
'scanned when time$ is set
Return
Have fun
Ben Zijlstra |
|
Back to top |
|
|
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Fri May 29, 2015 12:54 pm Post subject: Config CLOCK=USER |
|
|
Thanks for the quick reply Ben!
That makes things clear; but for what can these be used? Are these routines called before or after accessing the time variables?
I.e. writing to Time$ needs to trigger an update of _hour, _min and _sec. You don't want an ISR accessing the same variables at the time, so a lock/unlock for the user clock ISR is expected.
Thanks,
Bas |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri May 29, 2015 1:03 pm Post subject: Clock examples in the samples directory |
|
|
There are three examples in the sample directory of Bascom.
The DateTime_test1 is very nice.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
poesboes
Joined: 27 Jan 2009 Posts: 11 Location: Utrecht
|
Posted: Fri May 29, 2015 2:15 pm Post subject: Re: Clock examples in the samples directory |
|
|
bzijlstra wrote: | There are three examples in the sample directory of Bascom.
The DateTime_test1 is very nice.
Have fun
Ben Zijlstra |
Excellent example Ben! It answers all my questions!
Thanks,
Bas |
|
Back to top |
|
|
|