Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20762

BASCOM-AVR : Xmega256a3bu backup battery for rtc32 : REPLY

$
0
0
[quote:00789d48d5="Gino_71"]In the config clock of rtc32 it is remarked that backup battery is enabled[/quote:00789d48d5]I see no matching line in your code. [quote:00789d48d5]but any time I switch off and on the clock is reset.[/quote:00789d48d5]Sure, what do you expect? Maybe you should try to understand what you're dealing with. The Bascom Config Clock is a [b:00789d48d5]soft-RTC[/b:00789d48d5], which uses the output from a 32768 crystal-oscillator, puts it on a counter/prescaler, drives an ISR with it and updates the soft-clock within the ISR. Variables in SRam used by this soft-clock are _sec, _min, a.s.o. At power-up SRam-variables are invalid, thus SRam and containing variables are erased by Bascom's init routine, it will always start from zero, or whatever time you write into the variables at time of init. The RTC within this kind of ATXMega however is a [b:00789d48d5]hardware-RTC[/b:00789d48d5] and consists out of an crystal-oscillator, prescaler and 32bit-wide counter, which can be kept running for the cost of some nano-Amperes from a backup-battery. This hard-RTC can be fed by 1Hz or 1024Hz, at 1Hz the theoretical life till overflow is about 136 years. Do you at least read the data sheet before starting something like that, or do you believe magic functionality will appear somehow, if you only write code that contains somewhere the word 'RTC'? There is a solution of course, similar to how it would be done by an I2C-RTC, a bit more complicated however, as you need to write the code which converts the hard-RTC's 32bit value into sec, min, hour, day, ..., and vice versa. For this a code frame would look like: [code:1:00789d48d5]Config Clock = User Getdatetime: Return Setdate: Return Settime: Return[/code:1:00789d48d5] In Getdatetime you need to write routines, which convert the RTC's 32bit value into regular _sec, _min, ..., in SetDate/SetTime routines to convert _sec, _min, ... into the RTC's 32bit value.

Viewing all articles
Browse latest Browse all 20762

Latest Images

Trending Articles

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>