9 years ago.

Altering the input voltage range of AnalogIn

Is it possible to change the range of the Voltage input. For example, as I understand it, AnalogIn produces a float between 0.0 and 1.0, when a voltage between the range of 0-3.3V is read. Float 1.0 = 3.3v and float 0.0 = 0v and so on inbetween. Is it possible to alter the voltage range input, for example to have 1.81v equal float 0.0 and 2.77v to give float 1.0 with the values in between being linear?

Question relating to:

2 Answers

9 years ago.

The answer is that it depends.

The ADC hardware outputs an integer that varies between 0 at 0V and it's maximum at 3.3V(*see below), what that maximum value is depends on the part being used, some have a 10 bit ADC in which case it will be 1024, some have 12 (4k max) and some may have 16 bits (64k max).

The libraries output a float between 0 and 1 calculated by dividing the number from the hardware by the possible range for your hardware.

So in a way you could get the range you want of 1.81V to 2.77V by adding and multiplying the current ADC by the correct numbers, that's basic maths. The problem is you're only using part of the ADC range, you'll lose about 4 bits of resolution by doing that since the resolution won't be any better than when you were looking at the range of 0 to 3.3V.

If you need the full resolution of the ADC then the simplest approach would be an external amplifier to change your signal so that it uses the full input range.

The ADC hardware in the cpu will often have separate power and ground pins used to give it it's 0 and max voltage levels. In theory changing the voltages on these pins will change the range the ADC uses. However on most mbed boards these are tied directly to the system power rails, a few may make them available to the user I don't know. But even if they are available they are normally intended more as a means to provide a lower noise supply to improve accuracy rather than a way to significantly change the range, I'd be wary of making such large changes from the 0 and 3.3V rails without very careful checking of the CPU data sheets.

Alternatively if you need 12 bit resolution between 1.81V and 2.77V use an mbed with a 16 bit ADC between 0 and 3.3V

  • The voltage for the maximum ADC output is normally listed as 3.3V. In reality it's whatever the CPU supply voltage is. Due to the diodes most mbeds have in their power supply chains in order to offer multiple power sources this voltage is normally somewhere between 3.1 and 3.2V, if running from a battery as some mbeds offer it could be even lower. If you need a relative measurement (e.g. the position of a control that is between 0 and VCC) then this distinction doesn't matter but if you are measuring an external voltage source then you may need to do a calibration if you want accurate results, in that situation make sure you define the 3.3V as a constant at the start so that you can change it easily.

8 years, 10 months ago.

Andy, Most Controllers have an internally generated reference voltage you can activate using CPU registers. I almost always use that internal voltage because input voltage when battery operated can vary in low power systems as the battery voltage decays. I think mbed needs a command to activate the internal reference voltage or select the differential input pin when available for that controller. I know you can do the same with an external precision regulator feeding the vRef pin but why use an extra physical component when it is built into the micro controller. The easy default answer is to use a voltage regulator that feeds a constant 3.3V source but switching regulators cost extra and the linear regulators waste power.

See the Kinetis data sheet where they mention a operating voltage from 1.71V to 3.6V with a 1.2V Voltage reference. If I run this micro controller on a two cell battery I can operate it across a wide range of vin as the battery voltage draws down to where each sell has as low as 0.86V. The only way to get good measurements across this range without using a external component to supply the precision compare voltage is to configure the ADC to use the internal reference voltage. Internally generated reference voltages for ADC have been common since the PIC and Atmel 8 bit chips introduced it years ago. . http://cache.freescale.com/files/32bit/doc/data_sheet/MKMxxZxxACxx5.pdf?fasp=1 1.71V to 3.6V with a

http://cache.freescale.com/files/microcontrollers/doc/ref_manual/KL46P121M48SF4RM.pdf - Page #474 (28.2.3) Also See the 28.2.5 (Differential Analog Channel Inputs).