Shop OBEX P1 Docs P2 Docs Learn Events
EXTREME rapid deployment — Parallax Forums

EXTREME rapid deployment

LoopyBytelooseLoopyByteloose Posts: 12,537
edited 2012-10-23 00:27 in Propeller 1
If you just need a relay board to handle bench items from a computer via a USB link, I am finding PropForth (and probably Tachyon Forth, as well) have very excellent advantages.

I installed PropForth on a Propeller Proto Board a few days ago, and I am already comfortable with writing and saving words. It is rather easy.

If you want to use something like 4 i/o pins to toggle relays, you can quickly set up words to turn on and off devices that are even powered by AC mains.

Let's just say you want lights on, just create a word ' LightsON', and another 'LightsOFF'. From Minicom serial software in your laptop, all you have to do is type LightsOn and that particular relay will do so. If you need to reconfigure, you can either remove the words or redefine them from the Mincom screen

What does this look like? The example below is for Pin 1 (not Pin 0) on the Proto board and works just fine. More relays can go to other pins and the names in the dictionary can be easy to remember, no menus to write or screens to format or Control code keys to provide. Since the serial port is already up and running, that is another task eliminated.

: LightsON 1 pinout 1 pinhi ;
: LightsOFF 1 pinout 1 pinlo ;

Want more?

:D DoorOpen 2 pinout 2 pinhi ;
:D DoorLocked 2 pinout 2 pinlo ;

I actually like this a lot more than Basic language programing. I want something, I get it right away.

Comments

  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-10-21 18:44
    Hi Loopy;

    You finally drank the forth KoolAid!!!!!!

    Forth is such a dream to use as a controller language.

    Try something, didn't work, immediately try again until it dos.
    Debug cycle is extremely fast as no conventional compiling needs to be done.

    It is a bit of a mind bender until you get the hang of it,

    Duane J
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-21 19:05
    It helps to factor and generalize words in Forth. For instance you can have the one word for LIGHTS and then simply say whether you want them on or off or even dimmed.
    : LIGHTS ( on/off -- ) 1 PIN! ;
    Now you can simply say:
    ON LIGHTS
    or
    OFF LIGHTS
    as ON and OFF are simply constants for readability (TRUE and FALSE).
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-22 03:48
    Thanks Peter,
    I just wanted to post something extremely easy to do for wary beginners. The fact that Forth uses a dictionary that extends itself can too easily evolve into rather long example discussions.

    Factoring to improve a word definition is always worthwhile. Nearly all Forth programs (word definitions) improve with review and revision. One keeps learning more and I suspect the insight is transferable to how one programs in other languages, tighter and better code.

    For a 4 relay board, one could and probably would probably define and 'AllON' and an 'AllOFF' and if one wanted combinations of the 4 i/o, there are twelve permutations that could become more words.

    Once one is able to control 4 i/o with toggles, one can also easily move on to using the 4 bits to drive a stepper with looping and appropriate delays.

    In sum, it is just so easy to get some hardware working and verified.

    EVEN if you don't want Forth to be your final software for a Propeller application, IT IS an important tool for quickly verifying that your wiring and hardware built are correct.

    Historically Forth has been often used first on prototype hardware so that the developers don't have to wonder if a bug is located in hardware or software.

    Great stuff.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-22 06:39
    Forth certainly is a very flexible language. It rapidly leads to divergent dictionaries according to the personal choices of individual users.

    So, I was pondering PIN! mentioned above. First impression was that it meant to toggle the pin, but I see you have the ON and OFF words do the actual control. So after a bit of investigation, I see that it returns the state of a pin. It is interesting as the two Propeller Forths are differing quite a bit in how a simple change of pin state is done.

    I can't say either is more right than the other, just different.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-22 07:09
    Forth certainly is a very flexible language. It rapidly leads to divergent dictionaries according to the personal choices of individual users.

    So, I was pondering PIN! mentioned above. On the surface, it seems to obviously mean to TOGGLE the pin state. But both @ and ! have a more fundamental purpose in Forth in general as they move data to and from stack cells and into data memory.

    So I am curious, is this standard Tachyon Forth word, or just a proposed alternative? I have yet to figure out how to toggle pins in Tachyon Forth. I guess I should work through your Blinky example.

    My main words for setting and clearing port pins uses a mask so that more than one pin may be accessed. These words are OUTSET and OUTCLR plus they also make sure that the DIR register is set accordingly so there is no need to make the pin an output in a separate operation. The words PIN@ and PIN! are analogous to @ and ! which fetch or store to an address. In like manner PIN@ and PIN! will fetch from a pin or store to a pin. As for toggling a pin there is not a word for it in the standard dictionary as toggling is fairly easy to do but has very limited uses as normally you either want the pin set or cleared. However there is the CLOCK word which uses a mask specified in COGREG 0 that toggles port pins rapidly.

    There are also specialized port access words which maintain I/O masks in cog registers for very fast access plus some use the stack without pushing and popping such as SHROUT, SHRINP. All these words are there to enable Tachyon Forth to press the pedal to the metal when it comes to bit-banging I/O. Some cog routines are paged in as needed for repetitive tasks such as SPI etc and these normally clock at around 2.8MHz or so.

    BTW, the Propeller is not your standard micro as you have by now guessed :) So Tachyon Forth is tailored to suit the Propeller, not some other micro, so other than core word subsets for memory and stack operations etc there is not much that might be regarded as standard for the specialized words, nor should there be.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-22 09:20
    Thanks again,
    I am just getting to know Forth as previous efforts by me were abandoned. I guess I didn't know quite enough to appreciate its usefulness.

    I discovered I loaded Tacyhon V1.0 and now you are up to V1.1, so I have some catching up to do with it. And it is now quite clear that you demonstrated output in Tachyon quite clearly. I just wasn't up to speed.

    I am sure people will have strong preferences for one or the other and for a huge variety of reasons. About all I can figure out is that it is best to stick with one in the beginning rather than trying to master both at the same time.

    I went with PropForth as it seemed that I didn't have to log onto the web to keep up. They have created quite a bit of documentation. But I am sure others enjoy following active develop via your thread.

    I suppose I could print the whole thread to a PDF file and catch up that way.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-22 09:35
    Thanks again,
    I am just getting to know Forth as previous efforts by me were abandoned. I guess I didn't know quite enough to appreciate its usefulness.

    I discovered I loaded Tacyhon V1.0 and now you are up to V1.1, so I have some catching up to do with it. And it is now quite clear that you demonstrated output in Tachyon quite clearly. I just wasn't up to speed.

    I am sure people with have strong preferences for one or the other and for a huge variety of reasons. About all I can figure out is that it is best to stick with one in the beginning rather than trying to master both at the same time.

    I went with PropForth as it seemed that I didn't have to log onto the web to keep up. The have created quite a bit of documentation. But I am sure others enjoy following active develop via your thread.

    I don't know which links you have been following but I'm on V2 now. Just follow the links in my sig and then at the end of the Intro page link. There has never been a need to "log on" to download as the Dropbox versions are directly accessible as are the webpage versions of the Google docs. The "sign in" version is for editing and commenting etc or simply to view the fully formatted document.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2012-10-23 00:27
    I have revisited the Dropbox and see V2. Initially, I think I loaded V1 because my terminal software - minicom - was already set up for a compatible baud rate and I didn't want to get too fancy to start, so I loaded the bare bones - no VGA, no SDcard.

    And I finally have noticed that your posting have the TACHYON files via Dropbox right at the bottom of every posting by you.

    Please excuse the fumblings of a beginner.
Sign In or Register to comment.