Shop OBEX P1 Docs P2 Docs Learn Events
BASIC Discussion - Page 3 — Parallax Forums

BASIC Discussion

13

Comments

  • jmgjmg Posts: 15,173
    David Betz wrote: »
    jmg wrote: »
    You could look at Spin2cpp, as that can also output P1 PASM and P2 PASM
    - ie operationally close to PropBASIC, but I think PropBASIC is more mature, and probably generates better code.
    You might want to check that. The last I heard PropBASIC just did a simple unoptimized translation into PASM. I think Bean said it was pretty much one-to-one. I believe Eric has at least some optimization in his PASM generator and going through GCC gives you all of its optimizations.
    I was going on my memory of Bean's comments and examples, where it looked to have quite good code generation.
    As expected, given it is a mature product that was used in real designs.
    Spin2cpp is quite new, so I'd expect not as far up the experience curve.

    If anyone wants to post side by side examples, that would be interesting.

    My favourite PropBASIC example was the 0.5Hz~40MHz Reciprocal Counter.

    A compiled Spin version of that would also be a good Spin - Basic comparison.
  • MicksterMickster Posts: 2,693
    edited 2017-01-11 01:20
    However I just wonder how large your programs are because you keep saying that it generates PASM code with zero overhead, which is true for any tiny bit of code that can fit into an absolute maximum of 496 PASM instructions in a cog, less though as some need to be registers. Doesn't it generate LMM code which requires a runtime interpreter and runs about ten times slower than PASM yet has the same memory overhead? Could you fit a FAT32 filesystem into a Prop and still have room for an application?

    My applications include FAT32 and Ethernet servers so there is no way in the world that it could ever run in a cog or LMM or even CMM, and XMM would be way too slow.

    From the PropBASIC documentation:
    Native versus LMM programs:

    PropBasic can generate two different type of code. Native or LMM.
    Native code is generated by default. When a native code program is started the code is loaded into a COG's RAM and is executed directly.
    LMM code is generated by appending the word LMM to the PROGRAM command or the TASK command. When a LMM program is started a small “execution” program is loaded into the COG RAM with a pointer to the LMM code. The LMM code is read from HUB RAM one instruction at a time. That instruction is executed, then the next instruction is fetched and executed and so on.

    Native code has the advantage of being about 5 times faster than LMM code. But it is limited to 496 PASM instruction.

    LMM code has the advantage of allowing large programs to be created. Although they run about 5 times slower.

    LMM code is also larger for a given set of PropBasic commands. This is because some instructions need extra data. For example a jump and call instruction use 2 LONGs instead of 1.
    A single PropBasic program can have some TASKs that are native code and some that are LMM. It is fairly typical for the main program to be LMM, and the TASKs to be native code. Since TASK code tends to be smaller and in some cases needs to run fast (like video drivers).
    When a CALL is used in LMM, the return address is stored on a stack that is maintained by the compiler. The stack default to 16 nested calls. But the size can be changed using the STACK directive. The size of the stack may be from 4 to 255. If
    the STACK directive is used it should be directly after the device directives (DEVICE and FREQ).

    Personally, I only use COG (Native) mode and have no desire to use FAT32 or Ethernet servers on the Prop.

  • Mickster wrote: »
    Personally, I only use COG (Native) mode and have no desire to use FAT32 or Ethernet servers on the Prop.

    So these programs that you write must be very simple programs surely, hardly leveraging anywhere near the full power of the Prop. Even user interfaces require quite a bit of source code to implement. I still think however that PropBasic itself is well implemented with the PASM and LMM models but I know that I couldn't use it for a lot of stuff that I do as it would end up being too limited. Anyway, I like an interactive environment to work in if I can, just what we are used to on a PC when we write PC software, so the same when I write Prop software.

  • Hey guys, I did intently cut in, but wondered if I had the stuff that I needed.

    I am thoroughly enjoying my new found environment. Just wanted to ask if BST was still relevant.

    I have PropellerIDE with PropBASIC in Linux, Mint. I had trouble finding the proprietary Parallax font needed to run it.

    May be wasting time to find something outdated.
  • MikeDYur wrote: »
    Hey guys, I did intently cut in, but wondered if I had the stuff that I needed.

    I am thoroughly enjoying my new found environment. Just wanted to ask if BST was still relevant.

    I have PropellerIDE with PropBASIC in Linux, Mint. I had trouble finding the proprietary Parallax font needed to run it.

    May be wasting time to find something outdated.

    I find the PropellerIDE rather slow when I try to navigate using the arrow keys but I much prefer BST in Linux MInt 18.1. Just copy the Propeller font into a .fonts folder in your home folder and restart the IDE.



  • MikeDYurMikeDYur Posts: 2,176
    edited 2017-01-11 15:52
    Thanks Peter Jakacki, I will get to this in the morning. I really appreciate the help.

    EDIT: High winds, power out, no choice.

    EDIT2: @Peter, The power is still out, estimated time for repair is 6:00pm. I may have to go out in the car, if I want to play with Propellers on my power hungry laptop.

    EDIT3: Thanks again Peter, I ran across the installed fonts folder before in Linux Mint (Sarah), couldn't find it now even with a search of the file system. So I extracted it to the desktop, and opened it with the font viewer, and installed it from there. No time to mess with BST though, battery running low, it doesn't help charging my phone through USB either. Now I need to un-join Wikispaces, don't think there will be a reason for needing that.

    Mike Y.
  • jmg wrote: »
    David Betz wrote: »
    jmg wrote: »
    You could look at Spin2cpp, as that can also output P1 PASM and P2 PASM
    - ie operationally close to PropBASIC, but I think PropBASIC is more mature, and probably generates better code.
    You might want to check that. The last I heard PropBASIC just did a simple unoptimized translation into PASM. I think Bean said it was pretty much one-to-one. I believe Eric has at least some optimization in his PASM generator and going through GCC gives you all of its optimizations.
    I was going on my memory of Bean's comments and examples, where it looked to have quite good code generation.
    As expected, given it is a mature product that was used in real designs.
    Spin2cpp is quite new, so I'd expect not as far up the experience curve.

    spin2cpp itself has been around since Dec. 2011, so it's pretty mature. The PASM code generator is relatively new, but it does have an optimizer. PropBASIC doesn't have an optimizer, but on the other hand the language is constructed so that programmers are encouraged to write code that will compile well. For example, in Spin you can do:
      x := a + b + c
    
    whereas in PropBASIC you would have to write
      x = a + b
      x = x + c
    
    Both would generate the same PASM code in spin2cpp and PropBASIC.

    In LMM mode spin2cpp will have a considerable advantage, because it uses the same kind of FCACHE mechanism that GCC does, so small loops end up running entirely out of COG memory. For example, the classic FFT benchmark runs in 171 ms with spin2cpp producing LMM PASM, whereas for PropBASIC LMM it's 691 ms. Neither one is as good as PropGCC, which has a much better optimizer and can can get down to 65ms.
  • MicksterMickster Posts: 2,693
    edited 2017-01-11 16:59
    So these programs that you write must be very simple programs surely, hardly leveraging anywhere near the full power of the Prop.

    Thanks to the Prop's architecture, yes, quite simple. I am hoping to replicate my current US$3,000 OTS hardware for a couple hundred bucks and also add some functionality that I currently don't have with the OTS solution.

    Four cogs are each dedicated to reading a quadrature encoder at rates of up to 1,638,400 quad-counts/sec (4,096 line encoder on a 6,000 RPM motor).

    Something that I don't have on my OTS system is the ability to snapshot the position count on each occurrence of the Index pulse which would be useful for checking count integrity. Encoders don't always simply die, they can gradually lose counts and the first thing you know is that you are either knee deep in scrap parts or the machine crashed. I have included this feature.

    Two cogs are each dedicated to generating two PWM motor commands (19.531KHz, 12bit), two trapezoidal motion profiles including accel (counts/sec/sec), slew (counts/sec), decel (counts/sec/sec) and two PID loops with post-PID offsets.

    One cog for 485 comms.
    Even user interfaces require quite a bit of source code to implement.
    Mine use a lot of source code because I'm a big believer in sex appeal/customer perception (the salesman side of me).
    Even back in my DOS days, I used a Microtouch (now 3M) capacitive (hated those plastic resistive things) touchscreen where the sensor was contoured to fit the CRT and had a touch resolution of 1024 X 1024. I painted my GUI screens (EGA resolution) and stuffed them in a RAM disk (upper 384K of the DOS 1MB RAM).
    At the time, my competitors all had monochrome screens with a Lotus 123 layout and clunky old buttons for data-input...LOL

    A broken UI (happens all too often) renders a piece of equipment useless. I now use an OTS Android tablet....you've already seen it....because MTTR (mean time to repair) has to be my top priority.

    Anyway, I like an interactive environment to work in if I can, just what we are used to on a PC when we write PC software, so the same when I write Prop software.
    Sure, me too. I just did a 3-axis CNC retrofit in Oz, would you believe. Sent them the parts, they wired them in and I took care of setup, debug, code modifications from my bed (time diff), here in the UK. Lil lady was blown away when she realized that I was making a machine move in Oz from my laptop, using Teamviewer.
    This is why I am currently evaluating the ByPic and Micromite as a possible host to the Prop. Any changes to the Prop will be purely parametric.

  • jmgjmg Posts: 15,173
    ersmith wrote: »
    spin2cpp itself has been around since Dec. 2011, so it's pretty mature.
    The PASM code generator is relatively new, but it does have an optimizer.

    Thanks for the update.
    ersmith wrote: »
    For example, the classic FFT benchmark runs in 171 ms with spin2cpp producing LMM PASM, whereas for PropBASIC LMM it's 691 ms. Neither one is as good as PropGCC, which has a much better optimizer and can can get down to 65ms.
    Do you have numbers for Spin2spp, in pure LMM, and PropBASIC doing in-COG FFT, to complete the set ?


  • Heater.Heater. Posts: 21,230
    edited 2017-01-12 00:19
    Eric,
    ...the classic FFT benchmark... Neither one is as good as PropGCC, which has a much better optimizer and can can get down to 65ms.
    Do you happen to mean the "heater_fft" ?

    I was amazed that PropGCC can get the C version of that to run almost as fast as my hand crafted PASM, all in COG, version.




  • ersmithersmith Posts: 6,053
    edited 2017-01-11 21:08
    jmg wrote: »
    For example, the classic FFT benchmark runs in 171 ms with spin2cpp producing LMM PASM, whereas for PropBASIC LMM it's 691 ms. Neither one is as good as PropGCC, which has a much better optimizer and can can get down to 65ms.
    Do you have numbers for Spin2spp, in pure LMM, and PropBASIC doing in-COG FFT, to complete the set ?

    By "pure LMM" do you mean with fcache disabled? As it turns out that doesn't make as much difference as I thought it would -- the time goes up to 177ms (from 171), so I guess the better performance of spin2cpp was due to its optimizer and a faster multiplication routine more than fcache.

    As for in-COG, the FFT test program doesn't fit in a COG, so all the comparisons have to be done with LMM. (Heater did do a hand-crafted PASM+Spin that ran the FFT in a COG and got the best performance of all at 25 ms).

    (And yes, Heater, I was referring to the "heater_fft".)

    Eric
  • When I first programmed I was flipping switches and pushing buttons on the control console. The computer had vacuum tubes. The units had been refurbished and needed retesting. The first 'solid state' computers had very much the same consoles. There were test programs that had to be run. I had copies of the programs and could go directly to memory and 'patch' it to make it cycle a part of code that was having a problem and get my oscope and the logic drawings and troubleshoot to find the bad component or wiring error.

    After my children got their first degrees I went to college and learned a lot of different languages. My favorite was BAL (BasicAssemblyLanguage) because it was closest to the actual computer code it generated. Eventually it became just 'Basic' and PBasic was just the latest variant I have learned.

    I am finishing up a project just in the nick of time. I bought up a bunch of BS2OEM kits as soon as the end of BS2 was announced. The product/system my partner and I plan to sell/market is usable with just two units but having at least 4 units will make for a much more effective demo video. The code is already written and now all I have to do is build two additional units to start showing the world what we built.

    I needed the extra BS2s because my eyes are having trouble seeing what I am looking at and my palsied arthritic hands do not solder a well as when I passed NASA certification. That being the case I do let the magic smoke escape now and then<g>. I am going to make a run at getting a handle on Prop Basic. I have always been a 'learn by doing' type of student so I would appreciate getting pointed at the best place to start on the Prop and Prop Basic.

    I Thank Y'all in advance for your ideas and suggestions.


    trooks
  • MicksterMickster Posts: 2,693
    edited 2017-01-12 19:25
    trooks wrote: »
    I would appreciate getting pointed at the best place to start on the Prop and Prop Basic.

    It appears that the code examples were written for the original "Demo" board.

    I'm not sure of this but maybe the following combo would be compatible(?)

    Quickstart

    Human Interface

    PropBasic is included with the PropellerIDE

  • jmgjmg Posts: 15,173
    trooks wrote: »
    I have always been a 'learn by doing' type of student so I would appreciate getting pointed at the best place to start on the Prop and Prop Basic.
    Once you have the DOCs, Some working code is a good place to start :

    My favourite is the Reciprocal Frequency Counter 0.5Hz~40MHz
    (0.5Hz to allow 1pps GPS calibrate of the counter timebase)

    http://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now

  • Thanks again for the inputs. The more I read the more convinced I am that the Propeller, at least for me, is a waste of time and memory space. I am going to get the 'breadboard learning kit in a parts box' (#32305) just to prove it beyond a doubt. Truth to tell I have bought up a number of Propeller boards at several Radio Shacks. They were likely leftovers after some local colleges and universities completed the current year lab assignments and they were really cheap^H^H^H^H^H inexpensive.

    I have had a lot of good advice here mixed in with advice to move on from BS2 to Propeller<G>. I have been most satisfied with the sales staff. They have gone a bit beyond what could normally be expected when shippers had problems finding me way out here in the sticks. Without the BS2 there is not much more here for me.

    I reasonably expect that the first video my partner and I put on the net will go viral in _some_ circles. I promise to post a link here for Y'all.

    A final question if I may. I will be going to a different microprocessor and have been looking for programmers. Some can even be set up to program a number of different microprocessors. If any here have experience with such I would appreciate any recommendations or warnings. I will check back here before I make a purchase.

    trooks

    Since one of my first paying jobs had to do with plowing my autobiography will have a most unusual title:
    "Singletree mule to single cog programmer"
  • trooks wrote: »
    Without the BS2 there is not much more here for me.
    I'm not sure why you say "without the BS2". As far as I know, only one BASIC Stamp module is being discontinued. I believe that the rest our alive and well and supported here on the forums.

  • trooks wrote: »
    Thanks again for the inputs. The more I read the more convinced I am that the Propeller, at least for me, is a waste of time and memory space. I am going to get the 'breadboard learning kit in a parts box' (#32305) just to prove it beyond a doubt.

    Please give it a chance. It's only when you start playing with the demo code that you start to understand how cool this device is.

    A few years ago, a couple of young computer geeks asked to hang out at my place because they were excited about the fact that I actually made machinery work by programming computers. I had 3 Propeller boards rigged-up and I fired-up a few Spin demos for them to play with (Basic wasn't cool because that was what they'd been told). Darn kids wouldn't go away once they got the grasp of it. The Prop really is an amazing device, especially if the alternative is dealing with a bunch of interrupts.

  • Heater.Heater. Posts: 21,230
    trooks,

    I know nothing of STAMPs and the BASIC they use. I find your posts somewhat confusing. But that has never stopped me before, so here we go: :)
    The more I read the more convinced I am that the Propeller, at least for me, is a waste of time and memory space.
    I presume you mean your own time and mental space rather than that of any micro-controller. This is a shame because the the Propeller is a wonderful machine. Programming in Spin is no harder than any BASIC. Hardware wise it has many endearing features, like being able to run multiple processes at the same time, with no hassle struggling with a real-time OS or juggling interrupts. It's like having 8 STAMPS in a single package!
    I will be going to a different microprocessor and have been looking for programmers. Some can even be set up to program a number of different microprocessors. If any here have experience with such I would appreciate any recommendations or warnings. I will check back here before I make a purchase.
    Other micro-controllers is of course way off topic for a Parallax forum but...

    Of course it's impossible to advice on choice of micro or any component without knowing the intended application.

    If your long term experience is with STAMPs and BASIC and you would like to continue with such simplicity you are going to be seriously disappointed. What are the options:

    1) PIC from Microchip. A great device but you will need to be messing with their IDE and learning to program in C. You will also need dongles to program them. Like the PicKit 3 or whatever it is called.

    2) AVR ATMEL (Now belongs to Microchip) Same as above.

    3) Arduino. Well that is basically AVR and the Arduino guys have created a dead simple programming environment for it. However you will need to be learning C++ to use that.

    4) Other micro-controllers, STM32, Cyprus, etc. I was recently given a Cyprus micro dev board. Small, low power, fast, dirt cheap. It's great but again to use it you have to get familiar with their huge and complex IDE and learn C/C++

    5) Espruino. https://www.espruino.com/ The Espruino is great. It tames the complexity of STM32 and other ARM based MCUs with Javascript. It has the most drop dead simple development environment.

    6) Micropython https://micropython.org/ Like Espruino but using the Python language.

    7) Perhaps other members hear could suggest more options...


    I notice you said you have some great product under development that uses 4 STAMPS. Already sounds like something a single Propeller could do with a lot less complexity, size and expense.





  • yetiyeti Posts: 818
    edited 2017-01-14 16:26
    Heater. wrote: »
    7) Perhaps other members hear could suggest more options...

    Two BASIC-in-a-chip (PIC32) examples are:
    * http://bypic.co.uk
    * http://geoffg.net/micromite.html
    So PIC does not automagically mean C...

    ...and there is Duinomite-BASIC for the Olimex-Maximite-Clones. More than only a bit dusted but the source is freely available, which is not the case for newer Maximite-BASIC versions...

    And there are RetroBSD for PIC32MX and LiteBSD for PIC32MZ with lots of languages.

    An other interesting high level language approach is Oberon for microcontrollers by http://www.astrobe.com (but not for me because of "No Source — No Go!")...

    For ESP8266 there are at least one BASIC, one LISP and 3 FORTH dialects (JS, Lua and Micropython were mentioned already)... GitHub's search will find them... and several C SDKs...
  • KeithEKeithE Posts: 957
    edited 2017-01-14 17:45
    Heater - if you haven't checked out the micromite take a look at the PIC32MX170F256B (MCU 256KB Flash 64KB RAM 40MHz, 10-bit ADC) that can run it. Less than $4 if multiple chips are purchased. You can purchase them preprogrammed with micromite if you don't want to futz around. It includes a built-in text editor for those who are into that sort of thing. Basic has 64-bit ints and floats and can be extended with modules written in C/assembler. Some of the pins have special functions such as PWM so you don't have to manually generate servo pulses. If Parallax were ever to extend basic stamp they should take a close look for inspiration. You may have seen the Ello 2M Laptop project posted to the forums.

    It's got decent documentation too - http://geoffg.net/Downloads/Micromite/Micromite Manual.pdf

    BTW - for ESP8266 the Wemos D1 mini boards sure are getting a lot of attention. Only $5 and they have 16 MB of flash. (Yes that's megabytes!)
  • Heater.Heater. Posts: 21,230
    edited 2017-01-14 17:06
    yeti,

    Wow. Never ceases to amaze me what there is available.

    In my dotage I'm loath to use any language that is not standardized, cross platform, open source and in common use. I have had to deal with consequences of "disappearing platforms" too many times over the decades. Which rules out most of these interesting adventures into "language X on hardware Y".

    I made an exception for the Propeller and Spin. Why? I don't know. It's so unique. More like a programmable logic device than a micro-controller. It's so simple. And now we have Open Source Tools for the Prop and if we ever really need to we can put the Prop into an FPGA.

    Aside: Yep, we can even program the ESP8266 in Javascript.



  • heater wrote:
    I made an exception for the Propeller and Spin. Why? I don't know. It's so unique. More like a programmable logic device than a micro-controller.
    I've always compared PASM to microprogramming. It's more like programming a channel on a mainframe than programming a microcontroller.

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    heater wrote:
    I made an exception for the Propeller and Spin. Why? I don't know. It's so unique. More like a programmable logic device than a micro-controller.
    I've always compared PASM to microprogramming. It's more like programming a channel on a mainframe than programming a microcontroller.

    -Phil

    PASM would have to be the simplest and easiest assembler language I have used/seen, and I have used/seen a lot !!!
  • Cluso99 wrote: »
    heater wrote:
    I made an exception for the Propeller and Spin. Why? I don't know. It's so unique. More like a programmable logic device than a micro-controller.
    I've always compared PASM to microprogramming. It's more like programming a channel on a mainframe than programming a microcontroller.

    -Phil

    PASM would have to be the simplest and easiest assembler language I have used/seen, and I have used/seen a lot !!!

    You're probably right, I was starting to think 6502 but then I thought LDA/STA then LDX/STX then LDY/STY etc whereas we just say MOV in PASM where every one of the 496 "registers" can be an accumulator. Closest CPU to programming in PASM I think was the TMS9900 modeled after the TI990 mini.

  • Heater.Heater. Posts: 21,230
    I hope no passers by take my comment about "programmable logic device" too literally. The Prop is of course an excellent and very easy to use micro controller. Well, 8 of them in a package!

    I agree that PASM is probably the simplest assembler language ever.

    I mean, writing:

    add a, b

    is less mental effort than writing even the high level language:

    a = a + b

    Compared to 6502 and such a lot of the simplicity comes from it being a 32 bit machine. I don't recall any assembler code I have written that did not use a lot of at least 16 bit numbers. Which means you straight away have to write multiple instructions for ever little operation.

    Then, as noted above, one was always having to load stuff before operating on it, then store it back a again.

    All that messing around we had to do starts to make Forth look like a good idea :)

  • Heater.Heater. Posts: 21,230
    The Micromite looks like an incredible piece of work.

    Sadly comes under a very restrictive license so is pretty much off the radar for me.

    Still, I'm tempted to get hold of one for the fun of it.
  • trooks,

    When was the BS2 OEM discontinued because I just noticed last week that it's no longer for sale?
  • yetiyeti Posts: 818
    edited 2017-01-15 09:04
    Heater. wrote: »
    The Micromite looks like an incredible piece of work.

    Sadly comes under a very restrictive license so is pretty much off the radar for me.
    I know a guy who actually got the source but still it is not of much use because of all the restrictions. I always make jokes about the sources like "you have to lock yourself alone in a windowless toilet to be allowed to read them."... :-Þ
    Heater. wrote: »
    Still, I'm tempted to get hold of one for the fun of it.
    I tried but the universe kept me from doing so: I ordered a PICKit-2 and -3 programmer from the friendly chinese not really next door and a bag of empty PIC chips from Microchip-Direct in Ireland. The later was delivered 6hrs before I got home on it's delivery day and a neighbour signed for it. Then he had to leave and didn't want me to wait too long for it, so he deposited it at my door. And when I came come, there was no mailbag from Ireland...

    Well... that's merciful fate! ;-)

    It stopped me from breaking "No Source — No Go!" and that's ok for me now... \o/

    I have some Duinomites (Olimex-ish Maximite clones, bought to play with RetroBSD)... I could run a newer Maximite-BASIC on them instead of the old (but completely open sourced) fork by Olimex of Maximite-BASIC-2.7 but I think I learned my lesson... :-Þ

    Now the PICKits are collecting dust while dreaming of a new mission...:-(
  • Heater.Heater. Posts: 21,230
    Ah yeah. I don't want to have to buy a PICKit-3 to use it. Which probably ties me to Windows. I have enough of such useless dongles around the place.

    Think I'l just crack open another tube of Propellers and continue....

Sign In or Register to comment.