Page 1 of 1

ADC issue

Posted: Fri Jul 19, 2024 3:17 pm
by alexanderpruss
When I put a standard red LED with a 100ohm resistor on a gpio (or just between ground and V3) on my black pill, and I connect PA6 to ground with a 10K resistor, analogRead(PA6) returns around 300 when the LED is on, and 0 when it's off. Is 10K not enough for a pulldown?

I don't have any issue with the built in LED on the board.

Re: ADC issue

Posted: Fri Jul 19, 2024 5:05 pm
by GonzoG
Checked with bluepill (F103) and blackpill (F411) and no problems. It reads 1-2 with LED connected.
There must be something wrong with your circuit.

If I connected 100 Ohm resistor to GND and then LED and pull down resistor to it, then I got ~150-170 with white, blue and green LEDs and ~350 with yellow and red LEDs, but this is expected as there is voltage loss on this 100 Ohm resistor and it depends on current drawn by LED.

Re: ADC issue

Posted: Sat Jul 20, 2024 5:33 am
by ag123
working some numbers
300 / 4096 * 3.3 = 0.24v

Then look at some datasheets
https://downloads.cree-led.com/files/ds/h/HB-C4SMA.pdf
it turns out forward voltage can run from 2-3.8v
TYPICAL ELECTRICAL & OPTICAL CHARACTERISTICS (TA = 25°C) table

given that if the voltage is measured across the 100 ohm resistor, 0.24v isn't after all incorrect
the other thing is to use a large sample time, especially if you are using a higher series resistance to the adc.

Re: ADC issue

Posted: Mon Jul 22, 2024 5:54 pm
by alexanderpruss
But the 100 ohm resistor is not connected to the ADC pin, only to V3 or another GPIO.

Re: ADC issue

Posted: Tue Jul 23, 2024 8:02 am
by STM32ardui
alexanderpruss wrote: Mon Jul 22, 2024 5:54 pm But the 100 ohm resistor is not connected to the ADC pin, only to V3 or another GPIO.
Learn to describe your problem correctly, so everyone has the same understanding!

From your start posting
alexanderpruss wrote: Fri Jul 19, 2024 3:17 pm When I put a standard red LED with a 100ohm resistor ... (or just between ground and V3) on my black pill, and I connect PA6 to ground with a 10K resistor ...
it can be this:
ADC-problem.jpg
ADC-problem.jpg (12.73 KiB) Viewed 2850 times