The Text string size limit in Picaxe Table memory. How to store 300 characters?

Lobobo

Member
Hi. I am trying to show different text messages on 20x4 LCD screen from PICAXE 28x2. In total I have around 300 symbols. Suddenly I faced the problem as the picaxe cannot store this much of data. I tried to use TABLE command and later on to call strings by using READTABLE command.
example:

Code:
TABLE 0,  ("Monday")
TABLE 6,  ("Tuesday")
TABLE 13, ("Wednesday")
TABLE 22, ("You are Welcome")
'TABLE etc.......
TABLE 290, ("Thanks mate")
It looks like this way I can store only 256 symbols of my strings. Is there any other way how to store remaining 50 characters what I need for my project?

Thank you.
 

westaust55

Moderator
Are you able to consider the 20M2 chip instead?

The M2 parts have 512 bytes of TABLE memory (see the READTABLE and TABLECOPY commands). M2 parts also have 512 bytes od RAM (partly used by the bit/byte/word variables).
You can then copy your table to RAM if necessary and use the bptr and @bptr functions to access the table.
 

Lobobo

Member
Are you able to consider the 20M2 chip instead?

The M2 parts have 512 bytes of TABLE memory (see the READTABLE and TABLECOPY commands). M2 parts also have 512 bytes od RAM (partly used by the bit/byte/word variables).
You can then copy your table to RAM if necessary and use the bptr and @bptr functions to access the table.
I am afraid I cannot use any smaller chip than 28 pins because of every IO on this one is used. I could use 40 pins chip, but that one has the same amount of memory. The question: can I connect 08M2 chip via I2C and keep some data in it's memory. And could I request that data from that slave chip via I2C?
 

Dippy

Moderator
I can't help with PICAXE choice, but have you thought about space saving by joining word-parts?
You have "Monday" , "Tuesday" etc.
Well, in cases like this you can store "Mon" and "Tues" etc. and then tack the "day" on the end when displaying.
"day" goes in a separate location.

With a little thought and planning you may be able to do similar things with many other text strings.
 

matherp

Senior Member
Can you include a eeprom in your circuit such as the 24LC512? Then you can write a program to load this up with all your strings as a one off activity and then use them in your real application
 

Lobobo

Member
I was thinking about this option and I will try this but thorough the task I would like to learn different programming techniques. Just to expand my capabilities within a Picaxe. In a future I have plans to have even more strings on the project, so I thought it would be benefficial to find the other solutions to this issue...
 

Lobobo

Member
Eeprom seems like this is the solution. I just had a hope to connect another chip what would make me extra memory and extra IOs. It's just my knoledge not deep enough for that task, but maybe Eeprom is the easiest way to resolve the issue. Thanks.
 

inglewoodpete

Senior Member
The question: can I connect 08M2 chip via I2C and keep some data in it's memory. And could I request that data from that slave chip via I2C?
Using another PICAXE just means another chip to program and debug, although of course that is good for PICAXE sales! Since you are contemplating using i2c to host another chip, I'll put my vote alongside matherp and suggest using an i2c EEPROM chip like the 24LC256 or others in that family.
 

Dippy

Moderator
Yes, choose the method (and PICAXE) appropriate to the task.
Table, Internal EEPROM, external EEPROM.

You've got plenty of choices, but I don't think I'd use another Micro unless it has some other function.
And often a minor code tweak can be enough to keep things simpler.
 

westaust55

Moderator
Another possibility:
If you use an M2 part, as already mentioned, they have i2c comms therefore you can use the 512 byte TABLE memory capability within the M2 part and now use a MCP23017 which will give you a further 16 bi-directional IO implimented in two 8-bit ports. the MCP23017 is available from Futurlec.

Another consideration is how big will the PICAXE BASIC program be?
M2 parts have 2 kbytes whereas X2 parts have four 4 kbytes slots.
 

nick12ab

Senior Member
Internal EEPROM's already been suggested, but if you can't use any of that, you could use the lookup command.
 

Lobobo

Member
The westaust55 idea sounds very atractive. M2 chip with port expander. That I will check on next project. I haven't got programming done yet, but my heating system controler shouldn't take more than 2Kbit. For this ongoing project I will get I2C eeprom as PCB already printed.
Thanks guys.
 

Lobobo

Member
Internal EEPROM's already been suggested, but if you can't use any of that, you could use the lookup command.
Lookup? I have to check it. I writting from phone so will check it later, but it something to do with putting text in program body and lookup would take the text from there if I remember well...
 

Lobobo

Member
And internal eeprom must have at least 256 kb, so my missing 50 characters would fit there I suppose. It seems there quite a few options without changing hardware appeared in front of my eyes... Lookup, internal eeprom. Brilliant. Thank you guys.
 

westaust55

Moderator
The LOOKUP command can accept a statement with up to 256 values (pointer = 0 to access the first value).
A consequence of many values in a lookup command is that the commands becomes slower to execute as the number of values increases.

You could always have several lookup commands, each with say 50 values and then use a ON...GOSUB or ON...GOTO to get to the correct LOOKUP depending upon the value.

as a form of pseudo code:

say pointer can have a value of 0 to say 300

offset1 = pointer / 50 ; 50 assumes 300 values spread over 6 LOOKUP commands
offset2 = pointer // 50
ON offset1 GOTO (look0, look1, look2, look3, look4, look5)
:
:
look0:
LOOKUP offset2, (value0, value1, . . . value 49), character
 

nick12ab

Senior Member
Also look here for LOOKUP optimization. The lookups were divided by IF statements and word variables were used instead of byte variables. It takes advantage of the byte and word variable memory being shared so a value would be written to whatever word variable cw1 was defined as and the two shared byte variables can be used to get the bytes.
Code:
if executebyte < 32 then
    lookup  executebyte,(0,$1020,$4444,$1474,$1D15,$1515,$1516,$1038,$FE83,$2214,$0808,$7F10,$4E71,$0002,$0808,$0000,$0808,$0000,$0000,$0808,$0808,$0808,$0000,$0808,$0808,$FFFF,$3E41,$3E41,$7F7F,$7F41,$7F00,$487E),cw1
    lookup  executebyte,(0,$7F01,$5F44,$1C17,$1700,$1F00,$7C16,$5410,$8183,$0814,$2A08,$100F,$0171,$0502,$0808,$FF00,$FF08,$F808,$0F08,$0F00,$F800,$FF00,$FF08,$0F08,$F808,$FFFF,$7549,$5D49,$7F7F,$4141,$7F00,$4949),cw2
    lookup  executebyte,(0,$0100,$4400,$1400,$0000,$0000,$1500,$1F00,$FE00,$2200,$0800,$1000,$4E00,$0000,$0808,$0000,$0808,$0808,$0808,$0000,$0000,$0000,$0808,$0808,$0808,$FFFF,$3E00,$3E00,$7F00,$7F00,$7F00,$4200),cw3
elseif executebyte < 64 then
    executebyte = executebyte - 32
    lookup  executebyte,($0000,$0000,$0003,$147F,$242A,$2313,$3649,$0005,$001C,$0041,$1408,$0808,$0050,$0808,$0060,$2010,$7F41,$0000,$7949,$4149,$0F08,$4F49,$7F49,$0101,$7F49,$0F09,$0036,$0056,$0814,$1414,$0041,$0201),cw1
    lookup  executebyte,($0000,$4F00,$0003,$147F,$7F2A,$0864,$5522,$0300,$2241,$221C,$3E08,$3E08,$3000,$0808,$6000,$0804,$4141,$0000,$4949,$4949,$0808,$4949,$4949,$0101,$4949,$0909,$3600,$3600,$2241,$1414,$2214,$5109),cw2
    lookup  executebyte,($0000,$0000,$0000,$1400,$1200,$6200,$5000,$0000,$0000,$0000,$1400,$0800,$0000,$0800,$0000,$0200,$7F00,$7F00,$4F00,$7F00,$7F00,$7900,$7900,$7F00,$7F00,$7F00,$0000,$0000,$0000,$1400,$0800,$0600),cw3
elseif executebyte < 96 then
    executebyte = executebyte - 64
    lookup  executebyte,($3E41,$7C12,$7F49,$3E41,$7F41,$7F49,$7F09,$3E41,$7F08,$0041,$2040,$7F08,$7F40,$7F02,$7F04,$3E41,$7F09,$3E41,$7F09,$4649,$0101,$3F40,$1F20,$3F40,$6314,$0304,$6151,$007F,$0204,$0041,$0402,$4040),cw1
    lookup  executebyte,($5D55,$1112,$4949,$4141,$4122,$4949,$0909,$4949,$0808,$7F41,$413F,$1422,$4040,$0C02,$0810,$4141,$0909,$5121,$1929,$4949,$7F01,$4040,$4020,$3840,$0814,$7804,$4945,$4141,$0810,$417F,$0102,$4040),cw2
    lookup  executebyte,($1E00,$7C00,$3600,$2200,$1C00,$4100,$0100,$7A00,$7F00,$0000,$0100,$4100,$4000,$7F00,$7F00,$3E00,$0600,$5E00,$4600,$3100,$0100,$3F00,$1F00,$3F00,$6300,$0300,$4300,$0000,$2000,$0000,$0400,$4000),cw3
else
    executebyte = executebyte - 96
    lookup  executebyte,($0000,$2054,$7F48,$3844,$3844,$3854,$087E,$0C52,$7F08,$0044,$2040,$7F10,$0041,$7C04,$7C08,$3844,$7C14,$0814,$7C08,$4854,$043F,$3C40,$1C20,$3C40,$4428,$0C50,$4464,$081C,$0402,$0808,$0804,$1020),cw1
    lookup  executebyte,($0305,$5454,$4444,$4444,$4448,$5454,$0901,$5252,$0404,$7D40,$443D,$2844,$7F40,$1804,$0404,$4444,$1414,$1418,$0404,$5454,$4440,$4020,$4020,$3040,$1028,$5050,$544C,$2A08,$7F02,$2A1C,$0810,$7F20),cw2
    lookup  executebyte,($0000,$7800,$3800,$2000,$7F00,$1800,$0200,$3E00,$7800,$0000,$0000,$0000,$0000,$7800,$7800,$3800,$0800,$7C00,$0800,$2000,$2000,$7C00,$1C00,$3C00,$4400,$3C00,$4400,$0800,$0400,$0800,$0800,$1000),cw3
end if
 

kevrus

New Member
Unless you have used all of the available program space, why can't you just have few of the text strings directly in the program and not stored in the table?
 

Lobobo

Member
The LOOKUP command can accept a statement with up to 256 values (pointer = 0 to access the first value).
A consequence of many values in a lookup command is that the commands becomes slower to execute as the number of values increases.............
..........................
if executebyte < 32 then
lookup executebyte,(0,$1020,$4444,$1474................
......................................................................
It's pretty complicated to understand with scratch knowledge the "offsets", "pointers" and sophisticate "lookup" way of using. It's easier for newbie like me to learn thorough practical examples like the example below I worked out of the lookup usage:
for b0 = 0 to 4
lookup b0,("Hello"),b1 ; put ASCII character into b1
pause 2000
next b0
Thats how I am going to get my text strings loaded into variable. First way I use is TABLE, second EEPROM, third lookup as above, fourth if needed external EEPROM. Maybe later on if needed I will try these sophisticate methods to understand better.
Thanks guys.
 

Marcwolf

Senior Member
Nick12ab
Many thanks for that. I have been looking at ways to store animatronic sequences within a PicAxe and this seems to be a god way of doing it. Likewise I am limited with the number of pins I have available for external memory support.
 

KeithRB

Senior Member
It was alluded above, but why not use your own version of LZW? Put all the words in memory by themselves and then also store a number like 0x 011224FF which would use word 1, word 12 and word 24. You can also save all the spaces this way.
 

westaust55

Moderator
Don't forget about all that unused, free RAM too:

http://www.picaxeforum.co.uk/entry.php?36-Extending-PICAXE-named-variables-by-300-or-more!

This will not help with power-off storage, but may optimize your code to allow more table space.

- Ray
Although the OP is seemingly locked into a 28X2 part for the IO count, when considering the M2 parts,
there is already 512 bytes of TABLE memory and for the larger M2 parts also 512 bytes of RAM available.
The extended M2 RAM space (above address 255) would be accessed via the bptr and @bptr functions.

TABLE memory is part of program space and thus non volatile.
 
Top