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.
9 years, 9 months ago.
Voltage measurement
Hello,
I am trying to measure a simple vboltage which I vary from 0 to 3V (below maximum), using a bench power supply. I apply this voltage to the pin p20 of my LPC1768 and every second for 20 seconds I read the voltage value and write it to a txt file. Unfortunately this does not work. Here is my code:
include the mbed library with this snippet
#include "mbed.h" LocalFileSystem local("local"); // Create the local filesystem under the name "local" AnalogIn ain(p20); float voltage; int main() { FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing for(int i=0 ; i<=20 ; i++){ voltage = ain.read(); fprintf(fp, "%f " ,voltage); wait(1); } fclose(fp); }
The results of such a code are as follows (whatever the voltage and variations it's always the same.
1.28928e-231 1.17771e-311 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251 -2.86389e+251
Please help me figure what is wrong with my code. Thanks. Maxstag
Something very odd is going on there, a copy and paste of your code works fine for me.
Did you try updating the mbed library just in case it's pulled in an old version somehow? And check that you are building for the LPC1768 in the top right of the compiler window.
Once you figure this out don't forget to multiply by 3.3 (or in practice about 3.15) to get actual voltage.
posted by Andy A 03 Jul 2014