Shop OBEX P1 Docs P2 Docs Learn Events
flexspin - wish list for C programmers (solved) — Parallax Forums

flexspin - wish list for C programmers (solved)

ReinhardReinhard Posts: 489
edited 2021-01-10 13:12 in Propeller 2
Hi
I would like to have something like "smartpin.h" for example.
I got these functions from forum member andy a long time ago.
Thanks again for that.

void pinconfig (int pin, int mode, int x, int y)
{
_dirl (pin);
_wrpin (pin, mode);
_wxpin (pin, x);
_wypin (pin, y);
_pinl (pin);
}
Call example:
pinconfig (ADC, 0b100011_0000000_00_11000_0, 9, 0); // ADC10bit Ainp

I use these functions very gladly and successfully for ADC and DAC methods.
Unfortunately, I cannot establish a reference to the smartpin documentation.
I just do not understand.
So a header like "smartpin.h" would be super helpful.
Is there such a thing?

In the meantime, people in Germany became aware of the P2
and I very much hope that the P2 will prevail here.

Many greetings Reinhard

Comments

  • That function is already there. It kind of uses the SPIN object parameters.

    _pinstart(16, P_ADC | P_ADC_1X, 9, 0);

    All of the SPIN constants are there. Look in the SPIN documentation at the bottom of the document.

    Mike
  • Actually the function "pinconfig" you showed is already built in to flexspin as "_pinstart" (the same as the Spin2 PINSTART builtin method). I forgot to document that, it's fixed in github now. We should add it to the universal propeller2.h file for other compilers too.

    Almost everything from the Spin2 documentation is available in FlexC; the built in methods generally have an underscore in front of them for the C versions, but the constants don't (they probably should but they're defined in such a way that they shouldn't interfere with user symbols that have the same names). So symbols like P_TRUE_A, P_ADC_FLOAT, and so on are available in flexcc and flexspin as defined in Chip's Spin2 document.
  • iseries wrote: »
    That function is already there. It kind of uses the SPIN object parameters.

    _pinstart(16, P_ADC | P_ADC_1X, 9, 0);

    All of the SPIN constants are there. Look in the SPIN documentation at the bottom of the document.

    Mike

    Thank you for the quick response, but what SPIN documentation to you mean ?

    Reinhard
  • TubularTubular Posts: 4,702
    edited 2021-01-09 21:27
    The spin2 documentation link is in the first page of the "PNut/Spin2 Latest Version" sticky thread,
    https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit?usp=sharing
  • ersmith wrote: »
    Actually the function "pinconfig" you showed is already built in to flexspin as "_pinstart" (the same as the Spin2 PINSTART builtin method). I forgot to document that, it's fixed in github now. We should add it to the universal propeller2.h file for other compilers too.

    Almost everything from the Spin2 documentation is available in FlexC; the built in methods generally have an underscore in front of them for the C versions, but the constants don't (they probably should but they're defined in such a way that they shouldn't interfere with user symbols that have the same names). So symbols like P_TRUE_A, P_ADC_FLOAT, and so on are available in flexcc and flexspin as defined in Chip's Spin2 document.
    I have spin2cpp-5.0.3 installed, but I can not find a builtin _pinstart(..)

    Reinhard
  • @Tubular
    Thank you , I have download the doc as pdf and the section Built-In Symbols for Smart Pin Configuration is very helpful.

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2021-01-09 23:30
    I can pinconfig (ADC, 0b100000_0000000_00_11000_0, 9, 0)
    with _pinstart (ADC, 0b100000_0000000_00_11000_0, 9, 0)
    replace. It compiles with no errors.
    Still, I don't understand it yet.
    I suspect that the parameter mode describes the PPPPPPPPPPPPP_TT_MMMMM field.
    That is 20bit.
    The constants in the SPIN documentation are 32 bits wide.
    How is the AAAA_BBBB_FFF field described (Xval, Yval ???)

    PINSTART(PinField, Mode, Xval, Yval) Start PinField smart pin(s): DIR=0, then WRPIN=Mode, WXPIN=Xval, WYPIN=Yval, then DIR=1
    _pinstart(ADC, 0b100000_0000000_00_11000_0, 9, 0); // ADC10bit GND ref


    D/# = %AAAA_BBBB_FFF_PPPPPPPPPPPPP_TT_MMMMM_0 4+4+3+13+2+5+1=32bit
    | | | 1000000000000_00_11000_0
    | | | | | |_______11000 = ADC sample/filter/capture, internally clocked
    | | | | |___________00 ?
    | | | |_________________ADC GIO 1x
    | | |_____________________________?1
    | |_________________________________?2
    |_______________________________________?3



    Sorry, the formatting went wrong
  • The mode value is 32 bits; whoever gave you that example just left off the upper bits because they're all 0.
  • I get it from this example by forum member

    void pinconfig(int pin, int mode, int x, int y)
    {
    _dirl(pin);
    _wrpin(pin,mode);
    _wxpin(pin,x);
    _wypin(pin,y);
    _pinl(pin);
    }

    void main()
    {
    int v, v0, v3, da;

    clkset(_SETFREQ, _CLOCKFREQ);
    _setbaud(BAUD);

    pinconfig(ADC, 0b100000_0000000_00_11000_0, 9, 0); // ADC10bit GND ref

    _waitx(_CLOCKFREQ/100);
    v0 = _rdpin(ADC);
    pinconfig(ADC, 0b100001_0000000_00_11000_0, 9, 0); // ADC10bit VCC ref
    _waitx(_CLOCKFREQ/100);
    v3 = _rdpin(ADC);
    pinconfig(ADC, 0b100011_0000000_00_11000_0, 9, 0); // ADC10bit Ainp
    da = 0x4000;
    pinconfig(DAC, 0b10100_00000000_01_00010_0, 1, da); // DAC16bit dither

    while(1) {
    _waitx(_CLOCKFREQ/10);
    v = _rdpin(ADC); //read ADC
    _wypin(DAC,da); //write DAC
    da = (da + 128) & 0xFFFF; //ramp up DAC value
    printf("ADval = %d mV\n",(v-v0)*3300/(v3-v0));
    }
    }
  • ReinhardReinhard Posts: 489
    edited 2021-01-09 23:44
    @ersmith please kann you give me an example to replace this
    pinconfig(ADC, 0b100000_0000000_00_11000_0, 9, 0); // ADC10bit GND ref
    pinconfig(ADC, 0b100001_0000000_00_11000_0, 9, 0); // ADC10bit VCC ref
    pinconfig(ADC, 0b100011_0000000_00_11000_0, 9, 0); // ADC10bit Ainp
    pinconfig(DAC, 0b10100_00000000_01_00010_0, 1, da); // DAC16bit dither

    with _pinstart(.....) at best with symbolic names ?
    this can help me to understand

    Thank you
    Reinhard
  • @Reinhard: I'm not the best person to ask about the smart pin modes, I haven't tried very many of them. But "pinconfig" and "_pinstart" seem to do exactly the same thing, so just replacing "pinconfig" with "_pinstart" everywhere should work.
  • AribaAriba Posts: 2,690
    edited 2021-01-10 05:53
    It was me that gave you that example. Many things have improved since then.
    There is now the standard function PINSTART(), which does exactly the same as pinconfig().
    And all the predefined constants makes it more readable:
    pinconfig(ADC, 0b100000_0000000_00_11000_0, 9, 0); // ADC10bit GND ref
    -> _pinstart(ADC, P_ADC + P_ADC_GIO, 9, 0);
    
    pinconfig(ADC, 0b100001_0000000_00_11000_0, 9, 0); // ADC10bit VCC ref
    -> _pinstart(ADC, P_ADC + P_ADC_VIO, 9, 0);
    
    pinconfig(ADC, 0b100011_0000000_00_11000_0, 9, 0); // ADC10bit Ainp
    -> _pinstart(ADC, P_ADC + P_ADC_1X, 9, 0);
    
    pinconfig(DAC, 0b10100_00000000_01_00010_0, 1, da); // DAC16bit dither
    -> _pinstart(DAC, P_DAC_DITHER_RND + P_DAC_990R_3V + P_OE, 1, da);
    
    Andy
  • Ariba wrote: »
    It was me that gave you that example. Many things have improved since then.


    @Ariba
    Many Thanks. This is very helpful. I didn't think that you can combine the symbols to get any desired configuration. Sometimes I don't see the forest for the trees.
    I wasn't on the play for a few months. A lot happened with the development environment.
    Can you give me a tip where I can find out what the parameters Xval and Yval mean for the _pinstart() function and how they work.

    Reinhard
  • ersmith wrote: »
    @Reinhard: I'm not the best person to ask about the smart pin modes, I haven't tried very many of them. But "pinconfig" and "_pinstart" seem to do exactly the same thing, so just replacing "pinconfig" with "_pinstart" everywhere should work.

    Thank you anyway.

    Reinhard
  • Reinhard wrote: »
    Can you give me a tip where I can find out what the parameters Xval and Yval mean for the _pinstart() function and how they work.

    Reinhard

    The Spin2 document is the best place to look. There's also a supplementary document on smart pins that I haven't read yet but sounds useful. Both are linked to from https://www.parallax.com/propeller-2/documentation/.
  • Thank you, these are the documents I was looking for.

    Parallax Propeller 2 Documentation 2020-06-05 v33 (Rev B/C silicon)
    Parallax Propeller 2 Spin2 Language Documentation 2021-01-06
    and the Smartpin doc

    Reinhard
Sign In or Register to comment.