• Scamp - a Forth-based Embedded Computer

    11/22/2020 at 00:57 3 comments

    The story behind this little machine goes back a couple of years. I had wanted to quickly test out a motor control idea, and grabbed an Arduino and a little H-bridge board, and sat down to write some code. The code wasn't hard, and the development process, while not long, took much more time than it should have. I'd spent more time dealing with the IDE and the tools, than in actually being creative. The overhead was much greater than it should have been. It was mildly frustrating, and I pondered how doing "embedded stuff" wasn't as much fun as it used to be. That made me think back to my favourite embedded systems I'd worked with in the past, and what made them nice to use. Consistently, they were all Forth-based machines I'd used in the 80s and 90s. 

    So what exactly is Forth? 

    Forth is a compiler, an interpreter, a debugger and, in a fashion, an operating system too. Forth is an extensible, highly-interactive, stack-based language. It is extremely efficient and extremely versatile. 

    Forth is very interactive. You can type commands in, and interact directly with hardware at a register level. The functionality of the language makes it ideal for debugging both system hardware and software. Forth is typically coded directly in assembly language both for speed of operation and to take advantage of the characteristics of the machine.  That makes it very fast. Forth is unlike any other conventional programming language.

    Commands (known as words in Forth) get an immediate response. This, coupled with Forth’s ability to talk directly to hardware, makes it an excellent environment for embedded system applications.

    Forth words are the equivalent of functions in C, Python or Java, or subroutines in assembly language. Forth allows the execution of any word in isolation from the command line. Thus, words can be independently tested and verified outside of the main application. So rather than writing a single, large program, small segments of code are written and tested independently (and interactively). These words are then combined to create new words, eventually ending up with a single word that is the whole application. This new word is also available to the developer, and in this way the language both grows and becomes richer as the developer works with it. In addition, the words used to create the new word are still available and can be run as programs in their own right, or used to create other new words. Forth is both versatile and powerful.

    So why is Forth not widely used? It's very powerful, and the development process is much faster. But, you can't write sloppy code with Forth. It's not forgiving. You really have to think about what you're trying to do. This isn't a bad thing, because invariably you will come up with a solution is that is tighter and more robust. 

    Hardware for Forth

    With fond memories of Forth in mind, I looked around at what off-the-shelf, forth-based embedded systems might be available now. Answer ... none.  There are several varieties of Forth kicking around, as source code. And these can be ported to various dev boards or other embedded systems. But there was still effort involved in getting Forth running. Granted, it's not hard (well, mostly). For someone just wanting to try Forth in an embedded context, or someone completely new to embedded systems, this presented a barrier to entry. Why can't you just buy a Forth-based machine off the shelf and start using it? To me it seemed an obvious thing.

    I decided to design and produce a small embedded machine with Forth preinstalled. I selected FlashForth, written by Mikael Nordman, as the Forth environment. The first hardware version was in a DIP form factor, similar to an Arduino. 

    I quickly came to the conclusion that the breadboard wasn't always necessary, and so the form factor of the machine changed. By using a single inline connector on the underside of the PCB, modules...

    Read more »