Wellys Dev

  • Home
  • Search/Topics
  • Writings
  • About

    2024

  • 2024-04-01
    FlashForth: Execution Speed

    Where I discuss the various methods of increasing execution speed in Forth and demonstrate the ease in doing so.

    Introduction

    In this entry, I showed the relative speeds of board/language combinations from a ARM M0 running CircuitPython to a Pi Pico running C. While execution speed is important in embedded microcontrollers, development speed is equally important along with ease of development. A great attribute of Forth is its ability to combine all three. In this entry, I’ll show how you can start with a simple, fast example and make it significantly faster without great difficulty.

  • 2024-03-22
    FlashForth: Debouncing Buttons -

    Where I discus debouncing buttons in Flashforth as well as indexing arrays.

    Introduction

    Elliott Williams had a great post several years ago as to the best solution to debouncing buttons. The technique worked extremely well in C, and I wanted to attempt it in Forth. It actually works better in Forth, as Forth easily handles the 16-bit data to de-bounce properly. I’ll work through the technique in FlashForth as well as spend some time at the end as to the execution timing of the technique.

  • 2024-03-13
    FlashForth: Compile a New Version

    Where I describe in detail how to compile a new version of FlashForth.

    Introduction

    Its helpful to be able to compile a new version of FlashForth. A simple reason is to increase the baudrate from 38400 to 250000, increasing your productivity. It isn’t difficult, however the tool chain can be a bit complex.

    Requirements

    You will need to install both the MPLAB IDE and the XC8 compiler for this exercise. You will also need a hardware programmer such as the Atmel ICE or Microchip SNAP. And finally, you will definitely need the source code of which to compile, Flashforth on github.

  • 2024-03-12
    FlashForth: Hardware Abstract Layer (HAL)

    UPDATED: This page contains a both a Forth hardware abstraction level (HAL) much like the m328def.inc file for AVR programming in C and an example of debouncing buttons.

    New Words

    This HAL provides the words:

    I/O Words

    The Arduino pins are defined by bit port so one can use the following commands using the Arduino pin number. This is true for pins D0-D13.

    high    ( bit port -- )     set a Arduino pin high
    low     ( bit port -- )     set a Arduino pin low
    toggle  ( bit port -- )     toggle output value on an Arduino pin
    output  ( bit port -- )     set Arduino pin as output
    input   ( bit port -- )     set a Arduino pin as input
    pullup  ( bit port -- )     set Arduino pin as input_pullup
    read    ( bit port -- f )   read a Arduino pin, returns bit value
    

    For example:

  • 2024-03-12
    FlashForth: Datasheets

    Why the microcontroller datasheet is so important to programming in Forth.

    The Datasheet

    The ATmega328P datasheet is critical to understanding how to program the 328P. Exploring it with Forth is the joy of Forth as Forth allows you to interactively test commands, ports, timers, ADC’s etc of the 328P. And once you are convinced you have the correct set of commands to make what you want to happen, you can codify it into a word that becomes part of the vocabulary of Forth.

  • 2024-03-11
    FlashForth: Understanding the ATmega328P PWM

    Where I use Forth to develop a better understanding of the ATmega328P PWM capabilities. Revised from original post on April 17, 2021

    Sources

    • Flashforth Example on Github

    Introduction

    Pulse Width Modulation (PWM) is a technique used to control analog circuits using digital signals. It is the capability to change either the frequency or duty cycle of a digital signal. The former is the number of times the signal switches from low to high in a given period of time and the latter, is how long it is either high or low.

  • 2024-03-11
    Flashforth: Working with the Uno

    Where I describe how to use Forth with an Arduino Uno and make it easier to program the Uno in Forth.

    Introduction

    The Arduino Uno benefits from an incredible software framework. Between the programs already developed by the Arduino organization, and the hundreds of libraries which were created by others, you can find a program which does what you need. This makes it extremely easy to hit the ground running with a project. FlashForth isn’t like this.

  • 2024-03-10
    FlashForth: blink

    Where I demonstrate your first embedded application, much like the C Language “Hello, World” program, blink.

    A simple program, Blink

    To begin to understand how to program in Forth, I’ll iterate over several versions of blink.

    Light the LED

    First, let’s interactively light the built-in LED. On an Uno, we know it is pin 13, which corresponds to Port B, bit 5 on our microcontroller, the ATmega328P.

    This is lesson one, all references in Forth, are references to the ATmega328P, which is the microcontroller on the Uno, and not the pins on the Uno. This is why the data sheet for the ATmega328P is so important. I’ll call out the specific references as we go, however, the more you use FlashForth, the more you will come to read and understand the ATmega328P datasheet. As you begin to write more Forth programs, you will be able to create the words necessary to reference the Uno, just as you did with the Arduino framework.

  • 2024-03-09
    FlashForth: Simple Setup

    UPDATED: Where I describe how to use FlashForth, a phenomenal version of Forth for the ATmega328P to learn how to use Forth in an embedded system.

    Notes for Video

    This video demonstrates the ease of loading FlashForth on to an Arduino Uno, and replacing it with Optiboot, when you wish to use the Arduino software framework, again.

  • 2023

  • 2023-04-05
    Mecrisp-Stellaris Forth: An IDE for the RP2040

    Where I describe how I develop Forth on my Mac using Sublime Text 3 and Serial, as my Forth IDE.

    Summary

    1. Edit Forth code in Sublime Text 4.
    2. Execute ST’s Build command which transfers the code to the board for on-board compiling for Forth, typically a 1-2 second transfer (1500 bytes/sec).
    3. Use the macOS app, Serial for communicating with Forth on the board.

    Sources

    • FlashForth Shell
    • Piotr’s xfr for Mecrisp-Stellaris Forth
    • Jan’s upload.c for Mecrisp-Stellaris Forth
    • Terry’s IDE Notes

    Install Forth on RP2040

    1. Setup

    Increase Baud Rate

    Make the change in: mecrisp-stellaris-x.y.z/mecrisp-stellaris-source/rp2040-ra/terminal.s lines 165-166 and added the comment below the lines, replacing the comment line 168:

Page 1 of 3
Copyright © 2025 Lief Koepsel
  • Home
  • Search/Topics
  • Writings
  • About