[SOLVED] AnalogRead problem

DrBanana
Thu Oct 26, 2017 8:31 am
I have a voltage divider connected to PA4 pin of STM32F103RE

Voltages on PA4 oscillate from 2.0 to 2.6 volts, but the analogRead on PA4 going way off.

Here is the code
void setup() {
pinMode(PA4, INPUT_ANALOG);
Serial.begin(9600);
}

void loop() {
int analogValue = analogRead(PA4);
Serial.println(analogValue);
}


Pito
Thu Oct 26, 2017 8:36 am
What are the resistor’s values ?

DrBanana
Thu Oct 26, 2017 8:48 am
[Pito – Thu Oct 26, 2017 8:36 am] –
What are the resistor’s values ?

12 VCC(+-2) – 10k + 1.5K – GND


ahull
Thu Oct 26, 2017 9:49 am
If Vin is between 10 and 14 volts, Vout should be between 1.3 and 1.8V approx.

http://www.calculatoredge.com/electroni … divide.htm

How do you get 2.0 to 2.6V ? I’m not sure I understand your circuit.


DrBanana
Thu Oct 26, 2017 9:56 am
[ahull – Thu Oct 26, 2017 9:49 am] –
If Vin is between 10 and 14 volts, Vout should be between 1.3 and 1.8V approx.

http://www.calculatoredge.com/electroni … divide.htm

How do you get 2.0 to 2.6V ? I’m not sure I understand your circuit.

Could be, I saw the waves in oscilloscope, nothings goes above 3v and was around 2v. The voltage divider seems not the problem, but the analog values changing are. Voltage doesn’t go 0 at voltage divider while analogRead returns it.


Pito
Thu Oct 26, 2017 10:53 am
12 VCC(+-2) – 10k + 1.5K – GND
Divider’s input voltage:

Input Voltage.JPG
Input Voltage.JPG (67.52 KiB) Viewed 522 times

Pito
Thu Oct 26, 2017 10:58 am
Double-check the GND wiring, it seems your GND is floating (some breadboards do not have a continual GND rail handy).

DrBanana
Thu Oct 26, 2017 11:47 am
the wiring is good, hardware seems all good. I think the problem is in reading analog.

zmemw16
Thu Oct 26, 2017 4:19 pm
try with just an AA battery to PA4 and ground ?
then maybe AA+ to 1k/2k to gnd, pa4 to junction of the R’s
that should demonstrate or eliminate an analogue read problem, barring a bad crimp in the wires :D
stephen

ahull
Thu Oct 26, 2017 10:16 pm
.. also try the analog read on some different pins (perhaps PA0, PA1 or PB0) to see if the problem is perhaps just a dodgy solder joint on the pin in question.

DrBanana
Sun Oct 29, 2017 1:53 am
Sorry guys, it was fault in schematics, so is in hardware.

zmemw16
Sun Oct 29, 2017 3:06 am
AC battery :?:
:D

Leave a Reply

Your email address will not be published. Required fields are marked *