forgive my ignorance

johnlong

Senior Member
Hi All
Just a quick question
Playing around with the 40x2 the manual states that it can have a program length of
4096 ish bytes. Ok thats fine but it has 4 slots that all can have 4096 bytes in each
16K in total
So the question is when you download the program does the editor compress the code down
and if so in to how many bytes and where within the chip is the program and subsequent slots
stored.
Can I take it that after the slot directive is issued the slot that the program is in is compressed
and the slot pointed too is then uncompressed.
Also do you need to declare at the begining of each slot the symbols as defined in slot0 or will
these be passed automatically between the slots
regards
john
 

oracacle

Senior Member
each slot is its own programme, I don't think there is any compression going on, seems it would be too bulky and time consuming to decompress

you can share symbols using an include directive, same goes for shared sub procedures. If you don't do this you will have to declare in each slot. When your code is compiled each will get a copy of the included file so it does not work as cheat to save programme space - its the same as typing out all symbols and sub procedures for each slot.

variables are however maintained, if you store the 3 in b0 and then call run 1, it will still contain the number 3.

I very much doubt you will get answer on where its stored, the code is interpreted by the boot loaded firmware - this is the bit that makes the picaxe unique and as far as we all can tell is closely guarded secret on how it works. the firmware is loaded and the picaxe facility and can not be downloaded for examination and reverse engineering.
 

lbenson

Senior Member
You have to divide your program up yourself, transfer control to other slots, usually having a value in some variable which will tell your code what to execute. Then when you return to the main slot, you must have a way to resume program execution at the point you want, without going though any initialization code which you execute upon power up. I use a select statement at the start of each slot to go to the subroutine I want. For instance:
Code:
select routineNumber
  case: "1"
      gosub routine1
  case: "2"
      gosub routine2
 end select
As oracacle says, all variables (b0, w0, etc.) and all ram and scratchpad and eeprom spaces are available, but not your symbol names for the variables unless you separately rename them, or, preferably, create a file of definitions (but usually no code) which you include in your program for each slot.

You download the programs to each slot separately.
 

johnlong

Senior Member
Thanks for the response
As you have instructed Ibenson I have followed that methology already over the 3 slots it was more
a question of seeing whats ticking inside the slab of black not as a reverse engineering exercise
just more like a car take it apart see what moves and where you trap yer fingers thing
baffling to me how you can have only 1 programe at 4k but the chip can hold 16k over 4 slots
thats why I assumed there must be some squashing of size going on or 12k floating around that
could be land grabbed.
With the 4k limit being within editor its self or the loading of the program (firmwear hope that makes sense)
Just have to keep copying and pasting the symbols to the top of each slot then
regards
john
 

techElder

Well-known member
Just have to keep copying and pasting the symbols to the top of each slot
johnlong, I don't think anyone has said just the right thing about SYMBOLs within each SLOT. The right thing is something called #INCLUDE "filename". That's where you develop and save your SYMBOL definitions one time in one place.

The #INCLUDE "filename" is placed in the program for each slot near the top.

Look it up here: http://picaxe.com/BASIC-Commands/A-Z/
 

inglewoodpete

Senior Member
Managing the use of the slots in you 28X2 or 40X2 is an exercise in itself.

I built a 40X2 based home theatre controller a few years ago and needed to use 3 slots to fit all the code. I modularised the code into slots for the program's kernel (Slot 1), the menu system (Slot 2) and I/O routines including 16 x 2 LCD (Slot 3). At the time I wrote the program, there was no option to have #include files.

I used a single file for all the code but use #define/#ifdef/#ifndef/#endif for conditional inclusion/exclusion of code in each slot. I found it easier to manage all code in one file, although it made for a large file. Things like the symbol definitions and interrupt routine are included in each slot, since they are fairly universal.

The PIC18F25K22 (28X2) and PIC18F45K22 (40X2) each have 32k of Flash. Obviously, Rev-Ed can fit the PICAXE's 'personality' (firmware) into 16k of that flash (actually, more like 12k), leaving 4 x 4k for the four slots of user program.

By contrast, the PIC18F14K22, used for the 20X2, has a total of 16k of flash and is limited to only 4k of flash available for the user program.
 

johnlong

Senior Member
The #INCLUDE "filename" is placed in the program for each slot near the top.

Look it up here: http://picaxe.com/BASIC-Commands/A-Z/
Thanks for that Tex thats one I have not seen before
It states that it should be saved in Ascii or some UT never heard of formate
So when declaring the symbols do I need to write them as such
"symbol RT=b1" within the basicinc file or is there an option to save them as an Ascii through the save as route

Boy you have scared me Inglewoodpete never seen so many #
I have gone for the route of setting a variable as a flag so when that condition is met the Run slot command is enacted with the return back to the menu via
the setinterupt on detection of a pin going high
I too have wrote the whole code as one but as things have expanded reming out the sections that I am not working on becomes a chore so I have split it up into
3. Now looking like it may become 4 (LCD's are so hungry they just love a big chunk to byte at) think I will move the setting up of the ds1307 into its own menu
Leaving the settting of the variables and dirs in slot0 date and time slot1 back too slot0 off to 2 or 3 depending on the choices made
regards
john
 

lbenson

Senior Member
Picaxe basic files are ascii text files, so just save your includes as you would any other program.

For instance, I have 20htmlServer_includes.bas and 40htmlSecurity_includes.bas.

Then in each slot I have

#include "c:\dl\picaxe\20htmlServer_includes.bas"
 

johnlong

Senior Member
Thanks Ibenson
never knew that the basic was in ascii to be honest never thourght about what formate it was in
just the program type away and get frustrateted latter has being my motto:confused:
 

inglewoodpete

Senior Member
Boy you have scared me Inglewoodpete never seen so many #

I too have wrote the whole code as one but as things have expanded reming out the sections that I am not working on becomes a chore so I have split it up into
I think you have misunderstood my use of #define/#ifdef/#ifndef/#endif. They do the conditional inclusion/exclusion of code for each slot without doing all that REMing that you refer to. Just change one "#define" and you can reprogram a different slot.
 

hippy

Technical Support
Staff member
For anyone who has never used #SLOT or #INCLUDE directives, my simple example code is shown below. This consists of three files, an include file which contains a symbol definition both slot programs will use, and two program files for two slots. All my files are in a C:\tmp directory; change that to suit whatever directory name you are using -

Code:
; This file is "C:\tmp\symbols.basinc"
Symbol counter = b0
Code:
; This file is "C:\tmp\slot0.bas"
#Slot 0
#Include "C:\tmp\symbols.basinc"
counter = counter + 1
SerTxd( "Slot 0 = ", #counter, CR, LF )
Pause 500
Run 1
Code:
; This file is "C:\tmp\slot1.bas"
#Slot 1
#Include "C:\tmp\symbols.basinc"
counter = counter + 1
SerTxd( "Slot 1 = ", #counter, CR, LF )
Pause 500
Run 0
When the program is run, and you open a terminal window with the appropriate baud rate, you should see lines alternating between "Slot 0 =" and "Slot 1 =" with an incrementing 'counter' value.
 

tmfkam

Senior Member
Like JohnLong I'm curious about the 4k 'slots'.

Why 4k? Why, if there is room for 16k of program, can we not have one program, of 16k? Two of 8k? Three of 2k and one of 10k etc.?

Is 4k the maximum program that can be held in RAM by the PicAxe interpreter and still leave enough RAM to execute the byte code produced by the PicAxe interpreter? (Assuming that is how the PicAxe system works within the PIC.) Or is there another reason?

Like I say, just curious.
 

AllyCat

Senior Member
Hi,

AFAIK the answer is the (program memory) "address space". The early versions of Basic didn't have "labels" just a GOTO <line number> command, where the number had some finite limit.

Similarly, the PIC instruction set (i.e. the assembler code which the editor/compiler must produce) has instructions made up from a limited number of bits. For an M2, it's 14 bits of which 3 bits are the "opcode" (e.g. Jump/GOTO) and the remaining 11 bits are the address, i.e. 1 of 2048 locations (the slot size). The base chip of the X2 looks rather more complicated but one of the Jump instructions has a 4 bit opcode and 12 bits of address field (i.e. 4096 addresses).

If the chip has more address space, it can be considered as being divided into "pages" of memory (cf Slots), but the program needs to use special methods to jump between them. One "easy" way for the editor/compiler to handle that is to force the program-writer to treat them as (almost) separate programs. ;)

Cheers, Alan.
 

johnlong

Senior Member
Nice one Allycat
2 bits more for double bubble then it also clears up why you can not have duplicate lables in the program, so much more thourghtful then goto line 23 if line 23=x then line 678 boy would that be a pain struggle with words and only got 10 fingers (or 0 to 9)

regards john
 

hippy

Technical Support
Staff member
Why 4k? Why, if there is room for 16k of program, can we not have one program, of 16k? Two of 8k? Three of 2k and one of 10k etc.?
At the proverbial end of the day there are a whole range of options and one either has to pick one, a subset, or allow multiple options or subsets. Some will favour one choice and others will prefer another. We chose the 4K slot option, and that allowed for 4 slots.

I can't recall all the issues and details which got debated and the arguments for and against but 4K was ultimately the option chosen, considered appropriate for the majority of PICAXE users while also being flexible enough for those who wanted more than one slot. That seems to have been proven to be the case.

Not everyone will agree the choice was the best one to make but that would likely be said of whatever choice had been made.
 

techElder

Well-known member
I like the idea of the choice staying consistent through time. Consistency is what I value most with the PICAXE.
 

tmfkam

Senior Member
At the proverbial end of the day there are a whole range of options and one either has to pick one, a subset, or allow multiple options or subsets. Some will favour one choice and others will prefer another. We chose the 4K slot option, and that allowed for 4 slots.

I can't recall all the issues and details which got debated and the arguments for and against but 4K was ultimately the option chosen, considered appropriate for the majority of PICAXE users while also being flexible enough for those who wanted more than one slot. That seems to have been proven to be the case.

Not everyone will agree the choice was the best one to make but that would likely be said of whatever choice had been made.
Thanks Hippy, and all others who replied and explained.

Presumably as the program code in the original PIC is static, once it is compiled and loaded into it's page of memory space all the jumps and GoTo's stay in their allocated page locations which may not be the case for a BASIC program which is being converted to byte code 'on the fly' as the program is executed?
 

hippy

Technical Support
Staff member
Presumably as the program code in the original PIC is static, once it is compiled and loaded into it's page of memory space all the jumps and GoTo's stay in their allocated page locations which may not be the case for a BASIC program which is being converted to byte code 'on the fly' as the program is executed?
User programs use variable-size tokens so it is not quite as inflexible as native PIC memory, but yes, once the program is compiled and downloaded the GOTO addresses are all fixed and only reference within the slot downloaded to. Only the RUN command allows a jump from one slot to another.
 

AllyCat

Senior Member
Hi,

Revolution Education Ltd,
Unit 2 Industrial Quarter,
Bath Business Park,
Foxcote Ave,
Bath,
Somerset,
England,
The United Kingdom,
Europe, (no comment)
The Earth,
The Solar System,
The Milky Way Galaxy,
The Universe.

Generally it's more efficient to quote just a "Local" Address and then use (e.g.) a "RUN {in} AUSTRALIA" and load the associated TomTom map (cf SLOT) when necessary. ;)

Cheers, Alan.

PS: You could amuse yourself estimating how many binary data bits each of those lines represents.
 
Top