[SOLVED] AnalogRead problem

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
DrBanana
Posts: 59
Joined: Fri Apr 22, 2016 11:15 am

[SOLVED] AnalogRead problem

Post by 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

Code: Select all

void setup() {
	pinMode(PA4, INPUT_ANALOG);
	Serial.begin(9600);
}

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

Code: Select all

0
521
4095
3483
918
2403
3180
0
1206
3875
4095
0
1171
4004
1967
850
3390
3543
0
1380
3989
2048
381
3011
2564
113
2184
3091
1525
709
4062
1661
843
2703
3016
0

User avatar
Pito
Posts: 1628
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: AnalogRead problem

Post by Pito » Thu Oct 26, 2017 8:36 am

What are the resistor's values ?
Pukao Hats Cleaning Services Ltd.

DrBanana
Posts: 59
Joined: Fri Apr 22, 2016 11:15 am

Re: AnalogRead problem

Post by DrBanana » Thu Oct 26, 2017 8:48 am

Pito wrote:
Thu Oct 26, 2017 8:36 am
What are the resistor's values ?
12 VCC(+-2) - 10k + 1.5K - GND

User avatar
ahull
Posts: 1657
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: AnalogRead problem

Post by 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.
- Andy Hull -

DrBanana
Posts: 59
Joined: Fri Apr 22, 2016 11:15 am

Re: AnalogRead problem

Post by DrBanana » Thu Oct 26, 2017 9:56 am

ahull wrote:
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.

User avatar
Pito
Posts: 1628
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: AnalogRead problem

Post by 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 274 times
Divider's output voltage:
Divider.JPG
Divider.JPG (76.73 KiB) Viewed 275 times
Last edited by Pito on Thu Oct 26, 2017 11:09 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1628
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: AnalogRead problem

Post by 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).
Pukao Hats Cleaning Services Ltd.

DrBanana
Posts: 59
Joined: Fri Apr 22, 2016 11:15 am

Re: AnalogRead problem

Post by 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
Posts: 1489
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: AnalogRead problem

Post by 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

User avatar
ahull
Posts: 1657
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: AnalogRead problem

Post by 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.
- Andy Hull -

Post Reply