Shop OBEX P1 Docs P2 Docs Learn Events
Jumping from 2.7 to 5.7 — Parallax Forums

Jumping from 2.7 to 5.7

From JUNO Extend:
\ Define common variable sizes

pub DOUBLE 8 4 [C] AVAR ; IMMEDIATE
pub LONG 4 4 [C] AVAR ; IMMEDIATE
pub WORD 2 2 [C] AVAR ; IMMEDIATE
---
pub BYTE 1 1 [C] AVAR ; IMMEDIATE

How is this done in 5v7.
p.s. - I am digging before I ask but am stumped.

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2020-02-29 03:00
    @artkennedy - I think I can answer your other post and this one together. First off, ANS Forth mixes variables and headers and code all together which is a real mess and does not stop variable or buffer overruns from messing up other variables and headers and especially code, which would lead to more code getting messed up etc. Ugly, very ugly.

    Tachyon is an embedded Forth for the Propeller and not only has to reliably run in products 24/7, but it has very little memory to do it in compared to many micros, even small micros. So Tachyon separates code, dictionary headers, and data both for reliability and also for managing memory better. The dictionary can have private "pri" headers that can be stripped out and the dictionary shrunk, and whole data structures can be erased in one hit since the memory locations are contiguous, rather than variable by variable.

    Now back to what this means for variables and for tables.
    In Tachyon if you want to have a variable for a single byte you say "byte myvar". If you want 16 bytes you say that too with "16 bytes myvars". If you want a 16-bit word or a long or many of them you do the same. But TABLE is different, unlike variables that can change and be lost on power-ups (if not backed up), the contents of the table are meant to be fixed constants, such as a look-up or conversion table. So when you say "TABLE mytable" it creates a "variable" in code space but does not allocate any memory. It is up to you to fill that table with as much as it needs. This is what the | and || and , does in that it will take that value and compile it as a byte, or word, or long, into the next location in the table in code memory. The more you add, the more it uses, there is no need to preallocate memory with ALLOT which really is not what you want. In fact there is no way to "compile" values into that memory that has been allocated, you can only store it there by indexing the table etc which is what I do for more complex methods of generating table values. Otherwise don't do it.

    Don't forget to interact and play "what ifs" with Tachyon, even just for a sanity check.

    Confirm where the code pointer is:
    ...  HERE .W --> 3C84  ok
    

    Create a new 32-bit variable
    ...  long alongvariable
    

    Confirm that it is indeed not in code memory:
    ...  alongvariable .W --> 7604  ok
    ...  HERE .W --> 3C84  ok
    

    Try some more and confirm that the address advances accordingly:
    ...  4 longs astack
    ...  astack .W --> 7608  ok
    

    Now double check what TABLE does:
    ...  TABLE mytable
    ...  mytable .W --> 3C88  ok
    ...  HERE .W --> 3C88  ok
    

    Sp no memory was allocated for the table except for the code that returns with the table address.

    BTW, uses lower case for byte/word/long etc. V3 still used upper-case for this whereas V5 has it in lower case and doesn't try to convert upper and lower since this can be the source of many code bugs when variables and code have the same name but different case.

    btw - Conventional Forths use C, and W, perhaps to compile byte and word values, just like it does when it uses , to compile a 32-bit value (for 32-bit Forths). But I found that makes for a very messy looking table and hard to read. Which is easier to read?:
    TABLE rtcs	0 C, 1 C, 2 C, 4 C, 5 C, 6 C, 3 C,
    		2 C, 3 C, 4 C, 5 C, 7 C, 8 C, 6 C,
    
    or
    TABLE rtcs	0 | 1 | 2 | 4 | 5 | 6 | 3 |
    		2 | 3 | 4 | 5 | 7 | 8 | 6 |
    

  • Thanks Peter. This is very helpful.
  • I just need to calm down. The tools don't fit my hand anymore - but they will.
  • MJBMJB Posts: 1,235
    artkennedy wrote: »
    I just need to calm down. The tools don't fit my hand anymore - but they will.

    it is a pitty that interesting comments by @"Peter Jakacki" like the one above get lost in the forum threads,
    especially if new ones are started all the time and not the main Tachyon threads are used.
    I have been a bit lazy recently collecting those snippets in THIS document.
    some parts are a bit old, but maybe still helpful.
  • What I'm up to is building a system to control cheap 433.92 MHz RF controlled relays from various manufacturers and do things with them that can't be done with the little hand held remotes. The greatest number of relays from a given manufacturer that I have found is six. I want to do some experiments to see if I can send additional codes for more relays.
    I want to operate the clock for the system only when needed which will be a very small percentage of the time in order to save power. So I want to be able to run the clock cog only when it is needed. Using this code I can run the clock and stop it but when I attempt to restart there is not response. I could use a workaround for this but it would be better if it is possible to restart the cog. Can this be done?
    Perhaps the cog is not really stopped because .TASKS still lists it but it is no longer switching the pin.

    : RFCLOCK --- runs independently except for starting and stopping
    rfclkdur W@ --- nominal duration of clock pulse
    5 - --- adjust for processing delays
    2 / --- 50% duty cycle
    BEGIN --- begin
    0 HIGH DUP us --- leading edge
    0 LOW DUP us --- trailing edge
    AGAIN --- until COGSTOP
    ; ---

    600 rfclkdur W!
    : CLOCKSTART ' RFCLOCK 6 RUN ;
    : CLOCKSTOP 6 COGSTOP ;
  • Isn't it easier to setup a counter to output the frequency you want?
    0 APIN 250 KHZ
    

    When you want to stop it:
    MUTE
    
Sign In or Register to comment.