flexspin - wish list for C programmers (solved)
Reinhard
Posts: 489
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
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
_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
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.
Thank you for the quick response, but what SPIN documentation to you mean ?
Reinhard
https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit?usp=sharing
Reinhard
Thank you , I have download the doc as pdf and the section Built-In Symbols for Smart Pin Configuration is very helpful.
Reinhard
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
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));
}
}
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
There is now the standard function PINSTART(), which does exactly the same as pinconfig().
And all the predefined constants makes it more readable: Andy
@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
Thank you anyway.
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/.
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