Loading up the Scratchpad

vk6bgn

New Member
Hello All,

What I would basically like to do (i think) is preload all PICAXE 28X2 scratchpad (1024) memory byte locations with numbers between 2 - 30. (skips a couple numbers) I'm trying to preload the 100 most commonly used words in the English language. I think I need to write (PUT? PEEK?) them consecutively into the scratchpad all at once, but read (GET? PEEK?) them consecutively out only a few at a time. The word THE obviously would be three addresses. And the word THERE would be 5.

And example of the numbers that represent words are, 3,12,2 = THE, 3,16,2,10,2 = THERE, 6,5,9 = AND, 14,16,2,10,2 = WHERE. Obviously they are not ASCII numbers.

I think the question is....... how do I write to 1024 consecutive addresses with 1024 non consecutive numbers into the scratchpad?

I'm sure I can read them out and get them through my Morse routine as spoken words in MORSE, but can't figure how to get them into the scratchpad. :-( (it's probably very simple)

After reading the manual for a while and searching the forums, I can't seem to find anything as simple as EEPROM 0, (3,12,2,3,16,2,10,2 ........) but for the scratchpad. I've use the EEPROM for other stuff so there isn't not much left there to use.


Comments appreciated.

"TheAddict"
 

hippy

Technical Support
Staff member
You could use a sequence of PUT commands ...

Put 0, T_VALUE
Put 1, H_VALUE
Put 2, E_VALUE

Or you can do it using the @ptrinc variable ...

ptr = 0
@ptrinc = T_VALUE
@ptrinc = H_VALUE
@ptrinc = E_VALUE

The later is probably best because it becomes easier to change things without having to renumber PUT locations.
 

Buzby

Senior Member
This type of code will put the ASCII values of the characters into the scratchpad.

Code:
ptr = 0

for b0 = 0 to 20
	lookup b0,("My first set of words"),@ptrinc
next

for b0 = 0 to 14
	lookup b0,("Some more words"),@ptrinc
next

etc ...
 

rossko57

Senior Member
Presumably you'll also want some means indicating end-of-word (else how can you distinguish THERE from THE RED). Buzby's code shows how to include space characters so your interpreter can generate inter-word pauses. You'd probably want some means of distinguishing end-of-sentence too, else it'll be difficult to recover them from scratchpad. A trailing space character would do, perhaps.

I can feel "The quick brown fox ..." coming on, followed by "Now is the time for all good men ..." ;)
 

westaust55

Moderator
Are you able to consider adding an external i2c EEPROM? You can store lots of data then and need only 2 IO pins.

There has been discussion about how to define the end of each word. How are you planning to address the starting point for each word? Usually some form of lookup table is required since the words are of varying length.
If it is only going to be a lookup for text words and say in uppercase only (so highest character ASCII value is $7F) then you could set the most significant bit high as the marker for the last character in a word.
 
Last edited:

Buzby

Senior Member
... How are you planning to address the starting point for each word? ...
Another idea is to make every word exactly 10 characters, using spaces to pad them out. Then a random number between 0-100, multiplied by 10, will give a 0-1000 pointer to the start of each of the 100 words.

A bit wasteful of the EEPROM capacity, but meets the Top 100 Words requirement, and is really easy to program.
 

vk6bgn

New Member
Thanks All,

Some really great ideas to pursue.

@Hippy, that's a lot of PUTs to put at least a few hundred values into the Scratchpad. Would be really nice if there was something like SCRATCHPAD 0, (#, #, #, #, #, #, ,,,,,,). Just like using EEPROM 0 (#, #, #, #, #, ,,,,,,,)

Thanks Everyone.
 

inglewoodpete

Senior Member
Thanks All,

Some really great ideas to pursue.

@Hippy, that's a lot of PUTs to put at least a few hundred values into the Scratchpad. Would be really nice if there was something like SCRATCHPAD 0, (#, #, #, #, #, #, ,,,,,,). Just like using EEPROM 0 (#, #, #, #, #, ,,,,,,,)

Thanks Everyone.
Scratchpad, being volatile RAM cannot be preloaded like EEPROM or TABLE.

However, if you check the syntax of the PUT statement in the manual, you will see that it can be configured like the EEPROM, TABLE or POKE statements. Of course, like the POKE command, it is executed at runtime.
 

Goeytex

Senior Member
Just playing around ....

Code:
#Picaxe 28X2

Symbol EW = 254 'END OF WORD  


Put 0,3,12,2,EW,3,6,2,10,2,EW,6,5,9,EW,14,16,2,10,2,EW
;     T H  E    W H E R  E    A N D    T  H  E  R E
Put 20, 10,6,14,EW,3,6,10,EW,10,2,9,EW,9,2,6,9,EW,12,6,14,14,2,10,EW 
;       R  A T     W A R     R  E D    D E A D,   H  A T  T  E R         

'Test
For ptr = 0 to 43
  
  if @ptr <> EW then
   sertxd (#@ptr,",")
 
  else 
       sertxd ("  ")
  endif

next
 

hippy

Technical Support
Staff member
One trick to make entering and setting 'letter values' a little easier is to use actual ASCII characters and then run through the scratchpad to convert each ASCII character to the actual letter value desired.

Also take a look at the TABLECOPY command which can help in moving data specified in TABLE commands into scratchpad.
 

vk6bgn

New Member
Hi Hippy,

Thanks for the advice. I used to use ASCII numbers but eventually settled on the following a few years back with a little help from others. It's pretty easy. Just a modulus divide, odd or even = dot or dash. Keep shifting right until the encoded number equals 1. Example, the encoded number for the letter H = 16. And so, // 2 divide is 0, 0 ,0 ,0. A zero = a dot and four dots equals a letter H. But you probably knew that. ;-)

I have been looking at Table and Table copy too.

Thanks Again.


Code:
Morse:

	If b18 = 5 then Gosub WordSpace    'counter for 5 letter groups
	If b12 = 0 then WordSpace
	Do
	b14 = b12 // 2             'returns remainder, odd(1) or even(0) = (dit or dah) b12 = encoded character number
	b12 = b12 / 2              'shift right
	If b14 = 0 then Gosub dit
	If b14 = 1 then Gosub Dah

	Loop until b12 = 1
	Gosub CharacterSpace
	Return


	Dit:
	High C.4              'Relay on
	High C.3              'LED on
	Sound C.5, (b2,b4)    'Sound on 
	Low C.4               'Relay off
	Low C.3               'LED off
	Sound C.5, (0,b4)     'Sound off  
	Return

	Dah:
	High C.4
	High C.3
	Sound C.5, (b2,b5)
	Low C.4
	Low C.3
	Sound C.5, (0,b4)
	Return

	CharacterSpace:
	Sound C.5, (0,b5)
	Return

	WordSpace:
	Sound C.5, (0,b7)
	b18 = 0              '5 letter groups reset
	Return
 

mrburnette

Senior Member
I used to use ASCII numbers but eventually settled on ...
Based upon my old post http://www.picaxeforum.co.uk/entry.php?30-Notes-behind-Magic-Morse
This example (Will run in Simulator for 28X2) uses both TABLE and EEPROM to store words which are separated by a comma. The word list came from Wikipedia and I have only implemented a few just to have something to run in the simulator. Building out the EEPROM and TABLE would be required. A spreadsheet of the Wiki stuff is attached showing where I would anticipate the logical break to occur.

Code:
' Demo code storing common words into ScratchPad
' M. Ray Burnette, 2013 based on Magic Morse number

' Variables used: B1, B2, B3, B11, B12, B13, B14, B15
' 400 Bytes / 4096
#picaxe 28x2
'
'
' Test will load Scratchpad to location 115
'
' Pre-Load Scratchpad RAM from EEPROM
ptr = 0
For B2 = 0 to 77 ' Word #60== 240 Bytes
	Read B2, B1
	@ptrinc = B1	
NEXT
' Repeat pre-loading of Scratchpad RAM from TABLE

FOR B2 = 0 to 37 ' last Word in TABLE is 'US," = word 100
	ReadTable B2, B1
	@ptrinc = B1
NEXT


' Generate a listing of Common Words loaded in ScratchPad
PTR = 0	' Initialize for beginning of ScratchPad
B1 = 999	' read ScratchPad until a null is found
DO WHILE B2 != 0
	B2 = @PTRINC
	B1 = B2
	IF B1 = 44 THEN ' a comman separates individual words
		SerTxd("Next Word...")
	ELSE
		B1 = B2 - 65	' Normalize ASCII Lookup Syntax
		GoSub ASCII2MM	'B3 = MM#
		GoSub DITDAH
		SerTxd ("Character: ",B2," Lu: ", #B1,"Morse Code is ",B11,B12,B13,B14,B15)
	
	ENDIF
LOOP

END

ASCII2MM:
	'Literal     A, B, C, ...  Z
	'ASCII	65, 66, 67 ... 90
	Lookup B1, (18,12,44,11,1,36,27,4,2,116,43,20,26,10,59,52,92,19,3,9,35,68,51,76,108,28), B3

RETURN

DITDAH:
	'B3 = MM#	' Magic Morse number

	B11 = " "	' DIT = . or DAH = - or NOT TRANSMITTED = " "
	B12 = " "	' DIT = . or DAH = - or NOT TRANSMITTED = " "
	B13 = " "	' DIT = . or DAH = - or NOT TRANSMITTED = " "
	B14 = " "	' DIT = . or DAH = - or NOT TRANSMITTED = " "
	B15 = " "	' DIT = . or DAH = - or NOT TRANSMITTED = " "

	If B3 > 128 then : B15 = "-" : B3 = B3 - 129 : ENDIF
	If B3 > 64  then : B14 = "-" : B3 = B3 - 65  : ENDIF
	If B3 > 32  then : B13 = "-" : B3 = B3 - 33  : ENDIF
	If B3 > 16  then : B12 = "-" : B3 = B3 - 17  : ENDIF
	IF B3 > 8   then : B11 = "-" : B3 = B3 - 9   : ENDIF
	
	IF B3 > 0 AND B11 = " " then : B11 = "." : B3 = B3 - 1 : ENDIF
	IF B3 > 0 AND B12 = " " then : B12 = "." : B3 = B3 - 1 : ENDIF
	IF B3 > 0 AND B13 = " " then : B13 = "." : B3 = B3 - 1 : ENDIF
	IF B3 > 0 AND B14 = " " then : B14 = "." : B3 = B3 - 1 : ENDIF
	IF B3 > 0 AND B15 = " " then : B15 = "." : B3 = B3 - 1 : ENDIF
RETURN

' 100 Most common English Words from Wikipedia split between EEPROM and TABLE
EEPROM 0,  ("THE,")
EEPROM 4,  ("BE,")
EEPROM 7,  ("TO,")
EEPROM 10, ("OF,")
EEPROM 13, ("AND,")
EEPROM 17, ("A,")
EEPROM 19, ("IN,")
EEPROM 22, ("THAT,")
EEPROM 27, ("HAVE,")
EEPROM 32, ("I,")
EEPROM 34, ("IT,")
EEPROM 37, ("FOR,")
EEPROM 41, ("NOT,")
EEPROM 45, ("ON,")
EEPROM 48, ("WITH,")
EEPROM 53, ("HE,")
EEPROM 56, ("AS,")
EEPROM 59, ("YOU,")
EEPROM 63, ("DO,")
EEPROM 66, ("AT,")
EEPROM 69, ("THIS,")
EEPROM 74, ("BUT,")
' EEPROM 78 - 240 goes in here...

TABLE 0,  ("PEOPLE,")
TABLE 7,  ("INTO,")
TABLE 12, ("YEAR,")
TABLE 17, ("YOUR,")
TABLE 22, ("GOOD,")
TABLE 27, ("SOME,")
TABLE 32, ("COULD,")
' TABLE 38 --> go here
Simulator output looks like (Lu is the LookUp number derived by substracting 65 from the ASCII value):

Character: T Lu: 19Morse Code is -
Character: H Lu: 7Morse Code is ....
Character: E Lu: 4Morse Code is .
Next Word...

Character: B Lu: 1Morse Code is -...
Character: E Lu: 4Morse Code is .
Next Word...

Character: T Lu: 19Morse Code is -
Character: O Lu: 14Morse Code is ---
Next Word...

Character: O Lu: 14Morse Code is ---
Character: F Lu: 5Morse Code is ..-.
Next Word...
View attachment 100CommonEnglishWords.zip
 
Top