Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:06 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : ’Out of Memory’ with LCD_LIB.BAS

Author Message
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 09:20pm 24 Feb 2012
Copy link to clipboard 
Print this post

Hi all.
I have written more subroutines to perform the 9 functions that run an LCD screen. The library itself now takes 66% of available memory.
As I'm writing the subroutines I'm writing test subroutines so anyone could test all the functionality if ever there is a change to the code or MMBasic. I've maxed out memory .

My proposed strategy is:
Share string variables where-ever possible (256 bytes per string = 1/120 of available memory)
Remove advisory print statements and put them in the documentation (such as, "this test should clear the LCD screen")
Remove comments and move them to the documentation

If desperate:
Move multi lines to single lines, removing spaces
Ignore some functionality like setting 8 line input and reading the lcd status
Have the program RUN sub programs, but then I have to manage passing values entered by the user in the main program.

Any other suggestions?

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
crackerjack

Senior Member

Joined: 11/07/2011
Location: Australia
Posts: 164
Posted: 09:49pm 24 Feb 2012
Copy link to clipboard 
Print this post

Assembly? Only kidding...

You can try:

* Reduce the number of literal values by using a single constant (yes, in MMBasic, a variable!) if possible;
* Reuse variables rather than declaring new ones (look out for side-effect city);
* Try a declarative approach rather than imperative where possible. Easier said than done in [MM]Basic, but possible in some cases.
* Shift data storage out to files;

Good luck...
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 10:00pm 24 Feb 2012
Copy link to clipboard 
Print this post

Hi James,

Where have you maxed out memory? Is it Program or General Memory?

The output from the MEMORY command would help.

If you are using USB only you can turn off the video and that would return about 23K to the general memory pool (in 3.X).

Geoff
Geoff Graham - http://geoffg.net
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:29am 27 Feb 2012
Copy link to clipboard 
Print this post

I ran out of program memory.



The screen capture above shows that the incomplete library takes 18kB or 60% of program memory.
The library and its supporting test code takes 30kB or 99% of program memory.

I've attached the code. It tests OK for 4x20 LCD screens so far, but doesn't have some of the functions implemented yet.

James

2012-02-27_102443_lcd_lib.zip
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 12:57am 27 Feb 2012
Copy link to clipboard 
Print this post

Remove all the debug/test code from the actual Function library
Create a Separate program/library to test functionality.

[code]_LCD_Display$ = ""
_LCD_Cursor$ = ""
_LCD_Blink$ = ""
_LCD_Type$ = ""
_LCD_MoveDir$ = ""
_LCD_Shift$ = ""
_LCD_Type$ = ""
_LCD_Direction$ = ""
_LCD_Bits = 0
_LCD_Lines = 0
_LCD_Font$ = ""[/code]
Most of the above variables could be Integers/data constants
anything except STRINGS

Using configuration file entries for the parameters
(i have a alpha version using config file and drive 2 16x2 plus a 8x2 module at the SAME time) which uses <20% of the memory


Edited by djuqa 2012-02-28
VK4MU MicroController Units

 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 01:47am 27 Feb 2012
Copy link to clipboard 
Print this post

That's a fair point about the debug code. I use lots of comments to explain what I'm doing - but people looking at the code are likely to need them. I may need to maintain two copies - one with comments and test code, and one stripped down for efficiency. Hey - that sounds like the basis of an interesting program.

If I split the program into a separate test program (12kB of program memory so far) and a library (18kB), then load the test program and merge in the library, wouldn't I still be using 30kB or 99% of program memory?

I could split the test code into multiple smaller programs and use RUN to manage them, but then I get back to the parameter problem above.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 12:41am 01 Mar 2012
Copy link to clipboard 
Print this post

I followed djuqa's suggestion and converted string parameters to numeric, and I wrote a short program to strip out blank lines and remarks. Now I have a fully commented source program for developing the library, and a stripped down version for distribution.

Memory usage for the library dropped from 18kb (60%) to 6kb (20%). The lesson is that libraries (not individual subs) may have to do without comments so there is space for users to fit in their own programs, but there will have to be good supporting documentation.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024