ADC issue

Post here first, or if you can't find a relevant section!
Post Reply
alexanderpruss
Posts: 2
Joined: Fri Jul 19, 2024 1:33 pm

ADC issue

Post 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.
GonzoG
Posts: 503
Joined: Wed Jan 15, 2020 11:30 am
Answers: 36
Location: Prudnik, Poland

Re: ADC issue

Post 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.
ag123
Posts: 1907
Joined: Thu Dec 19, 2019 5:30 am
Answers: 30

Re: ADC issue

Post 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.
alexanderpruss
Posts: 2
Joined: Fri Jul 19, 2024 1:33 pm

Re: ADC issue

Post by alexanderpruss »

But the 100 ohm resistor is not connected to the ADC pin, only to V3 or another GPIO.
STM32ardui
Posts: 142
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: ADC issue

Post 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 2847 times
Post Reply

Return to “General discussion”