Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Time$ problem with ATMega1284p regfile

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

Bascom Member



Joined: 28 Jan 2006
Posts: 34

ecuador.gif
PostPosted: Thu Jan 10, 2019 4:34 pm    Post subject: Time$ problem with ATMega1284p regfile Reply with quote

Hi everybody.

With version 2.0.8.1 the time$ statement gives incorrect results with $regfile="m1284pdef.dat".

Code:
$version 0 , 0 , 7
$regfile = "m1284pdef.dat"
$crystal = 7372800
$baud = 9600

$hwstack = 256
$swstack = 256
$framesize = 256

$projecttime = 0

Config Date = Dmy , Separator = /                           ' ANSI-Format, Timer2
Config Clock = User


Time$ = "09:43:00"
Date$ = "10/11/19"

Print Time$
Print Date$

End

Getdatetime:
Return

Setdate:
Return


Settime:
Return
 


In this example Print Time$ shows 00:09:43 (it must be 09:43:00).
the same code with $regfile="m328pdef.dat" is OK.

The problem remains if you run in real time on an ATmega1284P (it's not just the simulator's problem). And in an Atmega328P the Time $ works well in real time

Thank you in advance for your help




(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile Yahoo Messenger MSN Messenger
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1628

blank.gif
PostPosted: Thu Jan 10, 2019 9:56 pm    Post subject: Reply with quote

Not sure if it's a bug or a feature, but the compiler keeps internal variables _sec, _min,..., _mont, _year not in order, instead squeezes other internals like ___READRAMPZ inbetween.
I can not see a good reason to interrupt the order of the date/time variables, especially as libs like datetime.lib rely on a certain order.
So I guess it is a compiler's problem of variable's placement, which seems even worse with XMega, where a whole lota bunch of internals is squeezed between time and date:
Code:
_SEC
_MIN
_HOUR
___READRAMPZ
_XMEGAREG
___LTMPAX
___DWTMPAX
___BTMPAX
___WTMPAX
___STMPAX
___DOUBLEA
___DOUBLEAX
_DAY
_MONTH
_YEAR

Out of this reason the TO's example did not work for XMega, time was always reported '00:00:00'.
I did not try to fix the XMega issue, but a fix for the ATM1284P, where the internal var for its RAMPZ-register creates the trouble looks like that:
Open datetime.lib, create a copy before.
Look for [_MAKE_DT], and there for
Code:
   sbiw zl, 3                          ; Advance Pointer to _sec

Replace with:
Code:
*#IF varexist("___READRAMPZ") AND _XMEGA=0
   sbiw zl, 4                          ; a fix for this occassion
*#ELSE  
   sbiw zl, 3                          ; Advance Pointer to _sec
*#ENDIF

Goto Menu --> Tools --> Lib Manager, mark datetime.lib and click the button 'Compile', close with 'OK'
After new compilation of the project it should work fine.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4678
Location: Holland

blank.gif
PostPosted: Thu Jan 10, 2019 10:10 pm    Post subject: Reply with quote

This is a known problem. It has an easy fix too : dim your variables BEFORE the config clock. Or dim 1 dummy byte before CONFIG CLOCK.
The reason for the problem is that some internal variables are automatic added depending on the options. And the date time variables depend on their order.

Here is the official note :
rearranging memory order for usb support caused a bug in config clock : the date time bytes are not mapped after each other. This will cause a problem for $time function. A workaround is simple: dim a dummy or actual byte BEFORE the CONFIG CLOCK statement.

_________________
Mark
Back to top
View user's profile Visit poster's website
ofvy

Bascom Member



Joined: 28 Jan 2006
Posts: 34

ecuador.gif
PostPosted: Thu Jan 10, 2019 10:52 pm    Post subject: Time$ problem with ATMega1284p regfile Reply with quote

Hi Albertsm.

Thank you very much for your quick response.
In the simulator it works now with ATmega1284P. Tomorrow I test it in an ATMega1284P in real time.

Best regards
Back to top
View user's profile Yahoo Messenger MSN Messenger
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