tenbaht / sduino

An Arduino-like programming API for the STM8
http://tenbaht.github.io/sduino/
GNU Lesser General Public License v2.1
347 stars 213 forks source link

ADC not working #114

Open allenchak opened 3 years ago

allenchak commented 3 years ago

I would like to measure an external voltage source which must between 5v and 12v. I know there are not support over 5v input source to any port, therefore, I used a voltage divider to reduce the voltage to one of eleven voltage. The expected voltage for analoagRead(A0) is 0.455v - 1.091v and the expected analoagRead(A0) value should be 141 - 339.

I am using PC4 as an analogue input pin, here is the detailed schematic. I try to put a capacitor (C1, between 10nF to 10uF), but still unable to calculate the correct value of the external voltage. Screen Shot 2020-11-18 at 12 15 32 AM

The expected voltage for analoagRead(A0) is 0.455v - 1.091v and the expected analoagRead(A0) value should be 141 - 339.

I used a multimeter to measure the analogue pin voltage, which matches my calculated value. But the analogRead(A0) value does not match. However, it is work perfect for any potentiometer (B103, B503, B104, etc).