Yeah, it's not so easy at the moment. It's hard to follow the smartpin description, and you never know if it may be the compiler that has a bug.
For example the _wrpin / _wxpin / _wypin in flex-C have the pin and value parameters in reverse order to the Assembler commands. Not sure if this is intentional, I had to check the listing to find that out.
Cool is that flex-C allows underscores in binary constants (0b011_0000), like Spin does.
You can for sure also use inline assembly instead of _wrpin, _dirl and so on, as you have done.
My testcode reads the GND and VCC reference values only once at begin, for a serious program, you need to recalibrate them from time to time.
It's amazing how stable the raw ADC value is with Sinc2 filtering, compared to other microcontrollers. Also at 13 bits resolution the values differ only marginally. But for an exact measurement you need to know the ADC value for 0V and 3.3V, they are not 0 and 1023 as you would expect with a 10bit SAR ADC.
@Ariba , another question
in your pinconfig (....) you set x = 9 for the adc
void pinconfig(int pin, int mode, int x, int y)
{
_dirl(pin);
_wrpin(pin,mode);
_wxpin(pin,x);
_wypin(pin,y);
_pinl(pin);
}
count from 0 ... 9 is 10 counts
is this the reason for 10bit adc ?
with other words can I say adc - resolution = 2 ^ (x+1) (in a meaningful x-range)
Do you have the newest document, that describes the Rev-B silicon? There is a table on page 72, which shows possible resolution and sample modes you can set with the X value.
Yes for 'SINC2 sampling' it's just the number of bits -1, you write into the X parameter. Works up to value 13, you have then 14 bits for the full range. But in praxis only a part of the full range fits into the -0.3V ... 3.6V that a pin can handle with an ADC gain of 1.
Comments
Can read the raw Values w/o scaling.
Anyway
Thanks
@Ariba and @evanh
For example the _wrpin / _wxpin / _wypin in flex-C have the pin and value parameters in reverse order to the Assembler commands. Not sure if this is intentional, I had to check the listing to find that out.
Cool is that flex-C allows underscores in binary constants (0b011_0000), like Spin does.
You can for sure also use inline assembly instead of _wrpin, _dirl and so on, as you have done.
My testcode reads the GND and VCC reference values only once at begin, for a serious program, you need to recalibrate them from time to time.
It's amazing how stable the raw ADC value is with Sinc2 filtering, compared to other microcontrollers. Also at 13 bits resolution the values differ only marginally. But for an exact measurement you need to know the ADC value for 0V and 3.3V, they are not 0 and 1023 as you would expect with a 10bit SAR ADC.
thank you for this hint. Comes it from temperature effects ?
in your pinconfig (....) you set x = 9 for the adc count from 0 ... 9 is 10 counts
is this the reason for 10bit adc ?
with other words can I say adc - resolution = 2 ^ (x+1) (in a meaningful x-range)
Do you have the newest document, that describes the Rev-B silicon? There is a table on page 72, which shows possible resolution and sample modes you can set with the X value.
Yes for 'SINC2 sampling' it's just the number of bits -1, you write into the X parameter. Works up to value 13, you have then 14 bits for the full range. But in praxis only a part of the full range fits into the -0.3V ... 3.6V that a pin can handle with an ADC gain of 1.