7 years, 5 months ago.

analog input

hi,i have connected 10K pot to my mbed....... 1 vcc 2 wiper to pin 20(analog input) 3 GNDinclude "mbed.h"

AnalogIn ain(p20); int val=0;

int main() { while(1) {

printf("analog input is (%f)",ain.read()); wait(1); wait(1); wait(1);

include "mbed.h" AnalogIn ain(p20);

int main() { while(1) { printf("analog input is (%f)",ain.read()); wait(1); wait(1); }}

i am getting output in serial port.. when the voltage is 3.3 ,i am getting 1.000 and when 0V getting 0.000

i know above values are correct..... but can anyone tell me how conversions are made inside.....as i am giving 3.3v......but it will be displayed 1.000 ....why it is?

1 Answer

7 years, 5 months ago.


When reading analogue signals micro-controllers use a reference voltage, the mbeds is 3.3v, this is compared to the incoming voltage (pin 20 in your case) and depending on the resolution of the converter (the mbeds is 12bit so gets a value between 0 and 4095) you get 0 for 0.0v and 4095 for the reference voltage,

the mbed libraries then normalise this value into a floating point variable for convenience, this is done simply by dividing the integer ( 0 - 4095 ) by the maximum ( 4095 ), this is the value between 0 and 1 you are getting.


Accepted Answer

Is there a way to input a different (especially higher) reference voltage?

posted by Vitit Kantabutra 12 Sep 2016

There is often an analogue reference pin on micro-controllers that you would connect the reference voltage to, the maximum voltage you can use will vary between micro-controllers but its unlikely you can use a voltage much higher than the operating voltage, its used to feed a cleaner, more accurate, voltage from an external voltage source. If you need to measure a higher voltage range, like 0 - 10v, then you can use a voltage divider before the adc.

posted by Chris Pepper 12 Sep 2016