Electronic Design

  
Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


[Design Application]
Forth Still Suits Embedded Applications
Although Sometimes Viewed Merely As An Interesting Relic, Forth Still Holds A Role In Today's Embedded Systems.

Tom Napier  |   ED Online ID #7489  |   November 22, 1999


At the other extreme, I do my general programming in Forth in a windowed environment. It has pull-down menus and slider input of parameters. Forth runs in one window, while the source editor runs in another. A mouse click moves you between the two.

Despite the advantages that Forth offers, however, you may find it difficult to employ on your next project because of corporate inertia. The last thing a harried project manager wants is to have today's project take longer and cost more as designers learn a new language. Writing and debugging an embedded program in less time is a good thing. And manufacturing with a cheaper microprocessor and a smaller PROM nearly always pays dividends. But changing how things are done costs time and money. Just balance the cost against the benefits of writing in a language which is fast and interactive, requires fewer programmer-hours, and leads to shorter, more reliable code.

The C juggernaut has a lot of corporate momentum behind it, so switching to Forth may be difficult to justify in the short term. If you plan to stay in the embedded-systems business, however, Forth's lower development costs and cheaper hardware can make it a profitable long-term option. *

A Sample Of Forth
This Forth fragment from a real application accepts an input frequency between 0000 and 9999. It interpolates between entries in a 100-point calibration table to generate the nonlinear drive voltage for a voltage-controlled oscillator. Here, Forth code is written in upper case, with comments in lower case. Comments are demarcated by parentheses or by a backslash and the end of the line of code. Definitions begin with "colon" (:), end with a semicolon (;), and contain a "stack picture" to guide future programmers. The "picture" is the comment in parentheses following the definition's name word. It shows the parameters on the stack that the word will use (bottom to top), followed by those that it will leave on the stack when it finishes execution.

  10000 CONSTANT MAX-INPUT     \ Define a constant named MAX-INPUT.       

100 CONSTANT WIDTH \ The separation between table entries.

CREATE TABLE1 MAX-INPUT WIDTH / CELL * ALLOT \ Generates TABLE1 having room for 100 stack elements. \ CELL is the stack element size in bytes, typically 4. \ This table will be filled when the system is calibrated.

: INTERPOLATE ( point1 point2 fraction width --> value ) \ fraction/width = interpolation factor between point1 and point2

>R >R \ Move width and fraction to the return stack OVER - \ Size of interval = point2 - point1 R> R> \ Recover width and fraction */ \ Do size*fraction/width with double precision + \ Add result to point 1 ; \ End of definition

: LOOK.UP ( user input --> equivalent value from table )

DUP 0 MAX-INPUT WITHIN? NOT \ Test user's input IF ERROR1 DROP 5000 \ Flag error and insert dummy THEN \ Some Forths use "ENDIF" WIDTH /MOD \ Get table index and fraction DUP TABLE1 + @ \ Look up lower table entry SWAP 1+ TABLE1 + @ \ Look up upper table entry ROT WIDTH \ Move fraction to top of stack and get width INTERPOLATE \ Call the interpolation routine ; \ End of definition

For More Information On Forth
The starting place for learning more about Forth is the nonprofit Forth Interest Group (FIG). FIG publishes a journal, "Forth Dimensions," and sells books and public-domain versions of Forth. For reading I recommend Leo Brodie's classic but dated book, "Starting Forth." If you can't find it elsewhere, you can buy it from FIG. His "Thinking Forth" is also worth reading.

If you want to obtain a Forth compiler, commercial versions of Forth for embedded systems can be bought for between $30 for a public-domain version to around $2000 for a comprehensive cross-compiling version that runs on a PC. Forth Inc. is the biggest commercial Forth source for embedded and other applications. A number of smaller Forth vendors also advertise in "Forth Dimensions." Given some familiarity with Forth, it's not difficult to take a public-domain Forth and rewrite it to run on the micro of your choice. I've written five or six Forth compilers, all loosely based on the 1978 vintage FIG-Forth for the 8080.

Forth Inc.
111 N. Sepulveda Blvd.
Suite 300
Manhattan Beach, CA 90266
www.forth.com
forthinc@forth.com

Forth Interest Group
100 Dolores St.
Suite 183
Carmel, CA 93923
www.forth.org


<-- prev. page     1 2 3 [4]     next page -->

Reprints   Printer-Friendly  Email this Article  RSS    Font Size   What's This?


  • Network-On-Chip Tools Arrive for The Masses
  • Tackling System Design Challenges Through Early Verification
  • ESL Tools Take Center Stage As Designers Move Up
  • Parasitic Extraction Tool Targets Next-Generation Custom ICs
  • Synopsys Jumps Into ESL-Synthesis Pool
  • Verify Control Systems Before Committing To Hardware
  • You're Using How Many FPGAs?
  • Tool Up For The FPGA Blitz
    1) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (181 views today)
    2) Hot Hands For Some Cool Rock: Motion Sensing Meets Audio Engineering
    (171 views today)
    3) GPS-Derived Grandmaster Clock Delivers Ultra-Precise Time And Frequency Sync
    (91 views today)
    4) What's All This Transimpedance Amplifier Stuff, Anyhow? (Part 1)
    (79 views today)
    5) Downconverting Mixers Lower Power Consumption While Improving Performance
    (73 views today)
    ALL TOP 20



    POST YOUR COMMENTS HERE
    Name:

    Email:
    Your Comments:

    Enter the text from the image below


    Please refresh the page if you have trouble reading this text.

    Search Electronic Design
         
      
     
    Web Seminar
    Sponsored By:
    Title: Read Pacing: A Performance Enhancing Feature of PCI Express Gen 2 Switch Devices
    Speakers: 
    Date: 07/01/08
    Register: 

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF
    Mobile Dev & Design Schematics Find Power Products Military Electronics EE Events Related Resources