10 years, 1 month ago.

voltage sensing using KL25Z

Hi I am new to analog world I am using voltage divider and KL25Z to measure the input voltage using analog pin of KL25Z I am getting issues in converting these digital values to actual ones. As analog pin gives values in the range of 0 and 1, can any one help me out how I can convert these values to analog one

thanks in advance

any analog pin on any controller will not give you a 0 or 1. There can be many possibilities if such a case arises and one of them can be that you haven’t configured the analog pin correctly and it is just reading a 0 or 1 as a digital input. Please check your header files and pin configuration within the program. The second issue could be that you’re not reading the value correctly. What you read in an unsigned int and you need to convert it to a float with your required value by using the proper conversion given in the datasheet or information document of its ADC.

http://www.7pcb.ca/

posted by vedat tokem 29 Apr 2014

1 Answer

10 years, 1 month ago.

Zain,

The KL25Z has 16 bit A:D converters and has a reference voltage of 3.3v.

A 16 bit A:D has a value anywhere between 0 and 65535. With a 3.3v reference, you get a resolution of 50.035uv per count.

Example: Let's say that you have 1.13v on one of the A:D pins. This gives you an A:D raw value of 1.13 / 0.00005035 = 22441 (rounded to nearest bit).

mbed returns a floating A:D value between 0.0 and 1.0 - a percentage of the voltage seen at the A:D pin.

So, mbed returns 22441 / 65535 or "0.3424"

I hope this helps,

...kevin

Accepted Answer

ok I got some idea, can u explain this lil further, what I will get if I have connected 25 volts at the source end, means my open circuit voltage is 25V, what I will get ?? because 25/.00005035=496524.329

means mbed returns 496524.329/65535=7.57 which is not b/w 0 and 1

posted by zain aftab 28 Mar 2014

Any voltage higher than 3,3v will blow up the chip. You will need a resistive voltage divider to scale the 25v input down to 3.3v

posted by Kevin Braun 28 Mar 2014

If you are dealing with higher voltages it is also a good idea to put a diode between the analog input and the 3.3V rail. Ideally you'd set the resistors in the divider such that the pin never goes outside 0V to 3.3V but sometimes you can still get voltage spikes that you hadn't planned for or just miscalculate the values.

With the diode in there if the input exceeds 3.9V (3.3V plus 1 diode drop of 0.6V) the diode turns on and clamps the voltage. The resistive divider will limit the currents flowing so the power supply parts should be fine and that way the CPU can't get far enough outside it's normal range to do any damage.

Similarly you can use a diode to ground if there is a risk the voltage could go negative.

Just make sue you put the diodes the correct way around or you'll clamp the input to the power rail at all times or if you also have one to ground and put both wrong short out the power supply.

posted by Andy A 28 Mar 2014