2017年4月19日 星期三

Use ADC to measure battery.

In my project I use a 8 bits resolution ADC to measure battery . 3.0 V as 100% and 2.2 V as 0%.
When input is 3.0 V the ADC value is 255 and 2.2 V for 180. Because it's unnecessary to be very accurate so I use simple equation y = ax +b to calculate the percentage of the battery.

100 = 255 a + b ........ (1)
0     = 180 a + b ........ (2)

Use 1 and 2 we can calculate a = 4/3 and b = -240.











Ref:
      Float divide and integer divide in C.

沒有留言:

張貼留言

Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...