Last updated 19 January 2012


Cartoon of the day Copyright © J.D. "Illiad" Frazer.
A Forth-related one Copyright © J.D. "Illiad" Frazer.
Cartoon of every other day.
How to write good code.
Tech support - if only.
Tech support for your family and friends.
Geek in a can.

Applications written in Forth


Back in the days when we used to send printed catalogues all over the world, there was a section in the catalogue with this title. This page is the electronic edition of that section. Please send contributions.



ARM Cortex compiler: M0/M1/M3/M4 now


The cross compiler for ARM and Cortex devices has matured well, and since July it has covered M0/M1/M3 as well as ARM. We have since extended it to support Cortex-M4 devices, the first two families are the Freescale Kinetis parts and the ridiculously fast STM32F4xx parts (on the ridiculously cheap STM32F4 Discovery board).

One nice feature of Cortex CPUs is that there is no assembler start-up code - it's all high-level Forth. Cortex-Mx processors use an expanded version of the ARM Thumb instruction set. The original Thumb-1 instruction set used 16 bit opcodes that were translated to ARM 32 bit instructions during the decode. The Thumb-1 instruction set was not capable enough to work on its own and had to be used with ARM 32 bit instructions as well.

In the Cortex-M0/M1 CPUs, the Thumb-1 instruction set was extended just enough to provide a minimal standalone instruction set. Cortex-M0 CPUs are mostly designed as cost-sensitive replacements for designs which would otherwise use 8 bit CPUs. Low price is achieved by small silicon at the cost of a rather ugly and low performance instruction set. Despite this, the VFX code generator does a good job. With Cortex-M0 parts at US$ 0.55 in volume from Nuvoton, there's very little reason to use an 8-bit CPU any more.

All the restrictions were removed in the Cortex-M3/M4 parts which are rapidly replacing ARM7 designs in embedded systems. The additional instructions and addressing modes in Cortex-M3/M4 give the VFX code generator the opportunity to generate very good code even for the most complex source code. The performance benchmarks of these parts are impressive.

See the cross compilers page. Note that Forth 7 cross compilers are available under Mac OS X and Linux as well as Windows.


VFX Forth v4.5 for Windows, Mac OS X, Linux and DOS


The VFX Forth chassis is mature, and is used for all sizes of applications up to those exceeding 1M lines of source code. New in v4.5 is the cross platform GUI and graphics package using GTK+. The example below is generated from exactly the same source code on Windows, Mac OS X and Linux.


New software, new toys


We have loathed the Windows file search box for many years. At long last we have found the tool that does what you need. It's called Everything and it is available from VoidTools as donationware. A lovely piece of code - recommended. Searches can include wild cards and regular expressions. Oh, and there's documentation too.

In uncertain economic times, you can either clamp down on spending or try to kickstart the economy single-handed. Stephen's been buying toys again, for research purposes of course, you understand.

The Architect has a tribe rather than a family, so organising gatherings takes a lot of electronics, and keeping up with the younger ones requires a lot of Facebook surfing. So we bought an iPad2 and a 10" Android tablet. The Architect tells me that the iPad is hers. It's certainly the easier to use and the display is wonderful. We put both of them out at a tribal gathering. No instruction was given (or needed). If you are a teenager or younger, you seem to know how to use both of them. We have trialled them at ages down to two and a half. Given a choice, almost everyone takes the iPad first.

After a few business trips, I note that managers love their iPads, but most will not buy them for other staff. Depending on how good the upcoming low cost 7" Android tablets are, there's a possibility that Android can take that segment of the tablet market. There is, however, the problem of how much money Android will make for its developers.


Forth meetings - EuroForth


Face to face meetings with people you have only met electronically are very productive.

EuroForth is consistently the best international Forth conference, attracting people from as far away as Australia, South Africa and the USA. EuroForth 2011 was held in Vienna, and EuroForth 2012 is expected to be held in the U.K.

EuroForth

EuroForth home page

Forth Tagung

Forth Tagung is the annual German Forth conference. It is a pleasant and relaxed experience. Details appear on the Forth-Gesellschaft web site.
Forth-Tagung.


Forth Library Action Group (FLAG)


There's a huge amount of Forth source code scattered around the Internet in one form or another. In order to coordinate the availability of library code in source form, Stephen started the FLAG project (Forth Library Action Group). This is not an MPE project, it is done in Stephen's "ample spare time".

FLAG

Comments include:
"FLAG is looking good!"
"I find updating my files, including the html description files, in FLAG to be quite easy. Nicely done ..."

If you have code to contribute, comments or criticisms, please contact Stephen directly.


Well, it amused us


From Swig, the wine merchants:
Our South African pre-arrival offer is now available online.
  www.swig.co.uk
Those of you that received a copy through the post, please note that there is a typographical error in the first paragraph. The wines will be delivered to you in August (not November!). Obviously, we deliberately include clerical errors of this nature in all our mailouts as a mark of authenticity. If you ever receive a Swig offer without any howling cock-ups in it, please discard it as it will doubtless be a fake.

From the bottom of a client's email:
IMPORTANT DISCLAIMER: This email is intended for the use of the individual addressee(s) named above and may contain information that is confidential, privileged or unsuitable for overly sensitive persons with low self-esteem, no sense of humour or irrational religious beliefs. If you are not the intended recipient, any dissemination, distribution or copying of this email is not authorised (either explicitly or implicitly) and constitutes an irritating social faux pas. Unless the word absquatulation has been used in its correct context somewhere other than in this warning, it does not have any legal or grammatical use and may be ignored. All spelling and grammer mistooks is intentional.

No animals were harmed in the transmission of this email, although the German Shepherd next door is living on borrowed time, let me tell you. Those of you with an overwhelming fear of the unknown will be gratified to learn that there is no hidden message revealed by reading this warning backwards, so just ignore that Alert Notice from Microsoft: However, by pouring a complete circle of salt around yourself and your computer you can ensure that no harm befalls you and your pets.

If you have received this email in error, please add some nutmeg and egg whites and place it in a warm oven for 40 minutes. Whisk briefly and let it stand for 2 hours before icing. For those of you with a nosey disposition our company is registered in England & Wales with the number aaaaa and our VAT number is bbbbbbb. Our registered address is as above. Please call before visiting so we can put the kettle on.


In praise of competent chips


After several years dealing mostly with the latest ARM chips, it was something of a shock to go back to our previous standard device before ARM. In those days we used Hitachi's (now Renesas) H8/300H family for a wide range of projects. This family has had a resurgence lately in its H8/Tiny form, and Renesas are being aggressive with the pricing. The single chip 32 bit CPUs can be had (in serious volume) for less than GBP 1.00 per chip with sensible quantities of Flash and a good selection of peripherals.

The chips aren't bad at all! For devices designed down to a price, the peripherals follow the "just work" philosophy too. They may not be structured like high-end parts, but the code for them is short and some of it even worked first time!

While updating the compiler and doing the H8/Tiny port, it was a bit of a revelation to find that the Renesas chips and tools "just worked" ... and quietly. During the Cortex-M3 development (see above), we managed to break every tool chain we laid our hands on - there were quite a few. The Renesas tools aren't glitzy, but they just do the job. A very pleasant surprise.

We have started looking at another old favourite and bought a low-cost evaluation kit. The chips are probably great, but the tool-chain requires more patience than we have time for. The local FAE's reaction is to give us the top-of-the-range toys. I don't want the latest software whizz-bangs, I just want it to work.


Lessons from the website redesign


After ten or more years of the same website design and ten years of updates, the MPE website had become old-fashioned and accumulated a great deal of "cruft". It was difficult to maintain while keeping a consistent presentation. It was time for a new chassis! All this inspired a look-around for suitable templates to start from: if reinventing the wheel is a bad thing in Forth, it certainly isn't a good idea for things outside our core disciplines.

Discussing this with the Architect one day after looking at many sites to see what I liked, she directed me one she likes, the Armitage Shanks Bluebook. As a site for busy professionals, it's a revelation in ease of navigation. After looking at the JavaScript books for too long, we concluded that some third-pary tools were a good idea. The ones we ended up with were found by the "stumble on" method of trying various phrases in search engines. If you know of better tools or other tools you think are essential, please let me know.

Colour picker

Asking a visually literate person such as any designer to sit next to you while you manipulate six-digit hexadecimal numbers by trial and error to find a colour is not a good idea! They have a very low boredom threshold. We needed a colour picker that would give us the magic numbers for the chosen colours.

We used the one from SpiceBrains. US$19.95 well spent. The Architect was happy.

Menus

I have a low boredom threshold with JavaScript, mostly because I do not use it very often. The result is that relearning the twiddly bits costs much more than just buying a bit of code. Because we saw it when looking for the colour picker, we spent another US$19.95 for the MLDDM package from SpiceBrains. You even get technical support.

The lower level packages come with a truly beautiful bit of deliberately obfuscated JavaScript. One of these days we'll buy the unlimited version with the proper source code!

HTML validator

Postel advised people writing TCP/IP stacks to be strict in what you send, and generous in what you will receive. As Bernd Paysan pointed out recently, the problem with Postel's approach to web design is that everyone has to deal with a vast amount of bad and technically invalid HTML and scripts. After doing the first VFX Forth (which was very brutal), we soon realised that we and our clients were writing better code. The motto is "crash early, and crash often". Then you will fix your bugs!

Having adopted that approach, and being on the Forth200x standards team, we could hardly take a different approach to the new website. After looking at the freebies, we went with CSE HTML Validator. Its ability to validate your whole site (including style sheets and JavaScripts) by pressing one button justifies the Pro version on its own. Non-webbies like us can use it.

An observation that initially surprised me was that some of our pages became much smaller while coping with the validator's rejection reports. On reflection, what we were doing with style sheets and JavaScript in particular was to factor our code in the same way as we should in Forth. It has the same benefits. Far too much HTML is written using "call by text editor". Now we only have to change code in one place (factor) and everything that uses it adjusts. Just as with Forth factoring, writing JavaScript in small chunks pays off. And I can understand it.


USB drivers v2


There's a category of software that can be roughly classified as "nothing works until everything works". USB drivers fall into this class. USB is one of the few jobs where buying a protocol analyser was a lifesaver. Most jobs can be debugged with a knife, fork, soldering iron and an oscilloscope. Not this one! The upgrade to version 2 of the USB software maintained this tradition as we now support Linux and Mac OS X as well as Windows, as well as virtual serial ports and composite devices. If only the Mac's USB implementation was as good as the rest of it. That was tough!

The result of all this is that we now have a layered USB driver system:

  • USB hardware driver,
  • USB core layer interfaces to the hardware layer and the class drivers,
  • Mass Storage Class (MSC) driver, as in memory sticks.
  • Communication Device Class (CDC) driver, as in RS232 serial converters.
  • Composite memory stick and serial device

It's been very nice to write this using the ARM VFX compiler and not having to write a line of assembler. We much enjoyed ourselves when Windows first went "ding-de-dong" and recognised the device as a disk drive.

For my own amusement, I rewrote the endpoint read/write routines in assembler. The result was no observable speed change in operation and only a marginal improvement in the measured time in the interrupt handler.


Forth in the press


After reading a Forth article a few months ago, Stephen got cross and in a fit of energy, sent a proposal to Dr Dobbs Journal. Within a few hours we got asked to do two articles. I was always told not to volunteer for anything! You can see the results.

Modern Forth here.
Extreme Forth here.


Debugging


I believe that the single thing that will improve code most is to teach people how to debug. The process is just formal scientific method. The second most inportant change is to fix bugs before you do anything else. The third is probably to use something like literate programming as part of writing the code - it has greatly improved our code quality, and almost always reveals bugs when we add it to incoming third-party code.

From observation of programmers, some can debug, others cannot. The majority of those who can are not great users of debuggers. If you can't observe, you can't debug. Tools that help me observe are the ones I want. When you debug a TCP/IP stack, Ethereal is much more useful than a debugger.

I once debugged a banknote sorting machine (16 bit TMS9995, a long time ago) with a pair of resistor-ladder DACs attached to the upper and lower 8 bits of the address bus and feeding a scope in X-Y mode. That told me far more about my program than any number of debuggers.

Debugging, especially for hard real time systems, has actually become more difficult rather than less over the years. These days, you can manipulate squillions of bits per peekosecond, and there's not a single pin change! And if you attach the usual invasive debugger, your peeksecond becomes a crashosecond.

Forth is a tool that greatly helps us observe a system.


Applications for Forth


These applications are recent uses of Forth, and the list is somewhat constrained by the tendency of clients to want us to sign non-disclosure agreements.


Forth applications you can hear

These Discovery Museum exhibits are controlled with software and hardware by Bill Codington (more below). The embedded hardware is a Cortex-M3 programmed with the MPE Forth cross compiler, and there's also a Linux PC in there running VFX Forth for Linux with Hanno Schwalm's fJACK Audio interface.





A Forth application you can see

Bill Codington specialises in lighting applications and software for artworks. A recent production is an animated display about the Rio Grande river. It was built using an ARM board and the MPE cross compiler. There are at least 34 separate tasks, 32 of which control lighting effects.



Baggage monitoring

Reveal Imaging make baggage inspection systems. The CT120 Controller board is programmed in Forth, cross compiled for an ARM7 processor with the MPE Forth 7 cross compiler.


A baggage inspection system

The Forth communicates with the airport baggage handling system, monitors I/O signals, reads Voltage, current, temperature, humidity, handles various safety systems, reads in barcodes, controls warning lights, controls two external conveyors (not shown in photo), and provides a means of testing the circuits. The software uses 8 state machines, 4 serial ports, 36 I/O and 8 ADCs.


Pollution monitoring

The embedded software for the Total Sulfur Analyzers in the Pilot Project shown in this link was developed on a 68332 platform using MPE's 68xxx cross compiler by Alberto Pasquale at Thermo Fisher Scientific.

Temperature control Temperature control Sample pump Sample pump

Vending machines

It is now possible for vending machines to brew tea and coffee with fresh milk, and to produce a cup of tea acceptable to professional tea tasters. The first trick is to prevent milk seeping into pipes and then going off overnight after the machine has been switched off. The next trick is prevent sedimentation in the boiler/heater mechanisms - it ruins the taste of tea! The final trick is to control the flow of water/steam through the coffee grounds or tea leaves, as these need a "wetting period" during which they swell before releasing flavour to the liquid. All controlled by an MPE system. Buckets were much in evidence during development.


Inside a vending machine
Inside a vending machine

A different project aims to protect vending machines from fraud by the route-men who stock the machines and empty the cash bags. Industry estimates are that each vending machine loses £2 per machine per week. There are 1.5 million machines in the UK alone, so that's about GBP 150M per year. Safer Systems, a vending machine security specialist asked us to help out. The system involves intercepting the local vending machine bus, logging the cash data, and transferring it to an RFID tag on the Custodian cash bag. When the cash bag is read, the cash value can be compared by the reader with what was actually in the bag. Reports are created and transmitted to a remote web site (designed and implemented by our sister company Remote Management Systems). Management can retrieve reports and live data directly from the web site. All the embedded systems involve Forth on ARM CPUs, and the readers use the PowerNet TCP/IP stack to access the remote web site. Sites are scalable to over 25,000 machines.


Seismic data logging


Guralp CMG-5TD
Guralp CMG-5TD

Guralp Systems (see web site make low-noise broadband seismometers, digitizers and networking equipment for science and engineering. Their new CMG-5TD is a complete seismic station in a sensor case, combining the well-regarded CMG-5T accelerometer with a full-featured CMG-DM24 to form a low-noise strong motion instrument with output over RS232 serial links, modem or (optionally) direct to local area networks over Ethernet.