Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bug in QSIN / QCOS

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

Bascom Member



Joined: 15 Oct 2009
Posts: 72

germany.gif
PostPosted: Wed Feb 02, 2022 12:06 pm    Post subject: Bug in QSIN / QCOS Reply with quote

I use qsin/qcos to draw an user defined scale with XMege256A3U for a gauge with FT81x.
Everything worked as it should, but after a small modification of my bascom code at a complete different location,
drawing the scale was corrupted.

before modification code


after modification code


So I tried to analyse this problem in AVR-Studio with disassembler.
I could see that qsin is using a lookup table.
So this problem occures if this lookup table overlaps in flash an address n * 1000hex
I think there is a bug in calculating the RAMPZ for reading the lookup table.


Yes I use BASCOM 2.0.8.2, but I tried also with newest version 2.0.8.5, same problem!

(BASCOM-AVR version : 2.0.8.2 , Latest : 2.0.8.5 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Feb 02, 2022 1:21 pm    Post subject: Reply with quote

in the int_trig.lib
there is this code :

#IF _ROMSIZE > 65536
call _SET_RAMPZ
#ENDIF

put a * before the call :

#IF _ROMSIZE > 65536
* call _SET_RAMPZ
#ENDIF

then save and use lib manager to compile to lbx

if that does not work,
put some code in the lib below the call :
In r0,rampz
sts {bsomevar},r0

then dim a byte named bsomevar and include the lib version using $lib before you call qsin
lib$ "int_trig.lib"

in your code after the call to sqin print the content of the variable.
it should contain the proper 64KB page

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

Bascom Member



Joined: 15 Oct 2009
Posts: 72

germany.gif
PostPosted: Wed Feb 02, 2022 4:39 pm    Post subject: Reply with quote

Hello Mark

I tried to change the lib.
But it was not working.

Then I changed the lib a second time, so I can debug with bsomevar.
First it worked, because the change in the basic code moved the complete lookup table to 64kb page 3.
Then I removed some other code, so the lookup table moved in flash a little bit down and it overlaps now 64kb page 2 and 64kb page 3 again.
Same problem again!

I print also out the used 64kb page with bsomevar.
All lookup table accesses were on 64kb page 2.
This is not correct. Some angles must be in 64kb page 2 and others must be in 64kb page 3 !
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Feb 02, 2022 8:43 pm    Post subject: Reply with quote

ok, so the page is correct.
after a look it is obvious.
add the code in bold after the addition.
that should fix it.

add r30,r16 ; add offset
adc r31,r17

#IF _ROMSIZE>65536
Brcc _QSINCOS1 ; no 64KB boundery overflow
* In r0, RAMPZ
Inc R0
* Out RAMPZ, R0
_QSINCOS1:
#ENDIF

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

Bascom Member



Joined: 15 Oct 2009
Posts: 72

germany.gif
PostPosted: Thu Feb 03, 2022 11:33 am    Post subject: Reply with quote

Now it is working!
I checked also the position of the lookup table and changed my bascom code,
that the table still overlaps 2 pages.

Thank 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