Quantcast
Channel: Sustainable Suburbia
Viewing all articles
Browse latest Browse all 234

ChipStick - A Small Scale Experimental Forth Machine - First Forth!

$
0
0


Two weeks ago, I introduced a new project, ChipStick - a small dev-board based on the MSP430FR2433 16-bit microcontroller.

The aim of ChipStick is to provide interactive programmable Smart hardware to bring your next project to life.

Late last night I received from Matthias Koch - the first draft of Mecrisp 2.03 Forth ported especially for the ChipStick.

I am please to announce that when loaded into the ferro-electric memory of the ChipStick that it burst into life and was immediately recognisable as a full-blown Forth System.

Forth provides the ideal interactive development tool to help breathe the life into your latest hardware.


Historical Note

Forth was developed in the late 1960s by Charles H. Moore, whilst working with radio telescopes, controlled to minicomputers.

There are numerous online documents describing the history of Forth - so I shall not go into too much detail - needless to say, that Charles "Chuck" Moore wanted a more efficient programming environment and wanted to have control over the whole system.

Forth became popular in the late 1970's - with the 8-bit microprocessor revolution. It offered an alternative to machine language and was well suited to the resource limited systems of those times - often fitting into 4Kbytes or less.

Needless to say , Forth is a very compact and versatile language - and a very good fit for the modern 16-bit and 32-bit microcontrollers. The Mecrisp implementation is about 11k bytes of FRAM.  On the MSP430FR2433 that leaves 4K of FRAM and 4K of SRAM for the Users application code.  There is also the 0.5kB Info RAM - which can be set as a protected area.

Using Forth

Forth uses natural language words, separated by whitespace.  Forth source code may be composed using nothing more than a text editor and uploaded to the target using a terminal program - such as Termite or TerraTerm.

Forth uses 16-bit integer maths as standard - though there are extensions for floating point. However integer math is not so much of a limitation  355 / 113  can be more useful than you think!

Forth consists of a dictionary of standard words, to which the user may add their own new definitions of words.

Any high level control can be broken down into a series of  smaller operations - for example a control cycle for a washing machine.

CHECK_DOOR
FILL
HEAT
CHURN
DRAIN
FILL
RINSE
DRAIN
SPIN
BEEP

Obviously there would be some decision making logic connecting these tasks,  and the CHURN cycle, and RINSE, DRAIN SPIN cycles may be repeated a number of times depending on the type of wash required - but it illustrates the point of reducing the problem to a series of self-contained tasks.

Once the problem has be thus decimated, the high level tasks may be written in Forth, using whatever native language is appropriate to the tongue of the user. If you want to use German, French or Mandarin for the high level names - that is perfectly acceptable.

Forth needs to have a good relationship with the register level hardware of the chosen microcontroller - and the closer to the actual microcontroller peripherals you can get - the more versatile Forth becomes.

It is fairly straight forward to define simple words that allow you to exercise the GPIO.  A quick look at the MSP430 datasheet -and you can construct these new words in a few minutes.  Additional words would be constructed for setting timers, reading ADCs, SPI, I2C transfers to displays or external devices plus anything else of the myriad of operations you might wish to do with the hardware.

Note how all these word definitions start with a colon : and end with a semicolon - this gives them the name "Colon Definitions"

Once entered into the dictionary - these new words are ready and available to use as you like, or combine to make larger words.

Setting the ports

: P1IN  512 C@ ;
: P1OUT 514 c! ;
: P1DIR 516 c! ;

: P2IN  513 C@ ;
: P2OUT 515 c! ;
: P2DIR 517 c! ;

: P3IN  544 C@ ;
: P3OUT 546 c! ;
: P3DIR 548 c! ;

Lighting LEDs on Port 2

: P2LEDSET 255 517 c! ;    (set all Port 2 pins to output)
: LEDNUM 515 C! ;          ( display a binary number on LEDs)

Onboard LED on Port 3.1

: LEDON 2 P3OUT ;
: LEDOFF 0 P3OUT ;

Dump the FRAM in HEX base

: hexdump hex c400 c800 do I c@ . space loop ;
: texdump hex c400 c800 do I c@ emit loop ;

Once you have these definitions store in memory, you can type  170 LEDNUM - and turn alternate LEDs on your LED array.

To be continued.

Meanwwhile  - If you want to catch up on previous ChipStick posts - have a look at the links below:






Viewing all articles
Browse latest Browse all 234

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>