Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Xmega256a3bu backup battery for rtc32

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

Bascom Member



Joined: 09 Sep 2017
Posts: 2

PostPosted: Tue Jul 02, 2019 9:22 pm    Post subject: Xmega256a3bu backup battery for rtc32 Reply with quote

Dear to all
I'm using this code to have a rtc.
This micro have a dedicated pins for the crystal and battery backup.
In the config clock of rtc32 it is remarked that backup battery is enabled but any time I switch off and on the clock is reset.
Can any one of you help me to set properly the code.
Thank you
Gino


$regfile = "xm256a3budef.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 64
$framesize = 64
$lib "glcdEADOGM128x3.lib"
Config Osc = Enabled , 32mhzosc = Enabled , 32khzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
$prog &HFF , &HFF , &H00 , &HFE , &HFF , &HFE , &HEF ' generated. Take care that the chip supports all fuse bytes.
'fuse 2 BOD enabled continuously fuse 5 BOD enabled continuously

'******************************RTC32 config *****************
Config Clock = Soft , Rtc32 = 1khz_32khz_crystosc , Gosub = Sectic
Config Date = Dmy , Separator = Minus
' QUESTE VARIABILI SONO DIMENSIONATE COME BYTE
'_sec
'_min
'_hour
'_day
'_month
'_year
'*******TIMER 0 CONFIGURAZIONE **********
Config Tce0 = Pwm_topbot , Prescale = 8 , Comparea = Disabled , Compareb = Disabled , Comparec = Disabled , Compared = Disabled , Resolution = Normal
Tce0_per = 55400 ' 360 GRADI CORRISPONDONO A CIRCA 46480

'**************** CONFIGURAZIONE LCD XPLAINED ***********
Config Graphlcd = 128x64eadogm , Si = Portd.3 , Sclk = Portd.1 , A0 = Portd.0 , Rst = Porta.3 , Cs1 = Portf.3
Cls

(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: Sat Jul 06, 2019 9:33 am    Post subject: Re: Xmega256a3bu backup battery for rtc32 Reply with quote

Gino_71 wrote:
In the config clock of rtc32 it is remarked that backup battery is enabled
I see no matching line in your code.

Quote:
but any time I switch off and on the clock is reset.
Sure, what do you expect?

Maybe you should try to understand what you're dealing with.

The Bascom Config Clock is a soft-RTC, 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 hardware-RTC 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:
Config Clock = User

Getdatetime:
Return
 
Setdate:
Return
 
Settime:
Return

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.
Back to top
View user's profile
Gino_71

Bascom Member



Joined: 09 Sep 2017
Posts: 2

PostPosted: Mon Jul 08, 2019 6:31 pm    Post subject: PostPosted: Sat Jul 06, 2019 9:33 am Post subject: Re: Xm Reply with quote

Hi MWS
Thank you for your kind words.
I will go deep in the data sheet and try to write the code to do per your tip.
I just write on the forum because no example and or info are provided around rtc32.
Thank you again for your input.
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Mon Jul 08, 2019 8:12 pm    Post subject: Reply with quote

Oh, my words have not been that kind. In case that suddenly happens, start to worry about me Very Happy
However they should have been able to push you into the right direction, for the conversion routines SYSSEC and friends will make your day easier.
As you have to use Config Clock = User, Bascom will not set up the crystal oscillator and channel it to the 32bit counter.
You have to set it up by the related registers as the data sheet tells you.
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