Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 1 month ago.
F401RE Analog In oddness
I've had good success with an F401RE interfacing several kinds of displays, an RFID reader, and some other odds and ends. I'm trying to read voltage with analog in and now I'm running into problems.
I'm using two resistors as a voltage divider exactly as described here: http://startingelectronics.com/articles/arduino/measuring-voltage-with-arduino/
I'm using 1M and 100k resisters, again, exactly as shown in the above page.
Here is the code that converts the value from the AnalogIn to a voltage:
#define R1 990000.0 #define R2 98100.0 #define VCC 5.030 #define V(x) (((VCC*x))/(R2/(R1+R2))) AnalogIn analog_value(A0); pc.printf("Value: %f\n", V(analog_value.read()));
R1 and R2 are the actual values of the resistors I'm using. VCC is the measured reference voltage of the board.
So here are the problems I'm running into: I have to subtract 6.5 volts from the calculated value for it to read correctly. That makes no sense to me whatsoever why it reads 6.5 volts higher than what the math should result in.
When measuring VCC (5.030) and 3V3 I get really good values (again, after subtracting 6.5 volts from the value). However when I measure ground I get around 0.3 volts.
If I switch to a different analog in, like A1, then suddenly that 6.5 volt difference above drops to around a 2 volt difference (thus it is reading 2 volts higher than it should with A1, and 6.5 volts higher than it should with A0). I don't understand why switching from one analog input to another causes totally different results.
Any ideas on what is going on here? Something is definitely out of whack somewhere. Thanks!
1 Answer
10 years, 1 month ago.
I would assume it is due to those resistors. You could try looking up in the datasheet what the max is for the F401, but for example on most NXP targets the maximum interface resistance is 7,5k. Not it won't break directly if you use 10k, but you are effectively using 100k, which is alot. Trying dividing both by 10, so 100k and 10k.
Thank you. I switched to 100k and 10k. The 100k is between the analog input and the voltage I'm measuring, and the 10k is between the analog input and ground. In the conversion calculation I'm using the actual measured resistance for maximum accuracy. Now I get the following results: Testing ground I get very close to 0 volts. That's good. Testing to VCC I get very close to 5 volts. That's good. Testing to 3V3 I get very close to 5 volts. Huh? Testing a 1.5 battery I get 2.2 volts. Testing a 14 V source (as measured on a proper meter), I get 22 V.
The other oddity is that I get values off by around 2V on analog input 0 compared to the other analog inputs. Something is still very screwy.
posted by 19 Nov 2014The problem was two-fold. The F401 doesn't work well with the higher impedance. Which is odd, because the 1M / 100k pair works fine with Arduino which apparently requires even less impedance than the F410RE according to data sheets.
Second, the reference voltage is 3.3V, not 5.0V.
Thanks for your help Erik.
posted by 29 Nov 2014