View previous topic :: View next topic |
Author |
Message |
16mk
Joined: 26 Feb 2016 Posts: 19
|
Posted: Wed Mar 11, 2020 11:58 pm Post subject: ATxmega Print instruction - good or bad |
|
|
Hello,
The Print instruction gives different results depending on the order of variable declarations.
1. Dim A(255) on the bottom of list.
Code: | $lib "xmega.lib"
$regfile = "xm16e5def.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
Dim B As Byte
Dim A(255) As Byte
Config Portc.3 = Output
Config Com1 = 4800 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1
A(1) = 123
Print #1 , A(1)
End |
Result of Print instruction is 123 ,OK
2. Dim A(255) on the top of list.
Code: | $lib "xmega.lib"
$regfile = "xm16e5def.dat"
$crystal = 2000000
$hwstack = 64
$swstack = 40
$framesize = 40
Dim A(255) As Byte
Dim B As Byte
Config Portc.3 = Output
Config Com1 = 4800 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM1:" For Binary As #1
A(1) = 123
Print #1 , A(1)
End |
There is no result of Print. When Dim A(251) the result is 123 but if Dim A(252) or 253 or 254 the result is 3
(BASCOM-AVR version : 2.0.8.2 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Mar 12, 2020 10:24 am Post subject: |
|
|
it should not matter. it seems to have to do with the processor you use.
for example the xm128a1 works normal. but this E5 series is a bit different. it has slightly different architecture.
i will check it further since i like to know the cause. _________________ Mark |
|
Back to top |
|
|
16mk
Joined: 26 Feb 2016 Posts: 19
|
Posted: Thu Mar 12, 2020 11:23 am Post subject: |
|
|
.rpt files:
1.
Code: | Variable Type Address(hex) Address(dec)
B Byte 2000 8192
A Byte(255) 2029 8233 |
2.
Code: | A Byte(255) 2000 8192
B Byte 2127 8487 |
There are 40 (dec) free cells between the end of the first variable and the beginning of the second. Maybe the area directly above 8192 is important to the print instruction (1. free, 2. occupied).
The second, third and next variables they are directly after each other.
Code: | A Byte(255) 2000 8192
B Byte 2127 8487
C Word 2128 8488
D Single 212A 8490
E Byte 212E 8494 |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Mar 12, 2020 12:04 pm Post subject: |
|
|
no that is not the problem.
xmega can not access register r0-r31 using pointers.
for this reason some data is used for temp storage of registers that would normally use the register r0-r31
this area is allocated automatic after the first dim.
previously it was allocated first. but since some code need to run at the start of a page that was changed.
anyhow the problem is in mcs.lib in the num2str code.
it depends on the address of this temp area if it works or not.
to change it, open mcs.lib
search for _num2str code
change this :
#IF _XMEGA
Loadadr _XMEGAREG(_BASE),Z
Mov r0,r30
Inc R0
Adiw R30,5
#ELSE
Ldi zl,15 ; point to registers + 1
Clr zh
#ENDIF
_Num2Str3:
Ld r24,-z ; get byte
Rcall _prcdwrd ; put nibbles into the string
#IF _XMEGA
cp r30,r0
#ELSE
cpi zl,11 ; are we almost ready?
into this :
#IF _XMEGA
Loadadr _XMEGAREG(_BASE),Z
adiw r30,1 ; advance
Movw r0,r30 ; change to movw
Adiw R30,4 ; last
#ELSE
Ldi zl,15 ; point to registers + 1
Clr zh
#ENDIF
_Num2Str3:
Ld r24,-z ; get byte
Rcall _prcdwrd ; put nibbles into the string
#IF _XMEGA
cp r30,r0
cpc r31,r1
#ELSE
cpi zl,11 ; are we almost ready?
#ENDIF
then save and compile the lib using Lib Manager
For 2083 the num2str was rewritten for xmega and for xtiny and some other workaround were rewritten/removed as well. _________________ Mark |
|
Back to top |
|
|
16mk
Joined: 26 Feb 2016 Posts: 19
|
Posted: Thu Mar 12, 2020 1:17 pm Post subject: |
|
|
Thanks, works. |
|
Back to top |
|
|
|
|
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
|
|