Shop OBEX P1 Docs P2 Docs Learn Events
Learning PropForth - Page 2 — Parallax Forums

Learning PropForth

2

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-20 00:25
    Hi Art,

    A bit of Forth history.... about storage and transfer of stored word definitions.

    1. The original Forth was NOT dependent of a OS with a file system to store written definitions. It used a system of BLOCKS and worked well with floopy disk.. which at that time was all that many could afford. A BLOCK was roughly equal to a floppy disk sector. This kind of floppy was NOT formated with a file system, just sectors to read from and write too.

    2. With the advent of cheap hard disks, Forth was modified to store into MS DOS and other file formats. GForth today uses this system quite nicely.

    3. Now that we have gotten microcontrollers with 32K or more of RAM, we have to revert to scheme that does NOT support an OS file system.

    PropForth decided to do so by having your code storage in text files on your PC and to transfer code by 'cut and paste' into the serial terminal. Problems with the download being too fast for the Propeller evolved into the scheme called "fl" (fastload) that runs the data through an additional Propeller Cog as a buffer. This seems to work well to keep up with cut and paste loads.

    I believe 'fl' also strips away comments and extra white spaces.

    4. PropForth did evolve to use an SDcard with FAT16 as the file system. So we have gone full circle with having an OS file system for storage and files can be loaded from the SDcard by calling their name.

    'fl' is still used as it strips away all the junk and just loads the Forth code. In that way, the file on your SDcard allows you to have Comments to remind you of what is what.

    The other alternative is rather dreary. Chuck Moose in his ColorForth is still holding to a BLOCK concept and you have two screens -- one with the actual code and a mate with the comments on such code.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-20 00:27
    Hmmm... Blocking and non-blocking? This may be a poor choice of semmantics. Fl does filtering, versus non-filtering and the author may have desired to express that concept, but chose these terms that conflict with the older concept of Blocks in Forth.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-20 00:31
    artkennedy wrote: »
    Thanks for the informative comment Loopy. Keep 'em coming. I feel for you with that neck pain. I drove public transit bus here for 37 years and my neck started hurting so much that I took a hand mirror to work with me to use at a certain railroad crossing where I had to look 'way back to my left. I was pretty lucky though when they finally exrayed my neck and found the inflamed nerve the doc just had me tale a lot of Aleve for a while and I'm much better now. It also helps to be retired. Hang in there.

    The neck is fine as long as I don't type too much, don't carry a big backpack of books, and don't have too much emotional stress that tenses the muscles. Oh, weather plays a role as well. l couldn't tolerate Oregon winters and even incoming typhoons in Taiwan will lay me low. There are just some very good reasons to retire to a warmer climate.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 00:32
    Never mind. Did experiment and answered :)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-20 00:49
    Have you actually gotten your HP-48 operating as a serial terminal?

    This is pretty much a hardware project, but once you get it working on P31 and P30, other items may fall into place easily. PropForth's manual presentation is pretty much a catalog of all and everything.

    It really helps to have a series of personal projects and the milestones they create. Then just use the book as a reference.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 10:10
    Just consider the ---. the +++, and the === stylistic window dressing of a text file. I think you can catch on to the difference in context that each represents.

    Found: TutorialIndex.txt which explains notations.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 10:42
    Thanks Loopy. That is very helpful. Last night I was loading a file I had written and heavily commented. I had to add a line delay in terraterm to get it to load. I will try deleting that and using "fl".
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 10:45
    > 1. The original Forth was NOT dependent of a OS with a file system to store written definitions. It used a system of BLOCKS and worked well with floopy disk.. which at that time was all > that many could afford. A BLOCK was roughly equal to a floppy disk sector. This kind of floppy was NOT formated with a file system, just sectors to read from and write too.

    I had a Heath H-89. They wanted $600 for a 5.25" hard sector floppy
    :innocent:
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-20 16:51
    Yeah, it was amazing how greedy the computer companies in the early days were about pre-formated floopy disks. An 8" or 5.25" floopy had a propretary format and you were not provided with software to create one from blanks. In some cases, you had to buy these disks for hundreds of dollars each, as if they were gold.

    I used to have software to scan and determine floopy format, then it would format over 60 various setups. Finally, everyone gave up and accepted MS-DOS formating.

    I know you desire to use an HP-48 for a small terminal interface. I am just wondering how this might work with PropForth's 'cut and paste' scheme. I have an HP-50 with an SDcard storage and I think if will do an RS232 port. It may be a bit more useful, but I've never considered trying it.

    I use an EEEpc, with minicom for serial interface and Gedit for text editing in a Debian Linux OS. To load .spin files I us an IDE called Brad's Spin Tool.
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-20 20:31
    artkennedy wrote: »
    What are the meanings of the terms "Blocking" and "Non-blocking" in the manual?

    You didn't give the context, so I can't be sure, but:

    key is blocking, it waits forever until it gets a key;

    ?fkey is non-blocking, if key is pressed at that exact instant, it returns a 1 and the byte value of the key, if a key is not pressed at that exact instant, it returns 0 and 256. In both cases ?fkey does not stop execution.
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-20 20:41
    artkennedy wrote: »
    One of the big goals is super low power and the hp48 does that.

    You can do low power on the prop, see the demo. Set the clock speed to slow using the internal clock. When it detects a key, it does a reset and comes up in full speed clock mode. You loose the first character but then it does the reset anyway.
    It also has a powerful real time clock system that can do things on schedules and the times themselves are subject to program modification etc.

    See the double math.f and time.f support demos. Using a 64 bit clock, it won't roll over for over 7,000 years. It also give clock tick count form time stamps, so ever record will have a unique time stamp, even when multiple props are logging independantly. (time stamp collisions are possible, but we have not detected any so far).
    BTW, in "tutorial-3.2 Serial Loopback.txt" this line appears:
    1. Run tutorial-1.1 Standard Developent System.txt
    I have been unable to find that file on the forum. Could you point me to it?

    The regression tests are being rewritten. They are all included in the download archive, if they are miss named in 5.5 you should look back in 5.0
    All the previous releases are in the same list, you have to change the "display current" to "display all" or "display deprecated"
    And the lines with "---" "+++" and "###" are puzzling. Are they from an earlier version of PF?
    Those are the control words for the test automation. Thise are being redone in 6.0; which will be out in April (approximately)
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-20 20:48
    A bit of Forth history.... about storage and transfer of stored word definitions.

    1. The original Forth was NOT dependent of a OS with a file system to store written definitions. It used a system of BLOCKS ....

    To clarify, blocking/non-blocking above refers to stopping program flow, and is not related to BLOCKS.
    in propforth BLOCKS in the context of external storage refers to the 512 byte sectors on the SD card. So two blocks is 1K bytes, and 2000 blocks is 1Meg bytes, etc. A 4 gig SD has about 65,538 blocks, if I recall.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 22:43
    The $600 item was the drive - not the disk ;)

    I also have an HP-50. It has a number of advantages over the 48 but I was already 'trained' on the 48 and I was very disappointed with the changes. I can code on the 48 in my sleep (and do) so messing around with the interface like that was just cruel. I will probably do my coding on my 48 and move it to the 50 when the work is almost done to take advantage of the speed and the better display. The dream of measurement and control with the 48 has been with me for a long time. It's time to do it.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 22:47
    In PropFORTH ver_5.5 reference -- (Preliminary draft_b - 7/3/2013)

    The definition of cognchan is not clear, to me anyway.

    \ cognchan ( n1 -- n2 ) number of io channels for cog n2

    ?? Shouldn't be something like:
    \ cognchan ( n1 -- n2 ) n2 is the number of channels in cog n1
  • artkennedyartkennedy Posts: 174
    edited 2014-01-20 23:04
    . . . or maybe I'm just misunderstanding the instruction . . .
  • artkennedyartkennedy Posts: 174
    edited 2014-01-21 00:40
    y'know, Loopy, that 3.2 tutorial is pretty good. I futzed around on my own until I got loaded with questions and a little experience and then I dove into 3.2. I got quite a few answers but there are a few more to go. A good start though. Tomorrow I will get back to your 3.2 supplement. I actually started there and then took your direction to go back and do the original first. Pretty good advice.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-21 01:57
    @art
    Thanks... You actually got me wondering about using my Hp-50gx with Forth on the Propeller and if there might be something interesting there.

    So I spent much of today trying to sort out if I had to buy or build a RS232 cable. Seems it is a must buy item and that it will take a few weeks to arrive due to being an international order.

    TheRS232 interface has several ways to provide a convenient terminal in Forth.

    A. Using a notebook or laptop computer with a USB to serial adapter -- when the Propeller doesn't have a USB interface on board. Or, just a straight USB link when the Propeller has a USB interface provided

    >>>>>>>>. Note - I strongly prefer Propeller boards with RS232 interface. The advantages are what follows.

    B. You can actually use one Propeller ProtoBoard to build a complete Dumb terminal with RS232 and/or RS422 (full duplex) interface. And then have that easily reach another Propeller near (with RS232) or far with RS422.

    C. You can buy a ready-made USB to RS422 dongle for your computer and connect to the Propeller at significant distance (1000 meters and at 3Mbaud) for both Forth and for downloading .spin binaries. FTDI provides the dongle with the appropriate signal for a Reset (required for programing) and the Propeller easily accommodates the RS422 receiver and transmitter chips required.

    D. You can use RS232 over wireless. I haven't explored this as it is a little expensive for my taste. Nonetheless, Parallax's Propeller has an excellent add-on wireless setup, Zigbee.

    ++++++++++++
    I have done A, B, and C. (but for B,I built my own RS232 to RS422 and used a USB to RS232 device to complete the project.

    I had to build this twice as the first one had too much crosstalk between the Rx and Tx. It is just a lot easier to buy the FTDI solution, add a RJ45 interface onto the dongle, and have 100% solid results with no external power supply.

    The reason I mention all this is that I presume that you want to program a remote setup with the HP48. In many cases, using CAT5 LAN cable can allow you to not even have to go out the door and deal with walking back and forth to modify code. As I recall, you ment

    Also, the RS422 full duplex drivers to/from ttl are cheaper and easier to build with than the ubiquitous RS232 to ttl devices (the MAX232 and its cronies).

    ********************

    In sum, if you want long wires between devices that can do RS232, there is the RS422 full duplex. So you won't have to wait for it to stop raining to test code on your solar panel.

    ^^^^^^^^^^^^^^^^
    Also, you mentioned wanting to use the RTC on the HP48. In many cases, that is handy just to reset the time on the Propeller and have the Propeller actually run its own RTC using Unix time (it is a method where everything is based on on 32 bit number representing seconds decades into the past and into the future.

    You certainly don't have to run the HP-48 connected 24/7 to have an excellent time base for starting and stopping event that are based on a 24 hour clock, a Day of Week event, or a Day of Month event.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-23 00:09
    Loopy, I would recount all the things I have done or tried with the hp48 but it's late and I'd better turn in. Some other time. I could send you my hp50 serial cable if you like and you could order one for me. I'm not using mine right now . . . Have you seen emu-48 for the PC or any of the outstanding emulators for Android?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-23 01:05
    Hi Art,
    I just mailed a check to a Mr. Eric Rechnin for a cable. I don't think much would be gained by you giving up yours at this point.

    In the world of endless interesting projects, I don't use the HP50gx much at all. The personal computer pretty much demolished the personal calculator business by putting a free calculator in every desktop. And I have a Zire72 PDA with an RPN calculator that also teaches me Chinese.

    So, mostly I am just curious about the protential for a handheld terminal. One might use this to recongifure a Propeller in a Sumorobot competition or such.

    Starbucks just told me they are closing right now for a Chinese New Years employee party.
    gotta go.

    My main points are...
    A. You have a lot of terminal options for Forth on the Propeller that might be appealing.
    B. Since RS232 uses the same asynchronous that RS422/full duplex, a lot of projects ca easily extend far beyond the limits of an RS232 cable.

    I have brought up the i/o communications menu in the HP-50gx and located the file that can change the baud rate and serial configuration.

    I am not sure that a Cut and Paste kind of exhange of code is possible. But it does seem one can key in Forth instructions and get back results. More might be done with downloads of prepared text files on the HP-50gx SDcard, but I am not sure.

    My main concern is that you find a 'sweet spot' of methodology and hardware that makes using Forth on the Propeller fun and easy.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-23 22:49
    My peripherals will all be located close to the Propeller. The X10 system for driving relays works by signalling over the AC power lines and the temperature sensors are already tested at the operational distances - they operate in the current mode and their supply voltage is good between 3 and 15 volts so that is simple. They are scanned at a low duty rate to prevent self heating. That will be easy using output pins.

    What is holding me up right now is learning how to use the serial port. If I can once get the prop talking with the hp48 we be good - that is, I am confident I can work in the DMM and the powerline modem because I am currently driving the modem with the serial port of the calculator and have also successfully done extensive testing between the hp48 and the DMM. Another hp48 is currently managing the solar pumps and valves via the PL modem on a time of day basis. What is lacking is sensor input to measure temperature. For that I need output pins to scan the sensors and means of reading the DMM to report the readings. The hp48 has only one serial port and thus cannot address both the DMM and the PLM and it does not have output pins for scanning the sensors. The propeller seems ideal for the task and can also provide decision make capability like my previous Forth system on the NMIX-022. When the system is complete the hp48 will be mostly relegated to user interface, with a few fancier possibilities as gravy.

    I am using a Sparkfun 8087 RS-232 Level Shifter between the hp48 and the Prop. No joy yet on my own experiments though, so back to the tutorial ;)

    I am currently working my way through your Tutorial 3.2 Supplement (Added material). I have noticed what seems to be a disagreement between the explanation of the serial commands in the tutorial and the PropForth documentation by Sal Sanci. Please note:

    9.1.300 serial
    \ serial ( n1 n2 n3 -- )
    \ n1 - tx pin
    \ n2 - rx pin
    \ n3 - baud rate

    In the tutorial you show n1=rx and n2=tx . Am I correct that this is reversed?
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-24 10:23
    Please location the loopback script in the test automation. You don't have to setup and run the automation, just type it in manually, it takes just a couple minutes. This will show you how the serial functions work. The test scripts show the exact steps for proper operation of each function tested. Then the serial test will show you how to connect the wires.

    Since your calculator already works, once you see the serial test it should just be a matter of getting the rwires right way around.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-24 12:01
    artkennedy wrote: »
    9.1.300 serial
    \ serial ( n1 n2 n3 -- )
    \ n1 - tx pin
    \ n2 - rx pin
    \ n3 - baud rate

    In the tutorial you show n1=rx and n2=tx . Am I correct that this is reversed?

    HI Art,
    Truthfully, I have no idea if I made a typo or provided the correct information. I wrote this document a long time ago and you are likely the first to read it with any real intent on learning from it. I would go with what the PropForth manual says unless something is obviously wrong.

    I haven't been working with PropForth for quite some time, and even longer in terms of multiple serial ports. I just did enough to confirm the feasibility of multiple ports. And wrote the document as part of a submission to a contest.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-25 23:17
    Thanks for filling me in on that, Loopy. My tests show that the manual is indeed correct in this case. The tutorial has been very helpful to me and it is very interesting to know that I may be the first. Maybe I can break some new ground. I am beginning to believe that my impasse is rooted in the failure of the Sparkfun level shifters to facilitate the serial communication with the hp48. These items were made for the Arduino to RS-232 world and this may be somewhat different. They use a "voltage stealing" technique to work without a MAX-232 chip. They also have a breakout board that uses the MAX3232 and I have ordered two of those. I will report results right here for sure.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-26 06:17
    Hi,
    The Sparkfun level shifters that you mention take the 3.3v and 0v (high and low respectively) and invert them to having true RS232 in which a +V equal to the original 0v, and a -V equal to the original +3.3v.

    On the other hand, the Propeller without level shifters is just another 3.3v logic device.

    Since the two inversions in the level shifters will cancel out, you may not need any.

    So instead of adding two inverters in between, one can simply connect the 3.3v level logical signals together and get good results over short distances of wire (let's just say 12 inches or less). If you do get something that isn't quite right, use a slower baud rate. My HP50gx is initially set for 115200 baud.

    Rx still goes to Tx, and Tx still goes to Rx. Just be sure to also have a shared ground. The 4th power wire on the HP-48 can be left disconnected.

    On the other hand, if you just want to snoop the HP-50gx with a regular computer, you need the SparkFun level shifter to connect to a regular RS232 port or to a RS232 to USB adapter.

    And you can use RealTerm on any Windows computer to see what the HP-48 is trying to do.

    It is Free and an excellent RS232 bench tool
    http://realterm.sourceforge.net/

    And the new RealTerm does even more than RS232 -- 1wire, I2C, SPI -- but I have no idea how. It seem you have to buy a $69.xx USD adapter for that.

    There are two types of data streams for RS232 -- a simple character-by-charcter stream, and larger packet streams. I am a bit concerned that the HP-48 might only generate and receive packets. This is not the usually set up for Forth, packets will likely overrun the incoming buffer in Forth, and outgoing characters will be ignored by the HP-48 unless they have the right presentation as a complete packet.

    ~~~~~~~~~~~~~~~
    I came across an Advanced Users Manual that is supposed to be backward compatible for the HP-48, 49, and 50 with more specific serial i/o info.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-27 03:14
    Hi, Loopy. I really appreciate you taking time to help. I have downloaded Realterm and will install it tomorrow - sounds good. I have communicated between my hp48 and PC on both real RS-232 ports and through USB converters for years however I am a bit leery about connecting it directly to the Prop. Doesn't the 48 send negative voltages as part of the data stream? I have consulted the "HP 48 I/O Technical Interfacing Guide" and I am not really sure about that and whether the positive tx pulses would be close to the power supply of 4.5v. I don't have a scope to look at it. Would 4.5v on a port pin hurt the Prop?

    This is clipped from the Guide:
    Output voltage swing. Min. Typ
    Load: 3 kW min, 500 pF max +/-3.0 3.5

    - not sure exactly what it means by "voltage swing".


    As for data format the 48 will allow to send users ( or program ) defined strings via XMIT. Also it watches the input buffer with BUFLEN and receives with SRECV ( n -- nstring ).
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-27 08:31
    Hi Art,
    Well, at the plug-in... it seems that the HP50g just has four pins. A Ground, a power supply of about 6 volts direct from the batteries, and an Rx and TX that swing between 3.3v and 0.

    This is NOT true RS232, which can swing as much as -12 to +12. And it is inverted from what true RS232 is.

    In other words, +3.3 is considered an RS-232 low and 0 is considered an RS-232 high. There is usually a level shifter inserted to invert AND to create the negative switch. If you cable has that built in, you need another level shifter to BOTH invert the logic and to protect the Propeller.

    On can use a chip. The ubiquitous one is the MAX232 which require a +5 volt power supply. There is also a harder to get 3.3 volt version.

    Or you can build an RS232 to Propeller interface from very cheap transistors.

    How to test for a negative? Well, a digital multimeter can usually tell you something. Or you can attach an LED and see if it lights up during RS232 messages even when the polarity is reversed. I suspect the only risk is that you may burn up an LED due to excessive voltage.

    If you have two computers with RS232 ports availabe, you might build a Y cable that has two computers connected to the HP48. One will have your usually Hp communications software. The other can have RealTerm snooping and capturing what the two computers are saying to each other.

    It you need a really cheap scope, there is software that uses the sound card ports on your computer to provide an oscilloscope. This is quite adequate for the speeds of serial ports. But I did construct a device that protects my microphone or aux input from excess voltages by using an opto-isolator in each stereo channel. You can run wires direct, but on a bad day you may just kill the audio inputs on the computer by doing so.

    If you want to build a sound card oscilloscope interface, I will have to dig around for information. The scope software is free and in Windows.
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-01-27 19:02
    If you can find LAC, you can use one of the prop's cogs as a logic analyser. You can monitor the start of the pins your are looking as, set the trigger, and sample as appropriate for the speed of the signal.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-28 00:25
    The logic analyzer that Prof Braino mentions is indeed handy. So is a home-brew one bit Logic tester. Forest Mims has touted building these.

    I strongly suspect that if the cable has a plug for the HP calculator on one end and a DB9 on the other, it includes a converter to true RS232 logic. That 6v power is there to provide for such a conversion. Only a cable that is bare wire from the HP would be certain to be raw signals.

    +++++++++++++++++

    I must admit that I set aside my HP50gx and its RS232 port as it seemed to be yet another Windows driven black box with a special cable. I am very much into visible generic interfaces and the HP-50gx seemed to go in another direction -- trying to establish a second market for add-on devices rather that to plug into all-and-everything.

    I can't be sure until my cable arrives and I do some hands-on investigation.

    But the bottom-line is that I find great joy in using a EeePC and a Propeller in combo for a very good working pair, and I can even do a heck of a lot more because my OS is Linux. There is a vast array of good free software with large active user groups.

    ++++++
    Of course, with the portability of the calculator -- you might visit someone that has a scope and get a quick peek at what your output really is.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-01-28 09:00
    Hi Art,
    Not sure if you are aware of the HP50 Advanced User Reference. Several entries on use of the serial io.

    OPENIO, BUFLEN, CLOSEIO, SBRK, SRECV, STIME, XMIT


    http://commerce.hpcalc.org/50gaur.php And there is a free download.
  • artkennedyartkennedy Posts: 174
    edited 2014-01-28 21:11
    Hi Loopy, I have an hp50 and several hp48g 's and all the docs. But thanks for the reference anyway. It has been quite a while since I have used my hp50 and I had forgotten how pi**** I was that they advertised that it had a RS232 port when it did not even approach the standard. I got one of those cables for it and it works fine. However I am currently working with the earlier hp48 ( I greatly prefer to work with it ) which does just fine with generic RS232. It has the functions you listed and I know how to use them.

    I am hoping to get my MAX3232 based adapters from SparkFun tomorrow and I am confident ( mostly ) that I will then be swimming. Here's a link if you are interested: www.sparkfun.com/products/11189

    I took a closer look at using the sound card for scope measurements and I see that input limits are 0.7v plus and minus. That means building an adapter. Could do - not into it.

    BTW, I also have an hp49g and an hp48ii ( may someone roast in a very hot place for misusing those hallowed digits ) and it is all Smile compared to the hp48g. Yes they have a USB port but only slave mode. Yes, they are faster and have more memory and even an SD port but the programming interface we old 48ers love was trashed and on top of all that they claimed a RS232 port for the 50 and it was a lie. Don't get me started! Oh, you did . . . sorry.

    After I get the system working I may modify the code for use with the 50 for the speed and better display and menu system and SD storeage . . . or not. We'll see.

    Smiles, Art
Sign In or Register to comment.