FORTH for the new AVRmegas?

Go To Last Post
35 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I saw ATMEL has some chips with 8k SRAM
on-board. Does anybody think a small FORTH
system could be developed so that once the
FLASH was programmed,, the chip could
basically run stand-alone.

I once had a Rockwell Chip that needed 8k,
so I think it's possible.

Any thoughts or ideas? -Joe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FORTH?

JChristoff
Illinois

Last Edited: Fri. Jan 7, 2011 - 04:22 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Joe,

Have a look at:

http://www.atmel.com/products/AV...

Apart from the FORTH that jgrunt mentions it seems like there's another couple to choose from.

(having done FORTH implementations (on PDP11s!) as a final year project at university 22 years ago I'm not sure I'd be in that great a hurry to bother with it on an AVR - but each to his own!)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmm. Used to do forth on 8080s. Probably wouldn't be hard on an AVR.

I about got kicked out of AI class when I commented, "Oh, just like in Forth," on some LISP feature :roll:

---
Formerly Torby. Stitch626 just seemed a more descriptive nicname.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When it comes to FORTH, the world is divided into 3 groups
1. Those who love it.
2. Those who hate it.
3 Those who know nothing about it.

Much , if not all, of your FORTH application could be in Flash as you will not be changing it. SRAM for code would only be required if you wish to change it on the fly. SRAM for stored variables and the 2 stacks would be a small fraction of 8K.

Laurence Boyd II

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please forgive me in advance. Are you saying that FORTH is the Islam of programmers?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I remember buying a plug-in ROM cartridge for the FORTH language for a Commodore VIC-20 back in 1985. Since nearly all the ROM cartridges for this ancient 1st-generation home computer were simple video games, and at the time video games were considered to be toys, the FORTH cartridge was only available at Toy's-R-Us (a large chain of toy stores in the USA).

I thought that it was odd that the only place that I was able to buy an advanced computer language was at a toy store. This was due to a series of marketing misclassifications at the time.

I would recommend not using FORTH and use C or assembler instead for programming the AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Are you saying that FORTH is the Islam of programmers?

Now, you could have talked all day and not said something like that :P

Half the department used and liked FORTH. The other half argued that we shouldn't and continued to use assembler. I switched between the two quite handily.

---
Formerly Torby. Stitch626 just seemed a more descriptive nicname.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
I remember buying a plug-in ROM cartridge for the FORTH language for a Commodore VIC-20 back in 1985. Since nearly all the ROM cartridges for this ancient 1st-generation home computer were simple video games, and at the time video games were considered to be toys, the FORTH cartridge was only available at Toy's-R-Us (a large chain of toy stores in the USA).

I thought that it was odd that the only place that I was able to buy an advanced computer language was at a toy store. This was due to a series of marketing misclassifications at the time.

I would recommend not using FORTH and use C or assembler instead for programming the AVR.

If what's wanted is an on-board interactive dev system, them C and assembler won't do the job. A FORTH or a Tiny BASIC or something of that sort would be. The first FORTH I used was an 8K version for the 6502 in the AIM 65 computer (you think a Vic-20 is 1st generation? It booted to BASIC, had built-in keyboard and video interface,and you didn't even have to solder any of it together! Try programming with toggle switches and panel lights or LEDs for an IDE.) ;)

Anyway, check out:
http://claymore.engineer.gvsu.ed...

This looks like what's wanted.

-Mark G.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I missed posting this link, too:
http://www.tinyboot.com/avr.html

It's not as complete a package as pfavr, but it's small. Both packages have plenty for the do-it-yourselfer to work on, but pfavr can be run as-is on a larger device (ATMega64 or 128.)

-Mark G.
(Who won't even start to get into the religious divides _among_ FORTH programmers, such as those who think the ANS standard is the worst thing that ever happened to FORTH and those who blindly believe in standards organizations that develop standards that break the predominant version of what they're claiming to write a standard for but it's OK since nobody gets profits off of it except the users.) :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
Please forgive me in advance. Are you saying that FORTH is the Islam of programmers?

I think a more accurate characterization would be that FORTH is the bagpipe music of the programming world.

-Mark G.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I set -up a couple of mega128 FORTH development boards using PfAVR FORTH
and it was GREAT! I wrote the programs
using a PC terminal program. I would try things
out and when it worked as expected, I would
keep it as a word to use later... Anyway
it takes 32k of external RAM. I'm hoping for
a complete on-chip solution. I guess till then
I use the 128 w ext 32k...

Regarding using FORTH. OK I am no programmer.
I'm a hardware hack that loves cpu's with a bunch
of boxes all on one chip.. hence the AVRmega128.

I got the C compilers, love the GCC and ATMANAVR, CodeVision, etc.. I did OK.
I was able to pretty much gain control of the BUTTERFLY. From that I learned a lot about
C programming. But when I put together the
mega128 and pfAVR system life got easy.

It is just to good to be true to be able to try things
out quickly. Verify it works and then use it later.
Forth has some time overhead but the CPU runs so fast... It's probably true that for complex programs
that real C compiler development is better.
However,, to read the thermistor and set the
relay on and beep ... maybe FORTH is the answer.

God willing... -Joe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
It is just to good to be true to be able to try things
out quickly.

Compile and downloading a C-snippet takes < 5 seconds with JTAG. The code in question can probably be written at least as fast in C as in Forth (unless it's a very simple thing), so I really don't see the advantage.

We used a Forth system in the testing phase of a new matrix printer once, and it worked really nice there, but then again, it would take more than a minute to compile and link a program with the C compiler we had then.

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As an experiment once, I wrote a CP/M bios in polyforth. Worked slick and took up little ram.

---
Formerly Torby. Stitch626 just seemed a more descriptive nicname.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using IRTC Forth from Ram Technology Systems. See: http://www.ram-tech.co.uk/

It costs 190 pounds with an ISP programmer. You can develop interactively on many of the AVR chips.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I ported the 6800 fig forth to our company's 6800 based computer (70s? 80s?). A couple of the hw guys loved it because they could peck in a small 'read-write this address in a loop' program real quick to test something. My observation was that the forth code was a bunch of subroutine calls that normally would be 3 bytes... an opcode and an address... but the opcode was eliminated because the instruction interpreter just fetched the operand addresses. This made the code 66% the size of the equivalent assembler program. Magic! And this was back when 4K or 8K was all the rom you had. Not so much of a win today though.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Forth is just magically delicious! I've been using it since the '70s for everything from
very small to quite involved embedded industrial applications, and recently for
some medical instruments employing color graphics, touch screens etc. Starting
in 1989, the general public got what I suspect was their first exposure to real life
graphic imaging presented on PCs along with touch screen interfaces in the form
of a drivers license testing system I developed in Forth.

Forth has some huge advantages:

About only "development system" you need is the actual hardware you are
designing/building, and a pc for dumb terminal/file storage functions.

Forth code is very compact, easily readable, and usually well "structured"
(because it pretty much has to be).

It runs almost as fast as assembly language.

The "write-some-code/test-the-code" cycle is not just fast, but pretty much
instantaneous. Complex bug free systems can be developed *very* quickly.

Program security is pretty good because a Forth program's object code is
pretty much un-decipherable gibberish.

Tom Pappano.
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Many things can be said about Forth, but this

Quote:
easily readable
is not one of them !

Quote:
Program security is pretty good because a Forth program's object code is
pretty much un-decipherable gibberish.
You did mean "source code", right ? ;-)

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Instead of something like:

    for (;;)
    {
        for(uint8_t i=0; i<8; ++i)
        {
            putstr("eat more possum");
        }
    }

You have:

begin 8 0 do ."eat more possum" loop again

All those C brackets, parens, and other junk are just pointless clutter 8-)

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try those two snippets at any noob (or expert even), or non-programmer and see which one is most understandable !

There's also a lot of subtle things that's clear from the C-code, but not from the Forth code, such as variable size and contents.

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tpappano wrote:
All those C brackets, parens, and other junk are just pointless clutter 8-)

#define endlessly for (;;) 
#define begin {
#define again }

    endlessly 
    begin 
        for(uint8_t i=0; i<8; ++i) 
        begin 
            putstr("eat more possum"); 
        again 
    again 

:D

Last Edited: Mon. Oct 31, 2005 - 05:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I heard Adobe put 2 teams on doing postscript way back when... a team using c and sw design and a team using forth and the forth guys were like done before the c guys had anything. This might all be folklore.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I heard Adobe put 2 teams on doing postscript way back when... a team using c and sw design and a team using forth and the forth guys were like done before the c guys had anything. This might all be folklore.

Folklore or not, what do you think Adobe written in today ?

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
All those C brackets, parens, and other junk are just pointless clutter

while (1) for(uint8_t i=0; i<8; ++i) putstr("eat more possum");

Is this better ? It's exacly the same, but a LOT more unreadable than the original "good style" C-code.

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Try those two snippets at any noob (or expert even), or non-programmer and see which one is most understandable !

Forth got its start as a language to program the computer that
controlled the Kitt Peak telescope. The language was specifically aimed at computer "noobies", the astronomers etc. who had little
or no computer experience. They did however, have skills using
RPN calculators, and RPN is one of Forth's nicest features. They
easily learned how to use Forth, and discovered the next neat
thing, that Forth's natural "information hiding" made Forth a
"language to write languages in".

Quote:
There's also a lot of subtle things that's clear from the C-code, but not from the Forth code, such as variable size and contents.

Normally, parameters are passed on the stack, and variables
are mostly needed only for data of global interest. They can
be defined as singles, doubles, floats, etc. similarly to C. In the
example given, there were no variables, so their size or content
didn't matter. The "size" of a parameter on the stack is not that
important, because the function that left it, and the one that will
use it, already know how big it is and what to do with it 8-)

Tom Pappano,
Tulsa, Oklahoma

ps I suspect that C is so prevalent more because AT&T
drove its usage by a large number of programmers. Much
like the Microsoft operating systems though very widely used,
are very poor.

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I suspect that C is so prevalent more because AT&T drove its usage by a large number of programmers.
That may have been of some importance, but the accessibility was probably much more important. In the 80'es when Turbo Pascal came out, everyone and his grandmother were writing Pascal. That was until Turbo-C (and later the Borland C packages) came out where they all switched to C. Forth were peeking up it's nose at about the same time, but was not easy to get and for most people, impossible to read, so it quickly faded. I tried Forth quite a bit then, and so did a lot of my friends and colleagues, and we were all skilled in punching our HP-25 RPN calculators, but still, there was no chance in hell Forth was going to be taken seriously.
I think the only really good thing about Forth was it's interactivity, as a interprting language, but it was just way too awkward. And inaccessible.

Quote:
Much like the Microsoft operating systems though very widely used, are very poor.
Yes, it's amazing that 90% of desktop OS users use it, itsn't it ? ;-)

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

People can, and do, write unreadable code in any language. Writing good code, readable in terms of the problem you are solving, takes work. It also requires that you be comfortable with the language you are using. There is no universal language for all. Even if there were, some would still write bad, unreadable, code with it. :(

Laurence Boyd II

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
People can, and do, write unreadable code in any language.
Ofcourse. I've seen many examples of C being misused. Just looking at the obfuscated C-contest entries is a good example. I've seen noobs write almost as bad code :(
But, how do you write readable, well documented and easily mantainable code in Forth ? Or in something like APL? A colleague of mine was an APL expert and used it a lot back in the 80'es. He used to describe it as a "write-only" language. ;-)

/Jesper
http://www.yampp.com
The quick black AVR jumped over the lazy PIC.
What boots up, must come down.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
He used to describe it as a "write-only" language.

In my good old days of VAX/VMS we used to have fun: The native compilers could take its input from SYS$INPUT (similar to Unix stdin) thus being fed from the keyboard. You'd go for a simple small program (say a hi-lo-game) and hopefully get it right. So now we had binary object code without having the source file. Link it and Your executable is ready. That is write only. 8) I know of no-one that tried this with a COBOL program though (if You've ever seen COBOL You get it...)

I suppose a similar trick could be acheived on Unix/Linux by redirecting stdin.

APL was an interesting language as I recall it, but more or less demanded a specially designed terminal. Lots of special symbol characters like square with vertical bar through it, square with horisontal bar through it.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
how do you write readable, well documented and easily mantainable code in Forth ?

Chose names for the words you define that mean something.
Keep your word definitions small, so you can see at once everything it does.
Use these words to build new, more powerful, words.
Use these in turn to build new, still more powerful, words, etc,etc.
What you might otherwise put in comments can become word names.

At the lowest level, your word names will descripe how you are doing something.
As you move up to higher levels, migrate to words which describe what, rather than how.

I found it useful to think of Forth not as my programming language, but rather as a tool box for building my own language, application specific, which I then used to solve my problem.

Laurence Boyd II

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
But, how do you write readable, well documented and easily mantainable code in Forth ?

The maintainability of any program in any language is dependent
upon the quality of the logic flow and the quality of the comments.
Forth is no different, except that (at the programmer's discretion)
the program itself can be very easily readable because Forth
words (the "routines") can be plain language related to the task
at hand.

ie:

: pump? tank empty if fillvalve open pump start then ;

Invoking the word "pump?" checks to see if the tank is empty,
and if it is, opens a valve and starts the pump. Lines like this
need very little explanation with "comments", as what is happening
is pretty obvious. Forth is to a large extent "self commenting".
I usually only need to add comments to funtions that do weird
and unfamiliar things, such as manipulating a laser printer
to print text that is a mixture of English and Mandarin.

Program readability is also enhanced in Forth because a
*lot* of logic can be clearly represented on a page, even
with generoulsly added comments.

I started using C because it is free and Avrs are supported,
but I am intrigued by "pfavr". It looks like it would be simple
to port this to the smaller devices. Once I do this, I will
probably switch and never look back 8-)

Tom Pappano
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I found it useful to think of Forth not as my programming language, but rather as a tool box for building my own language, application specific, which I then used to solve my problem.

Laurence is clearly one of the "enlightened ones" and has described the essential
beauty and power of the language far better than I! 8-)

Tom Pappano
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Due to the interest in the FORTH for the AVR's,
I hereby call on ATMEL to help develop such
a development environment. I know they support
such for 4-bits.... Help us bring the powerfull chips
to use. Many applications will not be suited to this
approach, but many will and can be implemented
quickly. How many projects are killed because of
the complexity of the AVR STUDIO, C compiler
issue? See if you need a computer to be a front
panel,, sense optical touch switch, control tri-color
LED, beep the speaker, signal the next computer
to advance.... it is a perfect solution. And if it
could be on 1 chip!!! All them I/O ports, A/D's,
timers, etc.... under FORTH control!

Come on ATMEL, help us sell your chips!!!!

-Joe

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I actually still have some of those Rockwell Forth microcontrollers.
65F11 and 65F12. They were my first exposure to Forth and were a
really cool concept that enabled building one-chip solutions. A fatal
flaw (in my world) was that they were not available in industrial temp
range. I "borrowed" their firmware code and ported it to my Ohio
Scientific C1P, and then compiled Forth apps to run on other 6502
targets. Worked so well I bought a $600 dual-floppy PC, and plunked
down another $750 for the friendlier and more versatile LMI metacompiler,
which I have been using more or less constantly ever since for 6502,
8051, and 80x86 family applications.

Tom Pappano
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used to add the following "tagline" below my signature block on BBS postings:

"Try not.  Do, or Do Not.  There is no try".  --- Yoda

I think it's about time I update that...

": pump? tank empty if fillvalve open pump start then ;"  --- Yoda

---
Mike
(wondering if he still has the CP/M Forth for the old IMSAI 8080)