ADC measure negative voltage??

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

ADC measure negative voltage??

Post by starter111 » Mon Jun 24, 2019 6:51 pm

Hi, I'm trying to use pyboard measure negative voltage. Is it a way to do so? I can add circuit if needed it.
please help..

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: ADC measure negative voltage??

Post by starter111 » Mon Jun 24, 2019 8:05 pm

never mind, looks like just need add two resistors for voltage divider.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ADC measure negative voltage??

Post by jimmo » Tue Jun 25, 2019 12:17 am

A voltage divider can only be used to scale a voltage down. i.e. you cannot change its polarity.

Negative voltages (i.e. below your microcontroller's ground) could damage the microcontroller.

Can you describe what you're doing in more detail and we can give you some hints.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADC measure negative voltage??

Post by Roberthh » Tue Jun 25, 2019 6:42 am

Depending on the range of the negative voltage and it's impedance, a voltage divider may work, just between Vdd-ADC_Input-Sensing_Input instead of GND-ADC_Input-Sensing_Input. Don't forget to add a protective Diode to the input, so it cuts off negative voltages.

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: ADC measure negative voltage??

Post by chrismas9 » Tue Jun 25, 2019 3:10 pm

I have used the method suggested by @roberthh. Here's how it works. Say you want to measure down to -12V.

Make a 5:1 voltage divider, eg 10k and 40k. Connect 10k between Aref (3V3) and ADC input. Connect 40k from ADC input to negative voltage.

When Vin = 0V ADCin = 3.3 - (3.3 + 0)/5 = 2.44V.

When Vin = -12V ADCin = 3.3 - (3.3 + 12)/5 = 0.24V.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: ADC measure negative voltage??

Post by starter111 » Tue Jun 25, 2019 8:36 pm

I have two 100k resistors.
r1.pin1 connect to 6v.
r1.pin2 connecto to r2.pin1 - adc read at this point.
r2.pin2 connect to somewhere close to -3v(voltage going to measure).

so negative voltage = r1.pin2 v - (6v - r1.pin2 v)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: ADC measure negative voltage??

Post by jimmo » Wed Jun 26, 2019 12:18 am

starter111 wrote:
Tue Jun 25, 2019 8:36 pm
so negative voltage = r1.pin2 v - (6v - r1.pin2 v)
Intuitively, with two 100k resistors, your ADC pin will be at the midpoint (i.e. the mean) between 6V and the voltage you're measuring.

So when the voltage is -3V, then you have 9V across the divider and so 4.5V across each resistor. So now your ADC is at 4.5V below 6V.

But yeah, don't forget the clamping diodes if you think that the input can go below -6V (or above 4V).

This is all assuming your negative voltage is referenced to the same ground etc.

chrismas9
Posts: 152
Joined: Wed Jun 25, 2014 10:07 am

Re: ADC measure negative voltage??

Post by chrismas9 » Wed Jun 26, 2019 12:27 am

I think there is a typo in your formula. With 100k resistors you will need a small cap on the ADC input as switched cap ADCs will draw transient current spikes from the inputs.

You don't say what MCU you are using but some STM32 ADC pins are completely intolerant of voltages outside supply and GND so use a Schottky diode pair like BAT54S to clamp to Vss and CDs.

starter111
Posts: 40
Joined: Wed Mar 08, 2017 7:24 am

Re: ADC measure negative voltage??

Post by starter111 » Wed Jun 26, 2019 6:06 pm

thanks for advice, is good idea to add diodes.
currently works well, is very accurate, just wondering is it any bandgap reference pin on pyboard?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADC measure negative voltage??

Post by Roberthh » Wed Jun 26, 2019 6:54 pm

The A3V3 can be used as 3.3 V reference.

Post Reply