View previous topic :: View next topic |
Author |
Message |
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Mon Nov 20, 2017 8:58 am Post subject: String variables suddenly emptied |
|
|
I have a problem that drives me really crazy:
I started to write a program to control some DACs, output on a LCD, read from a rotary encoder to control a power supply.
This was for an ATMega 8 and all went fine until the code grew too large and I had to change the µC.
So I compiled the program for an ATMega 328P and everything worked as intended.
Then I added step by step more code (e.g. to read out a port from the PCF8574) and all of the sudden I realised that functions that did perfectly work before, did not work as expected any longer:
I have a number of strings defined global for the output on the LCD, there is also some conversion from numbers to strings.
A value is assigned to a certain string variable in a subroutine and when returning from this subroutine and going to the next sub before using the variable, the string is all of the sudden emptied. If I reassign the value to the string short before using it, the prog works fine.
But this is not all yet: all of the sudden the µC seems not to properly execute a subroutine, but jumps back earlier than expected ...
I use ca. 1/3 of the available memory space.
The compiler gives me warnings that say the string size of my string variables might be too large to fit into STRBUF ?
Has anyone a clue?
Thank you for your help and suggestions
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Mon Nov 20, 2017 11:01 am Post subject: |
|
|
Hi,
check your compilation directive about the stack, and framesize
$regfile = "M168def.dat"
$crystal = 16000000
Config Clockdiv = 1 ' either use this or change the divider fuse byte
$hwstack = ?
$swstack = ?
$framesize = ?
You could try to increase it
Read the help about them.
JP |
|
Back to top |
|
|
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Mon Nov 20, 2017 10:55 pm Post subject: |
|
|
I use the following:
$regfile = "m328def.dat" 'ATMega 328P
$crystal = 20000000 'Quarz: 20 MHz
$baud = 19200
$hwstack = 32 'hardware stack
$swstack = 10 'software stack
$framesize = 40 'frame space
I tried to double the values, no effect ...
The compiler gives the following warnings:
Code: | Source string could be too big to fit into target string [VSET_STRING>___STRBUF] in line 0
Source string could be too big to fit into target string [VSET_STRING>___STRBUF] in line 0
Source string could be too big to fit into target string [CSET_STRING>___STRBUF] in line 0
Source string could be too big to fit into target string [CSET_STRING>___STRBUF] in line 0
Source string could be too big to fit into target string [VOLT_STRING>___STRBUF] in line 0
Source string could be too big to fit into target string [CURRENT_STRING>___STRB in line 0
Source string could be too big to fit into target string [POWER_STRING>___STRBUF in line 0
Source string could be too big to fit into target string [PV_STRING>___STRBUF] in line 0 |
JW[/code] |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Nov 21, 2017 10:37 am Post subject: |
|
|
I use :
$hwstack = 128
$swstack = 64
$framesize = 128
and I have a lot of warning:
Source string could be too big to fit into target string [S_SECOND>___STRBUF] in line 213
Source string could be too big to fit into target string [S_MINUTE>___STRBUF] in line 218
Source string could be too big to fit into target string [S_HOUR>___STRBUF] in line 232
Source string could be too big to fit into target string [S_DAY>___STRBUF] in line 249
Source string could be too big to fit into target string [SHORT_MONTH>___STRBUF] in line 259
Don't be worry about them if you do a good dim of the variable
JP |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Nov 21, 2017 10:46 am Post subject: |
|
|
in 2080 version the code explorer can show the used stack. while that is a new option and you need to read the help about it, it gives a good idea of the minimum required stack.
Without posting a piece of code that can demo the problem, there is little we can do.
take in mind that :
Code: | sub something()
local mylocal as string * 100
end sub
|
will use the frame space for 101 bytes already. _________________ Mark |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Nov 21, 2017 12:10 pm Post subject: |
|
|
thanks Mark,
I use the code explorer but I never open the info. I discover it just now !
very usefull for the free Sram.
is it working for all file of a project or only for the "in focus" file ?
JP |
|
Back to top |
|
|
jwolf
Joined: 18 Jan 2013 Posts: 24
|
Posted: Fri Dec 08, 2017 1:10 pm Post subject: String variables suddenly emptied |
|
|
Problem is fixed, it was not only one, but multiple problems:
1) stack sizes were too low taking into account the number of string variables I use combined with the fact that there is a lot of string conversion
2) some string variables were not DIM'd correctly (too short)
3) I make use of nested sub routines, causing an even higher demand for the stack
Thanks to the helpful suggestions I was able to find out what the problems were.
With the above points 1 and 2 corrected, the program runs as expected.
Thank you very much JP and Albert for your help and good hints!
Regards,
JW |
|
Back to top |
|
|
|