Replies: 4 comments 1 reply
-
Yes the correct formula is:
Because its +/- 2048 counts. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I didnt see this initially. hmm. This functionality may not have been tested much on DxCore (the enhanced analogRead() functions were mostly developed on the 2-series to take advantage of it;s fancy ADC, but then hastily ported to DxCore and I'm not sure whether I did much testing, so there may be an issue here, I will investigate... So, you have the voltage reference on one pin, and... what on the other? This is on a 28 or 32 pin part I take it? (if it;'s got more pins, you're reading from non-ADC pins) At times I wonder if I should have declared that all pin numbers shall be (port * 8)+bit, so 28 pin part pin numbers would start at 0, go up to 7 (PORTA), then there's no PORTB so next is PORTC with pins 16, have 17, 18, and 19 - it's only got a half port there so then it would jump to 24 for PORTD, continue through to 31, etc - which would make the pin numbers and PIN_Pxn constants equally portable, and digitalPinToPort(pin) could just be (pin >> 3) and digitalPinToBitPosition(pin) would be (pin & 0x07), and a whole bunch of garbage would be optimized away). It would definitely have been wierder to work with though; |
Beta Was this translation helpful? Give feedback.
-
Its the 28-pin part. I got it working. The rest about the sensor impedance and Vref don't matter much at this stage. Overall, it seems to work well. Just finishing up a hardware revision. Will have more to say after I get the board back and write more code that uses the ADC. As for pin numbering I was reluctant (old dog etc) to use the PIN_Pxx notation but now I like it. Just drop the old pin numbers all together. Is that possible/practical? |
Beta Was this translation helpful? Give feedback.
-
One thing to remember about the ADC in the Dx-series for differential measurements. The voltages you are measuring must both be less than VREF. which is a mondo bummer when the EA-series finally gets here it will have the 12-bit differential ADC with programmable gain amplifier like the 2-series has (and which prompted me to write that function!) |
Beta Was this translation helpful? Give feedback.
-
I just tried doing a differential reading and am confused about something. I don't seem to be getting an ADC reading that corresponds to the voltage of the signal. My math/assumptions etc could be wrong. This is the code I'm using to do the read:
adc = analogReadDiff(17, 16, 12, 0);
And the conversion to volts:
#define ADC_VREF 3.33 #define ADC_SCALE (ADC_VREF / 4096.0 / 2.0) volts = adc * ADC_SCALE;
Again I don't understand why line breaks are not working in code blocks. Sorry.
Also, I am using an external voltage reference hence 3.33V and a sample duration of 255 because sensor is very high impedance (100-100K resistance range). Hmmm should that be * 2.0 instead? Thx.
Beta Was this translation helpful? Give feedback.
All reactions