Getting started with P1 and how to code
cybersack
Posts: 10
in Propeller 1
This post by me was originally posted in the wrong place ... Propeller 2 Specs ... moving it to a better place.
Some very kind people already replied to the original posting, so you may have some related material there
Thanks for some really informative replies.
Please let me know if I am posting in the wrong place and I will move the topic accordingly.
So, in a nutshell, it sounds like:
* C libraries consume excessive RAM on a P1
* on a P1, Spin + Propeller Assembler is generally advised/preferred
* there are, however, optimized C libraries provided by Parallax which reduce the overhead (are they pre-loaded in the firmware ?)
* Spin byte-codes are especially compact (I assume like in java byte-code ops, there is a seek nature to the instruction set allowing smaller chunks to be loaded)
I have read this document:
https://propgcc.googlecode.com/hg/doc/Memory.html
About me:
* I am less comfortable playing with registers than I am with traditional object modelling and encapsulation (C++/Java where the metal is far far away)
* I have only rudimentary Assembler experience and would be significantly less productive there ... BUT if the potential win is significantly greater than choosing alternative paths, I would still adopt it
* C is fine (if I have good debugging tools with which I am proficient)
Spin sounds excellent from the perspectives of lower entry barriers and thinking-in-object-land.
Questions I have:
* Is Spin a language that you people feel has led you to obtain better results (quality/productivity) ?
* Is Spin a language that will be offered on the P2 ?
Otherwise, I am off to try and learn how to put my first project together .... and I am happy to hear anything you guys have to say
Once again, thanks for reading !
Some very kind people already replied to the original posting, so you may have some related material there
Thanks for some really informative replies.
Please let me know if I am posting in the wrong place and I will move the topic accordingly.
So, in a nutshell, it sounds like:
* C libraries consume excessive RAM on a P1
* on a P1, Spin + Propeller Assembler is generally advised/preferred
* there are, however, optimized C libraries provided by Parallax which reduce the overhead (are they pre-loaded in the firmware ?)
* Spin byte-codes are especially compact (I assume like in java byte-code ops, there is a seek nature to the instruction set allowing smaller chunks to be loaded)
I have read this document:
https://propgcc.googlecode.com/hg/doc/Memory.html
About me:
* I am less comfortable playing with registers than I am with traditional object modelling and encapsulation (C++/Java where the metal is far far away)
* I have only rudimentary Assembler experience and would be significantly less productive there ... BUT if the potential win is significantly greater than choosing alternative paths, I would still adopt it
* C is fine (if I have good debugging tools with which I am proficient)
Spin sounds excellent from the perspectives of lower entry barriers and thinking-in-object-land.
Questions I have:
* Is Spin a language that you people feel has led you to obtain better results (quality/productivity) ?
* Is Spin a language that will be offered on the P2 ?
Otherwise, I am off to try and learn how to put my first project together .... and I am happy to hear anything you guys have to say
Once again, thanks for reading !
Comments
I would include PropBASIC in that 'language list'
one starting thread, is an example in use...
http://forums.parallax.com/discussion/123170/propbasic-reciprocal-frequency-counter-0-5hz-to-40mhz-40mhz-now
Nope. If RAM is your main concern, use the "CMM" memory model which my benchmarks have shown to be roughly equivalent in speed and size to Spin (others have seen better and worse performance though).
This might be true, but I think that's pretty well expected. PropGCC has only been around for three years I think but Spin and the PropTool have been around since the chip was released some (15???) years ago. I'm ignoring all other languages and compilers (like Catalina) because these are the only two "Parallax supported" options which I think therefore gain the most popularity.
Ha the ones provided by Parallax in C are not optimized, and were not intended to be. They're meant to be easy and in C, not fast or small. libpropeller, PropWare and objects converted using spin2cpp are fast. Most objects in the Learn folder (Simple libraries) are not.
As mentioned in my above point, they're roughly equivalent to CMM instructions.
You're gonna love PropWare.
As Cluso mentioned in the other thread, the Propeller's assembly instructions are quite easy. On par with Intel 8051 - they're great! Definitely give it a shot sometime. You don't have to be an expert in every single instruction - just post your code once it's working and the PASM experts around here (not me) will tell you how to improve it with some of the less common opcodes.
This is obviously very personal and will differ for everyone. I'm sure others will reply to this question with an enthusiastic "YES!"
But, for me, no. I love C++ in embedded systems. It's been very hard to create PropWare and I've had to learn way more than I ever expected to, but I've been able to do things that just aren't possible with Spin. Certainly Spin can do things that C++ and PropGCC can't, but for me, the tradeoff is well worth it. I'm a very happy camper in C++/PropGCC land. I'm also a huge fanatic of fcache and inline assembly - the combination of which have allowed me to read/write files on an SD card with a single cog and a speed that is much faster than the Simple libraries.
There is this wonderful and fast
TACHYON Forth by Peter
forums.parallax.com/discussion/141061/tachyon-o-s-furiously-fast-forth-compact-bytecode-interactive-fat32-lan-vga-more#latest
With the prop P1 there are NO INTERRUPTS. So you don't have to worry about them. You just program a separate little module to run in its own cog (core).
So you mix spin and pasm programs. Where you don't need to have the speed just use spin. Its easy to use providing you don't try to squeeze everything out of it. ie avoid using the +=, ~, ~~, and other hard to read heiroglifics (wrong spelling ). use x := x+1 rather than x++, x := x + 2 rather than x += 2, x := 0 rather than x~, etc. Easier to read until you get used to spin. The same applies to C.
Spin can be thought of a simpler language but it REQUIRES indentation. PropTool has a switch to show how indentation is being applied. Not sure about the other IDE's.
If you are more familiar with C then by all means use it.
And if you want to learn a type of forth, then you cannot go past Peter's TACHYON. It's a realtime development language right on the prop and its running on the P2 FPGA too.
Two things come to mind. No need to worry about types in spin. And spin has less overhead for calling methods, so tight loops that invoke a function are much slower in C or C++ (I remember this was one of the big takeaways when benchmarking the TFT drivers a while ago)
Really? Why? I thought Spin function calls were expensive compared to PASM ones! Does the CMM kernel not have bytecodes (or whatever) for calls and returns or something? If not, why doesn't someone fix that?
However, I seem to recall that the fibo program runs significantly faster in LMM C than it does in Spin. Maybe CMM C is slower than Spin. It should be pretty easy to verify.
GCC pushes local variables to the stack before invoking a function and then, upon returning, pops them back off the stack. As I understand it, Spin doesn't. So if you have to call a function a lot and in different places (if you only call it one place, GCC will inline it for you), then it starts to slow down compared with Spin.
Not in that thread. I haven't seem him comment on the TFT code anywhere else either.
C: Can't comment, didn't try it.
Spin: It's so much like C. It has iterative loops, it has if than and while loops. As a guy pretty experienced in c it took like two weeks and one of two projects to be preeetty comfortable with Spin. It's really not that different. I don't see what the big whoop I'd about Spin vs C. Just learn Spin, really.
PASM: It's the only way to run a program FROM a Cog. It's significantly, absurdly faster than any other option. High speed communication? Shift in/ out, bit banging high speed signals, PASM is the only option. Honestly, as a guy that started ASM with PIC assembly in Atrium and was really confused by it, PASM has been a pleasure. The functions are powerful, foreseeable, and many mimic Spin functions.
Forth and Tachyon: It's the general consensus that Forths are king in productivity. But, they have the steepest learning curve. The language format is cryptic and backward. And it ends up being ALMOST as fast as PASM. Which really you're going to need to learn to master any forth.
This template should compile in SimpleIDE and help to even out the playing field.
I mentioned it was the iterative version but is the fibonacci algorithm chosen for benchmarking speed of processing or simply recursion? Are we *that* interested in recursion? How fast does C run the iterative benchmark etc?
BTW, I'm not trying to ruffle anyone's feathers but it seems artificial limits are being placed on performance because C is being used and as acknowledged it's not a good fit for the Propeller. No use talking about how good P2 will be as many other chips will be a better fit for C as well.
It's a lot more roomy, and I see P1 as just a bit tiny for it to all work, unless things get packed in real tight. PASM, Tachyon and SPIN all do that.
But, given just a little more room to work, a lot of this should balance out, particularly if a tight runtime set is developed for C.
I think there's a big difference between "not a good fit" and "not the best fit for every application."
First, let's all accept that "best" is an opinion.
Here's a few easy ones:
1) Education. Parallax believe that C is a better fit for their educational customers.
2) A developer who knows how to fully utilize the power available in today's IDEs (and therefore uses PropWare )
3) Any application where significant parts of the source code are readily available in C/C++ and easily adaptable for the Propeller (think: Arduino libraries)
4) Applications where cogs are the limiting factor. PropGCC's inline-assembler allows a better compromise of performance and code legibility when you have to run in a single cog
-Phil