Shop OBEX P1 Docs P2 Docs Learn Events
Propeller C Manual? — Parallax Forums

Propeller C Manual?

I'm fairly proficient at SPIN, trying to teach myself PropC. Is there a manual of some kind explaining usage of PropC code? I cant find anything and am trying to rely on start simple examples which don't contain everything that I am looking for.
«1

Comments

  • Have you tried the Learn site?

    http://learn.parallax.com/tutorials/language
  • If you've gone through the Start Simple examples, then it might time to stop exploring Propeller-specific C tutorials and start reading other C and C++ tutorials. Do you have some examples of things you'd like to do? Are you looking for reference material on syntax and the standard library, or are you looking for a 100+ page book that walks you through best practices and high-level concepts?
  • Yes, it is available within simple ide. Looking for a comprehensive list of PropC instructions like there is for SPIN.
  • There aren't really PropC "instructions" - there's just C. If you're looking for the functions to access the built-in Prop features and registers, those should be defined in propeller.h, cog.h, etc.

    Otherwise it follows the C/C++ spec.
  • They are defined,but hard for a beginner to understand as the whole syntax is not laid out.
  • JasonDorieJasonDorie Posts: 1,930
    edited 2016-09-29 00:03
    Try here: This is one of the help pages included with SimpleIDE:

    http://learn.parallax.com/support/C/propeller-c-reference

    Near the middle of the page is a link, "Open the latest Simple Library Reference release". It takes you here:
    https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple Libraries Index.html

    That's been my go-to reference for Propeller stuff in C.
  • Just so I understand the format of propeller.h, can you show me the syntax of dira and outa as used in PropC. I should be able to take it from there. I appreciate all your help.



  • DIRA in propeller.h is the DIRA register in hardware - it does not support any special commands. Use standard C syntax to assign values to the DIRA register. You can clear the entire DIRA register with "DIRA = 0;". Or, you can set only the lowest bit with "DIRA = 1;". Or, C's hexadecimal notation is 0x..., so you set pins 16-31 as output with "DIRA = 0xffff0000;".
  • Set a pin: DIRA = DIRA | (1 << pin);
    Clear a pin: DIRA = DIRA & ~(1<<pin);

    Each bit in the register corresponds to a pin on the Prop. Using standard bitwise operators you manipulate the bits:

    OR is | (vertical bar)
    AND is &
    NOT is ~
    XOR is ^

    These are bitwise operators, not logical operators - they perform their actions on individual bits.
  • yetiyeti Posts: 818
    edited 2016-09-29 19:29
    ...or binary!
    But gcc does not allow throwing underscores between the bits... :-(
    DIRA |= 0b00000000000000000000000000001111;
    
  • I appreciate the help guys :)
  • It looks like simpletools in the start simple examples does a lot of work for you.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2016-09-30 01:39
    Beavis3215 wrote: »
    It looks like simpletools in the start simple examples does a lot of work for you.

    Indeed it does. It is what is known as a "Hardware Abstraction Layer" (HAL) which is a buzzphrase that just means it provides a lot of low-level functions/objects/classes/whatever to interface with the physical world. The idea is that you should be able to use a HAL without knowing anything (or at least, not very much) about the hardware that is executing your code. Talking about pins again, simpletools provides the functions "high(1)" and "low(1)" to set a pin high or low. You don't have to know anything about how pins are controlled on the Propeller hardware to use these functions, so these are two excellent examples of functions that belong in a HAL. There are other HALs designed for the Propeller that are written in C and C++, but for someone that is still learning C, SimpleIDE and simpletools is a great place to start.
  • Beavis3215 wrote: »
    It looks like simpletools in the start simple examples does a lot of work for you.

    It does, but there is a speed cost. In the thread below, I compared simply transitioning a pin from high to low and found a great difference in number of clocks to do that based on the method used.

    PASM was the fastest at 6 clocks.
    Spin took over 500 clocks (depending on method)
    Prop C had a wide range depending on method and memory model. For example using SimpleIDE with CMM memory model was slowest at over 700 clocks, while using propeller.h with LMM took only 17 clocks.

    The detailed results are in this thread:
    https://forums.parallax.com/discussion/164271/solved-with-timing-results-problem-with-pasm-counters-ctra

    Tom
  • Is there a reference for the contents of simpletools.h?
  • I should have known that.Thanks
  • Beavis3215Beavis3215 Posts: 229
    edited 2016-09-30 22:29
    What do the prefixes such as void, long and int mean in the reference for simpletools.h?
  • David BetzDavid Betz Posts: 14,511
    edited 2016-09-30 22:43
    Beavis3215 wrote: »
    What do the prefixes such as void, long and int mean in the reference for simpletools.h?
    Those are the types of the return values for the corresponding functions. In other words:
    int foo(int a, int b);
    
    is a function that returns an integer value.
    void foo(int a, int b);
    
    is a function that returns no value.

  • Got it
  • Beavis, there are many tutorials on programming in C on the internet. I suggest that you try one of them to learn the basics of C. If you google "c programming tutorials" you'll get lots of hits. Unfortunately, I can't tell you which one would be the best to start with. If I were you I would probably start with one of the YouTube links, and then go from there.
  • Beavis3215Beavis3215 Posts: 229
    edited 2016-10-02 02:12
    /*
    3 button calculator

    */
    #include "simpletools.h" // Include simple tools

    int main() // Main function
    {
    set_directions(9,4,111111); // Output Lights
    set_directions(23,21,000); // Input Buttons
    int button1 = input(21); // Enter operand one at a time
    int button2 = input(22); // Plus and clear
    int button3 = input(23); // Equals


    while(1)
    {
    int a = 0;
    int b = 0;
    int c = 0;

    while(button2 == 0) // Enter first operand
    {
    if (button1 == 1)
    {
    a = a + 1;
    set_outputs(9,4,a);
    pause(100);
    }
    }
    while(button3 == 0) // Enter second operand
    {
    if (button1 == 1)
    {
    b = b + 1;
    set_outputs(9,4,b);
    pause(100);
    }
    c = a + b;
    set_outputs(9,4,c);
    }
    while(button2 == 0) //Clear when button 2 pushed
    {
    }


    }
    }
    Any Idea why this doesn't work?
    Enter first operand using button number 1, shown on leds. Hit button number 2 for plus. Enter second operand using button number one shown on leds. Add result using button number 3 and display on leds as long as it is not too big. Clear and start over using button number 2. Problem is not hardware as I have written an equivalent program in spin that works.
  • The constant 111111 is a decimal number. I think you want 0b111111, which is a binary number.
  • There is at least another problem too. Do i need to be concerned with a,b and c being decimal? if so what do you use?
  • Can you post your Spin program? That way we can compare it to your C code and tell where the differences are.
  • It's only when assigning constants to a variable that you have to worry about the form they're in.

    These statements are identical as far as the runtime code is concerned:
    int a = 16;
    int a = 0x10;
    int a = 0b10000;

    They just look different to you as the user. The different ways of representing number constants are for human readability only.

  • pub waitbutton(button,frac)

    If ina[button] == 1
    outa[9..4] := outa[9..4] + 1
    waitcnt(clkfreq/frac + cnt)




    3 Button Calculator
    obj wait : "waitbutton2"
    var byte a,b,x,y

    PUB Calc

    dira[9..4]~~
    dira[23..21] := %000

    outa[9..4] := %000000
    x := 0
    y := 0
    repeat
    repeat while x == 0
    wait.waitbutton(21,3)
    if ina[22] == 1
    x := 1
    a := outa[9..4]
    outa[9..4] := %000000

    repeat while y == 0
    wait.waitbutton(21,3)
    if ina[23] == 1
    y := 1
    b := a + outa[9..4]
    outa[9..4] := b


    The spin version does not have a "clear", but otherwise the logic "should be" the same.

  • JasonDorieJasonDorie Posts: 1,930
    edited 2016-10-02 20:40
    When you post code, if you click the "C" button in the edit window, or just put [ code ] [ /code ] around your code, without the spaces, you get pretty code like this:
      int number = 50 * 14;
      int number2 = 20 + Function( x );
      {
        // indenting gets preserved
      }
    

    It makes it much easier for the forum people to read your code and help you, particularly in Spin because the indenting itself controls much of the program flow.
  • Dave HeinDave Hein Posts: 6,347
    edited 2016-10-02 21:04
    Beavis, try the C code below. This is pretty much a one-to-one translation of your Spin code. It should function the same as your original code. I'm not sure if this code does what you intend. After pins 22 and 23 have been set to 1 the inner while loops will be blocked from running, and the outer while loop will just spin forever doing nothing.
    #include <simpletools.h>
    
    //3 Button Calculator
    void waitbutton(int button, int frac)
    {
        if (input(button) == 1)
        {
            set_outputs(9, 4, get_outputs(9, 4) + 1);
            waitcnt(CLKFREQ/frac + CNT) ;
        }
    }
    
    static char a, b, x, y;
    
    int main(void)
    {
        set_directions(9, 4, -1);
        set_directions(32, 21, 0);
        set_outputs(9, 4, 0);
    
        x = 0;
        y = 0;
    
        while (1)
        {
            while (x == 0)
            {
                waitbutton(21, 3);
                if (input(22) == 1)
                {
                    x = 1;
                    a = get_outputs(9, 4);
                    set_outputs(9, 4, 0);
                }
            }
    
            while (y == 0)
            {
                waitbutton(21, 3);
                if (input(23) == 1)
                {
                    y = 1;
                    b = a + get_outputs(9, 4);
                    set_outputs(9, 4, b);
                }
            }
        }
    }
    
  • Beavis3215Beavis3215 Posts: 229
    edited 2016-10-04 11:05
    This is awesome. I understand all except the -1 in set_directions(9, 4, -1). Thank you for your help, Jason too. Tried it and it works.
Sign In or Register to comment.